mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linyu Yuan <quic_linyyuan@quicinc.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	<linux-kernel@vger.kernel.org>, <bpf@vger.kernel.org>
Subject: Re: [RFC PATCH 2/2] trace: allocate temparary buffer for trace output usage
Date: Thu, 15 Dec 2022 09:22:59 +0800	[thread overview]
Message-ID: <f929751c-d299-b1d4-7163-74a3ffb18bfe@quicinc.com> (raw)
In-Reply-To: <20221214092550.1691829e@gandalf.local.home>

thanks for remind, will check and use it.


thanks

On 12/14/2022 10:25 PM, Steven Rostedt wrote:
> On Wed, 14 Dec 2022 22:11:42 +0800
> Linyu Yuan <quic_linyyuan@quicinc.com> wrote:
>
>> there is one dwc3 trace event declare as below,
>> DECLARE_EVENT_CLASS(dwc3_log_event,
>> 	TP_PROTO(u32 event, struct dwc3 *dwc),
>> 	TP_ARGS(event, dwc),
>> 	TP_STRUCT__entry(
>> 		__field(u32, event)
>> 		__field(u32, ep0state)
>> 		__dynamic_array(char, str, DWC3_MSG_MAX)
>> 	),
>> 	TP_fast_assign(
>> 		__entry->event = event;
>> 		__entry->ep0state = dwc->ep0state;
>> 	),
>> 	TP_printk("event (%08x): %s", __entry->event,
>> 			dwc3_decode_event(__get_str(str), DWC3_MSG_MAX,
>> 				__entry->event, __entry->ep0state))
>> );
>> the problem is when trace function called, it will allocate up to
>> DWC3_MSG_MAX bytes from trace event buffer, but never fill the buffer
>> during fast assignment, it only fill the buffer when output function are
>> called, so this means if output function are not called, the buffer will
>> never used.
>>
>> add __alloc_buf() and __get_buf() which will not allocate event buffer
>> when trace function called, but when trace output function called, it will
>> kmalloc buffer with size DWC3_MSG_MAX for temprary usage and free it
>> before trace output function return.
> This looks exactly like what the trace_seq *p is to be used for.
>
> static notrace enum print_line_t					\
> trace_raw_output_##call(struct trace_iterator *iter, int flags,		\
> 			struct trace_event *trace_event)		\
> {									\
> 	struct trace_seq *s = &iter->seq;				\
> 	struct trace_seq __maybe_unused *p = &iter->tmp_seq;		\
>                                          ^^^^^^^^^^^^^^^^^^^^
>
> 	struct trace_event_raw_##call *field;				\
> 	int ret;							\
> 									\
> 	field = (typeof(field))iter->ent;				\
> 									\
> 	ret = trace_raw_output_prep(iter, trace_event);			\
> 	if (ret != TRACE_TYPE_HANDLED)					\
> 		return ret;						\
> 									\
> 	trace_event_printf(iter, print);				\
> 									\
> 	return trace_handle_return(s);					\
> }									\
>
> That is a trace_seq buffer that is for temporary usage during the output.
>
> See:
>    include/trace/events/libata.h
>    include/trace/events/scsi.h
>
> As well as the macros trace_print_bitmask_seq(), trace_print_flags_seq(),
> trace_print_symbols_seq(), etc.
>
> -- Steve
>

  reply	other threads:[~2022-12-15  1:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 14:11 [RFC PATCH 1/2] trace: add new file under include/trace/stages/ for perf/bpf Linyu Yuan
2022-12-14 14:11 ` [RFC PATCH 2/2] trace: allocate temparary buffer for trace output usage Linyu Yuan
2022-12-14 14:25   ` Steven Rostedt
2022-12-15  1:22     ` Linyu Yuan [this message]
2022-12-15  1:53       ` Linyu Yuan
2022-12-15  3:16         ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f929751c-d299-b1d4-7163-74a3ffb18bfe@quicinc.com \
    --to=quic_linyyuan@quicinc.com \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®