]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/cpuset_parse.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "cgroups/cgroup.h"
11 #include "cgroups/cgroup_utils.h"
12 #include "memory_utils.h"
15 * Helper functions for cpuset_in-set
17 static char *cpuset_nexttok(const char *c
)
24 r
= strchr(c
+ 1, ',');
25 return r
? (r
+ 1) : NULL
;
28 static int cpuset_getrange(const char *c
, int *a
, int *b
)
32 ret
= sscanf(c
, "%d-%d", a
, b
);
37 * cpusets are in format "1,2-3,4"
38 * iow, comma-delimited ranges
40 bool cpu_in_cpuset(int cpu
, const char *cpuset
)
42 for (const char *c
= cpuset
; c
; c
= cpuset_nexttok(c
)) {
45 ret
= cpuset_getrange(c
, &a
, &b
);
46 if (ret
== 1 && cpu
== a
) /* "1" or "1,6" */
48 else if (ret
== 2 && cpu
>= a
&& cpu
<= b
) /* range match */
56 * get cpu number in cpuset
58 int cpu_number_in_cpuset(const char *cpuset
)
62 for (const char *c
= cpuset
; c
; c
= cpuset_nexttok(c
)) {
65 ret
= cpuset_getrange(c
, &a
, &b
);
69 cpu_number
+= a
> b
? a
- b
+ 1 : b
- a
+ 1;