Skip to content

Commit f2388f1

Browse files
author
Jyri Sarha
committed
debug_stream: text_msg: collect per-CPU state into cacheline-aligned struct
Replace separate per-CPU arrays (ds_buf[], reports_sent_cpu[], ds_pos[]) with a single struct ds_cpu_state table aligned to CONFIG_DCACHE_LINE_SIZE to avoid false sharing between cores. Also remove the reports_sent reset in the flush path, so that once an exception dump has been sent, the sent-flag stays set and suppresses further output. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent a3c44b3 commit f2388f1

1 file changed

Lines changed: 33 additions & 25 deletions

File tree

src/debug/debug_stream/debug_stream_text_msg.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,46 @@ void ds_msg(const char *format, ...)
4949
* in bursts, and sending more than one record in short time makes the
5050
* host-side decoder lose track of things.
5151
*/
52-
static struct {
53-
struct debug_stream_text_msg msg;
54-
char text[640];
55-
} __packed ds_buf[CONFIG_MP_MAX_NUM_CPUS];
56-
static int reports_sent_cpu[CONFIG_MP_MAX_NUM_CPUS];
57-
static size_t ds_pos[CONFIG_MP_MAX_NUM_CPUS];
52+
53+
/* Per-CPU state for exception dump and assert_print().
54+
* Cache-line aligned to avoid false sharing between cores.
55+
*/
56+
static struct ds_cpu_state {
57+
struct {
58+
struct debug_stream_text_msg msg;
59+
char text[640];
60+
} __packed buf;
61+
int reports_sent;
62+
size_t pos;
63+
} __aligned(CONFIG_DCACHE_LINE_SIZE) ds_cpu[CONFIG_MP_MAX_NUM_CPUS];
5864

5965
static void ds_exception_drain(bool flush)
6066
{
6167
unsigned int cpu = arch_proc_id();
68+
struct ds_cpu_state *cs = &ds_cpu[cpu];
6269

6370
if (flush) {
64-
ds_pos[cpu] = 0;
65-
reports_sent_cpu[cpu] = 0;
71+
cs->pos = 0;
6672
return;
6773
}
6874

69-
if (ds_pos[cpu] == 0)
75+
if (cs->pos == 0)
7076
return;
7177

72-
if (reports_sent_cpu[cpu] > 0)
78+
if (cs->reports_sent > 0)
7379
return;
7480

75-
ds_buf[cpu].msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
76-
ds_buf[cpu].msg.hdr.size_words =
77-
SOF_DIV_ROUND_UP(sizeof(ds_buf[cpu].msg) + ds_pos[cpu],
78-
sizeof(ds_buf[cpu].msg.hdr.data[0]));
81+
cs->buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
82+
cs->buf.msg.hdr.size_words =
83+
SOF_DIV_ROUND_UP(sizeof(cs->buf.msg) + cs->pos,
84+
sizeof(cs->buf.msg.hdr.data[0]));
85+
7986
/* Make sure the possible up to 3 extra bytes at end of msg are '\0' */
80-
memset(ds_buf[cpu].text + ds_pos[cpu], 0,
81-
ds_buf[cpu].msg.hdr.size_words * sizeof(ds_buf[cpu].msg.hdr.data[0]) - ds_pos[cpu]);
82-
debug_stream_slot_send_record(&ds_buf[cpu].msg.hdr);
83-
reports_sent_cpu[cpu] = 1;
84-
ds_pos[cpu] = 0;
87+
memset(cs->buf.text + cs->pos, 0,
88+
cs->buf.msg.hdr.size_words * sizeof(cs->buf.msg.hdr.data[0]) - cs->pos);
89+
debug_stream_slot_send_record(&cs->buf.msg.hdr);
90+
cs->reports_sent = 1;
91+
cs->pos = 0;
8592
}
8693

8794
static void ds_exception_dump(const char *format, va_list args)
@@ -90,11 +97,12 @@ static void ds_exception_dump(const char *format, va_list args)
9097
size_t avail;
9198
size_t written;
9299
unsigned int cpu = arch_proc_id();
100+
struct ds_cpu_state *cs = &ds_cpu[cpu];
93101

94-
if (reports_sent_cpu[cpu] > 0)
102+
if (cs->reports_sent > 0)
95103
return;
96104

97-
avail = sizeof(ds_buf[cpu].text) - ds_pos[cpu];
105+
avail = sizeof(cs->buf.text) - cs->pos;
98106
if (avail == 0) {
99107
ds_exception_drain(false);
100108
return;
@@ -108,9 +116,9 @@ static void ds_exception_dump(const char *format, va_list args)
108116
format[0] == ' ' && format[1] == '*' && format[2] == '*' && format[3] == ' ')
109117
format += 4;
110118

111-
len = vsnprintf(ds_buf[cpu].text + ds_pos[cpu], avail, format, args);
119+
len = vsnprintf(cs->buf.text + cs->pos, avail, format, args);
112120
if (len < 0) {
113-
ds_pos[cpu] = 0;
121+
cs->pos = 0;
114122
return;
115123
}
116124

@@ -122,9 +130,9 @@ static void ds_exception_dump(const char *format, va_list args)
122130
else
123131
written = (size_t)len;
124132

125-
ds_pos[cpu] += written;
133+
cs->pos += written;
126134

127-
if (ds_pos[cpu] >= sizeof(ds_buf[cpu].text))
135+
if (cs->pos >= sizeof(cs->buf.text))
128136
ds_exception_drain(false);
129137
}
130138

0 commit comments

Comments
 (0)