Don't use CLOCK_*_COARSE

These constants aren't available on the routers, so we have to live with
more precise timers.
parent 17bf3523
Pipeline #2021 passed with stage
in 1 minute and 14 seconds
......@@ -96,7 +96,7 @@ Flows Dissector::timeouts() {
std::lock_guard<std::mutex> guard(mutex);
result.swap(delayed);
}
uint64_t now = timeMsec(CLOCK_MONOTONIC_COARSE);
uint64_t now = timeMsec(CLOCK_MONOTONIC);
uint64_t ttlActive = now + inactivityTime;
// Move them to the back of the LRU and reset their TTL
for (const auto &f: result) {
......
......@@ -83,7 +83,7 @@ typedef std::lock_guard<std::mutex> MuxGuard;
FID::FID(uint64_t curtime) :
ctime(curtime),
rtime(timeGrab(CLOCK_MONOTONIC_COARSE)),
rtime(timeGrab(CLOCK_MONOTONIC)),
tid(std::this_thread::get_id()),
seq(fid_ord ++)
{ }
......
......@@ -113,7 +113,7 @@ bool NFQ::process() {
}
LOG(TRACE, "Received ", result, " packets");
timestamp = timeMsec();
timestamp_monotonic = timeMsec(CLOCK_MONOTONIC_COARSE);
timestamp_monotonic = timeMsec(CLOCK_MONOTONIC);
std::vector<std::unique_ptr<char[]>> bigPktBuff; // Buffer to copy big packets into and fill with zeroes
// Process the received messages and convert them to packets
for (int i = 0; i < result; i ++) {
......
......@@ -197,13 +197,13 @@ void Report::processFlows() {
CHECK(epoll_ctl(epollfd, EPOLL_CTL_ADD, it->fd(), &fds.back().event) != -1);
}
size_t active_count(fds.size());
uint64_t now = timeMsec(CLOCK_MONOTONIC_COARSE);
uint64_t now = timeMsec(CLOCK_MONOTONIC);
uint64_t end = now + 3000; // We provide 3 seconds to send everything
while (active_count > 0 && end >= now) {
const size_t max_events = 10;
struct epoll_event events[max_events];
int result = epoll_wait(epollfd, events, max_events, end - now);
now = timeMsec(CLOCK_MONOTONIC_COARSE);
now = timeMsec(CLOCK_MONOTONIC);
if (result == -1) {
CHECK(errno == EINTR);
result = 0;
......
......@@ -54,7 +54,7 @@ struct SPE::TaskHolder {
SPE::SPE(const SPE::Task &wakeup, const Procedure &periodic) :
periodic(periodic),
lastPeriodic(timeMsec(CLOCK_MONOTONIC_COARSE)),
lastPeriodic(timeMsec(CLOCK_MONOTONIC)),
epoll_fd(epoll_create(42)) /* 42 is arbitrary number; man says to pass any positive number that is ignored. */
{
TRC;
......@@ -114,7 +114,7 @@ void SPE::dropTask(const SPE::TaskHolder *holder) {
int SPE::timeoutCompute() const {
if (!periodic) // Nothing to run, don't wake
return -1;
uint64_t now = timeMsec(CLOCK_MONOTONIC_COARSE);
uint64_t now = timeMsec(CLOCK_MONOTONIC);
if (now >= lastPeriodic + periodicInterval) // The time is up, wake up imediatelly
return 0;
return lastPeriodic + periodicInterval - now;
......@@ -149,7 +149,7 @@ void SPE::run() {
}
// Run the periodic task, if the time is up and there's one
if (periodic) {
uint64_t now = timeMsec(CLOCK_MONOTONIC_COARSE);
uint64_t now = timeMsec(CLOCK_MONOTONIC);
if (now >= lastPeriodic + periodicInterval) {
lastPeriodic = now;
periodic();
......
......@@ -222,9 +222,9 @@ template<class ...Msgs> void log(LogLevel level, const char *file, size_t line,
#define TRC LOG(TRACE, "Passing here")
// Time in seconds
uint64_t timeGrab(clockid_t id = CLOCK_REALTIME_COARSE);
uint64_t timeGrab(clockid_t id = CLOCK_REALTIME);
// Time in msec
uint64_t timeMsec(clockid_t id = CLOCK_REALTIME_COARSE);
uint64_t timeMsec(clockid_t id = CLOCK_REALTIME);
bool inValgrind();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment