aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-11-09 17:05:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-11-09 17:07:44 +0100
commita82fb1b9d8a046e01dbad33bb57d064815d60e5c (patch)
treee4bebb81de379358ff6bff46948894069818f7d4
parent2f57b5139e701e04a7b543220f6bb117b5e71967 (diff)
downloadbusybox-a82fb1b9d8a046e01dbad33bb57d064815d60e5c.tar.gz
taskset: implement stride argument
function old new delta taskset_main 925 986 +61 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/taskset.c15
1 files changed, 10 insertions, 5 deletions
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;