+ if (enabled) {
+ latch_wait(&latch);
+ }
+}
+
+static void
+discard_stats(void) OVS_REQUIRES(mutex)
+{
+ if (system_stats) {
+ smap_destroy(system_stats);
+ free(system_stats);
+ system_stats = NULL;
+ }
+}
+
+static void * NO_RETURN
+system_stats_thread_func(void *arg OVS_UNUSED)
+{
+ pthread_detach(pthread_self());
+
+ for (;;) {
+ long long int next_refresh;
+ struct smap *stats;
+
+ ovs_mutex_lock(&mutex);
+ while (!enabled) {
+ ovs_mutex_cond_wait(&cond, &mutex);
+ }
+ ovs_mutex_unlock(&mutex);
+
+ stats = xmalloc(sizeof *stats);
+ smap_init(stats);
+ get_cpu_cores(stats);
+ get_load_average(stats);
+ get_memory_stats(stats);
+ get_process_stats(stats);
+ get_filesys_stats(stats);
+
+ ovs_mutex_lock(&mutex);
+ discard_stats();
+ system_stats = stats;
+ latch_set(&latch);
+ ovs_mutex_unlock(&mutex);
+
+ next_refresh = time_msec() + SYSTEM_STATS_INTERVAL;
+ do {
+ poll_timer_wait_until(next_refresh);
+ poll_block();
+ } while (time_msec() < next_refresh);