|
98 | 98 | dest='hrepeats',
|
99 | 99 | default=1,
|
100 | 100 | type=int,
|
101 |
| - help='Implies -H, number of times to run the vbench suite on the head commit.\n' |
102 |
| - 'Each iteration will yield another column in the output.' |
103 |
| - ) |
| 101 | + help='implies -H, number of times to run the vbench suite on the head commit.\n' |
| 102 | + 'Each iteration will yield another column in the output' ) |
104 | 103 | parser.add_argument('-a', '--affinity',
|
105 | 104 | metavar="a",
|
106 | 105 | dest='affinity',
|
107 | 106 | default=1,
|
108 | 107 | type=int,
|
109 |
| - help='Set processor affinity of the process. THe default is to bind to cpu/core #1 only.' |
110 |
| - 'requires the "affinity" python module.' ) |
111 |
| - |
| 108 | + help='set processor affinity of process by default bind to cpu/core #1 only. ' |
| 109 | + 'Requires the "affinity" or "psutil" python module, will raise Warning otherwise') |
112 | 110 | parser.add_argument('-u', '--burnin',
|
113 | 111 | metavar="u",
|
114 | 112 | dest='burnin',
|
@@ -388,14 +386,38 @@ def main():
|
388 | 386 | random.seed(args.seed)
|
389 | 387 | np.random.seed(args.seed)
|
390 | 388 |
|
| 389 | + affinity_set = False |
| 390 | + |
| 391 | + # try psutil first since it is more commonly present and better |
| 392 | + # maintained. Some people experienced problems with affinity package |
| 393 | + # (see https://code.google.com/p/psutil/issues/detail?id=238 for more references) |
391 | 394 | try:
|
392 |
| - import affinity |
393 |
| - affinity.set_process_affinity_mask(0,args.affinity) |
394 |
| - assert affinity.get_process_affinity_mask(0) == args.affinity |
395 |
| - print("CPU affinity set to %d" % args.affinity) |
| 395 | + import psutil |
| 396 | + if hasattr(psutil.Process, 'set_cpu_affinity'): |
| 397 | + psutil.Process(os.getpid()).set_cpu_affinity([args.affinity]) |
| 398 | + affinity_set = True |
396 | 399 | except ImportError:
|
397 |
| - print("Warning: The 'affinity' module is not available.") |
| 400 | + pass |
| 401 | + |
| 402 | + if not affinity_set: |
| 403 | + try: |
| 404 | + import affinity |
| 405 | + affinity.set_process_affinity_mask(0, args.affinity) |
| 406 | + assert affinity.get_process_affinity_mask(0) == args.affinity |
| 407 | + affinity_set = True |
| 408 | + except ImportError: |
| 409 | + pass |
| 410 | + |
| 411 | + if not affinity_set: |
| 412 | + import warnings |
| 413 | + warnings.warn("\n\n" |
| 414 | + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 415 | + "The 'affinity' or 'psutil' >= 0.5.0 modules are not available, results may be unreliable\n" |
| 416 | + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n" |
| 417 | + ) |
398 | 418 | time.sleep(2)
|
| 419 | + else: |
| 420 | + print("CPU affinity set to %d" % args.affinity) |
399 | 421 |
|
400 | 422 | print("\n")
|
401 | 423 | prprint("LOG_FILE = %s" % args.log_file)
|
|
0 commit comments