mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 10:10:46 +00:00
cgroups: fix support to filter tasks to move into a specified CGroup
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
This commit is contained in:
parent
3cab786d03
commit
21d18f8b78
@ -8,6 +8,7 @@ FIND=${FIND:-$BUSYBOX find}
|
|||||||
GREP=${GREP:-$BUSYBOX grep}
|
GREP=${GREP:-$BUSYBOX grep}
|
||||||
SED=${SED:-$BUSYBOX sed}
|
SED=${SED:-$BUSYBOX sed}
|
||||||
CAT=${CAT:-$BUSYBOX cat}
|
CAT=${CAT:-$BUSYBOX cat}
|
||||||
|
AWK=${AWK:-$BUSYBOX awk}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# CPUFrequency Utility Functions
|
# CPUFrequency Utility Functions
|
||||||
@ -134,20 +135,21 @@ cgroups_run_into() {
|
|||||||
cgroups_tasks_move() {
|
cgroups_tasks_move() {
|
||||||
SRC_GRP=${1}
|
SRC_GRP=${1}
|
||||||
DST_GRP=${2}
|
DST_GRP=${2}
|
||||||
GREP_EXCLUSE=${3:-''}
|
shift 2
|
||||||
|
FILTERS=$*
|
||||||
|
|
||||||
$CAT $SRC_GRP/tasks | while read TID; do
|
$CAT $SRC_GRP/tasks | while read TID; do
|
||||||
echo $TID > $DST_GRP/cgroup.procs
|
echo $TID > $DST_GRP/cgroup.procs
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$GREP_EXCLUSE" = "" ] && exit 0
|
[ "x$FILTERS" = "x" ] && exit 0
|
||||||
|
|
||||||
PIDS=`ps | $GREP "$GREP_EXCLUSE" | awk '{print $2}'`
|
PIDS=`ps | $GREP $FILTERS | $AWK '{print $2}'`
|
||||||
PIDS=`echo $PIDS`
|
PIDS=`echo $PIDS`
|
||||||
echo "PIDs to save: [$PIDS]"
|
echo "PIDs to save: [$PIDS]"
|
||||||
for TID in $PIDS; do
|
for TID in $PIDS; do
|
||||||
CMDLINE=`$CAT /proc/$TID/cmdline`
|
COMM =`$CAT /proc/$TID/comm`
|
||||||
echo "$TID : $CMDLINE"
|
echo "$TID : $COMM"
|
||||||
echo $TID > $SRC_GRP/cgroup.procs
|
echo $TID > $SRC_GRP/cgroup.procs
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -128,10 +128,42 @@ class Controller(object):
|
|||||||
srcg.directory, dstg.directory, exclude),
|
srcg.directory, dstg.directory, exclude),
|
||||||
as_root=True)
|
as_root=True)
|
||||||
|
|
||||||
def move_all_tasks_to(self, dest):
|
def move_all_tasks_to(self, dest, exclude=[]):
|
||||||
|
"""
|
||||||
|
Move all the tasks to the specified CGroup
|
||||||
|
|
||||||
|
Tasks are moved from all their original CGroup the the specified on.
|
||||||
|
The tasks which name matches one of the string in exclude are moved
|
||||||
|
instead in the root CGroup for the controller.
|
||||||
|
The name of a tasks to exclude must be a substring of the task named as
|
||||||
|
reported by the "ps" command. Indeed, this list will be translated into
|
||||||
|
a: "ps | grep -e name1 -e name2..." in order to obtain the PID of these
|
||||||
|
tasks.
|
||||||
|
|
||||||
|
:param exclude: list of commands to keep in the root CGroup
|
||||||
|
:type exlude: list(str)
|
||||||
|
"""
|
||||||
|
|
||||||
|
if isinstance(exclude, str):
|
||||||
|
exclude = [exclude]
|
||||||
|
if not isinstance(exclude, list):
|
||||||
|
raise ValueError('wrong type for "exclude" parameter, '
|
||||||
|
'it must be a str or a list')
|
||||||
|
|
||||||
|
logging.info('Moving all tasks into %s', dest)
|
||||||
|
|
||||||
|
# Build list of tasks to exclude
|
||||||
|
grep_filters = ''
|
||||||
|
for comm in exclude:
|
||||||
|
grep_filters += '-e "{}" '.format(comm)
|
||||||
|
logging.debug('Using grep filter: %s', grep_filters)
|
||||||
|
if grep_filters != '':
|
||||||
|
logging.info('Excluding tasks which name matches:')
|
||||||
|
logging.info('%s', ','.join(exclude))
|
||||||
|
|
||||||
for cgroup in self._cgroups:
|
for cgroup in self._cgroups:
|
||||||
if cgroup != dest:
|
if cgroup != dest:
|
||||||
self.move_tasks(cgroup, dest)
|
self.move_tasks(cgroup, dest, grep_filters)
|
||||||
|
|
||||||
def tasks(self, cgroup):
|
def tasks(self, cgroup):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user