diff options
author | Oliver Smith <osmith@sysmocom.de> | 2021-03-26 10:18:37 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2021-04-07 18:38:54 +0000 |
commit | 61401943473f448917ccab6e67ca75750747c234 (patch) | |
tree | 2f74cc0cb5aaa53782119828af2b40c192f4927a /include/osmocom/core | |
parent | 2d1a9fabcc9fb394fee6a857de797fe802fa4291 (diff) |
stat_item: make value ids item specific
Fix counting of values missed because of FIFO overflow in
osmo_stat_item_get_next(), by assigning a new item value id effectively
as item->value[n + 1].id = item->value[n].id + 1, instead of increasing
a global_value_id that is shared between all items and groups. With
global_value_id, the count of values missed was wrong for one item, as
soon as a new value was added to another item.
This partially reverts b27b352e ("stats: Use a global index for stat
item values") from 2015, right after stats was added to libosmocore. It
was supposed to make multiple readers (reporters) possible, which could
read independently from stat_item (and later added comments explain it
like that). But this remained unused, stats has implemented multiple
reporters by reading all stat_items once and sending the same data to
all enabled reporters. The patch caused last_value_index in struct
osmo_stat_item to always remain at -1.
Replace this unused last_value_index with stats_next_id, so stats can
store the item-specific next_id in the struct again. It appears that
stats is the only direct user of osmo_stat_item, but if there are
others, they can bring their own item-specific next_id: functions in
stat_item.c still accept a next_id argument.
Related: OS#5088
Change-Id: Ie65dcdf52c8fc3d916e20d7f0455f6223be6b64f
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/stat_item.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h index 4a19465f..29e35ef6 100644 --- a/include/osmocom/core/stat_item.h +++ b/include/osmocom/core/stat_item.h @@ -6,6 +6,7 @@ #include <stdint.h> +#include <osmocom/core/defs.h> #include <osmocom/core/linuxlist.h> struct osmo_stat_item_desc; @@ -23,9 +24,11 @@ struct osmo_stat_item_value { struct osmo_stat_item { /*! back-reference to the item description */ const struct osmo_stat_item_desc *desc; - /*! the index of the freshest value */ - int32_t last_value_index; - /*! offset to the freshest value in the value FIFO */ + /* internal use by stats API (stats.c): the id of the next value to + * be read from the FIFO. If accessing osmo_stat_item directly, without + * the stats API, store this value elsewhere. */ + int32_t stats_next_id; + /*! the index of the last value written to the FIFO */ int16_t last_offs; /*! value FIFO */ struct osmo_stat_item_value values[0]; @@ -98,7 +101,8 @@ static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item); int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id); -int osmo_stat_item_discard_all(int32_t *next_id); +int osmo_stat_item_discard_all(int32_t *next_id) + OSMO_DEPRECATED("Use osmo_stat_item_discard with item-specific next_id instead"); typedef int (*osmo_stat_item_handler_t)( struct osmo_stat_item_group *, struct osmo_stat_item *, void *); |