def create_from_options(options, args): """create cpuset as specified by options and args lists""" log.debug('entering create_from_options, options=%s args=%s', options, args) # figure out target cpuset name, if --set not used, use first arg if options.set: tset = options.set elif len(args) > 0: tset = args[0] else: raise CpusetException('cpuset not specified') cspec = None mspec = None cx = None mx = None if options.cpu: cset.cpuspec_check(options.cpu) cspec = options.cpu if options.mem: cset.memspec_check(options.mem) mspec = options.mem if options.cpu_exclusive: cx = options.cpu_exclusive if options.mem_exclusive: mx = options.mem_exclusive try: create(tset, cspec, mspec, cx, mx) if not mspec: modify(tset, memspec='0') # always need at least this log.info('--> created cpuset "%s"', tset) except CpusetExists: modify(tset, cspec, mspec, cx, mx) log.info('--> modified cpuset "%s"', tset) active(tset)
def make_shield(cpuspec, kthread): memspec = '0' # FIXME: for numa, we probably want a more intelligent scheme log.debug("entering make_shield, cpuspec=%s kthread=%s", cpuspec, kthread) # create base cpusets for shield cset.cpuspec_check(cpuspec) cpuspec_inv = cset.cpuspec_inverse(cpuspec) try: shield_exists() except: log.debug("shielding does not exist, creating") try: set.create(USR_SET, cpuspec, memspec, True, False) set.create(SYS_SET, cpuspec_inv, memspec, True, False) except Exception, instance: # unroll try: set.destroy(USR_SET) except: pass try: set.destroy(SYS_SET) except: pass log.critical( '--> failed to create shield, hint: do other cpusets exist?') raise instance log.info('--> activating shielding:')
def make_shield(cpuspec, kthread): memspec = '0' # FIXME: for numa, we probably want a more intelligent scheme log.debug("entering make_shield, cpuspec=%s kthread=%s", cpuspec, kthread) # create base cpusets for shield cset.cpuspec_check(cpuspec) cpuspec_inv = cset.cpuspec_inverse(cpuspec) try: shield_exists() except: log.debug("shielding does not exist, creating") try: set.create(USR_SET, cpuspec, memspec, True, False) set.create(SYS_SET, cpuspec_inv, memspec, True, False) except Exception, instance: # unroll try: set.destroy(USR_SET) except: pass try: set.destroy(SYS_SET) except: pass log.critical('--> failed to create shield, hint: do other cpusets exist?') raise instance log.info('--> activating shielding:')
def test_cpuspec_check(self): # these overlap with cpuset_inverse tests bellow # remove them after the code duplicaton is eliminated self.assertEqual(cset.cpuspec_check("0-3"), None) self.assertEqual(cset.cpuspec_check("0-1,,3"), None) with self.assertRaises(CpusetException): print('check of 1-2-3:', cset.cpuspec_check("1-2-3")) with self.assertRaises(CpusetException): print('check of 1!2-3:', cset.cpuspec_check("1!2-3")) with self.assertRaises(CpusetException): # 999999 CPUs ought to be enough for anybody cset.cpuspec_check("999999", usemax=True) with self.assertRaises(CpusetException): print('check of -3:', cset.cpuspec_check("-3"))
def make_shield(cpuspec, kthread): memspec = '0' # FIXME: for numa, we probably want a more intelligent scheme log.debug("entering make_shield, cpuspec=%s kthread=%s", cpuspec, kthread) # create base cpusets for shield cset.cpuspec_check(cpuspec) cpuspec_inv = cset.cpuspec_inverse(cpuspec) try: shield_exists() except: log.debug("shielding does not exist, creating") try: set.create(USR_SET, cpuspec, memspec, True, False) set.create(SYS_SET, cpuspec_inv, memspec, True, False) except Exception as instance: # unroll try: set.destroy(USR_SET) except: pass try: set.destroy(SYS_SET) except: pass log.critical('--> failed to create shield, hint: do other cpusets exist?') raise instance log.info('--> activating shielding:') else: log.debug("shielding exists, modifying cpuspec") # note, since we're going to modify the cpu assigments to these sets, # they cannot be exclusive, the following modify() calls will make # them exclusive again cset.unique_set(USR_SET).cpu_exclusive = False cset.unique_set(SYS_SET).cpu_exclusive = False set.modify(USR_SET, cpuspec, memspec, False, False) set.modify(SYS_SET, cpuspec_inv, memspec, False, False) # reset cpu exlusivity cset.unique_set(USR_SET).cpu_exclusive = True cset.unique_set(SYS_SET).cpu_exclusive = True log.info('--> shielding modified with:') # move root tasks into system set root_tasks = cset.unique_set('/').tasks log.debug("number of root tasks are: %s", len(root_tasks)) # figure out what in root set is not a kernel thread tasks = [] for task in root_tasks: try: os.readlink('/proc/'+task+'/exe') tasks.append(task) except: pass if len(tasks) != 0: log.info("moving %s tasks from root into system cpuset...", len(tasks)) proc.move('root', SYS_SET, tasks, verbose) # move kernel theads into system set if asked for if kthread == 'on': root_tasks = cset.unique_set('/').tasks tasks = [] for task in root_tasks: try: if proc.is_unbound(task): tasks.append(task) except: pass if len(tasks) != 0: log.info("kthread shield activated, moving %s tasks into system cpuset...", len(tasks)) proc.move('root', SYS_SET, tasks, verbose) # print out stats print_all_stats()