Skip to content

Commit 6439323

Browse files
author
Jyri Sarha
committed
telemetry2_thread_info.c: Review updates
1 parent 72e919e commit 6439323

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

src/debug/telemetry/telemetry2_thread_info.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* SPDX-License-Identifier: Apache-2.0
2-
* Copyright (c) 2024 Intel Corporation
3-
*/
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
//
3+
// Copyright(c) 2024 Intel Corporation.
44

55
#include <zephyr/logging/log.h>
66
#include <zephyr/kernel.h>
@@ -12,13 +12,12 @@
1212

1313
LOG_MODULE_REGISTER(thread_info);
1414

15-
/* to adsp backend header, data to be shared with user space client*/
1615
#define THREAD_INFO_MAX_THREADS 16
1716

1817
struct thread_info {
1918
char name[14];
20-
uint8_t stack_usage; /* precentage */
21-
uint8_t cpu_usage; /* precentage */
19+
uint8_t stack_usage; /* Relative stack usage U(0,8) fixed point value */
20+
uint8_t cpu_usage; /* Relative cpu usage U(0,8) fixed point value */
2221
} __packed;
2322

2423
#define THREAD_INFO_VERSION_0_0 0
@@ -27,14 +26,19 @@ struct thread_info {
2726
#define THREAD_INFO_STATE_BEING_UPDATED 1
2827
#define THREAD_INFO_STATE_UPTODATE 2
2928

29+
/* Core specific data, updated each round, including the thread table. */
3030
struct thread_info_core {
31-
uint8_t state;
32-
uint8_t counter; /* incremented every round */
33-
uint8_t load; /* precentage */
31+
uint8_t state; /* indicates if core data is in consistent state */
32+
uint8_t counter; /* incremented every round */
33+
uint8_t load; /* Core's load U(0,8) fixed point value */
3434
uint8_t thread_count;
3535
struct thread_info thread[THREAD_INFO_MAX_THREADS];
3636
} __packed __aligned(CONFIG_DCACHE_LINE_SIZE);
3737

38+
/* Thread info telemetry2 chunk header. Only initialized at first
39+
* thread info thread start. Should be used to find the core specific
40+
* sections where the thread info is when decoding.
41+
*/
3842
struct thread_info_chunk {
3943
struct telemetry2_chunk_hdr hdr;
4044
uint16_t core_count;
@@ -43,6 +47,10 @@ struct thread_info_chunk {
4347
} __packed;
4448

4549
#ifdef CONFIG_THREAD_RUNTIME_STATS
50+
/* Data structure to store the cycle counter values from the previous
51+
* round. The numbers are used to calculate what the load was on this
52+
* round.
53+
*/
4654
static struct previous_counters { // Cached data from previous round
4755
uint64_t active; // All execution cycles
4856
uint64_t all; // All cycles including idle
@@ -53,6 +61,9 @@ static struct previous_counters { // Cached data from previous round
5361
} previous[CONFIG_MP_MAX_NUM_CPUS];
5462
#endif
5563

64+
/* Data structure to be passed down to thread_info_cb() by
65+
* k_thread_foreach_my_core().
66+
*/
5667
struct user_data {
5768
struct thread_info_core *core_data;
5869
int thread_count;
@@ -252,7 +263,7 @@ static void thread_info_get(struct thread_info_core *core_data)
252263
ud.previous->all);
253264

254265
ud.stats_valid = true;
255-
load = (active_cycles * 100U) / all_cycles;
266+
load = (uint8_t) ((255LLU * active_cycles) / all_cycles);
256267
LOG_DBG("Core %u load %u / %u total %llu / %llu", arch_proc_id(),
257268
active_cycles, all_cycles,
258269
core_stats.total_cycles, core_stats.execution_cycles);

0 commit comments

Comments
 (0)