2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-29 13:27:59 +00:00

62 Commits

Author SHA1 Message Date
Ben Pfaff
04b331cdca timeval: Restore ability to warp time forward when time is not stopped.
Commit 31ef9f5178dee18 (timeval: Remove CACHE_TIME scheme.) inadvertently
removed the ability to warp time forward, for use in tests, except when
time is stopped.  This fixes the problem.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-09-13 14:30:05 -07:00
Ben Pfaff
3e509ec5ed timeval: Add Clang thread-safety annotations, fix unimportant violation.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-09-13 13:34:17 -07:00
Paul Ingram
2b31d8e713 vlog: Report timestamps in millisecond resolution in log messages.
To make debugging easier.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Paul Ingram <pingram@nicira.com>
2013-09-13 09:11:46 -07:00
YAMAMOTO Takashi
223fad326c lib/timeval: don't forget to initialize a rwlock
Commit 31ef9f5178 (timeval: Remove CACHE_TIME scheme.) removed
initialization of a rwlock which is still used for some operations.
This restores it.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-09-09 09:53:26 -07:00
Alex Wang
31ef9f5178 timeval: Remove CACHE_TIME scheme.
This commit removes the CACHE_TIME scheme from timeval module.  This
is for eliminating the lock contention over the read/write lock of
the cached time.  To get the time, the thread now will directly do
the system call 'clock_gettime()'.

As a side effect, timer can only be warpped after timer is stopped
by 'appctl time/stop' command.

Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-09-04 16:57:40 -07:00
Ben Pfaff
2ba4f163d9 ovs-thread: Add support for globally visible per-thread data.
DEFINE_PER_THREAD_DATA always declared its data item as "static", meaning
that it was only directly visible within a single translation unit.
This commit adds additional forms of per-thread data that allow the data
to be accessible from multiple translation units.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-08 13:18:10 -07:00
Ethan Jackson
97be153858 clang: Add annotations for thread safety check.
This commit adds annotations for thread safety check. And the
check can be conducted by using -Wthread-safety flag in clang.

Co-authored-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-30 21:30:45 -07:00
Ben Pfaff
4c694ff745 timeval: Make CPU usage and wakeup tracking per-thread.
This should make the "timeval" module thread-safe, except for its
calls into vlog (because vlog is not yet thread-safe).

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-12 13:52:29 -07:00
Ben Pfaff
75f9c912f2 timeval: Make reading the current time thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-12 13:47:10 -07:00
Ben Pfaff
6f2302b06c timeval: Fix typo in comment.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-11 17:04:52 -07:00
Ben Pfaff
94f3e5269e timeval: Remove backtrace feature.
The backtrace feature of timeval is useful because it provides a "poor
man's profile" view of Open vSwitch.  But it is not likely to be useful in
a multithreaded process, because signal delivery doesn't necessarily follow
the profile when there is more than one thread.  (A signal in a
multithreaded process are delivered to an arbitrary thread.)

Another problem with the backtrace feature is that it is difficult for
format_backtraces() to synchronize properly with the signal handler in a
multithreaded process.  In a single-threaded process, it can just block
the signal handler, but in a multithreaded process this does not prevent
signal delivery to threads other than the one running format_backtrace().

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-11 17:02:12 -07:00
Ben Pfaff
bc7ad7d474 timeval: New function xclock_gettime().
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ed Maste <emaste@freebsd.org>
2013-07-11 16:50:15 -07:00
Ben Pfaff
10a89ef04d Replace all uses of strerror() by ovs_strerror(), for thread safety.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28 16:09:38 -07:00
Ben Pfaff
728a8b141f ovs-thread: Add support for various thread-related assertions.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-28 16:09:37 -07:00
Ben Pfaff
5ad72ef5b6 timeval: Remove time_disable_restart(), time_enable_restart() functions.
These functions will not have the same useful effect when Open vSwitch
becomes multithreaded, because time_disable_restart() will disable time
advancing for every thread, not just for the thread that calls it.

These functions are no longer used, so this commit removes them.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-06 16:59:51 -07:00
Ben Pfaff
a19b84f4a6 timeval: Do not block SIGALRM around setting 'deadline' in time_alarm().
There is no need to do so because the signal handler does not read or
write 'deadline'.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-05 14:58:01 -07:00
Ben Pfaff
92829687b4 Use pthread_sigmask() in place of sigprocmask(), for thread safety.
POSIX says that multithreaded programs must not use sigprocmask() but must
use pthread_sigmask() instead.  This commit makes that replacement.

The actual use of signals in Open vSwitch is still not thread safe
following this commit, but this change is a necessary prerequisite for
fixing the other problems.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-02 13:55:45 -07:00
Ben Pfaff
93456ec8b0 timeval: Check for HAVE_BACKTRACE instead of HAVE_EXECINFO_H.
Other code in the tree uses HAVE_BACKTRACE and then blindly includes
<execinfo.h> if it is present, so this doesn't make anything worse.

Once we do that, HAVE_EXECINFO_H has no further users, so this commit also
removes the check for <execinfo.h>

Reported-by: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-24 08:59:11 -07:00
Ben Pfaff
4906f197e9 timeval: Avoid backtrace() from signal handler on x86-64.
backtrace() is really useful, but it is not signal safe everywhere.  We
need to reassess whether it is reasonable to use it anywhere, but
immediately we need to disable it on x86-64 (with glibc) because it is
causing segfaults in testing.

Bug #15497.
Reported-by: Ram Jothikumar <rjothikumar@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-03-07 17:13:49 -08:00
Ben Pfaff
6e97c6506e timeval: Don't issue poll interval warnings when we warp time.
It's not meaningful in that case.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-02-11 13:22:30 -08:00
Ben Pfaff
75b0b752d8 timeval: Avoid unnecessary integer overflow in time_alarm().
Durations longer than 4294967 seconds would unnecessarily overflow in the
multiplication here.

Found by Coverity.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-02-01 14:27:20 -08:00
Ben Pfaff
cb22974d77 Replace most uses of assert by ovs_assert.
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:03:37 -08:00
Ethan Jackson
543a550837 timeval: Fix occasional backtrace() related deadlock.
Occasionally, backtrace() will deadlock in the signal handler
because it does some non signal safe initialization.  Specifically,
it opens a shared object.  As a work around, this patch forces
backtrace() to run outside of a signal handler, so that future
calls will perform as expected.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-26 14:44:33 -07:00
Ethan Jackson
f43e80e023 poll-loop: Log backtraces when CPU usage is high.
Often when debugging Open vSwitch, one will see in the logs that
CPU usage has been high for some period of time, but it's totally
unclear why.  In an attempt to remedy the situation, this patch
logs backtraces taken at regular intervals as a poor man's
profiling alternative.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-25 11:14:07 -07:00
Ethan Jackson
7d1563e961 timeval: Coalesce backtraces with counts.
With this patch, `ovs-appctl backtrace` will return a unique list
of backtraces and a count of how many times it has been recorded.
This work had previously been done by ovs-parse-backtrace. However,
in future patches poll-loop will begin logging backtraces as a
matter of course.  At this point, coalescing the backtraces will
help keep these log messages brief.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-25 11:14:07 -07:00
Ethan Jackson
fdce775cc5 timeval: Take a backtrace on each SIGALRM.
With this patch, timeval will take a backtrace with each SIGALRM
allowing it to retrieve a profiling snapshot instantly.  This will
be useful in future patches when backtraces are logged.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-25 09:41:37 -07:00
Ethan Jackson
d7a291ac1c timeval: Simplify poll interval logging.
log_poll_interval() is a little bit too aggressive, and is
therefore less useful than it could be.  This patch removes the
mean interval calculation, and simply logs if the poll loop took
longer than 1 second instead.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-20 17:26:38 -07:00
Ethan Jackson
61a7b1e6fe timeval: Block SIGALRM when sleeping.
Commit 00a16895 (timeval: Don't require signals for time_alarm().)
Incorrectly disabled signals when when CACHE_TIME was disabled.  In
fact, the reverse was correct.  As a result of this bug, OVS would
wake once every 100ms unnecessarily.  It shouldn't have affected
correctness otherwise.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-16 15:02:45 -07:00
Ethan Jackson
9d232a6d57 timeval: Add new "backtrace" appctl command.
Often, it can be quite difficult to debug performance issues in
Open vSwitch.  Typically one needs to run something like gprof, but
that requires rebuilding and installing on the affected system
which is often problematic.  This patch adds a light weight
profiling solution which can be used in these situations.  The
ovs-appctl backtrace command prints out backtraces taken at 100
millisecond intervals over a 5 second period of time.  It is
currently only supported on systems which have the execinfo library
and enable time caching.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-14 19:36:39 -07:00
Ethan Jackson
361906b1e2 config: Add explicit support for building on ESX.
The ESX userspace looks quite a bit like linux, but has some key
differences which need to be specially handled in the build.  To
distinguish between ESX and systems which use the linux datapath
module, this patch adds two new macros "ESX" and "LINUX_DATAPATH".
It uses these macros to disable building code on ESX which only
applies to a true Linux environment.  In addition, it adds a new
route-table-stub implementation which is required for the build to
complete successfully on ESX.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-09 15:23:47 -07:00
Ethan Jackson
a457574880 timeval: Recover from failed timer_create() calls.
The timer_create() system call is not supported in ESX and returns
an error when called.  Aborting when this system call fails seems a
bit extreme. So instead, this patch simply falls back to disabling
the cached time optimization.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-05 11:33:11 -07:00
Ethan Jackson
00a1689587 timeval: Don't require signals for time_alarm().
Before this patch, time_alarm() used the SIGALRM handler to notify
the poll loop that it should exit the program.  Instead, this patch
simply implements time_alarm() directly in the pool loop.  This
significantly simplifies the code, while removing a call to
timer_create() which is not currently supported on ESX.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-10-05 11:17:00 -07:00
Leo Alterman
49635519ba timeval: On Linux x86-64 systems refresh time whenever it is requested.
64-bit Linux appears to avoid syscalls for clock_gettime(), so we can get
higher resolution timing and avoid having a timer firing off SIGALRM
without introducing extra overhead.

Signed-off-by: Leo Alterman <lalterman@nicira.com>
2012-08-09 15:06:38 -07:00
Raju Subramanian
e0edde6fee Global replace of Nicira Networks.
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc.

Feature #10593
Signed-off-by: Raju Subramanian <rsubramanian@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02 17:08:02 -07:00
Ben Pfaff
a5f607bc89 coverage: Make ovs-appctl command more useful and less alarming.
I've had a few complaints that ovs-vswitchd logs its coverage counters
at WARN level, but this is mainly wrong: ovs-vswitchd only logs coverage
counters at WARN level when the "coverage/log" command is used through
ovs-appctl.  This was even documented.

The reason to log at such a high level was to make it fairly certain that
these messages specifically requested by the admin would not be filtered
out before making it to the log.  But it's even better if the admin just
gets the coverage counters as a reply to the ovs-appctl command.  So that
is what this commit does.

This commit also improves the documentation of the ovs-appctl command.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-26 14:07:29 -07:00
Ben Pfaff
c563de0e38 timeval: Rate-limit logging rusage information.
I'd always assumed that the exponentially weighted moving average code
here was sufficient rate-limiting, but I actually encountered a
pathological case some time ago that forced this rusage information to
print once a second or so, which seems too often.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-26 14:06:27 -07:00
Ben Pfaff
f802352d41 timeval: Add "time/stop" unixctl command, for use in unit tests.
Although we try to avoid it, some unit tests are necessarily
timing-sensitive.  The new "time/stop" command that this commit adds should
help with that, by preventing time from advancing from the viewpoint of
the OVS "timeval" functions except when "time/warp" explicitly advances
the current time.  This should allow the unit tests that need it to become
reproducible regardless of the speed at which the tests run.

This commit adds one unit of "time/stop" to the unit test suite, in the one
timing-sensitive test of which I am currently aware.

Bug #9782.
Reported-by: Tim Chen <tchen@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-02-28 17:14:22 -08:00
Ethan Jackson
bde9f75de1 unixctl: New JSON RPC back-end.
The unixctl library had used the vde2 management protocol since the
early days of Open vSwitch.  As Open vSwitch has matured, several
Python daemons have been added to the code base which would benefit
from a unixctl implementations.  Instead of implementing the old
unixctl protocol in Python, this patch changes unixctl to use JSON
RPC for which we already have an implementation in both Python and
C.  Future patches will need to implement a unixctl library in
Python on top of JSON RPC.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-02-21 00:02:20 -08:00
Ben Pfaff
4ae90ff9e2 timeval: New function time_boot_msec(), factored out of vlog.
An upcoming commit has a new use for the time at which OVS started up, so
this moves this functionality to a common location.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-02-01 14:15:12 -08:00
Ben Pfaff
6197af6e4b timeval: Add ability to fast-forward time, for unit testing.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2011-12-19 14:53:54 -08:00
Ben Pfaff
cee03df4f5 poll-loop: Track the poll timeout as an absolute, not a relative time.
This is a necessary prerequisite for allowing time to be "fast forwarded"
in unit tests, to keep tests that depend on the passage of time from
running in real time.  Without this change, a code sequence like this:

	poll_timer_wait(1000);
	...fast forward time 5 seconds...
	poll_block();

would still sleep for a second, because the poll_loop module would still
have a relative timeout of 1000 ms.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2011-12-19 14:53:48 -08:00
Ben Pfaff
959ec62e32 poll-loop: Automatically log reason for wakeup when CPU usage spikes.
For a long time, the poll-loop module has had the ability to log the reason
for wakeups, which is valuable for debugging excessive use of CPU time.
But I have to ask users to turn up the log level for the module, which
wastes their time and mine.  This commit improves the situation by
automatically logging the reason for a wakeup whenever a process's
estimated CPU usage rises above 50%.  (ovs-vswitchd often uses less than
1% CPU; more than 5% CPU is uncommon.)
2011-05-24 12:23:42 -07:00
Ben Pfaff
279c9e0308 Log anything that could prevent a daemon from starting.
If a daemon doesn't start, we need to know why.  Being able to
consistently consult the log to find out is helpful.
2011-04-04 10:58:55 -07:00
Ben Pfaff
14865427e6 timeval: Only log poll intervals longer than 50 ms.
When poll interval-based logging was introduced a long time, we were
actively interested in looking at almost every long poll interval.  But
these days, with OVS working rather well, with pretty good latency, most
of the messages are red herrings that bother some administrators and
provoke false reports.  So this commit suppresses all but the most
egregious long poll intervals that may in fact be worth looking at.

NIC-366.
2011-03-30 11:31:16 -07:00
Ben Pfaff
d98e600755 vlog: Make client supply semicolon for VLOG_DEFINE_THIS_MODULE.
It's kind of odd for VLOG_DEFINE_THIS_MODULE to supply its own semicolon,
so this commit switches to the more common form.
2010-10-29 09:48:47 -07:00
Joe Perches
d295e8e97a treewide: Remove trailing whitespace
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Jesse Gross <jesse@nicira.com>
2010-08-30 13:23:08 -07:00
Ben Pfaff
5136ce492c vlog: Introduce VLOG_DEFINE_THIS_MODULE for declaring vlog module in use.
Adding a macro to define the vlog module in use adds a level of
indirection, which makes it easier to change how the vlog module must be
defined.  A followup commit needs to do that, so getting these widespread
changes out of the way first should make that commit easier to review.
2010-07-21 15:47:09 -07:00
Ben Pfaff
ff8bb7e76b timeval: Make time_init() static and remove calls to it.
Since the timeval module now initializes itself on-demand, there is no
longer any need to initialize it explicitly, or to provide an interface to
do so.
2010-07-21 15:47:09 -07:00
Ben Pfaff
7bc9188dda timeval: Make timeval module initialize itself.
It's more convenient if clients don't have to initialize modules
explicitly.
2010-07-21 15:43:30 -07:00
Ben Pfaff
f54e56fc50 timeval: Integrate CLOCK_MONOTONIC detection into time_init().
I don't see a reason that set_up_monotonic() should be separate from
time_init().  Doing all the time initialization in one place seems
reasonable, so this commit makes that change.
2010-07-21 15:40:26 -07:00