This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ Added `core.sys.linux.sched.CPU_COUNT`.
2
+
3
+ Added `core.sys.linux.sched.CPU_COUNT`, which returns the number of CPUs in set.
Original file line number Diff line number Diff line change 14
14
15
15
module core.sys.linux.sched ;
16
16
17
+ import core.bitop : popcnt;
17
18
import core.sys.posix.sched ;
18
19
import core.sys.posix.config ;
19
20
import core.sys.posix.sys.types ;
@@ -63,6 +64,14 @@ private // helpers
63
64
return (cpusetp.__bits[__CPUELT(cpu)] & __CPUMASK(cpu)) != 0 ;
64
65
return false ;
65
66
}
67
+
68
+ int __CPU_COUNT_S (size_t setsize, cpu_set_t* cpusetp) pure
69
+ {
70
+ int s = 0 ;
71
+ foreach (i; cpusetp.__bits[0 .. (setsize / cpu_mask.sizeof)])
72
+ s += popcnt(i);
73
+ return s;
74
+ }
66
75
}
67
76
68
77
// / Type for array elements in 'cpu_set_t'.
@@ -86,6 +95,11 @@ bool CPU_ISSET(size_t cpu, cpu_set_t* cpusetp) pure
86
95
return __CPU_ISSET_S (cpu, cpu_set_t.sizeof, cpusetp);
87
96
}
88
97
98
+ int CPU_COUNT (cpu_set_t* cpusetp) pure
99
+ {
100
+ return __CPU_COUNT_S (cpu_set_t.sizeof, cpusetp);
101
+ }
102
+
89
103
/* Functions */
90
104
int sched_setaffinity (pid_t pid, size_t cpusetsize, cpu_set_t * mask);
91
105
int sched_getaffinity (pid_t pid, size_t cpusetsize, cpu_set_t * mask);
You can’t perform that action at this time.
0 commit comments