From e173d585bb6c70303ba6afeac63b4f80ab577a64 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Wed, 21 Jun 2023 15:11:00 +0200 Subject: [PATCH] wip3: try to switch to timer_settime API. Signed-off-by: Federico Di Pierro --- userspace/falco/stats_writer.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index b5e10351c67..0d974816f58 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -15,7 +15,8 @@ limitations under the License. */ #include -#include +#include +#include #include #include @@ -40,8 +41,8 @@ static void timer_handler(int signum) bool stats_writer::init_ticker(uint32_t interval_msec, std::string &err) { - struct itimerval timer; - struct sigaction handler; + struct itimerspec timer = {}; + struct sigaction handler = {}; memset (&handler, 0, sizeof(handler)); handler.sa_handler = &timer_handler; @@ -51,14 +52,29 @@ bool stats_writer::init_ticker(uint32_t interval_msec, std::string &err) return false; } + timer_t timerid; + struct sigevent sev = {}; + /* Create the timer */ + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGALRM; + sev.sigev_value.sival_ptr = &timerid; + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) { + err = std::string("Could not create periodic timer: ") + strerror(errno); + return false; + } timer.it_value.tv_sec = interval_msec / 1000; - timer.it_value.tv_usec = (interval_msec % 1000) * 1000; + timer.it_value.tv_nsec = (interval_msec % 1000) * 1000 * 1000; timer.it_interval = timer.it_value; - if (setitimer(ITIMER_REAL, &timer, NULL) == -1) - { + + if (timer_settime(timerid, 0, &timer, NULL) == -1) { err = std::string("Could not set up periodic timer: ") + strerror(errno); return false; } + //if (setitimer(ITIMER_REAL, &timer, NULL) == -1) + //{ + // err = std::string("Could not set up periodic timer: ") + strerror(errno); + // return false; + //} return true; }