2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-13 14:07:02 +00:00
Files
openvswitch/lib/poll-loop.h
Ben Pfaff f89ffb0e2f poll-loop: Make wakeup logging more portable and easier to understand.
Until now, when the poll_loop module's log level was turned up to "debug",
it would log a backtrace of the call stack for the event that caused poll()
to wake up in poll_block().  This was pretty useful from time to time to
find out why ovs-vswitchd was using more CPU than expected, because we
could find out what was causing it to wake up.

But there were some issues.  One is simply that the backtrace was printed
as a series of hexadecimal numbers, so GDB or another debugger was needed
to translate it into human-readable format.  Compiler optimizations meant
that even the human-readable backtrace wasn't, in my experience, as helpful
as it could have been.  And, of course, one needed to have the binary to
interpret the backtrace.  When the backtrace couldn't be interpreted or
wasn't meaningful, there was essentially nothing to fall back on.

This commit changes the way that "debug" logging for poll_block() wakeups
works.  Instead of logging a backtrace, it logs the source code file name
and line number of the call to a poll_loop function, using __FILE__ and
__LINE__.  This is by itself much more meaningful than a sequence of
hexadecimal numbers, since no additional interpretation is necessary.  It
can be useful even if the Open vSwitch version is only approximately known.

In addition to the file and line, this commit adds, for wakeups caused by
file descriptors, information about the file descriptor itself: what kind
of file it is (regular file, directory, socket, etc.), the name of the file
(on Linux only), and the local and remote endpoints for socket file
descriptors.

Here are a few examples of the new output format:

932-ms timeout at ../ofproto/in-band.c:507
[POLLIN] on fd 20 (192.168.0.20:35388<->192.168.0.3:6633) at ../lib/stream-fd.c:149
[POLLIN] on fd 7 (FIFO pipe:[48049]) at ../lib/fatal-signal.c:168
2011-05-13 14:38:15 -07:00

73 lines
2.6 KiB
C

/*
* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* High-level wrapper around the "poll" system call.
*
* Intended usage is for the program's main loop to go about its business
* servicing whatever events it needs to. Then, when it runs out of immediate
* tasks, it calls each subordinate module's "wait" function, which in turn
* calls one (or more) of the functions poll_fd_wait(), poll_immediate_wake(),
* and poll_timer_wait() to register to be awakened when the appropriate event
* occurs. Then the main loop calls poll_block(), which blocks until one of
* the registered events happens. */
#ifndef POLL_LOOP_H
#define POLL_LOOP_H 1
#include <poll.h>
#include "util.h"
#ifdef __cplusplus
extern "C" {
#endif
struct poll_waiter;
/* Schedule events to wake up the following poll_block().
*
* The poll_loop logs the 'where' argument to each function at "debug" level
* when an event causes a wakeup. Ordinarily, it is automatically filled in
* with the location in the source of the call, and caller should therefore
* omit it. But, if the function you are implementing is very generic, so that
* its location in the source would not be very helpful for debugging, you can
* avoid the macro expansion and pass a different argument, e.g.:
* (poll_fd_wait)(fd, events, where);
* See timer_wait() for an example.
*/
struct poll_waiter *poll_fd_wait(int fd, short int events, const char *where);
#define poll_fd_wait(fd, events) poll_fd_wait(fd, events, SOURCE_LOCATOR)
void poll_timer_wait(long long int msec, const char *where);
#define poll_timer_wait(msec) poll_timer_wait(msec, SOURCE_LOCATOR)
void poll_timer_wait_until(long long int msec, const char *where);
#define poll_timer_wait_until(msec) poll_timer_wait_until(msec, SOURCE_LOCATOR)
void poll_immediate_wake(const char *where);
#define poll_immediate_wake() poll_immediate_wake(SOURCE_LOCATOR)
/* Wait until an event occurs. */
void poll_block(void);
/* Cancel a file descriptor callback or event. */
void poll_cancel(struct poll_waiter *);
#ifdef __cplusplus
}
#endif
#endif /* poll-loop.h */