aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Zakharenko <earwin@gmail.com>2020-05-09 03:08:36 +0300
committerKirill Zakharenko <earwin@gmail.com>2020-05-09 03:08:36 +0300
commit81516355961d55b6007fd4bc0032bb801b49486a (patch)
tree386c1dd635a64b6c2cf9891bf5e945ddd8e033a2
parenta89b22aa22322bf7275194b7d317e955fb1e4bdf (diff)
parent4b3e4dc86674af172e6be24fce843902db77756d (diff)
Merge fairwaves/wip-stats into fairwaves/production
-rw-r--r--include/osmocom/core/stats.h6
-rw-r--r--src/select.c2
-rw-r--r--src/stats.c50
-rw-r--r--src/vty/stats_vty.c2
4 files changed, 41 insertions, 19 deletions
diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h
index 06918477..b9edac2a 100644
--- a/include/osmocom/core/stats.h
+++ b/include/osmocom/core/stats.h
@@ -73,7 +73,7 @@ struct osmo_stats_reporter {
char *bind_addr_str; /*!< local bind IP address */
int dest_port; /*!< destination (UDP) port */
int mtu; /*!< Maximum Transmission Unit */
- int flush_period; /*!< period between regular flushes */
+ unsigned int flush_period; /*!< period between regular flushes */
/*! Maximum class/index to report. FIXME: More details! */
enum osmo_stats_class max_class;
@@ -89,7 +89,7 @@ struct osmo_stats_reporter {
struct msgb *buffer; /*!< message buffer for log output */
int agg_enabled; /*!< is aggregation enabled? */
int force_single_flush; /*!< set to 1 to force a flush (send even unchanged stats values) */
- int flush_period_counter; /*!< count sends between forced flushes */
+ unsigned int flush_period_counter; /*!< count sends between forced flushes */
struct llist_head list;
int (*open)(struct osmo_stats_reporter *srep);
@@ -131,7 +131,7 @@ int osmo_stats_reporter_set_max_class(struct osmo_stats_reporter *srep,
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix);
int osmo_stats_reporter_enable(struct osmo_stats_reporter *srep);
int osmo_stats_reporter_disable(struct osmo_stats_reporter *srep);
-int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, int period);
+int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, unsigned int period);
/* reporter creation */
struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name);
diff --git a/src/select.c b/src/select.c
index 8e312054..774056a9 100644
--- a/src/select.c
+++ b/src/select.c
@@ -334,7 +334,7 @@ int osmo_timerfd_disable(struct osmo_fd *ofd)
return timerfd_settime(ofd->fd, 0, &its_null, NULL);
}
-/*! schedule the osmcoom-wrapped timerfd to occur first at \a first, then periodically at \a interval
+/*! schedule the osmocom-wrapped timerfd to occur first at \a first, then periodically at \a interval
* \param[in] ofd Osmocom wrapped timerfd
* \param[in] first Relative time at which the timer should first execute (NULL = \a interval)
* \param[in] interval Time interval at which subsequent timer shall fire
diff --git a/src/stats.c b/src/stats.c
index 027b2313..8cccf67b 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -85,7 +85,7 @@
#include <osmocom/core/logging.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/stat_item.h>
-#include <osmocom/core/timer.h>
+#include <osmocom/core/select.h>
#include <osmocom/core/counter.h>
#include <osmocom/core/msgb.h>
@@ -102,7 +102,7 @@ static struct osmo_stats_config s_stats_config = {
};
struct osmo_stats_config *osmo_stats_config = &s_stats_config;
-static struct osmo_timer_list osmo_stats_timer;
+static struct osmo_fd osmo_stats_timer = {.fd=-1};
static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep,
const struct rate_ctr_group *ctrg,
@@ -140,23 +140,48 @@ static int update_srep_config(struct osmo_stats_reporter *srep)
return rc;
}
-static void osmo_stats_timer_cb(void *data)
+static int osmo_stats_timer_cb(struct osmo_fd *ofd, unsigned int what)
{
- int interval = osmo_stats_config->interval;
+ uint64_t expire_count;
+ int rc;
+
+ /* check that the timer has actually expired */
+ if (!(what & BSC_FD_READ))
+ return 0;
+
+ /* read from timerfd: number of expirations of periodic timer */
+ rc = read(ofd->fd, (void *) &expire_count, sizeof(expire_count));
+ if (rc < 0 && errno == EAGAIN)
+ return 0;
+ OSMO_ASSERT(rc == sizeof(expire_count));
if (!llist_empty(&osmo_stats_reporter_list))
osmo_stats_report();
- osmo_timer_schedule(&osmo_stats_timer, interval, 0);
+ return 0;
}
static int start_timer()
{
+ int rc;
+ int interval = osmo_stats_config->interval;
+
if (!is_initialised)
return -ESRCH;
- osmo_timer_setup(&osmo_stats_timer, osmo_stats_timer_cb, NULL);
- osmo_timer_schedule(&osmo_stats_timer, 0, 1);
+ struct timespec ts_first = {.tv_sec=0, .tv_nsec=1000};
+ struct timespec ts_interval = {.tv_sec=interval, .tv_nsec=0};
+
+ rc = osmo_timerfd_setup(&osmo_stats_timer, osmo_stats_timer_cb, NULL);
+ if (rc < 0)
+ LOGP(DLSTATS, LOGL_ERROR, "Failed to setup the timer with error code %d (fd=%d)\n",
+ rc, osmo_stats_timer.fd);
+ rc = osmo_timerfd_schedule(&osmo_stats_timer, &ts_first, &ts_interval);
+ if (rc < 0)
+ LOGP(DLSTATS, LOGL_ERROR, "Failed to schedule the timer with error code %d (fd=%d, interval %d sec)\n",
+ rc, osmo_stats_timer.fd, interval);
+
+ LOGP(DLSTATS, LOGL_INFO, "Stats timer started with interval %d sec\n", interval);
return 0;
}
@@ -349,11 +374,8 @@ int osmo_stats_set_interval(int interval)
* \param[in] srep stats_reporter to set flush period for
* \param[in] period Reporting interval in seconds
* \returns 0 on success; negative on error */
-int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, int period)
+int osmo_stats_reporter_set_flush_period(struct osmo_stats_reporter *srep, unsigned int period)
{
- if (period < 0)
- return -EINVAL;
-
srep->flush_period = period;
srep->flush_period_counter = 0;
/* force the flush now if it's not disabled by period=0 */
@@ -733,11 +755,11 @@ static void flush_all_reporters()
srep->force_single_flush = 0;
/* and schedule a new flush if it's time for it */
if (srep->flush_period > 0) {
- if (srep->flush_period_counter == srep->flush_period) {
+ srep->flush_period_counter++;
+ if (srep->flush_period_counter >= srep->flush_period) {
srep->force_single_flush = 1;
srep->flush_period_counter = 0;
- } else
- srep->flush_period_counter++;
+ }
}
}
}
diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index c1ea3dc7..46282817 100644
--- a/src/vty/stats_vty.c
+++ b/src/vty/stats_vty.c
@@ -252,7 +252,7 @@ DEFUN(cfg_stats_reporter_flush_period, cfg_stats_reporter_flush_period_cmd,
"0 to disable regular flush (default), 1 to flush every time, 2 to flush every 2nd time, etc\n")
{
int rc;
- int period = atoi(argv[0]);
+ unsigned int period = atoi(argv[0]);
struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty);
OSMO_ASSERT(srep);