Skip to content

Commit 5438459

Browse files
committed
sedi: Add sedi status utils in sedi_stats_utils.h
It contains utils good for bsp stats analyzing. Signed-off-by: Dong Wang <[email protected]>
1 parent 0d877c8 commit 5438459

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) 2023-2025 Intel Corporation. All Rights Reserved.
3+
*
4+
* This software and the related documents are Intel copyrighted materials,
5+
* and your use of them is governed by the express license under which they
6+
* were provided to you ("License"). Unless the License provides otherwise,
7+
* you may not use, modify, copy, publish, distribute, disclose or transmit
8+
* this software or the related documents without Intel's prior written
9+
* permission.
10+
*
11+
* This software and the related documents are provided as is, with no express
12+
* or implied warranties, other than those that are expressly stated in the
13+
* License.
14+
*/
15+
16+
/* {sum, count, max, min, unit string} */
17+
#define DEFINE_DSTATS(_name, _unit_str) \
18+
uint64_t __dstats_sum_##_name; \
19+
uint32_t __dstats_cnt_##_name; \
20+
uint32_t __dstats_max_##_name = (uint32_t)0; \
21+
uint32_t __dstats_min_##_name = (uint32_t)0; \
22+
const char *const __dstats_unit_str_##_name = _unit_str
23+
24+
#define DECLARE_DSTATS(_name) \
25+
extern uint64_t __dstats_sum_##_name; \
26+
extern uint32_t __dstats_cnt_##_name; \
27+
extern uint32_t __dstats_max_##_name; \
28+
extern uint32_t __dstats_min_##_name; \
29+
extern const char *const __dstats_unit_str_##_name
30+
31+
#define DSTATS_SUM(_name) __dstats_sum_##_name
32+
#define DSTATS_CNT(_name) __dstats_cnt_##_name
33+
#define DSTATS_MAX(_name) __dstats_max_##_name
34+
#define DSTATS_MIN(_name) __dstats_min_##_name
35+
#define DSTATS_UNIT_STR(_name) __dstats_unit_str_##_name
36+
37+
#define dstats_reset(_name) \
38+
do { \
39+
__dstats_sum_##_name = 0; \
40+
__dstats_cnt_##_name = 0; \
41+
__dstats_max_##_name = 0; \
42+
__dstats_min_##_name = 0; \
43+
} while (0)
44+
45+
#define dstats_update(_name, _value) \
46+
do { \
47+
__dstats_sum_##_name += _value; \
48+
__dstats_cnt_##_name++; \
49+
if ((_value) > __dstats_max_##_name) { \
50+
__dstats_max_##_name = (_value); \
51+
} \
52+
if (!__dstats_min_##_name || _value < __dstats_min_##_name) { \
53+
__dstats_min_##_name = (_value); \
54+
} \
55+
if (__dstats_cnt_##_name >= (uint32_t)-1) { \
56+
/* About to wrap around, clear sum and cnt and insert one average */ \
57+
__dstats_sum_##_name = \
58+
(uint32_t)(__dstats_sum_##_name / __dstats_cnt_##_name); \
59+
__dstats_cnt_##_name = 1; \
60+
} \
61+
} while (0)
62+
63+
#define dstats_get_avrg(_name) \
64+
((__dstats_cnt_##_name == 0) ? 0 : (uint32_t)(__dstats_sum_##_name / __dstats_cnt_##_name))
65+
66+
/* dump out as (sum, mean, max, min) */
67+
#define dstats_dump(_name, _log_func) \
68+
do { \
69+
if (__dstats_cnt_##_name == 0) { \
70+
break; \
71+
} \
72+
_log_func("DSTATS " #_name "(cnt, (aveg, max, min)): " \
73+
"(%u, (%u, %u, %u)%s)\n", \
74+
__dstats_cnt_##_name, \
75+
(uint32_t)(__dstats_sum_##_name / __dstats_cnt_##_name), \
76+
__dstats_max_##_name, __dstats_min_##_name, __dstats_unit_str_##_name); \
77+
} while (0)
78+
79+
#define DEFINE_DSEQ(_name, _cells_num, _unit_str) \
80+
uint32_t __dseq_cells_##_name[_cells_num] = {0}; \
81+
const uint32_t __dseq_cells_num_##_name = (_cells_num); \
82+
uint32_t __dseq_num_##_name = 0; \
83+
const char *const __dseq_unit_str_##_name = _unit_str; \
84+
uint32_t __dseq_head_##_name = 0
85+
86+
#define DECLARE_DSEQ(_name) \
87+
extern uint32_t __dseq_cells_##_name[]; \
88+
extern const uint32_t __dseq_cells_num_##_name; \
89+
extern uint32_t __dseq_num_##_name; \
90+
extern const char *const __dseq_unit_str_##_name; \
91+
extern uint32_t __dseq_head_##_name
92+
93+
#define dseq_reset(_name) \
94+
do { \
95+
for (uint32_t i = 0; i < __dseq_cells_num_##_name; i++) { \
96+
__dseq_cells_##_name[i] = 0; \
97+
} \
98+
__dseq_num_##_name = 0; \
99+
__dseq_head_##_name = 0; \
100+
} while (0)
101+
102+
#define dseq_update(_name, _value) \
103+
do { \
104+
uint32_t next = __dseq_head_##_name + __dseq_num_##_name; \
105+
next = next % __dseq_cells_num_##_name; \
106+
__dseq_cells_##_name[next] = (_value); \
107+
__dseq_num_##_name++; \
108+
if (__dseq_num_##_name > __dseq_cells_num_##_name) { \
109+
__dseq_num_##_name = __dseq_cells_num_##_name; \
110+
__dseq_head_##_name = (next + 1) % __dseq_cells_num_##_name; \
111+
} \
112+
} while (0)
113+
114+
#define dseq_dump(_name, _log_func) \
115+
do { \
116+
for (uint32_t i = 0; i < __dseq_num_##_name; i++) { \
117+
uint32_t idx = __dseq_head_##_name + i; \
118+
idx = idx % __dseq_cells_num_##_name; \
119+
_log_func("DSEQ " #_name " (%u/%u): 0x%x %s\n", i, __dseq_num_##_name, \
120+
__dseq_cells_##_name[idx], __dseq_unit_str_##_name); \
121+
} \
122+
} while (0)

zephyr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ if(CONFIG_INTEL_HAL)
99
zephyr_interface_library_named(BSP_SEDI)
1010
target_link_libraries(zephyr_interface INTERFACE BSP_SEDI)
1111
target_include_directories(BSP_SEDI INTERFACE ${BSP_SEDI_SRC}/include/driver)
12+
target_include_directories(BSP_SEDI INTERFACE ${BSP_SEDI_SRC}/include)
1213

1314
zephyr_library_named(modules_intel_hal)
1415
zephyr_library_link_libraries(BSP_SEDI)

0 commit comments

Comments
 (0)