Add a helper function cpus_online() that returns the count of online CPUs. Signed-off-by: Tommi Rantala <tommi.t.rantala@xxxxxxxxx> --- src/include/rt-utils.h | 1 + src/lib/rt-utils.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index ef0f6ac..d744ded 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -23,5 +23,6 @@ const char *policy_to_string(int policy); uint32_t string_to_policy(const char *str); pid_t gettid(void); +long cpus_online(void); #endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index ac6878c..0b1fc1e 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -320,3 +320,15 @@ pid_t gettid(void) { return syscall(SYS_gettid); } + +long cpus_online(void) +{ + long cpus = sysconf(_SC_NPROCESSORS_ONLN); + + if (cpus <= 0) + err_msg_n(errno, + "WARN: sysconf(_SC_NPROCESSORS_ONLN) returned %ld", + cpus); + + return cpus; +} -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html