Example #1
0
def make_kthread(state):
    log.debug("entering make_kthread, state=%s", state)
    shield_exists()
    if state == 'on':
        log.info('--> activating kthread shielding')
        root_tasks = cset.unique_set('/').tasks
        log.debug('root set has %d tasks, checking for unbound', 
                  len(root_tasks))
        tasks = []
        for task in root_tasks:
            try:
                if proc.is_unbound(task): tasks.append(task)
            except:
                pass
        if len(tasks) != 0:
            log.debug("total root tasks %s", len(root_tasks))
            log.info("kthread shield activated, moving %s tasks into system cpuset...",
                     len(tasks))
            proc.move('root', SYS_SET, tasks, verbose)
    else:
        log.info('--> deactivating kthread shielding')
        usr_tasks = cset.unique_set(SYS_SET).tasks
        tasks = []
        for task in usr_tasks:
            try:
                os.readlink('/proc/'+task+'/exe')
            except:
                tasks.append(task)
        if len(tasks) != 0:
            log.info("moving %s tasks into root cpuset...", len(tasks))
        proc.move(SYS_SET, '/', tasks, verbose)
    log.info('done')
Example #2
0
def make_kthread(state):
    log.debug("entering make_kthread, state=%s", state)
    shield_exists()
    if state == 'on':
        log.info('--> activating kthread shielding')
        root_tasks = cset.unique_set('/').tasks
        log.debug('root set has %d tasks, checking for unbound', 
                  len(root_tasks))
        tasks = []
        for task in root_tasks:
            try:
                if proc.is_unbound(task): tasks.append(task)
            except:
                pass
        if len(tasks) != 0:
            log.debug("total root tasks %s", len(root_tasks))
            log.info("kthread shield activated, moving %s tasks into system cpuset...",
                     len(tasks))
            proc.move('root', SYS_SET, tasks, verbose)
    else:
        log.info('--> deactivating kthread shielding')
        usr_tasks = cset.unique_set(SYS_SET).tasks
        tasks = []
        for task in usr_tasks:
            try:
                os.readlink('/proc/'+task+'/exe')
            except:
                tasks.append(task)
        if len(tasks) != 0:
            log.info("moving %s tasks into root cpuset...", len(tasks))
        proc.move(SYS_SET, '/', tasks, verbose)
    log.info('done')
Example #3
0
def reset_shield():
    log.info("--> deactivating/reseting shielding")
    shield_exists()
    tasks = cset.unique_set(USR_SET).tasks
    log.info('moving %s tasks from "%s" user set to root set...', 
             len(tasks), USR_SET)
    proc.move(USR_SET, 'root', None, verbose)
    tasks = cset.unique_set(SYS_SET).tasks
    log.info('moving %s tasks from "%s" system set to root set...', 
             len(tasks), SYS_SET)
    proc.move(SYS_SET, 'root', None, verbose)
    log.info('deleting "%s" and "%s" sets', USR_SET, SYS_SET)
    set.destroy(USR_SET)
    set.destroy(SYS_SET)
    log.info('done')
Example #4
0
def reset_shield():
    log.info("--> deactivating/reseting shielding")
    shield_exists()
    tasks = cset.unique_set(USR_SET).tasks
    log.info('moving %s tasks from "%s" user set to root set...', 
             len(tasks), USR_SET)
    proc.move(USR_SET, 'root', None, verbose)
    tasks = cset.unique_set(SYS_SET).tasks
    log.info('moving %s tasks from "%s" system set to root set...', 
             len(tasks), SYS_SET)
    proc.move(SYS_SET, 'root', None, verbose)
    log.info('deleting "%s" and "%s" sets', USR_SET, SYS_SET)
    set.destroy(USR_SET)
    set.destroy(SYS_SET)
    log.info('done')
Example #5
0
def destroy_sets(sets, recurse=False, force=False):
    """destroy cpusets in list of sets, recurse if true, if force destroy if tasks running"""
    log.debug('enter destroy_sets, sets=%s, force=%s', sets, force)
    nl = []
    if isinstance(sets, list):
        nl.extend(sets)
    else:
        nl.append(sets)
    # check that sets passed are ok, will raise if one is bad
    sl2 = []
    for s in nl:
        st = cset.unique_set(s)
        sl2.append(st)
        if len(st.subsets) > 0:
            if not recurse:
                raise CpusetException(
                    'cpuset "%s" has subsets, delete them first, or use --recurse'
                    % st.path)
            elif not force:
                raise CpusetException(
                    'cpuset "%s" has subsets, use --force to destroy' %
                    st.path)
            sl2.extend(st.subsets)
            for node in st.subsets:
                for nd in cset.walk_set(node):
                    sl2.append(nd)

    # ok, good to go
    if recurse: sl2.reverse()
    for s in sl2:
        s = cset.unique_set(s)
        # skip the root set!!! or you'll have problems...
        if s.path == '/': continue
        log.info(
            '--> processing cpuset "%s", moving %s tasks to parent "%s"...',
            s.name, len(s.tasks), s.parent.path)
        proc.move(s, s.parent)
        log.info('--> deleting cpuset "%s"', s.path)
        destroy(s)
    log.info('done')
Example #6
0
def destroy_sets(sets, recurse=False, force=False):
    """destroy cpusets in list of sets, recurse if true, if force destroy if tasks running"""
    log.debug('enter destroy_sets, sets=%s, force=%s', sets, force)
    nl = []
    if isinstance(sets, list):
        nl.extend(sets)
    else:
        nl.append(sets)
    # check that sets passed are ok, will raise if one is bad
    sl2 = []
    for s in nl: 
        st = cset.unique_set(s)
        sl2.append(st)
        if len(st.subsets) > 0:
            if not recurse:
                raise CpusetException(
                        'cpuset "%s" has subsets, delete them first, or use --recurse'
                        % st.path)
            elif not force:
                raise CpusetException(
                        'cpuset "%s" has subsets, use --force to destroy'
                        % st.path)
            sl2.extend(st.subsets)
            for node in st.subsets:
                for nd in cset.walk_set(node):
                    sl2.append(nd)

    # ok, good to go
    if recurse: sl2.reverse()
    for s in sl2:
        s = cset.unique_set(s)
        # skip the root set!!! or you'll have problems...
        if s.path == '/': continue
        log.info('--> processing cpuset "%s", moving %s tasks to parent "%s"...',
                 s.name, len(s.tasks), s.parent.path)
        proc.move(s, s.parent)
        log.info('--> deleting cpuset "%s"', s.path)
        destroy(s)
    log.info('done')
Example #7
0
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()
Example #8
0
     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()
Example #9
0
     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
Example #10
0
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()