git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bridge: Only store instant_stats on device changes
[sliver-openvswitch.git]
/
vswitchd
/
system-stats.c
diff --git
a/vswitchd/system-stats.c
b/vswitchd/system-stats.c
index
b164228
..
1d9cb78
100644
(file)
--- 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)
{
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);
}
if (n_cores > 0) {
smap_add_format(stats, "cpu", "%ld", n_cores);
}
@@
-148,7
+148,7
@@
get_memory_stats(struct smap *stats)
char key[16];
int value;
char key[16];
int value;
- if (
sscanf(line, "%15[^:]: %u", key, &value) == 2
) {
+ if (
ovs_scan(line, "%15[^:]: %u", key, &value)
) {
int *valuep = shash_find_data(&dict, key);
if (valuep) {
*valuep = value;
int *valuep = shash_find_data(&dict, key);
if (valuep) {
*valuep = value;
@@
-192,7
+192,7
@@
get_boot_time(void)
while (fgets(line, sizeof line, stream)) {
long long int btime;
while (fgets(line, sizeof line, stream)) {
long long int btime;
- if (
sscanf(line, "btime %lld", &btime) == 1
) {
+ if (
ovs_scan(line, "btime %lld", &btime)
) {
boot_time = btime * 1000;
goto done;
}
boot_time = btime * 1000;
goto done;
}
@@
-344,7
+344,7
@@
count_crashes(pid_t pid)
paren = strchr(line, '(');
if (paren) {
int x;
paren = strchr(line, '(');
if (paren) {
int x;
- if (
sscanf(paren + 1, "%d", &x) == 1
) {
+ if (
ovs_scan(paren + 1, "%d", &x)
) {
crashes = x;
}
}
crashes = x;
}
}
@@
-506,12
+506,12
@@
get_filesys_stats(struct smap *stats OVS_UNUSED)
\f
#define SYSTEM_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
\f
#define SYSTEM_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
-static
pthread_mutex_t mutex = PTHREAD_ADAPTIVE
_MUTEX_INITIALIZER;
+static
struct ovs_mutex mutex = OVS
_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static struct latch latch;
+static struct latch latch
OVS_GUARDED_BY(mutex)
;
static bool enabled;
static bool enabled;
-static bool started;
-static struct smap *system_stats;
+static bool started
OVS_GUARDED_BY(mutex)
;
+static struct smap *system_stats
OVS_GUARDED_BY(mutex)
;
static void *system_stats_thread_func(void *);
static void discard_stats(void);
static void *system_stats_thread_func(void *);
static void discard_stats(void);
@@
-521,7
+521,7
@@
void
system_stats_enable(bool enable)
{
if (enabled != enable) {
system_stats_enable(bool enable)
{
if (enabled != enable) {
-
xpthread
_mutex_lock(&mutex);
+
ovs
_mutex_lock(&mutex);
if (enable) {
if (!started) {
xpthread_create(NULL, NULL, system_stats_thread_func, NULL);
if (enable) {
if (!started) {
xpthread_create(NULL, NULL, system_stats_thread_func, NULL);
@@
-532,7
+532,7
@@
system_stats_enable(bool enable)
xpthread_cond_signal(&cond);
}
enabled = enable;
xpthread_cond_signal(&cond);
}
enabled = enable;
-
xpthread
_mutex_unlock(&mutex);
+
ovs
_mutex_unlock(&mutex);
}
}
}
}
@@
-549,7
+549,7
@@
system_stats_run(void)
{
struct smap *stats = NULL;
{
struct smap *stats = NULL;
-
xpthread
_mutex_lock(&mutex);
+
ovs
_mutex_lock(&mutex);
if (system_stats) {
latch_poll(&latch);
if (system_stats) {
latch_poll(&latch);
@@
-560,7
+560,7
@@
system_stats_run(void)
discard_stats();
}
}
discard_stats();
}
}
-
xpthread
_mutex_unlock(&mutex);
+
ovs
_mutex_unlock(&mutex);
return stats;
}
return stats;
}
@@
-576,7
+576,7
@@
system_stats_wait(void)
}
static void
}
static void
-discard_stats(void)
+discard_stats(void)
OVS_REQUIRES(mutex)
{
if (system_stats) {
smap_destroy(system_stats);
{
if (system_stats) {
smap_destroy(system_stats);
@@
-594,11
+594,11
@@
system_stats_thread_func(void *arg OVS_UNUSED)
long long int next_refresh;
struct smap *stats;
long long int next_refresh;
struct smap *stats;
-
xpthread
_mutex_lock(&mutex);
+
ovs
_mutex_lock(&mutex);
while (!enabled) {
while (!enabled) {
-
xpthread
_cond_wait(&cond, &mutex);
+
ovs_mutex
_cond_wait(&cond, &mutex);
}
}
-
xpthread
_mutex_unlock(&mutex);
+
ovs
_mutex_unlock(&mutex);
stats = xmalloc(sizeof *stats);
smap_init(stats);
stats = xmalloc(sizeof *stats);
smap_init(stats);
@@
-608,11
+608,11
@@
system_stats_thread_func(void *arg OVS_UNUSED)
get_process_stats(stats);
get_filesys_stats(stats);
get_process_stats(stats);
get_filesys_stats(stats);
-
xpthread
_mutex_lock(&mutex);
+
ovs
_mutex_lock(&mutex);
discard_stats();
system_stats = stats;
latch_set(&latch);
discard_stats();
system_stats = stats;
latch_set(&latch);
-
xpthread
_mutex_unlock(&mutex);
+
ovs
_mutex_unlock(&mutex);
next_refresh = time_msec() + SYSTEM_STATS_INTERVAL;
do {
next_refresh = time_msec() + SYSTEM_STATS_INTERVAL;
do {