From: Ben Pfaff Date: Wed, 11 Feb 2015 02:00:22 +0000 (-0800) Subject: timeval: Correctly report usage statistics in log_poll_interval(). X-Git-Tag: v2.3.2~37 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=f8438a401ca308d5849d79b2bf31d2218f537747 timeval: Correctly report usage statistics in log_poll_interval(). Most of the information that timeval was reporting for long poll intervals was comparing per-thread with per-process statistics, which yielded nonsense a lot of the time. Signed-off-by: Ben Pfaff Acked-by: Alex Wang --- diff --git a/lib/timeval.c b/lib/timeval.c index ca663a013..874263ccc 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,6 +92,7 @@ DEFINE_STATIC_PER_THREAD_DATA(long long int, last_wakeup, 0); static void log_poll_interval(long long int last_wakeup); static struct rusage *get_recent_rusage(void); +static int getrusage_thread(struct rusage *); static void refresh_rusage(void); static void timespec_add(struct timespec *sum, const struct timespec *a, const struct timespec *b); @@ -497,31 +498,35 @@ log_poll_interval(long long int last_wakeup) const struct rusage *last_rusage = get_recent_rusage(); struct rusage rusage; - getrusage(RUSAGE_SELF, &rusage); - VLOG_WARN("Unreasonably long %lldms poll interval" - " (%lldms user, %lldms system)", - interval, - timeval_diff_msec(&rusage.ru_utime, - &last_rusage->ru_utime), - timeval_diff_msec(&rusage.ru_stime, - &last_rusage->ru_stime)); - if (rusage.ru_minflt > last_rusage->ru_minflt - || rusage.ru_majflt > last_rusage->ru_majflt) { - VLOG_WARN("faults: %ld minor, %ld major", - rusage.ru_minflt - last_rusage->ru_minflt, - rusage.ru_majflt - last_rusage->ru_majflt); - } - if (rusage.ru_inblock > last_rusage->ru_inblock - || rusage.ru_oublock > last_rusage->ru_oublock) { - VLOG_WARN("disk: %ld reads, %ld writes", - rusage.ru_inblock - last_rusage->ru_inblock, - rusage.ru_oublock - last_rusage->ru_oublock); - } - if (rusage.ru_nvcsw > last_rusage->ru_nvcsw - || rusage.ru_nivcsw > last_rusage->ru_nivcsw) { - VLOG_WARN("context switches: %ld voluntary, %ld involuntary", - rusage.ru_nvcsw - last_rusage->ru_nvcsw, - rusage.ru_nivcsw - last_rusage->ru_nivcsw); + if (!getrusage_thread(&rusage)) { + VLOG_WARN("Unreasonably long %lldms poll interval" + " (%lldms user, %lldms system)", + interval, + timeval_diff_msec(&rusage.ru_utime, + &last_rusage->ru_utime), + timeval_diff_msec(&rusage.ru_stime, + &last_rusage->ru_stime)); + + if (rusage.ru_minflt > last_rusage->ru_minflt + || rusage.ru_majflt > last_rusage->ru_majflt) { + VLOG_WARN("faults: %ld minor, %ld major", + rusage.ru_minflt - last_rusage->ru_minflt, + rusage.ru_majflt - last_rusage->ru_majflt); + } + if (rusage.ru_inblock > last_rusage->ru_inblock + || rusage.ru_oublock > last_rusage->ru_oublock) { + VLOG_WARN("disk: %ld reads, %ld writes", + rusage.ru_inblock - last_rusage->ru_inblock, + rusage.ru_oublock - last_rusage->ru_oublock); + } + if (rusage.ru_nvcsw > last_rusage->ru_nvcsw + || rusage.ru_nivcsw > last_rusage->ru_nivcsw) { + VLOG_WARN("context switches: %ld voluntary, %ld involuntary", + rusage.ru_nvcsw - last_rusage->ru_nvcsw, + rusage.ru_nivcsw - last_rusage->ru_nivcsw); + } + } else { + VLOG_WARN("Unreasonably long %lldms poll interval", interval); } coverage_log(); }