Signed-off-by: Joe Stringer <[email protected]>
---
lib/ovs-thread.c | 10 ++++++++++
lib/ovs-thread.h | 4 ++++
ofproto/ofproto.c | 2 +-
vswitchd/system-stats.c | 2 +-
4 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index b3a87bb..02436e5 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -309,4 +309,14 @@ may_fork(void)
{
return !must_not_fork;
}
+
+/* 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
diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h
index 7f3195d..c6a7142 100644
--- a/lib/ovs-thread.h
+++ b/lib/ovs-thread.h
@@ -496,5 +496,9 @@ pid_t xfork_at(const char *where);
void forbid_forking(const char *reason);
bool may_fork(void);
+
+/* Useful functions related to threading. */
+
+unsigned int count_cpu_cores(void);
#endif /* ovs-thread.h */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index c4ce8a2..b282abe 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -738,7 +738,7 @@ ofproto_set_n_handler_threads(unsigned limit)
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;
}
}
diff --git a/vswitchd/system-stats.c b/vswitchd/system-stats.c
index 2960b87..1d9cb78 100644
--- a/vswitchd/system-stats.c
+++ b/vswitchd/system-stats.c
@@ -59,7 +59,7 @@ VLOG_DEFINE_THIS_MODULE(system_stats);
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);
}
--
1.7.9.5
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev