libosmocore 1.13.1.1-afb4 Osmocom core library

time_cc.h
Go to the documentation of this file.
1
4/* Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
5 *
6 * All Rights Reserved
7 *
8 * Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24#pragma once
25
26#include <stdint.h>
27
28#include <osmocom/core/timer.h>
29
35 struct osmo_tdef;
36 struct rate_ctr;
37
105 struct osmo_time_cc_cfg {
108 uint64_t gran_usec;
111 uint64_t round_threshold_usec;
113 uint64_t forget_sum_usec;
115 struct rate_ctr *rate_ctr;
116
118 int T_gran;
120 int T_round_threshold;
122 int T_forget_sum;
124 struct osmo_tdef *T_defs;
125};
126
158 struct osmo_time_cc {
159 struct osmo_time_cc_cfg cfg;
160
161 bool flag_state;
162
165 uint64_t total_sum;
166
167 struct osmo_timer_list timer;
168
170 uint64_t start_time;
173 uint64_t last_counted_time;
174
177 uint64_t sum;
180 uint64_t reported_sum;
181};
182
183 void osmo_time_cc_init(struct osmo_time_cc *tc);
184 void osmo_time_cc_set_flag(struct osmo_time_cc *tc, bool flag);
185 void osmo_time_cc_cleanup(struct osmo_time_cc *tc);
186
osmo_time_cc_set_flag
void osmo_time_cc_set_flag(struct osmo_time_cc *tc, bool flag)
osmo_time_cc_cleanup
void osmo_time_cc_cleanup(struct osmo_time_cc *tc)
osmo_time_cc_init
void osmo_time_cc_init(struct osmo_time_cc *tc)
osmo_tdef
Define a GSM timer of the form Tnnn, with unit, default value and doc string.
Definition: tdef.h:65
osmo_time_cc_cfg
Configuration for osmo_time_cc.
Definition: time_cc.h:105
osmo_time_cc_cfg::T_forget_sum
int T_forget_sum
Update forget_sum_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:122
osmo_time_cc_cfg::gran_usec
uint64_t gran_usec
Granularity in microseconds: nr of microseconds that one rate_ctr increment represents.
Definition: time_cc.h:108
osmo_time_cc_cfg::rate_ctr
struct rate_ctr * rate_ctr
Rate counter to report to, or NULL to not use it.
Definition: time_cc.h:115
osmo_time_cc_cfg::round_threshold_usec
uint64_t round_threshold_usec
Nr of microseconds above n * gran_usec at which to trigger a counter increment.
Definition: time_cc.h:111
osmo_time_cc_cfg::T_gran
int T_gran
Update gran_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:118
osmo_time_cc_cfg::T_round_threshold
int T_round_threshold
Update round_threshold_usec from this T timer value, or zero to not use any T timer.
Definition: time_cc.h:120
osmo_time_cc_cfg::T_defs
struct osmo_tdef * T_defs
Look up T_gran and T_forget_sum in this list of timers, or NULL to not use any T timers.
Definition: time_cc.h:124
osmo_time_cc_cfg::forget_sum_usec
uint64_t forget_sum_usec
Forget counted sub-gran time after the flag was false for this long.
Definition: time_cc.h:113
osmo_time_cc
Report the cumulative counter of time for which a flag is true as rate counter.
Definition: time_cc.h:158
osmo_time_cc::total_sum
uint64_t total_sum
Overall cumulative sum.
Definition: time_cc.h:165
osmo_time_cc::sum
uint64_t sum
Internal cumulative counter of time that flag_state was true.
Definition: time_cc.h:177
osmo_time_cc::cfg
struct osmo_time_cc_cfg cfg
Definition: time_cc.h:159
osmo_time_cc::last_counted_time
uint64_t last_counted_time
CLOCK_MONOTONIC reading in microseconds, at the time when the osmo_time_cc last evaluated the flag st...
Definition: time_cc.h:173
osmo_time_cc::flag_state
bool flag_state
Definition: time_cc.h:161
osmo_time_cc::timer
struct osmo_timer_list timer
Definition: time_cc.h:167
osmo_time_cc::reported_sum
uint64_t reported_sum
The amount of time that already reported cfg.rate_ctr increments account for.
Definition: time_cc.h:180
osmo_time_cc::start_time
uint64_t start_time
CLOCK_MONOTONIC reading in microseconds, at the time when the osmo_time_cc instance started counting.
Definition: time_cc.h:170
osmo_timer_list
A structure representing a single instance of a timer.
Definition: timer.h:52
rate_ctr
data we keep for each actual value
Definition: rate_ctr.h:29
timer.h
Osmocom timer handling routines.