Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
{
return !must_not_fork;
}
+\f
+/* Returns the total number of cores on this system, or 0 if the number cannot
+ * be determined. */
+unsigned int
+count_cpu_cores(void)
+{
+ long int n_cores = sysconf(_SC_NPROCESSORS_ONLN);
+
+ return n_cores > 0 ? n_cores : 0;
+}
#endif
void forbid_forking(const char *reason);
bool may_fork(void);
+\f
+/* Useful functions related to threading. */
+
+unsigned int count_cpu_cores(void);
#endif /* ovs-thread.h */
if (limit) {
n_handler_threads = limit;
} else {
- int n_proc = sysconf(_SC_NPROCESSORS_ONLN);
+ int n_proc = count_cpu_cores();
n_handler_threads = n_proc > 2 ? n_proc - 2 : 1;
}
}
static void
get_cpu_cores(struct smap *stats)
{
- long int n_cores = sysconf(_SC_NPROCESSORS_ONLN);
+ long int n_cores = count_cpu_cores();
if (n_cores > 0) {
smap_add_format(stats, "cpu", "%ld", n_cores);
}