cgroups: fix get attributes for controller noprefix mounted
CGroups controller can be mounted by specifying a "noprefix" option,
in which case attribute names are named as:
<mountpoint>/<attribute_name>
instead of the (more recent) naming schema using:
<mountpoint>/<contoller_name>.<attribute_name>
For example, Android uses the old format for backward compatibility
with user-space. Thus, it's possible in general to work on a target
system where some controller are mounted "noprefix" while others not.
This patchset adds a set of updates which allows to use the proper
attributes naming schema based on how the controller has been mounted.
This patch provides a more generic implementation of the get attributes
shutils which is working also for noprefix mounted controllers.
Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in
index f69bce3..ef4d3bd 100755
--- a/devlib/bin/scripts/shutils.in
+++ b/devlib/bin/scripts/shutils.in
@@ -62,12 +62,26 @@
################################################################################
cgroups_get_attributes() {
- [[ $# -eq 2 ]] || exit -1
+ test $# -eq 2 || exit -1
CGROUP="$1"
CONTROLLER="$2"
- $GREP '' $CGROUP/* | \
- $GREP "$CONTROLLER\." | \
- $SED -e "s|$CONTROLLER\.||" -e "s|$CGROUP/||"
+ # Check if controller is mounted with "noprefix" option, which is quite
+ # common on Android for backward compatibility
+ ls $CGROUP/$CONTROLLER\.* 2>&1 >/dev/null
+ if [ $? -eq 0 ]; then
+ # no "noprefix" option, attributes format is:
+ # mnt_point/controller.attribute_name
+ $GREP '' $CGROUP/* | \
+ $GREP "$CONTROLLER\." | \
+ $SED -e "s|$CONTROLLER\.||" -e "s|$CGROUP/||"
+ else
+ # "noprefix" option, attribute format is:
+ # mnt_point/attribute_name
+ $GREP '' $(\
+ $FIND $CGROUP -type f -maxdepth 1 |
+ $GREP -v -e ".*tasks" -e ".*cgroup\..*") | \
+ $SED "s|$CGROUP/||"
+ fi
}
cgroups_run_into() {