This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9c59ee7c58f2407e7e039137644102e33dcb955f Author: yinshengkai <yinsheng...@xiaomi.com> AuthorDate: Tue Oct 10 22:45:02 2023 +0800 note: optimize note performance and reduce lib_sprintf calls Signed-off-by: yinshengkai <yinsheng...@xiaomi.com> --- drivers/note/note_driver.c | 8 +++---- drivers/note/noteram_driver.c | 43 ++++++++++++++++++++++++++++++++++--- include/nuttx/sched_note.h | 50 ++++++++++++++++++++++++++++++++----------- 3 files changed, 80 insertions(+), 21 deletions(-) diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c index 6e7ae4d677..2438d63d4e 100644 --- a/drivers/note/note_driver.c +++ b/drivers/note/note_driver.c @@ -1396,8 +1396,8 @@ void sched_note_string_ip(uint32_t tag, uintptr_t ip, FAR const char *buf) } } -void sched_note_dump_ip(uint32_t tag, uintptr_t ip, uint8_t event, - FAR const void *buf, size_t len) +void sched_note_event_ip(uint32_t tag, uintptr_t ip, uint8_t event, + FAR const void *buf, size_t len) { FAR struct note_binary_s *note; FAR struct note_driver_s **driver; @@ -1435,9 +1435,8 @@ void sched_note_dump_ip(uint32_t tag, uintptr_t ip, uint8_t event, length = sizeof(data); } - note_common(tcb, ¬e->nbi_cmn, length, NOTE_DUMP_BINARY); + note_common(tcb, ¬e->nbi_cmn, length, event); sched_note_flatten(note->nbi_ip, &ip, sizeof(uintptr_t)); - note->nbi_event = event; memcpy(note->nbi_data, buf, length - sizeof(struct note_binary_s) + 1); } @@ -1712,7 +1711,6 @@ void sched_note_vbprintf_ip(uint32_t tag, uintptr_t ip, uint8_t event, note_common(tcb, ¬e->nbi_cmn, length, NOTE_DUMP_BINARY); sched_note_flatten(note->nbi_ip, &ip, sizeof(uintptr_t)); - note->nbi_event = event; } /* Add the note to circular buffer */ diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index f8675baaa0..dcfdfdcb5f 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -972,7 +972,44 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, } } break; - + case NOTE_DUMP_BEGIN: + case NOTE_DUMP_END: + { + FAR struct note_binary_s *nbi = (FAR struct note_binary_s *)p; + char c = note->nc_type == NOTE_DUMP_BEGIN ? 'B' : 'E'; + int len = note->nc_length - sizeof(struct note_binary_s); + ret += noteram_dump_header(s, &nbi->nbi_cmn, ctx); + if (len > 0) + { + ret += lib_sprintf(s, "tracing_mark_write: %c|%d|%.*s\n", + c, pid, len, (FAR const char *)nbi->nbi_data); + } + else + { + ret += lib_sprintf(s, "tracing_mark_write: %c|%d|%pS\n", + c, pid, (FAR void *)nbi->nbi_ip); + } + } + break; + case NOTE_DUMP_MARK: + { + int len = note->nc_length - sizeof(struct note_binary_s); + FAR struct note_binary_s *nbi = (FAR struct note_binary_s *)p; + ret += noteram_dump_header(s, &nbi->nbi_cmn, ctx); + ret += lib_sprintf(s, "tracing_mark_write: I|%d|%.*s\n", + pid, len, (FAR const char *)nbi->nbi_data); + } + break; + case NOTE_DUMP_COUNTER: + { + FAR struct note_binary_s *nbi = (FAR struct note_binary_s *)p; + FAR struct note_counter_s *counter; + counter = (FAR struct note_counter_s *)nbi->nbi_data; + ret += noteram_dump_header(s, &nbi->nbi_cmn, ctx); + ret += lib_sprintf(s, "tracing_mark_write: C|%d|%s|%ld\n", + pid, counter->name, counter->value); + } + break; case NOTE_DUMP_BINARY: { FAR struct note_binary_s *nbi; @@ -986,8 +1023,8 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, noteram_dump_unflatten(&ip, nbi->nbi_ip, sizeof(ip)); - ret += lib_sprintf(s, "0x%" PRIdPTR ": event=%u count=%u", ip, - nbi->nbi_event, count); + ret += lib_sprintf(s, "tracing_mark_write: 0x%" PRIdPTR + ": count=%u", ip, count); for (i = 0; i < count; i++) { ret += lib_sprintf(s, " 0x%x", nbi->nbi_data[i]); diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h index 6f1a45663d..933536ac30 100644 --- a/include/nuttx/sched_note.h +++ b/include/nuttx/sched_note.h @@ -127,8 +127,10 @@ #define sched_note_string(tag, buf) \ sched_note_string_ip(tag, SCHED_NOTE_IP, buf) +#define sched_note_event(tag, event, buf, len) \ + sched_note_event_ip(tag, SCHED_NOTE_IP, event, buf, len) #define sched_note_dump(tag, event, buf, len) \ - sched_note_dump_ip(tag, SCHED_NOTE_IP, event, buf, len) + sched_note_event(tag, SCHED_NOTE_IP, NOTE_DUMP_BINARY, buf, len) #define sched_note_vprintf(tag, fmt, va) \ sched_note_vprintf_ip(tag, SCHED_NOTE_IP, fmt, va) #define sched_note_vbprintf(tag, event, fmt, va) \ @@ -137,19 +139,20 @@ sched_note_printf_ip(tag, SCHED_NOTE_IP, fmt, ##__VA_ARGS__) #define sched_note_bprintf(tag, event, fmt, ...) \ sched_note_bprintf_ip(tag, SCHED_NOTE_IP, event, \ - fmt, ##__VA_ARGS__) + fmt, ##__VA_ARGS__) +#define sched_note_counter(tag, name, value) \ + sched_note_counter_ip(tag, SCHED_NOTE_IP, name, value) -#define sched_note_begin(tag) sched_note_string(tag, "B") -#define sched_note_end(tag) sched_note_string(tag, "E") +#define sched_note_begin(tag) \ + sched_note_event(tag, NOTE_DUMP_BEGIN, NULL, 0) +#define sched_note_end(tag) \ + sched_note_event(tag, NOTE_DUMP_END, NULL, 0) #define sched_note_beginex(tag, str) \ - sched_note_printf(tag, "B|%d|%s", _SCHED_GETTID(), str) + sched_note_event(tag, NOTE_DUMP_BEGIN, str, strlen(str)) #define sched_note_endex(tag, str) \ - sched_note_printf(tag, "E|%d|%s", _SCHED_GETTID(), str) + sched_note_event(tag, NOTE_DUMP_END, str, strlen(str)) #define sched_note_mark(tag, str) \ - sched_note_printf(tag, "I|%d|%s", _SCHED_GETTID(), str) -#define sched_note_counter(tag, name, value) \ - sched_note_printf(tag, "C|%d|%s|%" PRId32, \ - _SCHED_GETTID(), name, value) + sched_note_event(tag, NOTE_DUMP_MARK, str, strlen(str)) /**************************************************************************** * Public Types @@ -183,6 +186,11 @@ enum note_type_e NOTE_IRQ_LEAVE = 21, NOTE_DUMP_STRING = 22, NOTE_DUMP_BINARY = 23, + NOTE_DUMP_BEGIN = 24, + NOTE_DUMP_END = 25, + NOTE_DUMP_MARK = 28, + NOTE_DUMP_COUNTER = 29, + NOTE_TYPE_LAST }; enum note_tag_e @@ -381,13 +389,18 @@ struct note_binary_s { struct note_common_s nbi_cmn; /* Common note parameters */ uint8_t nbi_ip[sizeof(uintptr_t)]; /* Instruction pointer called from */ - uint8_t nbi_event; /* Event number */ uint8_t nbi_data[1]; /* Binary data */ }; #define SIZEOF_NOTE_BINARY(n) (sizeof(struct note_binary_s) + \ ((n) - 1) * sizeof(uint8_t)) +struct note_counter_s +{ + long int value; + char name[NAME_MAX]; +}; + /* This is the type of the argument passed to the NOTECTL_GETMODE and * NOTECTL_SETMODE ioctls */ @@ -526,7 +539,7 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter); #ifdef CONFIG_SCHED_INSTRUMENTATION_DUMP void sched_note_string_ip(uint32_t tag, uintptr_t ip, FAR const char *buf); -void sched_note_dump_ip(uint32_t tag, uintptr_t ip, uint8_t event, +void sched_note_event_ip(uint32_t tag, uintptr_t ip, uint8_t event, FAR const void *buf, size_t len); void sched_note_vprintf_ip(uint32_t tag, uintptr_t ip, FAR const char *fmt, va_list va) printf_like(3, 0); @@ -537,13 +550,24 @@ void sched_note_printf_ip(uint32_t tag, uintptr_t ip, FAR const char *fmt, ...) printf_like(3, 4); void sched_note_bprintf_ip(uint32_t tag, uintptr_t ip, uint8_t event, FAR const char *fmt, ...) printf_like(4, 5); + +static inline void sched_note_counter_ip(uint32_t tag, uintptr_t ip, + FAR const char *name, + long int value) +{ + struct note_counter_s counter; + counter.value = value; + strlcpy(counter.name, name, sizeof(counter.name)); + sched_note_event_ip(tag, ip, NOTE_DUMP_COUNTER, &counter, sizeof(counter)); +} #else # define sched_note_string_ip(t,ip,b) -# define sched_note_dump_ip(t,ip,e,b,l) +# define sched_note_event_ip(t,ip,e,b,l) # define sched_note_vprintf_ip(t,ip,f,v) # define sched_note_vbprintf_ip(t,ip,e,f,v) # define sched_note_printf_ip(t,ip,f,...) # define sched_note_bprintf_ip(t,ip,e,f,...) +# define sched_note_counter_ip(t,ip,n,v) #endif /* CONFIG_SCHED_INSTRUMENTATION_DUMP */ #if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT)