Loading...
Searching...
No Matches
time_cc.h
Go to the documentation of this file.
/* Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* All Rights Reserved
*
* Author: Neels Hofmeyr <nhofmeyr@sysmocom.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <stdint.h>
#include <osmocom/core/timer.h>
struct osmo_tdef;
struct rate_ctr;
struct osmo_time_cc_cfg {
uint64_t gran_usec;
uint64_t round_threshold_usec;
uint64_t forget_sum_usec;
struct rate_ctr *rate_ctr;
int T_gran;
int T_round_threshold;
int T_forget_sum;
struct osmo_tdef *T_defs;
};
struct osmo_time_cc {
struct osmo_time_cc_cfg cfg;
bool flag_state;
uint64_t total_sum;
struct osmo_timer_list timer;
uint64_t start_time;
uint64_t last_counted_time;
uint64_t sum;
uint64_t reported_sum;
};
void osmo_time_cc_init(struct osmo_time_cc *tc);
void osmo_time_cc_set_flag(struct osmo_time_cc *tc, bool flag);
void osmo_time_cc_cleanup(struct osmo_time_cc *tc);
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.