From 2ac4a1e2ecac31dd6289499f9a484b75c60f4b45 Mon Sep 17 00:00:00 2001 From: xiazhonglin Date: Thu, 18 May 2023 15:03:53 +0800 Subject: [PATCH] trace test Signed-off-by: xiazhonglin Change-Id: I287f56c88ba267ea1a9fb8eb54e31c3fe57e1d95 --- kernel/trace/trace.c | 35 +++++++++++++++++++++++++++++------ kernel/trace/trace.h | 1 + kernel/trace/trace_output.c | 11 +++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 146771d6d007..142936f4a0ff 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6692,6 +6692,9 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, ssize_t written; int size; int len; + bool marker_tradition; + size_t prune_cnt; + char * real_buf; /* Used in tracing_mark_raw_write() as well */ #define FAULTED_STR "" @@ -6703,16 +6706,23 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, if (!(tr->trace_flags & TRACE_ITER_MARKERS)) return -EINVAL; + marker_tradition = !(tr->trace_flags & TRACE_ITER_MARKERS_PRUNE); + if (cnt > TRACE_BUF_SIZE) cnt = TRACE_BUF_SIZE; BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); local_save_flags(irq_flags); + + prune_cnt = cnt; + if (!marker_tradition) + prune_cnt = sizeof(entry->ip) < cnt ? cnt - sizeof(entry->ip): 0; + //size = sizeof(*entry) + prune_cnt + 2; /* add '\0' and possible '\n' */ size = sizeof(*entry) + cnt + 2; /* add '\0' and possible '\n' */ /* If less than "", then make sure we can still add that */ - if (cnt < FAULTED_SIZE) + if (marker_tradition && cnt < FAULTED_SIZE) size += FAULTED_SIZE - cnt; buffer = tr->array_buffer.buffer; @@ -6725,9 +6735,13 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, entry = ring_buffer_event_data(event); entry->ip = _THIS_IP_; - len = __copy_from_user_inatomic(&entry->buf, ubuf, cnt); + real_buf = (char *)(&entry->ip); + if (marker_tradition) + real_buf = (char *)(&entry->buf); + len = __copy_from_user_inatomic(real_buf, ubuf, cnt); if (len) { - memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE); + if (marker_tradition) + memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE); cnt = FAULTED_SIZE; written = -EFAULT; } else @@ -6757,6 +6771,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf, return written; } +unsigned long trace_maker_ip = &tracing_mark_write; /* Limit it for now to 3K (including tag) */ #define RAW_DATA_MAX_SIZE (1024*3) @@ -6773,6 +6788,8 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf, ssize_t written; int size; int len; + bool marker_tradition; + size_t prune_cnt; #define FAULT_SIZE_ID (FAULTED_SIZE + sizeof(int)) @@ -6792,8 +6809,13 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf, BUILD_BUG_ON(TRACE_BUF_SIZE >= PAGE_SIZE); local_save_flags(irq_flags); - size = sizeof(*entry) + cnt; - if (cnt < FAULT_SIZE_ID) + marker_tradition = !(tr->trace_flags & TRACE_ITER_MARKERS_PRUNE); + + prune_cnt = cnt; + if (!marker_tradition) + prune_cnt = sizeof(entry->id) < cnt ? cnt - sizeof(entry->id): 0; + size = sizeof(*entry) + prune_cnt; + if (marker_tradition && cnt < FAULT_SIZE_ID) size += FAULT_SIZE_ID - cnt; buffer = tr->array_buffer.buffer; @@ -6808,7 +6830,8 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf, len = __copy_from_user_inatomic(&entry->id, ubuf, cnt); if (len) { entry->id = -1; - memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE); + if (marker_tradition) + memcpy(&entry->buf, FAULTED_STR, FAULTED_SIZE); written = -EFAULT; } else written = cnt; diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 8d67f7f44840..33058de6c63c 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1348,6 +1348,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, C(STOP_ON_FREE, "disable_on_free"), \ C(IRQ_INFO, "irq-info"), \ C(MARKERS, "markers"), \ + C(MARKERS_PRUNE, "markers_prune"), \ C(EVENT_FORK, "event-fork"), \ C(PAUSE_ON_TRACE, "pause-on-trace"), \ FUNCTION_FLAGS \ diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 000e9dc224c6..1af301515b94 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1297,6 +1297,7 @@ static struct trace_event trace_bprint_event = { .funcs = &trace_bprint_funcs, }; +extern unsigned long trace_maker_ip; /* TRACE_PRINT */ static enum print_line_t trace_print_print(struct trace_iterator *iter, int flags, struct trace_event *event) @@ -1304,10 +1305,16 @@ static enum print_line_t trace_print_print(struct trace_iterator *iter, struct print_entry *field; struct trace_seq *s = &iter->seq; + struct trace_array *tr = iter->tr; + trace_assign_type(field, iter->ent); - seq_print_ip_sym(s, field->ip, flags); - trace_seq_printf(s, ": %s", field->buf); + seq_print_ip_sym(s, trace_maker_ip, flags); + //if (tr->trace_flags & TRACE_ITER_MARKERS_PRUNE) { + // trace_seq_printf(s, ": zlxiaip %s", field->ip); + //} else { + trace_seq_printf(s, ": zlxia %s", field->buf); + //} return trace_handle_return(s); } -- Gitee