From a7b3584745d8e26e70f530ee18ba4e6af7c18ff1 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 7 Jul 2023 22:29:32 -0400 Subject: [PATCH] subsys/zbus: move to timepoint API Remove sys_clock_timeout_end_calc() usage as well as custom _zbus_timeout_remainder(). Signed-off-by: Nicolas Pitre --- include/zephyr/zbus/zbus.h | 1 - subsys/zbus/zbus.c | 25 +++++++++---------------- subsys/zbus/zbus_runtime_observers.c | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/include/zephyr/zbus/zbus.h b/include/zephyr/zbus/zbus.h index 1f294f5543..eba0b13f38 100644 --- a/include/zephyr/zbus/zbus.h +++ b/include/zephyr/zbus/zbus.h @@ -148,7 +148,6 @@ struct zbus_observer { #define ZBUS_REF(_value) &(_value) -k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks); /** @endcond */ /** diff --git a/subsys/zbus/zbus.c b/subsys/zbus/zbus.c index 5357e3439a..7c55e50f43 100644 --- a/subsys/zbus/zbus.c +++ b/subsys/zbus/zbus.c @@ -9,13 +9,6 @@ #include LOG_MODULE_REGISTER(zbus, CONFIG_ZBUS_LOG_LEVEL); -k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks) -{ - int64_t now_ticks = sys_clock_tick_get(); - - return K_TICKS((k_ticks_t)MAX(end_ticks - now_ticks, 0)); -} - #if (CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE > 0) static inline void _zbus_notify_runtime_listeners(const struct zbus_channel *chan) { @@ -34,7 +27,7 @@ static inline void _zbus_notify_runtime_listeners(const struct zbus_channel *cha } static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *chan, - uint64_t end_ticks) + k_timepoint_t end_time) { __ASSERT(chan != NULL, "chan is required"); @@ -47,7 +40,7 @@ static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *ch if (obs_nd->obs->enabled && (obs_nd->obs->queue != NULL)) { err = k_msgq_put(obs_nd->obs->queue, &chan, - _zbus_timeout_remainder(end_ticks)); + sys_timepoint_timeout(end_time)); _ZBUS_ASSERT(err == 0, "could not deliver notification to observer %s. Error code %d", @@ -63,7 +56,7 @@ static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *ch } #endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE */ -static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_ticks) +static int _zbus_notify_observers(const struct zbus_channel *chan, k_timepoint_t end_time) { int last_error = 0, err; /* Notify static listeners */ @@ -80,7 +73,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_ /* Notify static subscribers */ for (const struct zbus_observer *const *obs = chan->observers; *obs != NULL; ++obs) { if ((*obs)->enabled && ((*obs)->queue != NULL)) { - err = k_msgq_put((*obs)->queue, &chan, _zbus_timeout_remainder(end_ticks)); + err = k_msgq_put((*obs)->queue, &chan, sys_timepoint_timeout(end_time)); _ZBUS_ASSERT(err == 0, "could not deliver notification to observer %s.", _ZBUS_OBS_NAME(*obs)); if (err) { @@ -92,7 +85,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_ } #if CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE > 0 - err = _zbus_notify_runtime_subscribers(chan, end_ticks); + err = _zbus_notify_runtime_subscribers(chan, end_time); if (err) { last_error = err; } @@ -103,7 +96,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_ int zbus_chan_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t timeout) { int err; - uint64_t end_ticks = sys_clock_timeout_end_calc(timeout); + k_timepoint_t end_time = sys_timepoint_calc(timeout); _ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs"); _ZBUS_ASSERT(chan != NULL, "chan is required"); @@ -120,7 +113,7 @@ int zbus_chan_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t memcpy(chan->message, msg, chan->message_size); - err = _zbus_notify_observers(chan, end_ticks); + err = _zbus_notify_observers(chan, end_time); k_mutex_unlock(chan->mutex); @@ -148,7 +141,7 @@ int zbus_chan_read(const struct zbus_channel *chan, void *msg, k_timeout_t timeo int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout) { int err; - uint64_t end_ticks = sys_clock_timeout_end_calc(timeout); + k_timepoint_t end_time = sys_timepoint_calc(timeout); _ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs"); _ZBUS_ASSERT(chan != NULL, "chan is required"); @@ -158,7 +151,7 @@ int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout) return err; } - err = _zbus_notify_observers(chan, end_ticks); + err = _zbus_notify_observers(chan, end_time); k_mutex_unlock(chan->mutex); diff --git a/subsys/zbus/zbus_runtime_observers.c b/subsys/zbus/zbus_runtime_observers.c index 8e966e1942..ea4649c385 100644 --- a/subsys/zbus/zbus_runtime_observers.c +++ b/subsys/zbus/zbus_runtime_observers.c @@ -21,7 +21,7 @@ int zbus_chan_add_obs(const struct zbus_channel *chan, const struct zbus_observe { int err; struct zbus_observer_node *obs_nd, *tmp; - uint64_t end_ticks = sys_clock_timeout_end_calc(timeout); + k_timepoint_t end_time = sys_timepoint_calc(timeout); _ZBUS_ASSERT(!k_is_in_isr(), "ISR blocked"); _ZBUS_ASSERT(chan != NULL, "chan is required"); @@ -50,7 +50,7 @@ int zbus_chan_add_obs(const struct zbus_channel *chan, const struct zbus_observe } err = k_mem_slab_alloc(&_zbus_runtime_obs_pool, (void **)&obs_nd, - _zbus_timeout_remainder(end_ticks)); + sys_timepoint_timeout(end_time)); if (err) { LOG_ERR("Could not allocate memory on runtime observers pool\n");