2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00
ovs/lib/timer.h

75 lines
1.8 KiB
C
Raw Normal View History

/*
* Copyright (c) 2011, 2013 Nicira, Inc.
*
* 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.
*/
#ifndef TIMER_H
#define TIMER_H 1
#include <stdbool.h>
#include "timeval.h"
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 13:06:49 -07:00
#include "util.h"
struct timer {
long long int t;
};
long long int timer_msecs_until_expired(const struct timer *);
void timer_wait_at(const struct timer *, const char *where);
#define timer_wait(timer) timer_wait_at(timer, OVS_SOURCE_LOCATOR)
/* Causes 'timer' to expire when 'duration' milliseconds have passed.
*
* May be used to initialize 'timer'. */
static inline void
timer_set_duration(struct timer *timer, long long int duration)
{
timer->t = time_msec() + duration;
}
/* Causes 'timer' never to expire.
*
* May be used to initialize 'timer'. */
static inline void
timer_set_infinite(struct timer *timer)
{
timer->t = LLONG_MAX;
}
/* Causes 'timer' to expire immediately.
*
* May be used to initialize 'timer'. */
static inline void
timer_set_expired(struct timer *timer)
{
timer->t = LLONG_MIN;
}
/* True if 'timer' has expired. */
static inline bool
timer_expired(const struct timer *timer)
{
return time_msec() >= timer->t;
}
/* Returns ture if 'timer' will never expire. */
static inline bool
timer_is_infinite(const struct timer *timer)
{
return timer->t == LLONG_MAX;
}
#endif /* timer.h */