Sound Open Firmware
Loading...
Searching...
No Matches
performance_monitor.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2024 Intel Corporation. All rights reserved.
4 *
5 * Author: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
6 */
7
8#ifndef __SOF_PERFORMANCE_MONITOR_H__
9#define __SOF_PERFORMANCE_MONITOR_H__
10
11#include <ipc4/base_fw.h>
12
13/* to be moved to Zephyr */
14#define WIN3_MBASE DT_REG_ADDR(DT_PHANDLE(DT_NODELABEL(mem_window3), memory))
15#define ADSP_PMW ((volatile uint32_t *) \
16 (sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *) \
17 (WIN3_MBASE + WIN3_OFFSET))))
18
19#if IS_ENABLED(CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS)
27void perf_data_item_comp_init(struct perf_data_item_comp *perf, uint32_t resource_id,
28 uint32_t power_mode);
29
35struct perf_data_item_comp *perf_data_getnext(void);
36
42int free_performance_data(struct perf_data_item_comp *item);
43
49void perf_meas_set_state(enum ipc4_perf_measurements_state_set state);
50
56enum ipc4_perf_measurements_state_set perf_meas_get_state(void);
57
64int get_performance_data(struct global_perf_data * const global_perf_data);
65
72int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data);
73
80
87
92
93#else
94
95static inline
96void perf_data_item_comp_init(struct perf_data_item_comp *perf, uint32_t resource_id,
97 uint32_t power_mode)
98{}
99
100static inline struct perf_data_item_comp *perf_data_getnext(void)
101{
102 return NULL;
103}
104
105static inline
106int free_performance_data(struct perf_data_item_comp *item)
107{
108 return 0;
109}
110
111static inline void perf_meas_set_state(enum ipc4_perf_measurements_state_set state) {}
112
113static inline enum ipc4_perf_measurements_state_set perf_meas_get_state(void)
114{
115 return IPC4_PERF_MEASUREMENTS_DISABLED;
116}
117
118static inline int get_performance_data(struct global_perf_data * const global_perf_data)
119{
120 return 0;
121}
122
123static inline
124int get_extended_performance_data(struct extended_global_perf_data * const ext_global_perf_data)
125{
126 return 0;
127}
128
129static inline int reset_performance_counters(void)
130{
131 return 0;
132}
133
134static inline int enable_performance_counters(void)
135{
136 return 0;
137}
138
139static inline void disable_performance_counters(void) {}
140
141#endif
142
143#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
144
145struct io_perf_data_item {
146 /* ID of interface */
147 uint32_t id : 8;
148 /* Instance of interface / bus */
149 uint32_t instance : 8;
150 /* I/O direction from ACE perspective: 0 - Input, 1 - Output */
151 uint32_t direction : 1;
152 /* I/O state: 0 - powered down / disabled, 1 - powered up / enabled */
153 uint32_t state : 1;
154 /* Power Mode: 0 - D0, 1 - D0ix (clock gating enabled), */
155 uint32_t power_mode : 2;
156 uint32_t rsvd : 11;
157 /* The component still exists (0) or has been already deleted (1) */
158 uint32_t is_removed : 1;
159 /* Performance data */
160 /*
161 * I/O (id) - ID - Units - Description
162 *
163 * Host IPC - 0 - Count - Counter of Host IPC messages incoming and outcoming
164 * IDC - 1 - Count - Counter of IDC messages incoming and outcoming per DSP core
165 * DMIC - 2 - Bytes - Counter of bytes transferred over DMIC interface
166 * I2S - 3 - Bytes - Counter of bytes transferred over I2S interface
167 * SoundWire - 4 - Bytes - Counter of bytes transferred over SoundWire interface
168 * HD/A - 5 - Bytes - Counter of bytes transferred over HD/A interface
169 * USB - 6 - Bytes - Counter of bytes transferred over USB interface
170 * GPIO - 7 - Count - Counter of GPIO interrupts or triggers
171 * I2C - 8 - Bytes - Counter of bytes transferred over I2C interface
172 * I3C - 9 - Bytes - Counter of bytes transferred over I3C interface
173 * I3C interrupt - 10 - Bytes - Counter of I3C interrupts
174 * UART - 11 - Bytes - Counter of bytes transferred over UART interface
175 * SPI - 12 - Bytes - Counter of bytes transferred over SPI interface
176 * CSI-2 - 13 - Bytes - Counter of bytes transferred over CSI-2 interface
177 * DTF - 14 - Bytes - Counter of bytes transferred over DTF interface
178 */
179 uint64_t data;
180} __packed;
181
182/* those below are used for bits in io_perf_data_item, it just uses 32bit vars specifically */
183enum io_perf_data_item_dir {
184 IO_PERF_INPUT_DIRECTION = 0,
185 IO_PERF_OUTPUT_DIRECTION = 1,
186};
187
188enum io_perf_data_item_state {
189 IO_PERF_POWERED_DOWN_DISABLED = 0,
190 IO_PERF_POWERED_UP_ENABLED = 1,
191};
192
193enum io_perf_data_item_power_mode {
194 IO_PERF_D0_POWER_MODE = 0,
195 IO_PERF_D0IX_POWER_MODE = 1,
196};
197
198enum io_perf_data_item_id {
199 IO_PERF_IPC_ID = 0,
200 IO_PERF_IDC_ID = 1,
201 IO_PERF_DMIC_ID = 2,
202 IO_PERF_I2S_ID = 3,
203 IO_PERF_SOUND_WIRE_ID = 4,
204 IO_PERF_HDA_ID = 5,
205 IO_PERF_USB_ID = 6,
206 IO_PERF_GPIO_ID = 7,
207 IO_PERF_I2C_ID = 8,
208 IO_PERF_I3C_ID = 9,
209 IO_PERF_I3C_INTERRUPT_ID = 10,
210 IO_PERF_UART_ID = 11,
211 IO_PERF_SPI_ID = 12,
212 IO_PERF_CSI_2_ID = 13,
213 IO_PERF_DTF_ID = 14,
214 IO_PERF_INVALID_ID = 0xFF
215};
216
217struct io_global_perf_data {
218 /* Number of statistics */
219 uint32_t perf_item_count;
220 /* Performance statistics per I/O */
221 struct io_perf_data_item perf_items[0];
222};
223
224/* I/O Performance Monitor initialization. */
225/*
226 * @return ErrorCode
227 */
228int io_perf_monitor_init(void);
229
230/* Release slot */
231/*
232 * @param [in] slot_id pointer to io_perf_data_item
233 * @return ErrorCode
234 */
235int io_perf_monitor_release_slot(struct io_perf_data_item *slot_id);
236
237/* Get I/O performance data */
238/*
239 * @param [in] io_global_perf_data point to io_global_perf_data
240 * @return ErrorCode
241 */
242int
243io_perf_monitor_get_performance_data(struct io_global_perf_data *io_global_perf_data);
244
245/* Set control state of I/o performance measurements process */
246/*
247 * @param [in] state a state to set
248 * @return ErrorCode
249 */
250int
251io_perf_monitor_set_state(enum ipc4_perf_measurements_state_set state);
252
253/* Get control state of I/o performance measurements process */
254/*
255 * @return ipc4_perf_measurements_state_set
256 */
257enum ipc4_perf_measurements_state_set io_perf_monitor_get_state(void);
258
259/* Initialization of I/O performance data */
260/*
261 * @param [out] slot_id pointer to io_perf_data_item
262 * @param [in] init_data pointer to init data
263 */
264int io_perf_monitor_init_data(struct io_perf_data_item **slot_id,
265 struct io_perf_data_item *init_data);
266
267/* Update of I/O performance data */
268/*
269 * @param [in] slot_id pointer to io_perf_data_item
270 * @param [in] increment
271 * @note IMPORTANT: this function assumes each perf slot has only one user
272 * (use this only once per slot)
273 */
274void io_perf_monitor_update_data(struct io_perf_data_item *slot_id,
275 uint32_t increment);
276
277/* Update of I/0 state */
278/*
279 * @param [in] slot_id pointer to io_perf_data_item
280 * @param [in] power_up 0 - powered down / disabled, 1 - powered up / enabled
281 */
282void io_perf_monitor_update_io_state(struct io_perf_data_item *slot_id,
283 bool const power_up);
284
285/* Update of I/0 power mode */
286/*
287 * @param [in] slot_id pointer to io_perf_data_item
288 * @param [in] power_mode 0 - D0, 1 - D0ix (clock gating enabled)
289 */
290void io_perf_monitor_update_power_mode(struct io_perf_data_item *slot_id,
291 bool const power_mode);
292
293#endif //SUPPORTED(IO_PERFORMANCE_MEASUREMENTS)
294
295#endif
uint8_t rsvd
Definition auth_api_iface.h:3
uint32_t data[]
Definition debug_stream_slot.h:2
#define __packed
Definition ext_manifest.h:43
static int get_performance_data(struct global_perf_data *const global_perf_data)
Definition performance_monitor.h:118
static int get_extended_performance_data(struct extended_global_perf_data *const ext_global_perf_data)
Definition performance_monitor.h:124
static enum ipc4_perf_measurements_state_set perf_meas_get_state(void)
Definition performance_monitor.h:113
static void perf_meas_set_state(enum ipc4_perf_measurements_state_set state)
Definition performance_monitor.h:111
static void perf_data_item_comp_init(struct perf_data_item_comp *perf, uint32_t resource_id, uint32_t power_mode)
Definition performance_monitor.h:96
static int enable_performance_counters(void)
Definition performance_monitor.h:134
static int reset_performance_counters(void)
Definition performance_monitor.h:129
static struct perf_data_item_comp * perf_data_getnext(void)
Definition performance_monitor.h:100
static int free_performance_data(struct perf_data_item_comp *item)
Definition performance_monitor.h:106
static void disable_performance_counters(void)
Definition performance_monitor.h:139