From bafb3734ec857ba9efd509f9a0bfa2328125a066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Lepp=C3=A4nen?= Date: Tue, 5 Dec 2023 18:02:43 +0200 Subject: [PATCH 1/2] api: timer: require an array of timeout events in odp_timer_periodic_start() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With a periodic timer, require application to provide an array of timeout events in odp_timer_periodic_start(). Add a new API function odp_timer_periodic_events(), which returns the number of events. Signed-off-by: Jere Leppänen --- include/odp/api/spec/timer.h | 22 +++++++++++++++++++++- include/odp/api/spec/timer_types.h | 16 ++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/odp/api/spec/timer.h b/include/odp/api/spec/timer.h index c42c5cf5ef..f9410932be 100644 --- a/include/odp/api/spec/timer.h +++ b/include/odp/api/spec/timer.h @@ -310,6 +310,22 @@ int odp_timer_start(odp_timer_t timer, const odp_timer_start_t *start_param); */ int odp_timer_restart(odp_timer_t timer, const odp_timer_start_t *start_param); +/** + * Return the number of timeout events + * + * Returns in start_param.num_tmo_ev the number of events that the application must allocate and + * provide in odp_timer_periodic_start(). Application must set the values of first_tick and + * freq_multiplier in start_param before calling this function, the rest of the parameters are + * ignored. On return, the value of num_tmo_ev is set and the other parameters are not modified. + * + * @param timer_pool Timer pool + * @param start_param Periodic timer start parameters + * + * @retval 0 Success. + * @retval <0 Failure. + */ +int odp_timer_periodic_events(odp_timer_pool_t timer_pool, odp_timer_periodic_start_t *start_param); + /** * Start a periodic timer * @@ -319,6 +335,10 @@ int odp_timer_restart(odp_timer_t timer, const odp_timer_start_t *start_param); * call, the timer remains active until it is cancelled and all its timeout events have been * acknowledged. * + * Before calling this function, odp_timer_periodic_events() must be called to set the value of + * num_tmo_ev in start_param. The application must then allocate as many timeout events in an array, + * and set tmo_ev to point to the array. + * * Timer expiration frequency (period) is defined as a multiple of the timer pool base frequency * (odp_timer_pool_param_t::base_freq_hz). The timeout event type must be ODP_EVENT_TIMEOUT * (odp_timeout_t). @@ -358,7 +378,7 @@ int odp_timer_periodic_start(odp_timer_t timer, const odp_timer_periodic_start_t * indicates timeout events from a cancelled timer. These events may not arrive at the * requested interval, but are used to finalize the timer cancel request. Return value of 2 marks * the last event from a cancelled timer. After receiving it application may free the timer and - * the timeout event. + * the array of timeout events. * * @param timer Periodic timer * @param tmo_ev Timeout event that was received from the periodic timer diff --git a/include/odp/api/spec/timer_types.h b/include/odp/api/spec/timer_types.h index 0fd5d4f70d..ce2972bddd 100644 --- a/include/odp/api/spec/timer_types.h +++ b/include/odp/api/spec/timer_types.h @@ -501,12 +501,20 @@ typedef struct odp_timer_periodic_start_t { */ uint64_t freq_multiplier; - /** Timeout event + /** Number of timeout events * - * This event is enqueued to the destination queue when the timer expires. The event type - * must be ODP_EVENT_TIMEOUT. + * Number of timeout events in the tmo_ev array. This value is set by calling + * odp_timer_periodic_events(). */ - odp_event_t tmo_ev; + uint32_t num_tmo_ev; + + /** Array of timeout events + * + * One of these events is enqueued to the destination queue when the timer expires. The + * event type of the events must be ODP_EVENT_TIMEOUT. The application may free these + * events after receiving a return value of 2 (last event) from odp_timer_periodic_ack(). + */ + odp_event_t *tmo_ev; } odp_timer_periodic_start_t; From 1a415be0ae17553f2b59249b4c2f81ad269e5f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Lepp=C3=A4nen?= Date: Fri, 15 Dec 2023 17:35:03 +0200 Subject: [PATCH 2/2] api: timer: add periodic.max_tmo_events in timer capability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add periodic.max_tmo_events in timer capability. This is the maximum number of timeout events per timer that may be needed. Signed-off-by: Jere Leppänen --- include/odp/api/spec/timer.h | 1 + include/odp/api/spec/timer_types.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/odp/api/spec/timer.h b/include/odp/api/spec/timer.h index f9410932be..33ee252ae4 100644 --- a/include/odp/api/spec/timer.h +++ b/include/odp/api/spec/timer.h @@ -317,6 +317,7 @@ int odp_timer_restart(odp_timer_t timer, const odp_timer_start_t *start_param); * provide in odp_timer_periodic_start(). Application must set the values of first_tick and * freq_multiplier in start_param before calling this function, the rest of the parameters are * ignored. On return, the value of num_tmo_ev is set and the other parameters are not modified. + * The value of num_tmo_ev is less than or equal to periodic.max_tmo_events in timer capability. * * @param timer_pool Timer pool * @param start_param Periodic timer start parameters diff --git a/include/odp/api/spec/timer_types.h b/include/odp/api/spec/timer_types.h index ce2972bddd..c25f6d6f6e 100644 --- a/include/odp/api/spec/timer_types.h +++ b/include/odp/api/spec/timer_types.h @@ -213,6 +213,13 @@ typedef struct { /** Maximum supported base frequency value */ odp_fract_u64_t max_base_freq_hz; + /** Maximum number of timeout events that may be needed + * + * The number of timeout events per timer, as returned by + * odp_timer_periodic_events(), is less than or equal to this value. + */ + uint32_t max_tmo_events; + } periodic; } odp_timer_capability_t;