Change in ...libosmocore[master]: fsm: Allow millisecond granularity in osmo_fsm built-in timer
Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/14200 ) Change subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer .. Patch Set 7: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14200 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 Gerrit-Change-Number: 14200 Gerrit-PatchSet: 7 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-Comment-Date: Wed, 05 Jun 2019 10:01:16 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in ...libosmocore[master]: fsm: Allow millisecond granularity in osmo_fsm built-in timer
Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/14200 ) Change subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer .. fsm: Allow millisecond granularity in osmo_fsm built-in timer So far, the public API of osmo_fsm only allowed integral seconds as timeout. Let's change that to milli-seconds in order to cover more use cases. This introduces * osmo_fsm_inst_state_chg_ms() * osmo_fsm_inst_state_chg_keep_or_start_timer_ms() Which both work exactly like their previous counterparts without the _ms suffix - the only difference being that the timeout parameter is specified in milli-seconds, not in seconds. The value range for an unsigned long in milli-seconds even on a 32bit platform extends to about 48 days. This patch also removes the documentation notice about limiting the maximum value to 0x7fff due to time_t signed-ness. We don't use time_t but unsigned long. Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 --- M include/osmocom/core/fsm.h M src/fsm.c 2 files changed, 46 insertions(+), 23 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 41d01a5..1701c45 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -243,6 +243,13 @@ unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T, \ +__FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + /*! perform a state change while keeping the current timer running. * * This is useful to keep a timeout across several states (without having to round the @@ -273,6 +280,14 @@ unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T, \ +__FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + + /*! dispatch an event to an osmocom finite state machine instance * * This is a macro that calls _osmo_fsm_inst_dispatch() with the given diff --git a/src/fsm.c b/src/fsm.c index 411797d..37da9f9 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -1,7 +1,7 @@ /*! \file fsm.c * Osmocom generic Finite State Machine implementation. */ /* - * (C) 2016 by Harald Welte + * (C) 2016-2019 by Harald Welte * * SPDX-License-Identifier: GPL-2.0+ * @@ -584,7 +584,7 @@ } static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, -bool keep_timer, unsigned long timeout_secs, int T, +bool keep_timer, unsigned long timeout_ms, int T, const char *file, int line) { struct osmo_fsm *fsm = fi->fsm; @@ -592,11 +592,6 @@ const struct osmo_fsm_state *st = >states[fi->state]; struct timeval remaining; - /* Limit to 0x7fff seconds as explained by -* _osmo_fsm_inst_state_chg()'s API doc. */ - if (timeout_secs > 0x7fff) - timeout_secs = 0x7fff; - /* validate if new_state is a valid state */ if (!(st->out_state_mask & (1 << new_state))) { LOGPFSMLSRC(fi, LOGL_ERROR, file, line, @@ -627,11 +622,18 @@ "State change to %s (keeping " OSMO_T_FMT ", %ld.%03lds remaining)\n", osmo_fsm_state_name(fsm, new_state), OSMO_T_FMT_ARGS(fi->T), remaining.tv_sec, remaining.tv_usec / 1000); - } else if (timeout_secs) - LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lus)\n", - osmo_fsm_state_name(fsm, new_state), - OSMO_T_FMT_ARGS(T), timeout_secs); - else + } else if (timeout_ms) { + if (timeout_ms % 1000 == 0) { + /* keep log output legacy compatible to avoid autotest failures */ + LOGPFSMSRC(fi, file, line, "State change to %s ("
Change in ...libosmocore[master]: fsm: Allow millisecond granularity in osmo_fsm built-in timer
Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/14200 ) Change subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer .. Set Ready For Review -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14200 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 Gerrit-Change-Number: 14200 Gerrit-PatchSet: 6 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: pespin Gerrit-Comment-Date: Tue, 04 Jun 2019 10:13:10 + Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in libosmocore[master]: fsm: Allow millisecond granularity in osmo_fsm built-in timer
Pau Espin Pedrol has posted comments on this change. ( https://gerrit.osmocom.org/14200 ) Change subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer .. Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/14200 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 Gerrit-Change-Number: 14200 Gerrit-PatchSet: 1 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Pau Espin Pedrol Gerrit-Comment-Date: Mon, 27 May 2019 15:43:45 + Gerrit-HasComments: No Gerrit-HasLabels: Yes
Change in libosmocore[master]: fsm: Allow millisecond granularity in osmo_fsm built-in timer
Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/14200 Change subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer .. fsm: Allow millisecond granularity in osmo_fsm built-in timer So far, the public API of osmo_fsm only allowed integral seconds as timeout. Let's change that to milli-seconds in order to cover more use cases. This introduces * osmo_fsm_inst_state_chg_ms() * osmo_fsm_inst_state_chg_keep_or_start_timer_ms() Which both work exactly like their previous counterparts without the _ms suffix - the only difference being that the timeout parameter is specified in milli-seconds, not in seconds. The value range for an unsigned long in milli-seconds even on a 32bit platform extends to about 48 days. This patch also removes the documentation notice about limiting the maximum value to 0x7fff due to time_t signed-ness. We don't use time_t but unsigned long. Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 --- M include/osmocom/core/fsm.h M src/fsm.c 2 files changed, 37 insertions(+), 21 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/00/14200/1 diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 41d01a5..1701c45 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -243,6 +243,13 @@ unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T, \ +__FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + /*! perform a state change while keeping the current timer running. * * This is useful to keep a timeout across several states (without having to round the @@ -273,6 +280,14 @@ unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T, \ +__FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + + /*! dispatch an event to an osmocom finite state machine instance * * This is a macro that calls _osmo_fsm_inst_dispatch() with the given diff --git a/src/fsm.c b/src/fsm.c index 882a2b4..2d769b8 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -1,7 +1,7 @@ /*! \file fsm.c * Osmocom generic Finite State Machine implementation. */ /* - * (C) 2016 by Harald Welte + * (C) 2016-2019 by Harald Welte * * SPDX-License-Identifier: GPL-2.0+ * @@ -584,7 +584,7 @@ } static int state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, -bool keep_timer, unsigned long timeout_secs, int T, +bool keep_timer, unsigned long timeout_ms, int T, const char *file, int line) { struct osmo_fsm *fsm = fi->fsm; @@ -592,11 +592,6 @@ const struct osmo_fsm_state *st = >states[fi->state]; struct timeval remaining; - /* Limit to 0x7fff seconds as explained by -* _osmo_fsm_inst_state_chg()'s API doc. */ - if (timeout_secs > 0x7fff) - timeout_secs = 0x7fff; - /* validate if new_state is a valid state */ if (!(st->out_state_mask & (1 << new_state))) { LOGPFSMLSRC(fi, LOGL_ERROR, file, line, @@ -627,10 +622,10 @@ "State change to %s (keeping " OSMO_T_FMT ", %ld.%03lds remaining)\n", osmo_fsm_state_name(fsm, new_state), OSMO_T_FMT_ARGS(fi->T), remaining.tv_sec, remaining.tv_usec / 1000); - } else if (timeout_secs) - LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lus)\n", + } else if (timeout_ms) + LOGPFSMSRC(fi, file, line, "State change to %s (" OSMO_T_FMT ", %lums)\n", osmo_fsm_state_name(fsm, new_state), - OSMO_T_FMT_ARGS(T), timeout_secs); + OSMO_T_FMT_ARGS(T), timeout_ms); else LOGPFSMSRC(fi, file, line, "State change to %s (no timeout)\n",