Commit Graph

38 Commits

Author SHA1 Message Date
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Harald Welte 5eb67c2d66 rate_ctr: Make it safe to call rate_ctr_init() several times
There might be library code that has rate counters, and if the main
program calls rate_ctr_init() a second time, we can skip the second
initialization.

Change-Id: I6f5342a77518599eb5ac9a0f0605917a78fcc387
2021-11-14 20:46:11 +01:00
Pau Espin 09f075fad6 stat,rate_ctr: Allow setting group name and use it at report time
This patch adds a new field "name" to the rate_ctr and osmo_stat_item_group
structs, together with an API to set it. This new field allows for easy
identification of specific group instances when several of them exists,
rather than using a sometimes random/increasing index value.

If set, this name (string) is used instead of the index by the stats
reporter.

The name, if set, is also printed during "show stats" VTY commands.

It's up to the user or application to set up unique or meaningful names
to fullfill one's needs.

WARNING: this commit breaks ABI and possibly creates unexpected behavior
when run with non-rebuilt apps which use the modified structs directly
to get the coutners, or if use the static inline API rate_ctr_inc2().
Existing users of these structs should migrate to use new APIs
introduced in follow-up commits instead of accessing the field directly.

Related: SYS#5456
Change-Id: I0dc510783dd9ae8436dae8005a7b3330e80d36f3
2021-06-05 15:46:27 +00:00
Pau Espin 5fe3de5313 stat,rate_ctr: Introduce new API to get counter at given index
Having this API and forcing apps to use it will allow easily adding new
members to the group structure without having so much impact in users of
this struct.

Related: SYS#5456
Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
2021-06-01 21:06:55 +00:00
Daniel Willmann 26a9539e18 rate_ctr: Add functions to reset rate counter (groups)
Change-Id: If2f806d044cd0fb6929dac44ef8f8a15941ffe9b
Related: SYS#4877
2020-07-17 16:41:31 +00:00
Harald Welte ea8272c3b6 Revert "Print error message if application fails to call rate_ctr_init()"
This reverts commit 9685a48c7b which has
caused massive fall-out among (particularly) unit tests in osmo-{msc,bts,pcu}.

Change-Id: Iede72e86451d94cf678045992cb71f6b1bf16896
2019-05-10 11:52:58 +02:00
Harald Welte 9685a48c7b Print error message if application fails to call rate_ctr_init()
Change-Id: Ie8093b66b7e27cf863d2558fe21b2c6e0f3fcdfd
Closes: OS#3580
2019-05-10 07:09:51 +00:00
Vadim Yanitskiy ed3a3c6f1d src/rate_ctr.c: drop some incorrect \ref references
rate_ctr.c:411: warning: unable to resolve reference
                  to `handle_group' for \ref command
  rate_ctr.c:208: warning: unable to resolve reference
                  to `talloc' for \ref command

Change-Id: I24a80ff6cf11ce0455529515d1ecb9900f0271a8
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy c761044ecb Doxygen: fix documentation of rate_ctr_for_each_counter()
Doxygen was confused by duplicated documentation for both
definition and declaration of rate_ctr_for_each_counter().
Moreover, both variants contained some mistakes.

Let's avoid this duplication and keep the only (corrected) one.

Change-Id: Icca2d4a95bd5f96ae85a86909ec90fb8677cacf3
2019-03-27 08:56:21 +01:00
Max fb6f43ee0c rate_ctr_group_free(): guard against empty or NULL input
Change-Id: I859a91ee4400b3685c05971f8c66bceca6758724
2019-03-19 12:57:10 +00:00
Pau Espin dfc52a1d5e rate_ctr: Improve logging
Previous logic regarding logging of verification and mangling of
rate_ctr groups made it difficult to debug when an issue occurrs.

Change-Id: I992d165cab5ee6ca9b5b7e4a2210a0951954bd34
2018-07-21 08:22:57 +00:00
Neels Hofmeyr 62c43c6969 cosmetic: log: fix typo, clarify msg for rate_ctr name mangling
Change-Id: I9a04d501698f8a3360ef9dcbf04b57c5ac10e63b
2018-04-16 01:07:30 +02:00
Neels Hofmeyr 554f7b8a77 rate_ctr: fix osmo-sgsn DoS: don't return NULL on already used index
Recent patch I563764af1d28043e909234ebb048239125ce6ecd introduced returning
NULL from rate_ctr_group_alloc() when the index passed already exists.

Instead of returning NULL, find an unused group index and use that, adjust the
error message.

In stats_test.c, adjust, and also assert allocated counter group indexes
everywhere.

Rationale:

The original patch causes osmo-sgsn to crash as soon as the second subscriber
attempts to establish an MM context. Of course osmo-sgsn is wrong to a) fail to
check a NULL return value and crash and b) to fail to allocate an MM context
just because the rate counter group could not be allocated (it still rejects
the MM context completely if rate_ctr_group_alloc() fails).

Nevertheless, the price we pay for rate counter correctness is, at least in
this instance, way too high: osmo-sgsn becomes completely unusable for more
than one subscriber.

Numerous other places exist where rate_ctr_group_alloc() is called with a
constant index number; from a quick grep magic I found these possible breaking
points:

osmo-sgsn/src/gprs/gb_proxy.c:1431:     cfg->ctrg = rate_ctr_group_alloc(tall_bsc_ctx, &global_ctrg_desc, 0);
osmo-sgsn/src/gprs/gprs_sgsn.c:139:     sgsn->rate_ctrs = rate_ctr_group_alloc(tall_bsc_ctx, &sgsn_ctrg_desc, 0);
osmo-sgsn/src/gprs/gprs_sgsn.c:270:     ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, 0);
osmo-sgsn/src/gprs/gtphub.c:888:        b->counters_io = rate_ctr_group_alloc(osmo_gtphub_ctx,
                                                                              &gtphub_ctrg_io_desc, 0);
osmo-bsc/src/libfilter/bsc_msg_acc.c:87:        lst->stats = rate_ctr_group_alloc(lst, &bsc_cfg_acc_list_desc, 0);
osmo-pcu/src/bts.cpp:228:               m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:793:       tbf->m_ctrs = rate_ctr_group_alloc(tbf, &tbf_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:879:       tbf->m_ul_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_egprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:880:       tbf->m_ul_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_ul_gprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:970:               tbf->m_dl_egprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_egprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:977:               tbf->m_dl_gprs_ctrs = rate_ctr_group_alloc(tbf, &tbf_dl_gprs_ctrg_desc, 0);
osmo-pcu/src/tbf.cpp:1475:      ul_tbf->m_ctrs = rate_ctr_group_alloc(ul_tbf, &tbf_ctrg_desc, 0);
osmo-pcu/src/bts.cpp:226:               m_ratectrs = rate_ctr_group_alloc(tall_pcu_ctx, &bts_ctrg_desc, 1);

We can fix all of these callers and then reconsider returning NULL, but IMO
even into the future, rate counter group indexes are not something worth
failing to provide service for. For future bugs we should keep the automatic
index picking in case of index collisions. We will get an error message barfed
and can fix the issue in our own time, while the application remains completely
usable, and even the rate counters can still be queried (at wrong indexes, but
life is tough).

Related: I49aa95b610f2faec52dede2e4816da47ca1dfb14 (osmo-sgsn's segfault)
Change-Id: Iba6e41b8eeaea5ff6ed862bab3f34a62ab976914
2017-12-20 01:29:59 +01:00
Harald Welte d589f1dcfd rate_ctr: print proper error message if rate_ctr already exists
Change-Id: I86b7ccb0931f5a2a489bb8c7c6aee0894a126eb8
2017-12-18 17:15:02 +01:00
Max 3ef14a241a Do not allocate already existing counter group
Check that no group with the given name and index already exist before
allocating it. Add corresponding test case.

Change-Id: I563764af1d28043e909234ebb048239125ce6ecd
Related: OS#2757
2017-12-17 20:12:34 +00:00
Neels Hofmeyr 10ee73a7b3 rate_ctr: fix mem leak for mangled desc
Using the NULL context creates mem leaks that bother sanitizer builds.
Allocate as talloc "child" of the rate_ctr_group, so that the mangled desc (if
any) gets freed when the rate_ctr group is freed.

Remove the comment concerning osmo-msc: the way to fix the unexpected talloc
state in osmo-msc tests is to have no invalid rate counter names in osmo-msc.
See Ib1db8e3dc6c833174f1b0b1ca051b0861f477408 (osmo-msc).

Change-Id: Ief9abfeb78b7706200bcc6aaa5dcb04fbeaa9b5b
2017-11-20 16:21:44 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Harald Welte b48e82ca9e rate_ctr: Fix null pointer dereference in error path
In Change-Id Ifc6ac824f5dae9a848bb4a5d067c64a69eb40b56 we introduced
a variable de-reference before we check if it's NULL.

Let's reorder the statements to avoid this.

Fixes: Coverity CID#178219
Change-Id: I99265a7ee76f85c479543c19ce8c05ce5d43ae69
2017-10-24 16:46:33 +00:00
Harald Welte ae510dc4a7 rate_ctr: Enforce counter (and ctr_group) names are valid identifiers
As rate counters are automatically exposed on the CTRL interface,
we need to make sure they don't contain special characters such as '.'
which are not permitted/supported by CTRL.

In order to be able to run old versions of osmocom programs with
libosmocore versions after this commit, we introduce some special
name mangling:  Any '.' in the names are replaced with ':' during
counter group registration, if valid identifiers can be obtained
this way.

Change-Id: Ifc6ac824f5dae9a848bb4a5d067c64a69eb40b56
2017-10-24 16:00:45 +00:00
Harald Welte 53de0d3169 [doc] rate_ctr: Extend Doxygen API documentation with human-readable text on its use
Change-Id: If9abd46e1b0ebb6114522418fd3b45c1d802968a
2017-10-16 14:19:03 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Pablo Neira Ayuso 44f423f117 timer: add osmo_timer_setup()
Add a new function timer function to set up the timer, similar to what
we have in the Linux kernel. This patch also converts existing opencoded
timer setup in the libosmocore tree as initial client of this new
function.

This patch implicitly removes function callback passed by reference that
defeat compile time type validation.

Compile-tested only, but I ran make check that reports success when
testing timer infrastructure.

Change-Id: I2fa49972ecaab3748b25168b26d92034e9145666
2017-05-09 12:10:51 +02:00
Harald Welte 2d2e2cca0d Update doxygen annotations in libosmocore
This adds and improves doxygen API descriptions all over libosmocore,
reducing the 'white spots' that don't have any documentation.
2016-05-05 18:49:27 +02:00
Jacob Erlbeck ee702cd590 stats: Add TODO comment to rate_ctr
Currently the counters are scanned twice, once for interval
computation and once for reporting.

This adds a reminder to move the interval computation code to a
special stats reporter which just shall update the fields.

Sponsored-by: On-Waves ehf
2015-11-26 12:53:12 +01:00
Jacob Erlbeck 423c1e5a4f core: Extend rate_ctr by helper functions
For global value reporting, some additional helper functions are
needed. The statsd protocol expects differential counter values,
which are currently not provided by rate_ctr (except for s/m/h/d
intervals).

This commit adds several helper functions to rate_ctr:

- rate_ctr_difference  returns the counter delta since the last
                       call to this function for a given counter
- rate_ctr_for_each_counter
                       iterates through each counter of a group
- rate_ctr_for_each_group
                       iterates through all globally registered
                       counter groups

Note that the rate_ctr_difference function can only be used by a
single backend, since it modifies the 'previous' field in the
rate_ctr obj.

Sponsored-by: On-Waves ehf
2015-10-28 23:51:24 +01:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00
Harald Welte 9327c6dc0f doxygen: Add docs for rate_ctr 2011-08-17 17:14:12 +02:00
Pablo Neira Ayuso 0b21c1c885 timer: use namespace prefix osmo_timer*
Summary of changes:

s/struct timer_list/struct osmo_timer_list/g
s/bsc_add_timer/osmo_timer_add/g
s/bsc_schedule_timer/osmo_timer_schedule/g
s/bsc_del_timer/osmo_timer_del/g
s/bsc_timer_pending/osmo_timer_pending/g
s/bsc_nearest_timer/osmo_timers_nearest/g
s/bsc_prepare_timers/osmo_timers_prepare/g
s/bsc_update_timers/osmo_timers_update/g
s/bsc_timer_check/osmo_timers_check/g
2011-05-07 13:00:51 +02:00
Holger Hans Peter Freyther a9f526a1ab stats: Fix the compiler warnings
Do not remove the const, include strings.h for strcmp
2011-04-18 16:46:35 +02:00
Daniel Willmann 2d42ddeba3 Add functions to search for rate counters by name
* rate_ctr_get_group_by_name_idx, rate_ctr_get_by_name
2011-04-09 20:52:12 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00
Holger Hans Peter Freyther 4f4b0101c4 rate_ctr: No need to include the inttypes.h
There should not be any u_int*_t types in this file, no need
to include this file. It is breaking compilation with the last
x86 build of GNU ARM for GCC 3.4.
2010-12-20 13:38:22 +01:00
Harald Welte d2dce6df04 [rate_ctr] always 'overflow' in next larger inetrval when interval ends
If a second ends, we add the number of events in that just-ended second
to the number of events in the currently running minute.  The same happens
at the end of a minute: We add the number of events in that just-ended
minute into the number of events of the still-running hour, etc.

This gives a much more meaningful numbers and we don't end up with
"12 events per second, but 0 events per minute" kind of situations
anymore.
2010-05-13 13:28:12 +02:00
Harald Welte dd178b2dc9 rate_counters: Remove group-name-sprintf-with-idx string 2010-05-13 12:50:44 +02:00
Harald Welte 087fcff9a5 rate_ctr: Store the numeric index as part of 'rate_ctr_group' 2010-05-13 12:16:17 +02:00
Harald Welte 7b45d60887 Add new 'rate counter' implementation to libosmocore
A 'rate counter' is a counter that counts events but also keeps
track of the rate of events (per second, minute, hour and day).

'rate counters' are generally abstracted in 'rate counter groups',
which are instances of a 'rate counter group description'.  This
way we can have e.g. a description describing what kind of counters
a BTS (or TRX) has - and we can then create one instance of that
group for every BTS or TRX that exists.
2010-05-13 11:35:30 +02:00