Skip to content

Commit bc7034f

Browse files
Jyri Sarhalgirdwood
authored andcommitted
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 5ec546b commit bc7034f

1 file changed

Lines changed: 35 additions & 25 deletions

File tree

src/debug/debug_stream/debug_stream_text_msg.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,48 @@ 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_SOF_DEBUG_STREAM_SLOT_FORCE_MAX_CPUS];
56-
static int reports_sent_cpu[CONFIG_SOF_DEBUG_STREAM_SLOT_FORCE_MAX_CPUS];
57-
static size_t ds_pos[CONFIG_SOF_DEBUG_STREAM_SLOT_FORCE_MAX_CPUS];
52+
53+
/* Per-CPU state for exception dump and assert_print(). Static data is
54+
* currently placed in .bss and its ATM uncached so the ds_cpu table
55+
* elements do not need to be cache aligned, but if this changes we
56+
* need __aligned(CONFIG_DCACHE_LINE_SIZE) here.
57+
*/
58+
static struct ds_cpu_state {
59+
struct {
60+
struct debug_stream_text_msg msg;
61+
char text[640];
62+
} __packed buf;
63+
int reports_sent;
64+
size_t pos;
65+
} ds_cpu[CONFIG_SOF_DEBUG_STREAM_SLOT_FORCE_MAX_CPUS];
5866

5967
static void ds_exception_drain(bool flush)
6068
{
6169
unsigned int cpu = arch_proc_id();
70+
struct ds_cpu_state *cs = &ds_cpu[cpu];
6271

6372
if (flush) {
64-
ds_pos[cpu] = 0;
65-
reports_sent_cpu[cpu] = 0;
73+
cs->pos = 0;
6674
return;
6775
}
6876

69-
if (ds_pos[cpu] == 0)
77+
if (cs->pos == 0)
7078
return;
7179

72-
if (reports_sent_cpu[cpu] > 0)
80+
if (cs->reports_sent > 0)
7381
return;
7482

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]));
83+
cs->buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
84+
cs->buf.msg.hdr.size_words =
85+
SOF_DIV_ROUND_UP(sizeof(cs->buf.msg) + cs->pos,
86+
sizeof(cs->buf.msg.hdr.data[0]));
87+
7988
/* 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;
89+
memset(cs->buf.text + cs->pos, 0,
90+
cs->buf.msg.hdr.size_words * sizeof(cs->buf.msg.hdr.data[0]) - cs->pos);
91+
debug_stream_slot_send_record(&cs->buf.msg.hdr);
92+
cs->reports_sent = 1;
93+
cs->pos = 0;
8594
}
8695

8796
static void ds_exception_dump(const char *format, va_list args)
@@ -90,11 +99,12 @@ static void ds_exception_dump(const char *format, va_list args)
9099
size_t avail;
91100
size_t written;
92101
unsigned int cpu = arch_proc_id();
102+
struct ds_cpu_state *cs = &ds_cpu[cpu];
93103

94-
if (reports_sent_cpu[cpu] > 0)
104+
if (cs->reports_sent > 0)
95105
return;
96106

97-
avail = sizeof(ds_buf[cpu].text) - ds_pos[cpu];
107+
avail = sizeof(cs->buf.text) - cs->pos;
98108
if (avail == 0) {
99109
ds_exception_drain(false);
100110
return;
@@ -108,9 +118,9 @@ static void ds_exception_dump(const char *format, va_list args)
108118
format[0] == ' ' && format[1] == '*' && format[2] == '*' && format[3] == ' ')
109119
format += 4;
110120

111-
len = vsnprintf(ds_buf[cpu].text + ds_pos[cpu], avail, format, args);
121+
len = vsnprintf(cs->buf.text + cs->pos, avail, format, args);
112122
if (len < 0) {
113-
ds_pos[cpu] = 0;
123+
cs->pos = 0;
114124
return;
115125
}
116126

@@ -122,9 +132,9 @@ static void ds_exception_dump(const char *format, va_list args)
122132
else
123133
written = (size_t)len;
124134

125-
ds_pos[cpu] += written;
135+
cs->pos += written;
126136

127-
if (ds_pos[cpu] >= sizeof(ds_buf[cpu].text))
137+
if (cs->pos >= sizeof(cs->buf.text))
128138
ds_exception_drain(false);
129139
}
130140

0 commit comments

Comments
 (0)