From a82fb1b9d8a046e01dbad33bb57d064815d60e5c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 9 Nov 2019 17:05:14 +0100 Subject: taskset: implement stride argument function old new delta taskset_main 925 986 +61 Signed-off-by: Denys Vlasenko --- util-linux/taskset.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'util-linux') diff --git a/util-linux/taskset.c b/util-linux/taskset.c index 157bf5e4c..df1bc0a4f 100644 --- a/util-linux/taskset.c +++ b/util-linux/taskset.c @@ -121,10 +121,8 @@ static unsigned long *get_aff(int pid, unsigned *sz) * Parse the CPU list and set the mask accordingly. * * The list element can be either a CPU index or a range of CPU indices. - * Example: "1,3,5-7". - * - * note1: stride (e.g. 0-255:2) is not supported - * note2: leading and trailing whitespace is not allowed + * Example: "1,3,5-7". Stride can be specified: "0-7:2" is "0,2,4,6". + * Note: leading and trailing whitespace is not allowed. * util-linux 2.31 allows leading and sometimes trailing whitespace: * ok: taskset -c ' 1, 2' * ok: taskset -c ' 1 , 2' @@ -137,21 +135,28 @@ static void parse_cpulist(ul *mask, unsigned max, char *s) char *aff = s; for (;;) { unsigned bit, end; + unsigned stride = 1; bit = end = bb_strtou(s, &s, 10); if (*s == '-') { s++; end = bb_strtou(s, &s, 10); + if (*s == ':') { + s++; + stride = bb_strtou(s, &s, 10); + } } if ((*s != ',' && *s != '\0') || bit > end || end == UINT_MAX /* bb_strtou returns this on malformed / ERANGE numbers */ + || stride == 0 + || stride == UINT_MAX ) { bb_error_msg_and_die("bad affinity '%s'", aff); } while (bit <= end && bit < max) { mask[bit / BITS_UL] |= (1UL << (bit & MASK_UL)); - bit++; + bit += stride; } if (*s == '\0') break; -- cgit v1.2.3