Skip to content

Commit 1770cf2

Browse files
committed
abi: time: change odp_time_t abi type to uint64_t
Change odp_time_t ABI type from struct to uint64_t, which makes the time API implementation simpler. The change triggered a couple false positive 'maybe-uninitialized' warnings. Signed-off-by: Matias Elo <matias.elo@nokia.com>
1 parent 7d1695e commit 1770cf2

11 files changed

Lines changed: 50 additions & 84 deletions

File tree

include/odp/api/abi-default/time_types.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,13 @@
1111
extern "C" {
1212
#endif
1313

14-
/**
15-
* @internal Time structure used for both POSIX timespec and HW counter
16-
* implementations.
17-
*/
18-
struct odp_time_s {
19-
/** @internal Variant mappings for time type */
20-
union {
21-
/** @internal Used with generic 64 bit operations */
22-
uint64_t u64;
23-
24-
/** @internal Nanoseconds */
25-
uint64_t nsec;
26-
27-
/** @internal HW timer counter value */
28-
uint64_t count;
29-
30-
};
31-
};
32-
3314
/** @addtogroup odp_time
3415
* @{
3516
**/
3617

37-
typedef struct odp_time_s odp_time_t;
18+
typedef uint64_t odp_time_t;
3819

39-
#define ODP_TIME_NULL ((odp_time_t){.u64 = 0})
20+
#define ODP_TIME_NULL ((odp_time_t)0)
4021

4122
/**
4223
* @}

platform/linux-generic/arch/common/odp/api/abi/time_cpu_inlines.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: BSD-3-Clause
22
* Copyright (c) 2013-2018 Linaro Limited
3-
* Copyright (c) 2020-2023 Nokia
3+
* Copyright (c) 2020-2026 Nokia
44
*/
55

66
#ifndef ODP_ARCH_TIME_CPU_INLINES_H_
@@ -20,34 +20,38 @@ extern "C" {
2020

2121
typedef struct _odp_time_global_t {
2222
uint64_t freq_hz;
23-
uint64_t start_time;
23+
odp_time_t start_time;
2424
uint64_t start_time_ns;
2525

2626
} _odp_time_global_t;
2727

2828
extern _odp_time_global_t _odp_time_glob;
2929

30-
static inline odp_time_t _odp_time_cur(void)
30+
static inline uint64_t _odp_time_to_u64(odp_time_t time)
3131
{
32-
odp_time_t time;
32+
return (uint64_t)time;
33+
}
3334

34-
time.count = _odp_time_cpu_global();
35-
return time;
35+
static inline odp_time_t _odp_time_from_u64(uint64_t val)
36+
{
37+
return (odp_time_t)val;
3638
}
3739

38-
static inline odp_time_t _odp_time_cur_strict(void)
40+
static inline odp_time_t _odp_time_cur(void)
3941
{
40-
odp_time_t time;
42+
return _odp_time_from_u64(_odp_time_cpu_global());
43+
}
4144

42-
time.count = _odp_time_cpu_global_strict();
43-
return time;
45+
static inline odp_time_t _odp_time_cur_strict(void)
46+
{
47+
return _odp_time_from_u64(_odp_time_cpu_global_strict());
4448
}
4549

4650
static inline uint64_t _odp_time_to_ns(odp_time_t time)
4751
{
4852
uint64_t nsec;
4953
uint64_t freq_hz = _odp_time_glob.freq_hz;
50-
uint64_t count = time.count;
54+
uint64_t count = _odp_time_to_u64(time);
5155
uint64_t sec = 0;
5256

5357
if (count >= freq_hz) {
@@ -62,7 +66,6 @@ static inline uint64_t _odp_time_to_ns(odp_time_t time)
6266

6367
static inline odp_time_t _odp_time_from_ns(uint64_t ns)
6468
{
65-
odp_time_t time;
6669
uint64_t count;
6770
uint64_t freq_hz = _odp_time_glob.freq_hz;
6871
uint64_t sec = 0;
@@ -75,9 +78,7 @@ static inline odp_time_t _odp_time_from_ns(uint64_t ns)
7578
count = sec * freq_hz;
7679
count += (ns * freq_hz) / ODP_TIME_SEC_IN_NS;
7780

78-
time.count = count;
79-
80-
return time;
81+
return _odp_time_from_u64(count);
8182
}
8283

8384
static inline uint64_t _odp_time_res(void)
@@ -87,8 +88,8 @@ static inline uint64_t _odp_time_res(void)
8788

8889
static inline void _odp_time_startup(odp_time_startup_t *startup)
8990
{
90-
startup->global.count = _odp_time_glob.start_time;
91-
startup->global_ns = _odp_time_glob.start_time_ns;
91+
startup->global = _odp_time_glob.start_time;
92+
startup->global_ns = _odp_time_glob.start_time_ns;
9293
}
9394

9495
#ifdef __cplusplus

platform/linux-generic/arch/common/odp_time_cpu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ _odp_time_global_t _odp_time_glob;
2626
int _odp_time_init_global(void)
2727
{
2828
uint64_t count, diff, years;
29-
odp_time_t time;
3029
_odp_time_global_t *global = &_odp_time_glob;
3130

3231
memset(global, 0, sizeof(_odp_time_global_t));
@@ -41,9 +40,8 @@ int _odp_time_init_global(void)
4140
_ODP_PRINT("HW time counter freq: %" PRIu64 " hz\n\n", global->freq_hz);
4241

4342
count = _odp_time_cpu_global();
44-
time.count = count;
45-
global->start_time = count;
46-
global->start_time_ns = _odp_time_to_ns(time);
43+
global->start_time = _odp_time_from_u64(count);
44+
global->start_time_ns = _odp_time_to_ns(global->start_time);
4745

4846
/* Make sure that counters will not wrap */
4947
diff = UINT64_MAX - count;

platform/linux-generic/arch/default/odp/api/abi/time_inlines.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@ static inline odp_time_t _odp_time_cur_strict(void)
2727

2828
static inline uint64_t _odp_time_to_ns(odp_time_t time)
2929
{
30-
return time.nsec;
30+
return (uint64_t)time;
3131
}
3232

3333
static inline odp_time_t _odp_time_from_ns(uint64_t ns)
3434
{
35-
odp_time_t time;
35+
return (odp_time_t)ns;
36+
}
3637

37-
time.nsec = ns;
38+
static inline uint64_t _odp_time_to_u64(odp_time_t time)
39+
{
40+
return (uint64_t)time;
41+
}
3842

39-
return time;
43+
static inline odp_time_t _odp_time_from_u64(uint64_t val)
44+
{
45+
return (odp_time_t)val;
4046
}
4147

4248
#ifdef __cplusplus

platform/linux-generic/arch/default/odp_time.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@ static inline uint64_t time_nsec(struct timespec *t)
4141
odp_time_t _odp_time_cur(void)
4242
{
4343
int ret;
44-
odp_time_t time;
4544
struct timespec sys_time;
4645

4746
ret = clock_gettime(CLOCK_MONOTONIC_RAW, &sys_time);
4847
if (odp_unlikely(ret != 0))
4948
_ODP_ABORT("clock_gettime() failed\n");
5049

51-
time.nsec = time_nsec(&sys_time);
52-
53-
return time;
50+
return _odp_time_from_u64(time_nsec(&sys_time));
5451
}
5552

5653
uint64_t _odp_time_res(void)
@@ -67,8 +64,8 @@ uint64_t _odp_time_res(void)
6764

6865
void _odp_time_startup(odp_time_startup_t *startup)
6966
{
70-
startup->global.nsec = _odp_time_glob.start_time_ns;
71-
startup->global_ns = _odp_time_glob.start_time_ns;
67+
startup->global = _odp_time_from_u64(_odp_time_glob.start_time_ns);
68+
startup->global_ns = _odp_time_glob.start_time_ns;
7269
}
7370

7471
#include <odp/visibility_end.h>

platform/linux-generic/include/odp/api/plat/time_inlines.h

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,49 +100,33 @@ _ODP_INLINE uint64_t odp_time_to_ns(odp_time_t time)
100100

101101
_ODP_INLINE int odp_time_cmp(odp_time_t t2, odp_time_t t1)
102102
{
103-
if (odp_likely(t2.u64 > t1.u64))
103+
if (odp_likely(t2 > t1))
104104
return 1;
105105

106-
if (t2.u64 < t1.u64)
106+
if (t2 < t1)
107107
return -1;
108108

109109
return 0;
110110
}
111111

112112
_ODP_INLINE odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1)
113113
{
114-
odp_time_t time;
115-
116-
time.u64 = t2.u64 - t1.u64;
117-
118-
return time;
114+
return t2 - t1;
119115
}
120116

121117
_ODP_INLINE uint64_t odp_time_diff_ns(odp_time_t t2, odp_time_t t1)
122118
{
123-
odp_time_t time;
124-
125-
time.u64 = t2.u64 - t1.u64;
126-
127-
return odp_time_to_ns(time);
119+
return odp_time_to_ns(t2 - t1);
128120
}
129121

130122
_ODP_INLINE odp_time_t odp_time_add_ns(odp_time_t time, uint64_t ns)
131123
{
132-
odp_time_t t = _odp_time_from_ns(ns);
133-
134-
t.u64 += time.u64;
135-
136-
return t;
124+
return time + _odp_time_from_ns(ns);
137125
}
138126

139127
_ODP_INLINE odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
140128
{
141-
odp_time_t time;
142-
143-
time.u64 = t1.u64 + t2.u64;
144-
145-
return time;
129+
return t1 + t2;
146130
}
147131

148132
_ODP_INLINE odp_time_t odp_time_local_from_ns(uint64_t ns)

platform/linux-generic/include/odp_packet_io_internal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "C" {
2424
#include <odp/api/time.h>
2525

2626
#include <odp/api/plat/packet_io_inlines.h>
27+
#include <odp/api/plat/time_inlines.h>
2728

2829
#include <odp/autoheader_internal.h>
2930
#include <odp_classification_datamodel.h>
@@ -294,9 +295,7 @@ static inline int _odp_pktio_tx_aging_enabled(pktio_entry_t *entry)
294295

295296
static inline void _odp_pktio_tx_ts_set(pktio_entry_t *entry)
296297
{
297-
odp_time_t ts_val = odp_time_global();
298-
299-
odp_atomic_store_u64(&entry->tx_ts, ts_val.u64);
298+
odp_atomic_store_u64(&entry->tx_ts, _odp_time_to_u64(odp_time_global()));
300299
}
301300

302301
extern const pktio_if_ops_t _odp_dpdk_pktio_ops;

platform/linux-generic/odp_packet_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,7 +2604,7 @@ int odp_pktin_recv_mq_tmo(const odp_pktin_queue_t queues[], uint32_t num_q, uint
26042604
{
26052605
uint32_t i;
26062606
int ret;
2607-
odp_time_t t1, t2;
2607+
odp_time_t t1 = ODP_TIME_NULL, t2;
26082608
struct timespec ts;
26092609
int started = 0;
26102610
uint64_t sleep_round = 0;
@@ -2833,7 +2833,7 @@ int odp_pktout_ts_read(odp_pktio_t hdl, odp_time_t *ts)
28332833
if (odp_unlikely(ts_val == 0))
28342834
return 1;
28352835

2836-
ts->u64 = ts_val;
2836+
*ts = _odp_time_from_u64(ts_val);
28372837
return 0;
28382838
}
28392839

platform/linux-generic/odp_pcapng.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <odp/api/plat/packet_inlines.h>
1717
#include <odp/api/plat/packet_io_inlines.h>
18+
#include <odp/api/plat/time_inlines.h>
1819

1920
#include <odp_config_internal.h>
2021
#include <odp_global_data.h>
@@ -564,9 +565,8 @@ int _odp_pcapng_dump_pkts(pktio_entry_t *entry, int qidx,
564565
_ODP_ROUNDUP_ALIGN(seg_len, PCAPNG_DATA_ALIGN) +
565566
PCAPNG_DATA_ALIGN;
566567
epb[i].interface_idx = 0;
567-
epb[i].timestamp_high =
568-
(uint32_t)(pkt_hdr->timestamp.u64 >> 32);
569-
epb[i].timestamp_low = (uint32_t)(pkt_hdr->timestamp.u64);
568+
epb[i].timestamp_high = (uint32_t)(_odp_time_to_u64(pkt_hdr->timestamp) >> 32);
569+
epb[i].timestamp_low = (uint32_t)_odp_time_to_u64(pkt_hdr->timestamp);
570570
epb[i].captured_len = seg_len;
571571
epb[i].packet_len = seg_len;
572572

platform/linux-generic/odp_schedule_basic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ static inline int schedule_loop_sleep(odp_queue_t *out_queue, uint64_t wait,
18841884
odp_event_t out_ev[], uint32_t max_num)
18851885
{
18861886
int ret;
1887-
odp_time_t start, end, current, start_sleep;
1887+
odp_time_t start, end = ODP_TIME_NULL, current = ODP_TIME_NULL, start_sleep = ODP_TIME_NULL;
18881888
int first = 1, sleep = 0;
18891889

18901890
while (1) {

0 commit comments

Comments
 (0)