[LTP] [PATCH] cpuset_regression_test: Fix test, if cpuset groups exist already
Richard Palethorpe
rpalethorpe@suse.de
Tue Nov 23 10:46:21 CET 2021
Hello Joerg,
Joerg Vehlow <lkml@jv-coder.de> writes:
>>> +cpuset_find_breadth_first()
>>> +{
>>> + local what=$1
>>> +
>>> + # Breath first find implementation:
>>> + # Use awk to prepend the length of the path, sort it
>>> + # and remove the length again.
>>> + # Since all commands work line-based,
>>> + # this works with meta characters and spaces.
>>> + find . -mindepth 2 -name ${what} |
>>> + awk '{print length($0) " " $0}' |
>> This is the length of the path in characters. I think you want to count
>> the path components instead. The below is from my system
>>
>> find /sys/fs/cgroup -type d | awk '{print length($0) " " $0}' | sort -n
>> ...
>> 43 /sys/fs/cgroup/system.slice/wickedd.service
>> 44 /sys/fs/cgroup/sys-fs-fuse-connections.mount
>> ...
>>
>> sys-fs-fuse-connections.mount should come first in a breadth first
>> search.
> Actually it doesn't matter. The only thing, that matters here is that
> parent groups
> are handled before child groups. That is ensured, because the prefix
> of a child group is
> always the parent group and so the child is longer.
> At first I had it named "somewhat breadth-first" ;)
> Counting path components is not a trivial task, because there may be
> escaped slashes.
> Maybe not calling it breadth first, but parent-first would be a
> solution?
Sounds good, +1
>>
>>
>>> + sort -n | cut -d " " -f 2-
>>> +}
>>> +
>>> +# cpuset_backup_and_update <backup_dir> <what>
>>> # Create backup of the values of a specific file (<what>)
>>> -# in all cpuset groups and set the value to <value>
>>> +# in all cpuset groups and set the value to 1
>>> # The backup is written to <backup_dir> in the same structure
>>> # as in the cpuset filesystem
>>> cpuset_backup_and_update()
>>> {
>>> local backup_dir=$1
>>> local what=$2
>>> - local value=$3
>>> local old_dir=$PWD
>>> + local cpu_max=$((cpu_num - 1))
>>> + local res
>>> cd ${root_cpuset_dir}
>>> - find . -mindepth 2 -name ${what} -print0 |
>>> - while IFS= read -r -d '' file; do
>>> +
>>> + # First do breath-first search and set all groups to use all cpus.
>>> + # Breath-first is important, because the parent groups
>>> + # must have all cpus assigned to a child group first
>> This is confusing. Inline comments are not encouraged either. IMO the
>> commit message is enough or else you can add a brief explanation of the
>> saving and restore procedure at the top.
> Ok, I thought a bit of documentation why this is done would be a good
> idea, because it is not very obvious.
The main thing is that the comment doesn't make sense to me. In
particular the last sentence. Inline comments are also discouraged in
the style guide.
Also you can handle this depth-first, you just need to lift restrictions
before descending into the tree. So breadth-first is not really
important.
I think it's enough to explain at the top that descendents are bounded
by their ancestors. Then it's down to the reviewer or future developers
to figure out how the shell code handles that.
>
> Joerg
--
Thank you,
Richard.
More information about the ltp
mailing list