Skip to content

Commit 6a8148f

Browse files
committed
tracing: systemview: cleanup headers
Cleanup systemview headers and move sysview hooks into sysview_config.c Signed-off-by: Anas Nashif <[email protected]>
1 parent 0e3771b commit 6a8148f

File tree

4 files changed

+100
-76
lines changed

4 files changed

+100
-76
lines changed

subsys/tracing/sysview/SEGGER_SYSVIEW_Zephyr.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

subsys/tracing/sysview/sysview.c

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
#include <ksched.h>
1010

1111
#include <SEGGER_SYSVIEW.h>
12-
#include <Global.h>
13-
#include "SEGGER_SYSVIEW_Zephyr.h"
1412

15-
#if CONFIG_THREAD_MAX_NAME_LEN
16-
#define THREAD_NAME_LEN CONFIG_THREAD_MAX_NAME_LEN
17-
#else
18-
#define THREAD_NAME_LEN 20
19-
#endif
2013

2114
static uint32_t interrupt;
2215

@@ -72,70 +65,41 @@ void sys_trace_idle(void)
7265
SEGGER_SYSVIEW_OnIdle();
7366
}
7467

75-
static void set_thread_name(char *name, struct k_thread *thread)
68+
void sys_trace_semaphore_init(struct k_sem *sem)
7669
{
77-
const char *tname = k_thread_name_get(thread);
78-
79-
if (tname != NULL && tname[0] != '\0') {
80-
memcpy(name, tname, THREAD_NAME_LEN);
81-
name[THREAD_NAME_LEN - 1] = '\0';
82-
} else {
83-
snprintk(name, THREAD_NAME_LEN, "T%pE%p",
84-
thread, &thread->entry);
85-
}
70+
SEGGER_SYSVIEW_RecordU32(
71+
SYS_TRACE_ID_SEMA_INIT, (uint32_t)(uintptr_t)sem);
8672
}
8773

88-
void sys_trace_thread_info(struct k_thread *thread)
74+
void sys_trace_semaphore_take(struct k_sem *sem)
8975
{
90-
char name[THREAD_NAME_LEN];
91-
92-
set_thread_name(name, thread);
93-
94-
SEGGER_SYSVIEW_TASKINFO Info;
95-
96-
Info.TaskID = (uint32_t)(uintptr_t)thread;
97-
Info.sName = name;
98-
Info.Prio = thread->base.prio;
99-
Info.StackBase = thread->stack_info.size;
100-
Info.StackSize = thread->stack_info.start;
101-
SEGGER_SYSVIEW_SendTaskInfo(&Info);
76+
SEGGER_SYSVIEW_RecordU32(
77+
SYS_TRACE_ID_SEMA_TAKE, (uint32_t)(uintptr_t)sem);
10278
}
10379

104-
static void send_task_list_cb(void)
80+
void sys_trace_semaphore_give(struct k_sem *sem)
10581
{
106-
struct k_thread *thread;
107-
108-
for (thread = _kernel.threads; thread; thread = thread->next_thread) {
109-
char name[THREAD_NAME_LEN];
110-
111-
if (z_is_idle_thread_object(thread)) {
112-
continue;
113-
}
114-
115-
set_thread_name(name, thread);
116-
117-
SEGGER_SYSVIEW_SendTaskInfo(&(SEGGER_SYSVIEW_TASKINFO) {
118-
.TaskID = (uint32_t)(uintptr_t)thread,
119-
.sName = name,
120-
.StackSize = thread->stack_info.size,
121-
.StackBase = thread->stack_info.start,
122-
.Prio = thread->base.prio,
123-
});
124-
}
82+
SEGGER_SYSVIEW_RecordU32(
83+
SYS_TRACE_ID_SEMA_GIVE, (uint32_t)(uintptr_t)sem);
12584
}
12685

127-
128-
static U64 get_time_cb(void)
86+
void sys_trace_mutex_init(struct k_mutex *mutex)
12987
{
130-
return (U64)k_cycle_get_32();
88+
SEGGER_SYSVIEW_RecordU32(
89+
SYS_TRACE_ID_MUTEX_INIT, (uint32_t)(uintptr_t)mutex);
13190
}
13291

92+
void sys_trace_mutex_lock(struct k_mutex *mutex)
93+
{
94+
SEGGER_SYSVIEW_RecordU32(
95+
SYS_TRACE_ID_MUTEX_LOCK, (uint32_t)(uintptr_t)mutex);
96+
}
13397

134-
const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
135-
get_time_cb,
136-
send_task_list_cb,
137-
};
138-
98+
void sys_trace_mutex_unlock(struct k_mutex *mutex)
99+
{
100+
SEGGER_SYSVIEW_RecordU32(
101+
SYS_TRACE_ID_MUTEX_UNLOCK, (uint32_t)(uintptr_t)mutex);
102+
}
139103

140104
static int sysview_init(const struct device *arg)
141105
{

subsys/tracing/sysview/sysview_config.c

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,46 @@
66

77
#include <kernel.h>
88
#include <SEGGER_SYSVIEW.h>
9-
#include "SEGGER_SYSVIEW_Zephyr.h"
9+
#include <ksched.h>
10+
11+
extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
12+
13+
#if CONFIG_THREAD_MAX_NAME_LEN
14+
#define THREAD_NAME_LEN CONFIG_THREAD_MAX_NAME_LEN
15+
#else
16+
#define THREAD_NAME_LEN 20
17+
#endif
18+
19+
20+
static void set_thread_name(char *name, struct k_thread *thread)
21+
{
22+
const char *tname = k_thread_name_get(thread);
23+
24+
if (tname != NULL && tname[0] != '\0') {
25+
memcpy(name, tname, THREAD_NAME_LEN);
26+
name[THREAD_NAME_LEN - 1] = '\0';
27+
} else {
28+
snprintk(name, THREAD_NAME_LEN, "T%pE%p",
29+
thread, &thread->entry);
30+
}
31+
}
32+
33+
void sys_trace_thread_info(struct k_thread *thread)
34+
{
35+
char name[THREAD_NAME_LEN];
36+
37+
set_thread_name(name, thread);
38+
39+
SEGGER_SYSVIEW_TASKINFO Info;
40+
41+
Info.TaskID = (uint32_t)(uintptr_t)thread;
42+
Info.sName = name;
43+
Info.Prio = thread->base.prio;
44+
Info.StackBase = thread->stack_info.size;
45+
Info.StackSize = thread->stack_info.start;
46+
SEGGER_SYSVIEW_SendTaskInfo(&Info);
47+
}
48+
1049

1150
static void cbSendSystemDesc(void)
1251
{
@@ -16,6 +55,43 @@ static void cbSendSystemDesc(void)
1655
SEGGER_SYSVIEW_SendSysDesc("O=Zephyr");
1756
}
1857

58+
static void send_task_list_cb(void)
59+
{
60+
struct k_thread *thread;
61+
62+
for (thread = _kernel.threads; thread; thread = thread->next_thread) {
63+
char name[THREAD_NAME_LEN];
64+
65+
if (z_is_idle_thread_object(thread)) {
66+
continue;
67+
}
68+
69+
set_thread_name(name, thread);
70+
71+
SEGGER_SYSVIEW_SendTaskInfo(&(SEGGER_SYSVIEW_TASKINFO) {
72+
.TaskID = (uint32_t)(uintptr_t)thread,
73+
.sName = name,
74+
.StackSize = thread->stack_info.size,
75+
.StackBase = thread->stack_info.start,
76+
.Prio = thread->base.prio,
77+
});
78+
}
79+
}
80+
81+
82+
static U64 get_time_cb(void)
83+
{
84+
return (U64)k_cycle_get_32();
85+
}
86+
87+
88+
const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
89+
get_time_cb,
90+
send_task_list_cb,
91+
};
92+
93+
94+
1995
void SEGGER_SYSVIEW_Conf(void)
2096
{
2197
SEGGER_SYSVIEW_Init(sys_clock_hw_cycles_per_sec(),

subsys/tracing/sysview/tracing_sysview.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#include <init.h>
1111

1212
#include <SEGGER_SYSVIEW.h>
13-
#include <Global.h>
14-
#include "SEGGER_SYSVIEW_Zephyr.h"
13+
1514

1615
#ifdef __cplusplus
1716
extern "C" {

0 commit comments

Comments
 (0)