Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

stm class: sys-t: Improve ftrace source handling

Package messages from ftrace source with SyS-T Structured Binary Data
(later SBD) header and 64-bit ID. This provides modification-free
compatibility between ftrace and SyS-T arguments structure by applying
0xFFFF mask on message ID.

This happens due to the fact that SBD and ftrace structures have the
same principle of data storage: <header><args binary blob>.

The headers are bit-to-bit compatible and both contain event/catalog ID
with the exception, that ftrace header contains more fields within 64
bits which needs to be masked during encoding process, since SBD
standard doesn't support mask of ID field.

0 15 16 23 24 31 32 39 40 63
ftrace: <event_id> <flags> <preempt> <-pid-> <---->
SBD: <------- msg_id ------------------------------>

Signed-off-by: Mikhail Lappo <miklelappo@gmail.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240429130119.1518073-5-alexander.shishkin@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mikhail Lappo and committed by
Greg Kroah-Hartman
3c720592 ee27f44e

+83 -7
+83 -7
drivers/hwtracing/stm/p_sys-t.c
··· 20 20 MIPI_SYST_TYPE_RAW = 6, 21 21 MIPI_SYST_TYPE_SHORT64, 22 22 MIPI_SYST_TYPE_CLOCK, 23 + MIPI_SYST_TYPE_SBD, 23 24 }; 24 25 25 26 enum sys_t_message_severity { ··· 54 53 MIPI_SYST_STRING_PRINTF_64 = 12, 55 54 }; 56 55 56 + /** 57 + * enum sys_t_message_sbd_subtype - SyS-T SBD message subtypes 58 + * @MIPI_SYST_SBD_ID32: SBD message with 32-bit message ID 59 + * @MIPI_SYST_SBD_ID64: SBD message with 64-bit message ID 60 + * 61 + * Structured Binary Data messages can send information of arbitrary length, 62 + * together with ID's that describe BLOB's content and layout. 63 + */ 64 + enum sys_t_message_sbd_subtype { 65 + MIPI_SYST_SBD_ID32 = 0, 66 + MIPI_SYST_SBD_ID64 = 1, 67 + }; 68 + 57 69 #define MIPI_SYST_TYPE(t) ((u32)(MIPI_SYST_TYPE_ ## t)) 58 70 #define MIPI_SYST_SEVERITY(s) ((u32)(MIPI_SYST_SEVERITY_ ## s) << 4) 59 71 #define MIPI_SYST_OPT_LOC BIT(8) ··· 88 74 89 75 #define CLOCK_SYNC_HEADER (MIPI_SYST_TYPES(CLOCK, TRANSPORT_SYNC) | \ 90 76 MIPI_SYST_SEVERITY(MAX)) 77 + 78 + /* 79 + * SyS-T and ftrace headers are compatible to an extent that ftrace event ID 80 + * and args can be treated as SyS-T SBD message with 64-bit ID and arguments 81 + * BLOB right behind the header without modification. Bits [16:63] coming 82 + * together with message ID from ftrace aren't used by SBD and must be zeroed. 83 + * 84 + * 0 15 16 23 24 31 32 39 40 63 85 + * ftrace: <event_id> <flags> <preempt> <-pid-> <----> <args> 86 + * SBD: <------- msg_id ------------------------------> <BLOB> 87 + */ 88 + #define SBD_HEADER (MIPI_SYST_TYPES(SBD, ID64) | \ 89 + MIPI_SYST_SEVERITY(INFO) | \ 90 + MIPI_SYST_OPT_GUID) 91 91 92 92 struct sys_t_policy_node { 93 93 uuid_t uuid; ··· 312 284 return sizeof(header) + sizeof(payload); 313 285 } 314 286 287 + static inline u32 sys_t_header(struct stm_source_data *source) 288 + { 289 + if (source && source->type == STM_FTRACE) 290 + return SBD_HEADER; 291 + return DATA_HEADER; 292 + } 293 + 294 + static ssize_t sys_t_write_data(struct stm_data *data, 295 + struct stm_source_data *source, 296 + unsigned int master, unsigned int channel, 297 + bool ts_first, const void *buf, size_t count) 298 + { 299 + ssize_t sz; 300 + const unsigned char nil = 0; 301 + 302 + /* 303 + * Ftrace is zero-copy compatible with SyS-T SBD, but requires 304 + * special handling of first 64 bits. Trim and send them separately 305 + * to avoid damage on original ftrace buffer. 306 + */ 307 + if (source && source->type == STM_FTRACE) { 308 + u64 compat_ftrace_header; 309 + ssize_t header_sz; 310 + ssize_t buf_sz; 311 + 312 + if (count < sizeof(compat_ftrace_header)) 313 + return -EINVAL; 314 + 315 + /* SBD only makes use of low 16 bits (event ID) from ftrace event */ 316 + compat_ftrace_header = *(u64 *)buf & 0xffff; 317 + header_sz = stm_data_write(data, master, channel, false, 318 + &compat_ftrace_header, 319 + sizeof(compat_ftrace_header)); 320 + if (header_sz != sizeof(compat_ftrace_header)) 321 + return header_sz; 322 + 323 + buf_sz = stm_data_write(data, master, channel, false, 324 + buf + header_sz, count - header_sz); 325 + if (buf_sz != count - header_sz) 326 + return buf_sz; 327 + sz = header_sz + buf_sz; 328 + } else { 329 + sz = stm_data_write(data, master, channel, false, buf, count); 330 + } 331 + 332 + if (sz <= 0) 333 + return sz; 334 + 335 + data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, &nil); 336 + 337 + return sz; 338 + } 339 + 315 340 static ssize_t sys_t_write(struct stm_data *data, struct stm_output *output, 316 341 unsigned int chan, const char *buf, size_t count, 317 342 struct stm_source_data *source) ··· 372 291 struct sys_t_output *op = output->pdrv_private; 373 292 unsigned int c = output->channel + chan; 374 293 unsigned int m = output->master; 375 - const unsigned char nil = 0; 376 - u32 header = DATA_HEADER; 294 + u32 header = sys_t_header(source); 377 295 u8 uuid[UUID_SIZE]; 378 296 ssize_t sz; 379 297 ··· 429 349 } 430 350 431 351 /* DATA */ 432 - sz = stm_data_write(data, m, c, false, buf, count); 433 - if (sz > 0) 434 - data->packet(data, m, c, STP_PACKET_FLAG, 0, 0, &nil); 435 - 436 - return sz; 352 + return sys_t_write_data(data, source, m, c, false, buf, count); 437 353 } 438 354 439 355 static const struct stm_protocol_driver sys_t_pdrv = {