diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2019-02-21 02:27:48 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2019-03-06 00:51:15 +0100 |
commit | 5734bff3b01da2a7369da07f77ad617c3ac32096 (patch) | |
tree | cd2885915671d2f4dca4ea5b23cbfb7e02ab3b47 /src/fsm.c | |
parent | 8aa691f30b5f6d77ae05e590e5d3426550ee4452 (diff) |
represent negative T-timers as Osmocom-specific X-timers
fi->T values are int, i.e. can be negative. Do not log them as unsigned, but
define a distinct timer class "Xnnnn" for negative T values: i.e. for T == -1,
print "Timeout of X1" instead of "Timeout of T4294967295".
The negative T timer number space is useful to distinguish freely invented
timers from proper 3GPP defined T numbers. So far I was using numbers like
T993210 or T9999 for invented T, but X1, X2 etc. is a better solution. This way
we can make sure to not accidentally define an invented timer number that
actually collides with a proper 3GPP specified timer number that the author was
not aware of at the time of writing.
Add OSMO_T_FMT and OSMO_T_FMT_ARGS() macros as standardized timer number print
format. Use that in fsm.c, tdef_vty.c, and adjust vty tests accordingly.
Mention the two timer classes in various API docs and VTY online-docs.
Change-Id: I3a59457623da9309fbbda235fe18fadd1636bff6
Diffstat (limited to 'src/fsm.c')
-rw-r--r-- | src/fsm.c | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -108,8 +108,8 @@ void osmo_fsm_log_addr(bool log_addr) /*! Enable or disable logging of timeout values for FSM instance state changes. * * By default, state changes are logged by state name only, omitting the timeout. When passing true, each state change - * will also log the T number and the chosen timeout in seconds. osmo_fsm_inst_state_chg_keep_timer() will log remaining - * timeout in millisecond precision. + * will also log the T number (or Osmocom-specific X number) and the chosen timeout in seconds. + * osmo_fsm_inst_state_chg_keep_timer() will log remaining timeout in millisecond precision. * * The default for this is false to reflect legacy behavior. Since various C tests that verify logging output already * existed prior to this option, keeping timeout logging off makes sure that they continue to pass. Particularly, @@ -205,9 +205,9 @@ static void fsm_tmr_cb(void *data) { struct osmo_fsm_inst *fi = data; struct osmo_fsm *fsm = fi->fsm; - uint32_t T = fi->T; + int32_t T = fi->T; - LOGPFSM(fi, "Timeout of T%u\n", fi->T); + LOGPFSM(fi, "Timeout of " OSMO_T_FMT "\n", OSMO_T_FMT_ARGS(fi->T)); if (fsm->timer_cb) { int rc = fsm->timer_cb(fi); @@ -482,13 +482,13 @@ static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, if (fsm_log_timeouts) { if (keep_timer && fi->timer.active && (osmo_timer_remaining(&fi->timer, NULL, &remaining) == 0)) - LOGPFSMSRC(fi, file, line, "State change to %s (keeping T%d, %ld.%03lds remaining)\n", + LOGPFSMSRC(fi, file, line, "State change to %s (keeping " OSMO_T_FMT ", %ld.%03lds remaining)\n", osmo_fsm_state_name(fsm, new_state), - fi->T, remaining.tv_sec, remaining.tv_usec / 1000); + OSMO_T_FMT_ARGS(fi->T), remaining.tv_sec, remaining.tv_usec / 1000); else if (timeout_secs && !keep_timer) - LOGPFSMSRC(fi, file, line, "State change to %s (T%d, %lus)\n", + LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lus)\n", osmo_fsm_state_name(fsm, new_state), - T, timeout_secs); + OSMO_T_FMT_ARGS(T), timeout_secs); else LOGPFSMSRC(fi, file, line, "State change to %s (no timeout)\n", osmo_fsm_state_name(fsm, new_state)); @@ -535,6 +535,10 @@ static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, * timer_cb. If passing timeout_secs == 0, it is recommended to also pass T == * 0, so that fi->T is reset to 0 when no timeout is invoked. * + * Positive values for T are considered to be 3GPP spec compliant and appear in + * logging and VTY as "T1234", while negative values are considered to be + * Osmocom specific timers, represented in logging and VTY as "X1234". + * * See also osmo_tdef_fsm_inst_state_chg() from the osmo_tdef API, which * provides a unified way to configure and apply GSM style Tnnnn timers to FSM * state transitions. @@ -549,7 +553,9 @@ static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, * \param[in] fi FSM instance whose state is to change * \param[in] new_state The new state into which we should change * \param[in] timeout_secs Timeout in seconds (if !=0), maximum-clamped to 2147483647 seconds. - * \param[in] T Timer number (if \ref timeout_secs != 0) + * \param[in] T Timer number, where positive numbers are considered to be 3GPP spec compliant timer numbers and are + * logged as "T1234", while negative numbers are considered Osmocom specific timer numbers logged as + * "X1234". * \param[in] file Calling source file (from osmo_fsm_inst_state_chg macro) * \param[in] line Calling source line (from osmo_fsm_inst_state_chg macro) * \returns 0 on success; negative on error |