2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-28 12:58:00 +00:00

94 Commits

Author SHA1 Message Date
Frode Nordahl
6ece3d57b2 timeval: Add internal timewarp interface.
It may be desirable to make use of time warp functionality in unit
tests.

Separate logic from time/stop unixctl into timeval_stop() and add
a new timeval_warp() interface for directing monotonic clock into
slow path and advancing the current monotonic directly.

This will be used in a patch that implements unit tests for the
cooperative multitasking module.

Signed-off-by: Frode Nordahl <frode.nordahl@canonical.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2024-01-17 14:41:18 +01:00
Eelco Chaudron
05d6f419cd timeval: Add coverage counter for long poll interval events.
Martin Kennelly observes that even though this data is available to
humans via the journal/log files, these aren't exactly easy for a
developer to make any kind of behavioral inferences.  This kind of
log and counter would be useful when checking on system health to
let us know that an Open vSwitch component is noticing some kind of
system level hiccup.

Add a new coverage counter to track information on these events, and
let a developer or system engineer know how long these events have
occurred with some historical context.

Reported-at: https://lists.linuxfoundation.org/pipermail/ovs-discuss/2023-June/052523.html
Suggested-by: Martin Kennelly <mkennell@redhat.com>
Co-Authored-By: Aaron Conole <aconole@redhat.com>
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Simon Horman <horms@ovn.org>
Acked-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Aaron Conole <aconole@redhat.com>
2024-01-15 08:38:00 -05:00
Bhanuprakash Bodireddy
ca3cc1aad4 util: Add high resolution sleep support.
This commit introduces xnanosleep() for the threads needing high
resolution sleep timeouts.

usleep() that provides microsecond granularity is deprecated and threads
wanting sub-second(ms,us,ns) granularity can use this implementation.

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-11-28 15:53:23 -08:00
Richard Oliver
10fd9f6e47 timeval: Check for OS-provided clock_gettime on macOS
[Problem]
Compilation error on newer versions of macOS (Sierra onwards) due to
multiple declarations of clock_gettime.

[Solution]
Have configure check for clock_gettime and check this result in
timeval to avoid incorrectly declaring/defining clock_gettime again.

[Testing]
Source code now successfully builds on macOS.

Signed-off-by: Richard Oliver <richard@richard-oliver.co.uk>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-10-30 09:56:27 -07:00
Ilya Maximets
bf168c45b9 timeval: Add functions with microsecond granularity.
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-10-27 10:51:44 -07:00
Ilya Maximets
89bbc6a9cd timeval: Fix misleading function descriptions.
TIME_UPDATE_INTERVAL was removed long time ago.
Now each call leads to time update via syscall and it's
granularity is system dependent.

Fixes: 31ef9f5178de ("timeval: Remove CACHE_TIME scheme.")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2017-10-24 20:55:50 -07:00
Bhanuprakash Bodireddy
db2e457d6c timeval: Reorder elements in clock structure.
By reordering the elements in clock structure, pad bytes
can be reduced and also a cache line is saved.

Before: structure size:136, holes:3, sum padbytes:18, cachelines:3
After: structure size:120, holes:1, sum padbytes:2, cachelines:2

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
Co-authored-by: Antonio Fischetti <antonio.fischetti@intel.com>
Signed-off-by: Antonio Fischetti <antonio.fischetti@intel.com>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Daniele Di Proietto <diproiettod@vmware.com>
2016-10-17 18:35:21 -07:00
Terry Wilson
ee89ea7b47 json: Move from lib to include/openvswitch.
To easily allow both in- and out-of-tree building of the Python
wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to
include/openvswitch. This also requires moving lib/{hmap,shash}.h.

Both hmap.h and shash.h were #include-ing "util.h" even though the
headers themselves did not use anything from there, but rather from
include/openvswitch/util.h. Fixing that required including util.h
in several C files mostly due to OVS_NOT_REACHED and things like
xmalloc.

Signed-off-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-07-22 17:09:17 -07:00
Lance Richardson
291716e10f timeval: Add clock_gettime() for OS X
OS X does not implement clock_gettime(), implement replacement.

Signed-off-by: Lance Richardson <lrichard@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-03-22 18:41:38 -07:00
Ben Warren
3e8a2ad145 Move lib/dynamic-string.h to include/openvswitch directory
Signed-off-by: Ben Warren <ben@skyportsystems.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-03-19 10:02:12 -07:00
Ilya Maximets
2f8932e840 poll: Suppress logging for pmd threads.
'Unreasonably long poll interval's are reasonable for PMD threads.
Also reporting of high CPU usage is not necessary.

Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-01-11 09:59:49 -08:00
Russell Bryant
ee5315b9f9 timeval: Remove duplicate memset().
init_clock begins with a memset of 0 of the full clock struct.  This
memset at the end of a single struct member just makes extra sure that
it's set to 0, which is unnecessary.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2015-02-20 10:31:23 -08:00
Ben Pfaff
653ce9d684 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 <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
2015-02-11 15:00:48 -08:00
Thomas Graf
e6211adce4 lib: Move vlog.h to <openvswitch/vlog.h>
A new function vlog_insert_module() is introduced to avoid using
list_insert() from the vlog.h header.

Signed-off-by: Thomas Graf <tgraf@noironetworks.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-12-15 14:15:19 +01:00
Daniele Di Proietto
33c24cf9f4 timeval: Fix seq memory leak
'timewarp_seq' should be initialized only once, while init_clock() is
called multiple times (once for each clock instance).

Found by valgrind

Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-10-03 15:04:15 -07:00
Alex Wang
74467d5c88 unixctl: Make command description all lowercase.
Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-09-11 13:49:13 -07:00
Jarno Rajahalme
fc4a1204b7 lib/timeval: Use relaxed atomics also when writing on 'slow_path'.
Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-08-29 10:34:53 -07:00
Gurucharan Shetty
4537a423fb timeval: Initialize 'unix_epoch' for Windows correctly.
Till now, we were initializing 'unix_epoch' through time_init().
But if there was a call directly to xgettimeofday(), we would
miss the initialization causing overflows. This commit fixes it
by pre-calculating the value and assigning it globally.

Also add-in a missing return statement.

Reported-by: Alessandro Pilotti <apilotti@cloudbasesolutions.com>
Reported-by: Linda Sun <lsun@vmware.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-07-09 16:30:35 -07:00
Gurucharan Shetty
8661af7986 timeval: Provide a variation for time/warp command.
The new command is of the form 'time/warp LARGE_MSECS MSECS'.
It advances the current monotonic time by LARGE_MSECS. This is done MSECS
at a time in each run of the main thread. This gives other threads
time to run after the clock has been advanced by MSECS.

The old command would continue to work.

Rationale: On Windows, process creation is slower. When we have tests
that run 'ovs-appctl time/warp MSECS' hundreds of times in a for loop,
the time it takes to complete the test increases. This is specially
true for bfd tests. For e.g, the 11 bfd tests would take 3.5 minutes
to complete before this change and now takes a little less than 2 minutes.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-06-13 11:31:17 -07:00
Gurucharan Shetty
2b89438deb timeval: Workaround strftime bug in VS 2013.
Visual Studio 2013's behavior is to crash when 0 is passed as second
argument to strftime.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
2014-05-14 14:45:49 -07:00
Ben Pfaff
3308c69622 timeval: Preserve quiescence across time_poll().
Otherwise ovsrcu_synchronize() busy-waits in its loop because its
poll_block() un-quiesces, causing the global_seqno to increase, which is
what it waits for.

Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
2014-04-28 15:25:48 -07:00
Ben Pfaff
0f2ea84841 ovs-rcu: New library.
RCU allows multiple threads to read objects in parallel without any
performance penalty.  The following commit will introduce the first use.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2014-03-18 16:34:28 -07:00
Gurucharan Shetty
eb1ddf9852 timeval: Sleep instead of poll().
The WSAPoll() function, which is similar to poll() doesnot
simply sleep when the fd array is NULL. So use Sleep() instead.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-03-13 09:18:17 -07:00
Gurucharan Shetty
bae94bc773 timeval: gettimeofday() for Windows.
Use GetSystemTimePreciseAsFileTime() for gettimeofday().
GetSystemTimePreciseAsFileTime() provides the result that is more
high resolution than just the microsecond that gittimeofday() in
Linux provides. So we need to remove some additional precision.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-03-05 08:38:18 -08:00
Gurucharan Shetty
48f8613f26 timeval: clock_gettime() for Windows.
QueryPerformanceCounter() retrieves the current value of the performance
counter, which is a high resolution (<1us) time stamp that can be used for
time-interval measurements. So, use it for MONOTONIC clock.

The GetSystemTimePreciseAsFileTime() function retrieves the current system date
and time with the highest possible level of precision (<1us). Use it for
real time clock. This function returns a counter representing the number of
100-nanosecond intervals since January 1, 1601. To make it compatible with
Linux CLOCK_REALTIME, we need to calculate the 100-nanoseconds counter value
till 01/01/1970.

An upcoming commit implements gettimeofday() using the same clock, so,
carve out a function.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-03-05 08:38:18 -08:00
Gurucharan Shetty
84a6cbae36 fatal-signal: Fatal signal handling for Windows.
Windows does not have a SIGHUP or SIGALRM. It does have
a SIGINT and SIGTERM. The documentation at msdn says that
SIGINT is not supported for win32 applications because
WIN32 operating systems generate a new thread to specifically
handle Ctrl+C.

This commit handles SIGTERM for Windows. The documentation also
states that nothing generates SIGTERM in Windows, but one can
use raise(SIGTERM) to manage it. The idea for handling SIGTERM
for Windows is to just have a place holder if there is need to
raise() a signal for some other purpose.

We use SIGALRM in timeval.c if we wake up from a sleep after
'deadline'. For Windows, print an error message and then
use SIGTERM.

There is an atexit() function for Windows, so we can call cleanup
functions during exit.

An upcoming commit separately handles Ctrl+C so that we can call
clean up functions for that use case.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-02-26 12:34:28 -08:00
Linda Sun
4ca828d713 poll-loop: Port to Windows.
Use WaitForMultipleObjects for polling on windows.  This works on all kinds
of objects, e.g. sockets, files, especially ioctl calls to the kernel.
poll_fd_wait_event() is used if events need to be passed to pollfds.  latch
is signaled with event, to be waited/polled by WaitForMultipleObjects() as
well.  Changed array of fds to hmap to check for duplicate fds.

Signed-off-by: Linda Sun <lsun@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-01-17 16:11:20 -08:00
YAMAMOTO Takashi
ac3c0be096 timeval: Workaround for threaded test failures
BFD tests have the code like the following.

    # wait for a while to stablize everything.
    for i in `seq 0 9`; do ovs-appctl time/warp 500; done

They no longer work as intended because BFD code is run in a
separate monitor thread these days.  The loop merely "warp"
the time by 5000.  The monitor thread should have been woken
at least once, but it's far from "wait for a while to stablize
everything."

This commit mitigates the problem by sleeping a little in the
appctl handler.  This is not ideal but makes BFD tests success
on my environment.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-12-20 07:56:49 -08:00
Ben Pfaff
e2afa7cd68 timeval: Call coverage_clear() before coverage_log() in time_poll().
time_poll() calls log_poll_interval(), which in some circumstances calls
coverage_log().  Before this commit, time_poll() also called
coverage_clear() after log_poll_interval().  This made sense before commit
857165b5fd26 (coverage: Make thread-safe.), because coverage_log() would
log the most recent main loop's coverage counters separately and calling
coverage_clear() beforehand would zero out those counters.  However, it
doesn't make sense any longer because the most recent loop's counters are
no longer separately logged and in fact this practice now means that the
most recent loop's counters are omitted from the logged counters.

Therefore, this commit moves the call to coverage_clear() earlier, so that
the most recent loop's counters are included.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-10-09 17:02:57 -07:00
Alex Wang
53d98a1e9c timeval: Wake up all threads when time is warped.
This commit makes the main thread wake up all other threads when time is
warped.

Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-10-08 17:57:58 -07:00
Alex Wang
98cf638b19 coverage: Reimplement the "ovs-appctl coverage/show" command.
This commit changes the "ovs-appctl coverage/show" command to show the
the averaged per-second rates for the last few seconds, the last minute
and the last hour, and the total counts of all of the coverage counters.

Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-10-01 13:08:46 -07:00
Ben Pfaff
e6249c68a5 timeval: Replace rwlock by mutex.
It's only held briefly now and in general a mutex tends to be preferred for
that case.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-09-13 14:30:33 -07:00
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