27
27
from cpuset import cset
28
28
from cpuset .util import *
29
29
from cpuset .commands .common import *
30
- try : from cpuset .commands import set
30
+ try : from cpuset .commands import set
31
31
except SyntaxError :
32
32
raise
33
- except :
33
+ except :
34
34
pass
35
35
36
36
global log
57
57
and specifying the cpuset that the process is to be created in.
58
58
59
59
For example:
60
- # cset proc --set=blazing_cpuset --exec /usr/bin/fast_code
60
+ # cset proc --set=blazing_cpuset --exec /usr/bin/fast_code
61
61
This command will execute the /usr/bin/fast_code program
62
62
on the "blazing_cpuset" cpuset.
63
63
126
126
kernel threads will be added to the move. Unbound kernel threads
127
127
are those that can run on any CPU. If you also specify the
128
128
--force switch, then all tasks, kernel or not, bound or not,
129
- will be moved.
129
+ will be moved.
130
130
131
131
CAUTION: Please be cautious with the --force switch, since moving
132
132
a kernel thread that is bound to a specific CPU to a cpuset that
@@ -207,14 +207,14 @@ def func(parser, options, args):
207
207
208
208
cset .rescan ()
209
209
210
- tset = None
210
+ tset = None
211
211
if options .list or options .exc :
212
212
if options .set :
213
213
tset = cset .unique_set (options .set )
214
214
elif options .toset :
215
215
tset = cset .unique_set (options .toset )
216
216
elif len (args ) > 0 :
217
- if options .exc :
217
+ if options .exc :
218
218
tset = cset .unique_set (args [0 ])
219
219
del args [0 ]
220
220
else :
@@ -270,7 +270,7 @@ def func(parser, options, args):
270
270
set .active (tset )
271
271
# next, if there is a pidspec, move just that
272
272
if options .pid :
273
- if options .fromset and not options .force :
273
+ if options .fromset and not options .force :
274
274
fset = cset .unique_set (options .fromset )
275
275
elif options .toset and options .set :
276
276
fset = cset .unique_set (options .set )
@@ -295,15 +295,15 @@ def func(parser, options, args):
295
295
raise CpusetException ("origination cpuset not specified" )
296
296
nt = len (fset .tasks )
297
297
if nt == 0 :
298
- raise CpusetException ('no tasks to move from cpuset "%s"'
298
+ raise CpusetException ('no tasks to move from cpuset "%s"'
299
299
% fset .path )
300
300
if options .move :
301
- log .info ('moving all tasks from %s to %s' ,
301
+ log .info ('moving all tasks from %s to %s' ,
302
302
fset .name , tset .path )
303
303
selective_move (fset , tset , None , options .kthread , options .force ,
304
304
options .threads )
305
305
else :
306
- log .info ('moving all kernel threads from %s to %s' ,
306
+ log .info ('moving all kernel threads from %s to %s' ,
307
307
fset .path , tset .path )
308
308
# this is a -k "move", so only move kernel threads
309
309
pids = []
@@ -321,12 +321,12 @@ def list_sets(args):
321
321
log .debug ("entering list_sets, args=%s" , args )
322
322
l = []
323
323
if isinstance (args , list ):
324
- for s in args :
324
+ for s in args :
325
325
if isstr (s ):
326
326
l .extend (cset .find_sets (s ))
327
327
elif not isinstance (s , cset .CpuSet ):
328
328
raise CpusetException (
329
- 'list_sets() args=%s, of which "%s" not a string or CpuSet'
329
+ 'list_sets() args=%s, of which "%s" not a string or CpuSet'
330
330
% (args , s ))
331
331
else :
332
332
l .append (s )
@@ -350,7 +350,7 @@ def list_sets(args):
350
350
log .info (cset .summary (s ))
351
351
352
352
def move (fromset , toset , plist = None , verb = None , force = None ):
353
- log .debug ('entering move, fromset=%s toset=%s list=%s force=%s verb=%s' ,
353
+ log .debug ('entering move, fromset=%s toset=%s list=%s force=%s verb=%s' ,
354
354
fromset , toset , plist , force , verb )
355
355
if isstr (fromset ):
356
356
fset = cset .unique_set (fromset )
@@ -368,15 +368,15 @@ def move(fromset, toset, plist=None, verb=None, force=None):
368
368
tset = toset
369
369
if plist == None :
370
370
log .debug ('moving default of all processes' )
371
- if tset != fset and not force :
371
+ if tset != fset and not force :
372
372
plist = fset .tasks
373
373
else :
374
374
raise CpusetException (
375
375
"cannot move tasks into their origination cpuset" )
376
376
output = 0
377
- if verb :
377
+ if verb :
378
378
output = verb
379
- elif verbose :
379
+ elif verbose :
380
380
output = verbose
381
381
if output :
382
382
l = []
@@ -410,7 +410,7 @@ def selective_move(fset, tset, plist=None, kthread=None, force=None, threads=Non
410
410
ktskb = 0
411
411
sstsk = 0
412
412
target = cset .unique_set (tset )
413
- if fset :
413
+ if fset :
414
414
fset = cset .unique_set (fset )
415
415
if fset == target and not force :
416
416
raise CpusetException (
@@ -426,7 +426,7 @@ def selective_move(fset, tset, plist=None, kthread=None, force=None, threads=Non
426
426
# kernel threads do not have an excutable image
427
427
os .readlink ('/proc/' + task + '/exe' )
428
428
autsk += 1
429
- if fset and not force :
429
+ if fset and not force :
430
430
try :
431
431
task_check .index (task )
432
432
tasks .append (task )
@@ -440,9 +440,9 @@ def selective_move(fset, tset, plist=None, kthread=None, force=None, threads=Non
440
440
if thread != task :
441
441
log .debug (' adding thread %s' , thread )
442
442
tasks .append (thread )
443
- utsk += 1
443
+ utsk += 1
444
444
except ValueError :
445
- log .debug (' task %s not running in %s, skipped' ,
445
+ log .debug (' task %s not running in %s, skipped' ,
446
446
task , fset .name )
447
447
utsknr += 1
448
448
else :
@@ -459,11 +459,11 @@ def selective_move(fset, tset, plist=None, kthread=None, force=None, threads=Non
459
459
# this is in try because the task may not exist by the
460
460
# time we do this, in that case, just ignore it
461
461
if kthread :
462
- if force :
462
+ if force :
463
463
tasks .append (task )
464
464
ktsk += 1
465
465
else :
466
- if is_unbound (task ):
466
+ if is_unbound (task ):
467
467
tasks .append (task )
468
468
ktsk += 1
469
469
elif cset .lookup_task_from_cpusets (task ) == target .path :
@@ -480,7 +480,7 @@ def selective_move(fset, tset, plist=None, kthread=None, force=None, threads=Non
480
480
ktsknr += 1
481
481
# ok, move 'em
482
482
log .debug ('moving %d tasks to %s ...' , len (tasks ), tset .name )
483
- if len (tasks ) == 0 :
483
+ if len (tasks ) == 0 :
484
484
log .info ('**> no task matched move criteria' )
485
485
if sstsk > 0 :
486
486
raise CpusetException ('same source/destination cpuset, use --force if ok' )
@@ -535,8 +535,8 @@ def run(tset, args, usr_par=None, grp_par=None):
535
535
log .debug ('entering run, set=%s args=%s ' , s .path , args )
536
536
set .active (s )
537
537
# check user
538
- if usr_par :
539
- try :
538
+ if usr_par :
539
+ try :
540
540
user = pwd .getpwnam (usr_par )[2 ]
541
541
except KeyError :
542
542
try :
@@ -562,34 +562,34 @@ def run(tset, args, usr_par=None, grp_par=None):
562
562
pass # just forget it
563
563
# move myself into target cpuset and exec child
564
564
move_pidspec (str (os .getpid ()), s )
565
- log .info ('--> last message, executed args into cpuset "%s", new pid is: %s' ,
566
- s .path , os .getpid ())
565
+ log .info ('--> last message, executed args into cpuset "%s", new pid is: %s' ,
566
+ s .path , os .getpid ())
567
567
# change user and group before exec
568
568
if grp_par : os .setgid (group )
569
- if usr_par :
569
+ if usr_par :
570
570
os .setuid (user )
571
571
os .environ ["LOGNAME" ] = usr_par
572
572
os .environ ["USERNAME" ] = usr_par
573
573
os .environ ["USER" ] = usr_par
574
574
os .execvp (args [0 ], args )
575
575
576
576
def is_unbound (proc ):
577
- # FIXME: popen is slow...
577
+ # FIXME: popen is slow...
578
578
# --> use /proc/<pid>/status -> Cpus_allowed
579
579
# int(line.replace(',',''), 16)
580
580
# note: delete leading zeros to compare to allcpumask
581
581
line = os .popen ('/usr/bin/taskset -p ' + str (proc ) + ' 2>/dev/null' , 'r' ).readline ()
582
582
aff = line .split ()[- 1 ]
583
- log .debug ('is_unbound, proc=%s aff=%s allcpumask=%s' ,
583
+ log .debug ('is_unbound, proc=%s aff=%s allcpumask=%s' ,
584
584
proc , aff , cset .allcpumask )
585
585
if aff == cset .allcpumask : return True
586
586
return False
587
587
588
588
def pidspec_to_list (pidspec , fset = None , threads = False ):
589
589
"""create a list of process ids out of a pidspec"""
590
- log .debug ('entering pidspecToList, pidspec=%s fset=%s threads=%s' ,
590
+ log .debug ('entering pidspecToList, pidspec=%s fset=%s threads=%s' ,
591
591
pidspec , fset , threads )
592
- if fset :
592
+ if fset :
593
593
if isstr (fset ): fset = cset .unique_set (fset )
594
594
elif not isinstance (fset , cset .CpuSet ):
595
595
raise CpusetException ("passed fset=%s, which is not a string or CpuSet" % fset )
0 commit comments