EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_timer_types.h
1/*
2 * Copyright (c) 2017-2026, Nokia Solutions and Networks
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef EM_TIMER_TYPES_H_
31#define EM_TIMER_TYPES_H_
32
33#include <stdatomic.h>
34#include <stdbool.h>
35#include <stdint.h>
36
37#include <odp_api.h>
38
39#include <event_machine.h>
40
41#include "em_timer_conf.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/* ODP >= 1.50 has the new periodic timer API with odp_timer_periodic_alloc() etc. */
48#define PRE_1_50_ODP_TIMER_API \
49 (ODP_VERSION_API_NUM(1, 50, 0) > ODP_VERSION_API)
50
51/* per timer (ODP timer pool) */
52typedef struct event_timer_t {
53 odp_timer_pool_t odp_tmr_pool;
54 odp_pool_t tmo_pool;
55 em_timer_flag_t flags;
56 int idx;
57 int plain_q_ok;
58 bool is_ring;
59 uint32_t num_ring_reserve;
60 uint32_t num_tmo_reserve;
62
63/* Timer */
64typedef struct {
65 /* locks handling of these values */
66 odp_ticketlock_t timer_lock;
67 /* shared tmo pool if used */
68 odp_pool_t shared_tmo_pool;
69 /* odp timeout event pool for ring timers */
70 odp_pool_t ring_tmo_pool;
71 /* counter for shared pool mgmt */
72 uint32_t num_rings;
73 /* all timers count for cleanup */
74 uint32_t num_timers;
75 /* how many events reserved by ring timers so far */
76 uint32_t ring_reserved;
77 /* how many tmos reserved by timers so far */
78 uint32_t reserved;
79 /* how many times em_timer_ring_create() has been called, incremented only */
80 uint32_t num_ring_create_calls;
81 /* to verify that the timer data has been initialized before use */
82 uint32_t init_check;
83 /* event timers */
84 event_timer_t timer[EM_ODP_MAX_TIMERS];
86
87/* EM timeout handle points to this. Holds the timer state.
88 * Some values are copies from e.g. timer data for faster access.
89 */
90typedef struct em_timer_timeout_t {
91 odp_atomic_u32_t state; /* timeout state */
92 uint64_t period; /* for periodic */
93 uint64_t last_tick; /* for periodic */
94 em_tmo_flag_t flags; /* oneshot/periodic etc */
95 bool is_ring; /* ring or normal timer */
96 em_queue_t queue; /* destination queue */
97 odp_timer_t odp_timer; /* odp timer / em tmo */
98 odp_timer_pool_t odp_timer_pool;/* odp timer_pool <- em timer */
99 odp_buffer_t odp_buffer; /* this data is in odp buffer */
100 /* 2nd cache line: */
101 em_timer_t timer; /* related timer (can't lookup from odp timer pool) */
102 odp_pool_t ring_tmo_pool; /* if ring: this is the pool for odp timeout event */
103 odp_event_t odp_timeout; /* if ring: this is the pre-allocated odp timeout event */
104#if !PRE_1_50_ODP_TIMER_API
105 const void *user_ptr; /* user pointer, needed for deferred periodic alloc */
106 uint64_t multiplier; /* ring: current freq multiplier (0 = not yet allocated) */
107 em_fract_u64_t freq_hz; /* ring freq: current frequency */
108#endif
109 em_tmo_stats_t stats; /* per tmo statistics */
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* EM_TIMER_TYPES_H_ */