Re: [PATCH 3/8] usb: udc: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan



On 9/15/2023 10:16 AM, Steven Rostedt wrote:

On Fri, 15 Sep 2023 09:11:06 +0800
Linyu Yuan  wrote:


+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");

Note, there's a temp buffer trace_seq 'p' available for use as well. See
both include/trace/events/libata.h and include/trace/events/scsi.h:

const char *libata_trace_parse_status(struct trace_seq*, unsigned char);
#define __parse_status(s) libata_trace_parse_status(p, s)

I think that can be used instead of adding this TP_printk_init().


the reason add TP_printk_init() because when i first design some macro
which not

related to tracepoint,  it use too much stack.


Not sure what you mean about 'uses too much stack'. This is called by
the reading code and not some arbitrary location, and the above macros
are done in the same location as your "init" call, so I'm not sure how
that makes a difference on the stack.


but i think  TP_printk_init()  is good as it following most common way
to print.


I really do not want to add more versions of TRACE_EVENT() that I need
to maintain unless there is a really good reason to do so.

And I really don't want to encourage the use of a "TP_printk_init()"
because that just encourages more use cases that will make it hard for
user space to parse the TP_printk().



that's true, it is difficult to understand, when i add this new, it 
report build issue.



will consider other way for this case without new tracepoint macro.





-- Steve


Re: [PATCH 3/8] usb: udc: trace: reduce buffer usage of trace event

2023-09-14 Thread Steven Rostedt
On Fri, 15 Sep 2023 09:11:06 +0800
Linyu Yuan  wrote:

> >> +  snprintf(__s, 9, "ep%d%s", te.address, \
> >> +  (te.caps.dir_in && te.caps.dir_out) ? "" : \
> >> +  te.caps.dir_in ? "in" : "out");  
> > Note, there's a temp buffer trace_seq 'p' available for use as well. See
> > both include/trace/events/libata.h and include/trace/events/scsi.h:
> >
> >const char *libata_trace_parse_status(struct trace_seq*, unsigned char);
> >#define __parse_status(s) libata_trace_parse_status(p, s)
> >
> > I think that can be used instead of adding this TP_printk_init().  
> 
> 
> the reason add TP_printk_init() because when i first design some macro 
> which not
> 
> related to tracepoint,  it use too much stack.
> 

Not sure what you mean about 'uses too much stack'. This is called by
the reading code and not some arbitrary location, and the above macros
are done in the same location as your "init" call, so I'm not sure how
that makes a difference on the stack.

> 
> but i think  TP_printk_init()  is good as it following most common way 
> to print.
> 

I really do not want to add more versions of TRACE_EVENT() that I need
to maintain unless there is a really good reason to do so.

And I really don't want to encourage the use of a "TP_printk_init()"
because that just encourages more use cases that will make it hard for
user space to parse the TP_printk().

-- Steve


Re: [PATCH 2/8] usb: gadget: add anonymous definition in some struct for trace purpose

2023-09-14 Thread Linyu Yuan



On 9/15/2023 9:51 AM, Alan Stern wrote:

On Fri, Sep 15, 2023 at 09:02:48AM +0800, Linyu Yuan wrote:

On 9/14/2023 10:54 PM, Alan Stern wrote:

You didn't include the version number in the Subject: line.  Undoubtedly
Greg's automatic error checker will warn you about this.  Unless the
version number is clearly marked for each patch, it's difficult for his
programs to tell which email message contains the most recent version.

On Thu, Sep 14, 2023 at 06:02:56PM +0800, Linyu Yuan wrote:

Some UDC trace event will save usb udc information, but it use one int
size buffer to save one bit information of usb udc, it is wast trace
buffer.

Add anonymous union which have one u32 member can be used by trace event
during fast assign stage to save more entries with same trace ring buffer
size.

Signed-off-by: Linyu Yuan 
---

And you didn't include the version change information here, below the
"---" line.

Apart from that, this is a _lot_ better than before!  I don't know if
Greg will think this change is worth merging, but at least now it's
possible to read the code and understand what's going on.


according Steven's comment, maybe will always save data in little endian at
trace event

fast assign stage.

it will add definition of bit field back.

Yes, that would be even better because you wouldn't have to change the
definition of struct usb_gadget or struct usb_endpoint at all.  The fast
assign stage can simply do:

__entry->dw1 = (g->sg_supported << 0) |
(g->is_otg << 1) |
...

and then you can easily access the individual bits in __entry.  It
wouldn't be as fast but it would still save a lot of space.



how about __entry->dw1 = cpu_to_le32(g->dw1) ?






Alan Stern


Re: [PATCH 2/8] usb: gadget: add anonymous definition in some struct for trace purpose

2023-09-14 Thread Alan Stern
On Fri, Sep 15, 2023 at 09:02:48AM +0800, Linyu Yuan wrote:
> 
> On 9/14/2023 10:54 PM, Alan Stern wrote:
> > You didn't include the version number in the Subject: line.  Undoubtedly
> > Greg's automatic error checker will warn you about this.  Unless the
> > version number is clearly marked for each patch, it's difficult for his
> > programs to tell which email message contains the most recent version.
> > 
> > On Thu, Sep 14, 2023 at 06:02:56PM +0800, Linyu Yuan wrote:
> > > Some UDC trace event will save usb udc information, but it use one int
> > > size buffer to save one bit information of usb udc, it is wast trace
> > > buffer.
> > > 
> > > Add anonymous union which have one u32 member can be used by trace event
> > > during fast assign stage to save more entries with same trace ring buffer
> > > size.
> > > 
> > > Signed-off-by: Linyu Yuan 
> > > ---
> > And you didn't include the version change information here, below the
> > "---" line.
> > 
> > Apart from that, this is a _lot_ better than before!  I don't know if
> > Greg will think this change is worth merging, but at least now it's
> > possible to read the code and understand what's going on.
> 
> 
> according Steven's comment, maybe will always save data in little endian at
> trace event
> 
> fast assign stage.
> 
> it will add definition of bit field back.

Yes, that would be even better because you wouldn't have to change the 
definition of struct usb_gadget or struct usb_endpoint at all.  The fast 
assign stage can simply do:

__entry->dw1 = (g->sg_supported << 0) |
(g->is_otg << 1) |
...

and then you can easily access the individual bits in __entry.  It 
wouldn't be as fast but it would still save a lot of space.

Alan Stern


Re: [PATCH 3/8] usb: udc: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan



On 9/15/2023 12:54 AM, Steven Rostedt wrote:

On Thu, 14 Sep 2023 18:02:57 +0800
Linyu Yuan  wrote:


Save u32 members into trace event ring buffer and parse it for possible
bit fields.

Use new DECLARE_EVENT_CLASS_PRINT_INIT() class macro for output stage.

Signed-off-by: Linyu Yuan 
---
  drivers/usb/gadget/udc/trace.h | 154 +++--
  1 file changed, 69 insertions(+), 85 deletions(-)

diff --git a/drivers/usb/gadget/udc/trace.h b/drivers/usb/gadget/udc/trace.h
index a5ed26fbc2da..e1754667f1d2 100644
--- a/drivers/usb/gadget/udc/trace.h
+++ b/drivers/usb/gadget/udc/trace.h
@@ -17,7 +17,7 @@
  #include 
  #include 
  
-DECLARE_EVENT_CLASS(udc_log_gadget,

+DECLARE_EVENT_CLASS_PRINT_INIT(udc_log_gadget,
TP_PROTO(struct usb_gadget *g, int ret),
TP_ARGS(g, ret),
TP_STRUCT__entry(
@@ -25,20 +25,7 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
__field(enum usb_device_speed, max_speed)
__field(enum usb_device_state, state)
__field(unsigned, mA)
-   __field(unsigned, sg_supported)
-   __field(unsigned, is_otg)
-   __field(unsigned, is_a_peripheral)
-   __field(unsigned, b_hnp_enable)
-   __field(unsigned, a_hnp_support)
-   __field(unsigned, hnp_polling_support)
-   __field(unsigned, host_request_flag)
-   __field(unsigned, quirk_ep_out_aligned_size)
-   __field(unsigned, quirk_altset_not_supp)
-   __field(unsigned, quirk_stall_not_supp)
-   __field(unsigned, quirk_zlp_not_supp)
-   __field(unsigned, is_selfpowered)
-   __field(unsigned, deactivated)
-   __field(unsigned, connected)
+   __field(u32, gdw1)
__field(int, ret)
),
TP_fast_assign(
@@ -46,39 +33,35 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
__entry->max_speed = g->max_speed;
__entry->state = g->state;
__entry->mA = g->mA;
-   __entry->sg_supported = g->sg_supported;
-   __entry->is_otg = g->is_otg;
-   __entry->is_a_peripheral = g->is_a_peripheral;
-   __entry->b_hnp_enable = g->b_hnp_enable;
-   __entry->a_hnp_support = g->a_hnp_support;
-   __entry->hnp_polling_support = g->hnp_polling_support;
-   __entry->host_request_flag = g->host_request_flag;
-   __entry->quirk_ep_out_aligned_size = 
g->quirk_ep_out_aligned_size;
-   __entry->quirk_altset_not_supp = g->quirk_altset_not_supp;
-   __entry->quirk_stall_not_supp = g->quirk_stall_not_supp;
-   __entry->quirk_zlp_not_supp = g->quirk_zlp_not_supp;
-   __entry->is_selfpowered = g->is_selfpowered;
-   __entry->deactivated = g->deactivated;
-   __entry->connected = g->connected;
+   __entry->gdw1 = g->dw1;
__entry->ret = ret;
),
-   TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> 
%d",
+   TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s] 
--> %d",
__entry->speed, __entry->max_speed, __entry->state, __entry->mA,
-   __entry->sg_supported ? "sg:" : "",
-   __entry->is_otg ? "OTG:" : "",
-   __entry->is_a_peripheral ? "a_peripheral:" : "",
-   __entry->b_hnp_enable ? "b_hnp:" : "",
-   __entry->a_hnp_support ? "a_hnp:" : "",
-   __entry->hnp_polling_support ? "hnp_poll:" : "",
-   __entry->host_request_flag ? "hostreq:" : "",
-   __entry->quirk_ep_out_aligned_size ? "out_aligned:" : "",
-   __entry->quirk_altset_not_supp ? "no_altset:" : "",
-   __entry->quirk_stall_not_supp ? "no_stall:" : "",
-   __entry->quirk_zlp_not_supp ? "no_zlp" : "",
-   __entry->is_selfpowered ? "self-powered:" : "bus-powered:",
-   __entry->deactivated ? "deactivated:" : "activated:",
-   __entry->connected ? "connected" : "disconnected",
-   __entry->ret)
+   tg.sg_supported ? "sg:" : "",
+   tg.is_otg ? "OTG:" : "",
+   tg.is_a_peripheral ? "a_peripheral:" : "",
+   tg.b_hnp_enable ? "b_hnp:" : "",
+   tg.a_hnp_support ? "a_hnp:" : "",
+   tg.a_alt_hnp_support ? "a_alt_hnp:" : "",
+   tg.hnp_polling_support ? "hnp_poll:" : "",
+   tg.host_request_flag ? "hostreq:" : "",
+   tg.quirk_ep_out_aligned_size ? "out_aligned:" : "",
+   tg.quirk_altset_not_supp ? "no_altset:" : "",
+   tg.quirk_stall_not_supp ? "no_stall:" : "",
+   tg.quirk_zlp_not_supp ? "no_zlp" : "",
+   tg.quirk_avoids_skb_reserve ? "no_skb_reserve" : "",
+   tg.is_selfpowered ? "self-powered:" : 

Re: [PATCH 2/8] usb: gadget: add anonymous definition in some struct for trace purpose

2023-09-14 Thread Linyu Yuan



On 9/14/2023 10:54 PM, Alan Stern wrote:

You didn't include the version number in the Subject: line.  Undoubtedly
Greg's automatic error checker will warn you about this.  Unless the
version number is clearly marked for each patch, it's difficult for his
programs to tell which email message contains the most recent version.

On Thu, Sep 14, 2023 at 06:02:56PM +0800, Linyu Yuan wrote:

Some UDC trace event will save usb udc information, but it use one int
size buffer to save one bit information of usb udc, it is wast trace
buffer.

Add anonymous union which have one u32 member can be used by trace event
during fast assign stage to save more entries with same trace ring buffer
size.

Signed-off-by: Linyu Yuan 
---

And you didn't include the version change information here, below the
"---" line.

Apart from that, this is a _lot_ better than before!  I don't know if
Greg will think this change is worth merging, but at least now it's
possible to read the code and understand what's going on.



according Steven's comment, maybe will always save data in little endian 
at trace event


fast assign stage.

it will add definition of bit field back.




Alan Stern


Re: [PATCH 3/8] usb: udc: trace: reduce buffer usage of trace event

2023-09-14 Thread Steven Rostedt
On Thu, 14 Sep 2023 18:02:57 +0800
Linyu Yuan  wrote:

> Save u32 members into trace event ring buffer and parse it for possible
> bit fields.
> 
> Use new DECLARE_EVENT_CLASS_PRINT_INIT() class macro for output stage.
> 
> Signed-off-by: Linyu Yuan 
> ---
>  drivers/usb/gadget/udc/trace.h | 154 +++--
>  1 file changed, 69 insertions(+), 85 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/trace.h b/drivers/usb/gadget/udc/trace.h
> index a5ed26fbc2da..e1754667f1d2 100644
> --- a/drivers/usb/gadget/udc/trace.h
> +++ b/drivers/usb/gadget/udc/trace.h
> @@ -17,7 +17,7 @@
>  #include 
>  #include 
>  
> -DECLARE_EVENT_CLASS(udc_log_gadget,
> +DECLARE_EVENT_CLASS_PRINT_INIT(udc_log_gadget,
>   TP_PROTO(struct usb_gadget *g, int ret),
>   TP_ARGS(g, ret),
>   TP_STRUCT__entry(
> @@ -25,20 +25,7 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
>   __field(enum usb_device_speed, max_speed)
>   __field(enum usb_device_state, state)
>   __field(unsigned, mA)
> - __field(unsigned, sg_supported)
> - __field(unsigned, is_otg)
> - __field(unsigned, is_a_peripheral)
> - __field(unsigned, b_hnp_enable)
> - __field(unsigned, a_hnp_support)
> - __field(unsigned, hnp_polling_support)
> - __field(unsigned, host_request_flag)
> - __field(unsigned, quirk_ep_out_aligned_size)
> - __field(unsigned, quirk_altset_not_supp)
> - __field(unsigned, quirk_stall_not_supp)
> - __field(unsigned, quirk_zlp_not_supp)
> - __field(unsigned, is_selfpowered)
> - __field(unsigned, deactivated)
> - __field(unsigned, connected)
> + __field(u32, gdw1)
>   __field(int, ret)
>   ),
>   TP_fast_assign(
> @@ -46,39 +33,35 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
>   __entry->max_speed = g->max_speed;
>   __entry->state = g->state;
>   __entry->mA = g->mA;
> - __entry->sg_supported = g->sg_supported;
> - __entry->is_otg = g->is_otg;
> - __entry->is_a_peripheral = g->is_a_peripheral;
> - __entry->b_hnp_enable = g->b_hnp_enable;
> - __entry->a_hnp_support = g->a_hnp_support;
> - __entry->hnp_polling_support = g->hnp_polling_support;
> - __entry->host_request_flag = g->host_request_flag;
> - __entry->quirk_ep_out_aligned_size = 
> g->quirk_ep_out_aligned_size;
> - __entry->quirk_altset_not_supp = g->quirk_altset_not_supp;
> - __entry->quirk_stall_not_supp = g->quirk_stall_not_supp;
> - __entry->quirk_zlp_not_supp = g->quirk_zlp_not_supp;
> - __entry->is_selfpowered = g->is_selfpowered;
> - __entry->deactivated = g->deactivated;
> - __entry->connected = g->connected;
> + __entry->gdw1 = g->dw1;
>   __entry->ret = ret;
>   ),
> - TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> 
> %d",
> + TP_printk("speed %d/%d state %d %dmA 
> [%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> %d",
>   __entry->speed, __entry->max_speed, __entry->state, __entry->mA,
> - __entry->sg_supported ? "sg:" : "",
> - __entry->is_otg ? "OTG:" : "",
> - __entry->is_a_peripheral ? "a_peripheral:" : "",
> - __entry->b_hnp_enable ? "b_hnp:" : "",
> - __entry->a_hnp_support ? "a_hnp:" : "",
> - __entry->hnp_polling_support ? "hnp_poll:" : "",
> - __entry->host_request_flag ? "hostreq:" : "",
> - __entry->quirk_ep_out_aligned_size ? "out_aligned:" : "",
> - __entry->quirk_altset_not_supp ? "no_altset:" : "",
> - __entry->quirk_stall_not_supp ? "no_stall:" : "",
> - __entry->quirk_zlp_not_supp ? "no_zlp" : "",
> - __entry->is_selfpowered ? "self-powered:" : "bus-powered:",
> - __entry->deactivated ? "deactivated:" : "activated:",
> - __entry->connected ? "connected" : "disconnected",
> - __entry->ret)
> + tg.sg_supported ? "sg:" : "",
> + tg.is_otg ? "OTG:" : "",
> + tg.is_a_peripheral ? "a_peripheral:" : "",
> + tg.b_hnp_enable ? "b_hnp:" : "",
> + tg.a_hnp_support ? "a_hnp:" : "",
> + tg.a_alt_hnp_support ? "a_alt_hnp:" : "",
> + tg.hnp_polling_support ? "hnp_poll:" : "",
> + tg.host_request_flag ? "hostreq:" : "",
> + tg.quirk_ep_out_aligned_size ? "out_aligned:" : "",
> + tg.quirk_altset_not_supp ? "no_altset:" : "",
> + tg.quirk_stall_not_supp ? "no_stall:" : "",
> + tg.quirk_zlp_not_supp ? "no_zlp" : "",
> + tg.quirk_avoids_skb_reserve ? "no_skb_reserve" : "",
> + tg.is_selfpowered ? "self-powered:" : 

Re: [PATCH 0/8] usb: gadget: reduce usb gadget trace event buffer usage

2023-09-14 Thread Steven Rostedt
On Thu, 14 Sep 2023 18:02:54 +0800
Linyu Yuan  wrote:

> some trace event use an interger to to save a bit field info of gadget,
> also some trace save endpoint name in string forat, it all can be
> chagned to other way at trace event store phase.
> 
> bit field can be replace with a union interger member which include
> multiple bit fields.
> 
> ep name stringe can be replace to a interger which contaion number
> and dir info.
> 
> to allow trace output stage can get bit info from save interger,
> add DECLARE_EVENT_CLASS_PRINT_INIT() clas which allow user defined
> operation before print.
> 
> v1: 
> https://lore.kernel.org/linux-usb/20230911042843.2711-1-quic_linyy...@quicinc.com/
> v2: fix two compile issues that COMPILE_TEST not covered
> 
> https://lore.kernel.org/linux-usb/2023092446.1791-1-quic_linyy...@quicinc.com/
> v3: fix reviewer comments, allow bit fields work on both little and big endian
> 
> https://lore.kernel.org/linux-usb/20230912104455.7737-1-quic_linyy...@quicinc.com/
> v4: add DECLARE_EVENT_CLASS_PRINT_INIT() new trace class and use it
> 

All these changes make it useless for user space. :-(

-- Steve

> Linyu Yuan (8):
>   trace: add new DECLARE_EVENT_CLASS_PRINT_INIT class type
>   usb: gadget: add anonymous definition in some struct for trace purpose
>   usb: udc: trace: reduce buffer usage of trace event
>   usb: cdns3: trace: reduce buffer usage of trace event
>   usb: dwc3: trace: reduce buffer usage of trace event
>   usb: cdns2: trace: reduce buffer usage of trace event
>   usb: mtu3: trace: reduce buffer usage of trace event
>   usb: musb: trace: reduce buffer usage of trace event
> 
>  drivers/usb/cdns3/cdns3-trace.h| 201 ++---
>  drivers/usb/cdns3/cdnsp-trace.h| 105 +++
>  drivers/usb/dwc3/trace.h   |  99 ++
>  drivers/usb/gadget/udc/cdns2/cdns2-trace.h | 175 --
>  drivers/usb/gadget/udc/trace.h | 154 +++-
>  drivers/usb/mtu3/mtu3_trace.h  |  76 +---
>  drivers/usb/musb/musb_trace.h  |  20 +-
>  include/linux/tracepoint.h |  22 +++
>  include/linux/usb/gadget.h | 113 +++-
>  include/trace/bpf_probe.h  |   4 +
>  include/trace/perf.h   |  43 +
>  include/trace/stages/stage3_trace_output.h |   3 +
>  include/trace/trace_events.h   | 118 
>  13 files changed, 784 insertions(+), 349 deletions(-)
> 



Re: [PATCH 2/8] usb: gadget: add anonymous definition in some struct for trace purpose

2023-09-14 Thread Alan Stern
You didn't include the version number in the Subject: line.  Undoubtedly 
Greg's automatic error checker will warn you about this.  Unless the 
version number is clearly marked for each patch, it's difficult for his 
programs to tell which email message contains the most recent version.

On Thu, Sep 14, 2023 at 06:02:56PM +0800, Linyu Yuan wrote:
> Some UDC trace event will save usb udc information, but it use one int
> size buffer to save one bit information of usb udc, it is wast trace
> buffer.
> 
> Add anonymous union which have one u32 member can be used by trace event
> during fast assign stage to save more entries with same trace ring buffer
> size.
> 
> Signed-off-by: Linyu Yuan 
> ---

And you didn't include the version change information here, below the 
"---" line.

Apart from that, this is a _lot_ better than before!  I don't know if 
Greg will think this change is worth merging, but at least now it's 
possible to read the code and understand what's going on.

Alan Stern


Re: [PATCH 1/8] trace: add new DECLARE_EVENT_CLASS_PRINT_INIT class type

2023-09-14 Thread kernel test robot
Hi Linyu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on usb/usb-testing]
[also build test WARNING on usb/usb-next usb/usb-linus linus/master v6.6-rc1 
next-20230914]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Linyu-Yuan/trace-add-new-DECLARE_EVENT_CLASS_PRINT_INIT-class-type/20230914-180924
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
patch link:
https://lore.kernel.org/r/20230914100302.30274-2-quic_linyyuan%40quicinc.com
patch subject: [PATCH 1/8] trace: add new DECLARE_EVENT_CLASS_PRINT_INIT class 
type
config: arm-defconfig 
(https://download.01.org/0day-ci/archive/20230914/202309142216.gwm6q6l0-...@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20230914/202309142216.gwm6q6l0-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202309142216.gwm6q6l0-...@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/trace/events/migrate.h:8,
from mm/rmap.c:83:
>> include/linux/tracepoint.h:554: warning: "DECLARE_EVENT_CLASS_PRINT_INIT" 
>> redefined
 554 | #define DECLARE_EVENT_CLASS_PRINT_INIT(name, proto, args, tstruct, 
assign, print, init)
 | 
   In file included from include/trace/define_trace.h:103,
from include/trace/events/tlb.h:62,
from mm/rmap.c:82:
   include/trace/perf.h:59: note: this is the location of the previous 
definition
  59 | #define DECLARE_EVENT_CLASS_PRINT_INIT(call, proto, args, tstruct, 
assign, print, init) \
 | 
>> include/linux/tracepoint.h:580: warning: "TRACE_EVENT_PRINT_INIT" redefined
 580 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, struct, assign, 
print, init)  \
 | 
   In file included from include/trace/define_trace.h:102:
   include/trace/trace_events.h:49: note: this is the location of the previous 
definition
  49 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, tstruct, assign, 
print, init) \
 | 
--
   In file included from include/trace/events/net.h:12,
from net/core/net-traces.c:31:
>> include/linux/tracepoint.h:554: warning: "DECLARE_EVENT_CLASS_PRINT_INIT" 
>> redefined
 554 | #define DECLARE_EVENT_CLASS_PRINT_INIT(name, proto, args, tstruct, 
assign, print, init)
 | 
   In file included from include/trace/define_trace.h:103,
from include/trace/events/skb.h:95,
from net/core/net-traces.c:30:
   include/trace/perf.h:59: note: this is the location of the previous 
definition
  59 | #define DECLARE_EVENT_CLASS_PRINT_INIT(call, proto, args, tstruct, 
assign, print, init) \
 | 
>> include/linux/tracepoint.h:580: warning: "TRACE_EVENT_PRINT_INIT" redefined
 580 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, struct, assign, 
print, init)  \
 | 
   In file included from include/trace/define_trace.h:102:
   include/trace/trace_events.h:49: note: this is the location of the previous 
definition
  49 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, tstruct, assign, 
print, init) \
 | 
   In file included from include/trace/events/napi.h:9,
from net/core/net-traces.c:32:
>> include/linux/tracepoint.h:554: warning: "DECLARE_EVENT_CLASS_PRINT_INIT" 
>> redefined
 554 | #define DECLARE_EVENT_CLASS_PRINT_INIT(name, proto, args, tstruct, 
assign, print, init)
 | 
   In file included from include/trace/define_trace.h:103,
from include/trace/events/net.h:319:
   include/trace/perf.h:59: note: this is the location of the previous 
definition
  59 | #define DECLARE_EVENT_CLASS_PRINT_INIT(call, proto, args, tstruct, 
assign, print, init) \
 | 
>> include/linux/tracepoint.h:580: warning: "TRACE_EVENT_PRINT_INIT" redefined
 580 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, struct, assign, 
print, init)  \
 | 
   In file included from include/trace/define_trace.h:102:
   include/trace/trace_events.h:49: note: this is the location of the previous 
definition
  49 | #define TRACE_EVENT_PRINT_INIT(name, proto, args, tstruct, assign, 
print, init) \
 | 
   In file included from include/trace/events/sock.h:10,
from net/core/net-traces.c:33:
>> include/linux/tracepoint.h:554: warning: "DECLARE_EVENT_CLASS_PRINT_INIT" 

[PATCH 2/8] usb: gadget: add anonymous definition in some struct for trace purpose

2023-09-14 Thread Linyu Yuan
Some UDC trace event will save usb udc information, but it use one int
size buffer to save one bit information of usb udc, it is wast trace
buffer.

Add anonymous union which have one u32 member can be used by trace event
during fast assign stage to save more entries with same trace ring buffer
size.

Signed-off-by: Linyu Yuan 
---
 include/linux/usb/gadget.h | 113 +++--
 1 file changed, 72 insertions(+), 41 deletions(-)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 75bda0783395..4894f256df55 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -41,6 +41,7 @@ struct usb_ep;
  * @num_sgs: number of SG entries
  * @num_mapped_sgs: number of SG entries mapped to DMA (internal)
  * @length: Length of that data
+ * @dw1: trace event purpose
  * @stream_id: The stream id, when USB3.0 bulk streams are being used
  * @is_last: Indicates if this is the last request of a stream_id before
  * switching to a different stream (required for DWC3 controllers).
@@ -105,12 +106,17 @@ struct usb_request {
unsignednum_sgs;
unsignednum_mapped_sgs;
 
-   unsignedstream_id:16;
-   unsignedis_last:1;
-   unsignedno_interrupt:1;
-   unsignedzero:1;
-   unsignedshort_not_ok:1;
-   unsigneddma_mapped:1;
+   union {
+   struct {
+   u32 stream_id:16;
+   u32 is_last:1;
+   u32 no_interrupt:1;
+   u32 zero:1;
+   u32 short_not_ok:1;
+   u32 dma_mapped:1;
+   } __packed;
+   u32 dw1;
+   };
 
void(*complete)(struct usb_ep *ep,
struct usb_request *req);
@@ -163,13 +169,13 @@ struct usb_ep_ops {
  * @dir_out:Endpoint supports OUT direction.
  */
 struct usb_ep_caps {
-   unsigned type_control:1;
-   unsigned type_iso:1;
-   unsigned type_bulk:1;
-   unsigned type_int:1;
-   unsigned dir_in:1;
-   unsigned dir_out:1;
-};
+   u8  type_control:1;
+   u8  type_iso:1;
+   u8  type_bulk:1;
+   u8  type_int:1;
+   u8  dir_in:1;
+   u8  dir_out:1;
+} __packed;
 
 #define USB_EP_CAPS_TYPE_CONTROL 0x01
 #define USB_EP_CAPS_TYPE_ISO 0x02
@@ -199,6 +205,9 @@ struct usb_ep_caps {
  * @caps:The structure describing types and directions supported by endpoint.
  * @enabled: The current endpoint enabled/disabled state.
  * @claimed: True if this endpoint is claimed by a function.
+ * @dw1: trace event purpose
+ * @dw2: trace event purpose
+ * @dw3: trace event purpose
  * @maxpacket:The maximum packet size used on this endpoint.  The initial
  * value can sometimes be reduced (hardware allowing), according to
  * the endpoint descriptor used to configure the endpoint.
@@ -228,15 +237,30 @@ struct usb_ep {
const char  *name;
const struct usb_ep_ops *ops;
struct list_headep_list;
-   struct usb_ep_caps  caps;
-   boolclaimed;
-   boolenabled;
-   unsignedmaxpacket:16;
-   unsignedmaxpacket_limit:16;
-   unsignedmax_streams:16;
-   unsignedmult:2;
-   unsignedmaxburst:5;
-   u8  address;
+   union {
+   struct {
+   u32 maxpacket:16;
+   u32 maxpacket_limit:16;
+   } __packed;
+   u32 dw1;
+   };
+   union {
+   struct {
+   u32 max_streams:16;
+   u32 mult:2;
+   u32 maxburst:5;
+   } __packed;
+   u32 dw2;
+   };
+   union {
+   struct {
+   struct usb_ep_caps  caps;
+   u8  claimed:1;
+   u8  enabled:1;
+   u8  address;
+   } __packed;
+   u32 dw3;
+   };
const struct usb_endpoint_descriptor*desc;
const struct usb_ss_ep_comp_descriptor  *comp_desc;
 };
@@ -357,6 +381,7 @@ struct usb_gadget_ops {
  * @in_epnum: last used in ep number
  * @mA: last set mA value
  * @otg_caps: OTG capabilities of this gadget.
+ * @dw1: trace event purpose
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  * gadget driver must provide a USB OTG descriptor.
@@ -432,25 +457,31 @@ struct usb_gadget {
unsignedmA;
 

[PATCH 8/8] usb: musb: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 member into trace event ring buffer and parse it for possible
bit information.

Use DECLARE_EVENT_CLASS_PRINT_INIT() related macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/musb/musb_trace.h | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/musb/musb_trace.h b/drivers/usb/musb/musb_trace.h
index f246b14394c4..8add5e81ed8d 100644
--- a/drivers/usb/musb/musb_trace.h
+++ b/drivers/usb/musb/musb_trace.h
@@ -233,7 +233,7 @@ DEFINE_EVENT(musb_urb, musb_urb_deq,
TP_ARGS(musb, urb)
 );
 
-DECLARE_EVENT_CLASS(musb_req,
+DECLARE_EVENT_CLASS_PRINT_INIT(musb_req,
TP_PROTO(struct musb_request *req),
TP_ARGS(req),
TP_STRUCT__entry(
@@ -243,9 +243,7 @@ DECLARE_EVENT_CLASS(musb_req,
__field(int, status)
__field(unsigned int, buf_len)
__field(unsigned int, actual_len)
-   __field(unsigned int, zero)
-   __field(unsigned int, short_not_ok)
-   __field(unsigned int, no_interrupt)
+   __field(u32, rdw1)
),
TP_fast_assign(
__entry->req = >request;
@@ -254,18 +252,20 @@ DECLARE_EVENT_CLASS(musb_req,
__entry->status = req->request.status;
__entry->buf_len = req->request.length;
__entry->actual_len = req->request.actual;
-   __entry->zero = req->request.zero;
-   __entry->short_not_ok = req->request.short_not_ok;
-   __entry->no_interrupt = req->request.no_interrupt;
+   __entry->rdw1 = req->request.dw1;
),
TP_printk("%p, ep%d %s, %s%s%s, len %d/%d, status %d",
__entry->req, __entry->epnum,
__entry->is_tx ? "tx/IN" : "rx/OUT",
-   __entry->zero ? "Z" : "z",
-   __entry->short_not_ok ? "S" : "s",
-   __entry->no_interrupt ? "I" : "i",
+   tr.zero ? "Z" : "z",
+   tr.short_not_ok ? "S" : "s",
+   tr.no_interrupt ? "I" : "i",
__entry->actual_len, __entry->buf_len,
__entry->status
+   ),
+   TP_printk_init(
+   struct usb_request tr;
+   tr.dw1 = __entry->rdw1;
)
 );
 
-- 
2.17.1



[PATCH 7/8] usb: mtu3: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 members into trace event ring buffer and parse it for possible
bit information.

Use DECLARE_EVENT_CLASS_PRINT_INIT() related macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/mtu3/mtu3_trace.h | 76 +++
 1 file changed, 50 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3_trace.h b/drivers/usb/mtu3/mtu3_trace.h
index 03d2a9bac27e..22b821771c24 100644
--- a/drivers/usb/mtu3/mtu3_trace.h
+++ b/drivers/usb/mtu3/mtu3_trace.h
@@ -113,35 +113,43 @@ DEFINE_EVENT(mtu3_log_setup, mtu3_handle_setup,
TP_ARGS(setup)
 );
 
-DECLARE_EVENT_CLASS(mtu3_log_request,
+DECLARE_EVENT_CLASS_PRINT_INIT(mtu3_log_request,
TP_PROTO(struct mtu3_request *mreq),
TP_ARGS(mreq),
TP_STRUCT__entry(
-   __string(name, mreq->mep->name)
+   __field(u32, edw3)
__field(struct mtu3_request *, mreq)
__field(struct qmu_gpd *, gpd)
__field(unsigned int, actual)
__field(unsigned int, length)
__field(int, status)
-   __field(int, zero)
-   __field(int, no_interrupt)
+   __field(u32, rdw1)
),
TP_fast_assign(
-   __assign_str(name, mreq->mep->name);
+   __entry->edw3 = mreq->mep->ep.dw3;
__entry->mreq = mreq;
__entry->gpd = mreq->gpd;
__entry->actual = mreq->request.actual;
__entry->length = mreq->request.length;
__entry->status = mreq->request.status;
-   __entry->zero = mreq->request.zero;
-   __entry->no_interrupt = mreq->request.no_interrupt;
+   __entry->rdw1 = mreq->request.dw1;
),
TP_printk("%s: req %p gpd %p len %u/%u %s%s --> %d",
-   __get_str(name), __entry->mreq, __entry->gpd,
+   __s, __entry->mreq, __entry->gpd,
__entry->actual, __entry->length,
-   __entry->zero ? "Z" : "z",
-   __entry->no_interrupt ? "i" : "I",
+   tr.zero ? "Z" : "z",
+   tr.no_interrupt ? "i" : "I",
__entry->status
+   ),
+   TP_printk_init(
+   struct usb_ep te;
+   struct usb_request tr;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   tr.dw1 = __entry->rdw1;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
)
 );
 
@@ -170,11 +178,11 @@ DEFINE_EVENT(mtu3_log_request, mtu3_req_complete,
TP_ARGS(req)
 );
 
-DECLARE_EVENT_CLASS(mtu3_log_gpd,
+DECLARE_EVENT_CLASS_PRINT_INIT(mtu3_log_gpd,
TP_PROTO(struct mtu3_ep *mep, struct qmu_gpd *gpd),
TP_ARGS(mep, gpd),
TP_STRUCT__entry(
-   __string(name, mep->name)
+   __field(u32, edw3)
__field(struct qmu_gpd *, gpd)
__field(u32, dw0)
__field(u32, dw1)
@@ -182,7 +190,7 @@ DECLARE_EVENT_CLASS(mtu3_log_gpd,
__field(u32, dw3)
),
TP_fast_assign(
-   __assign_str(name, mep->name);
+   __entry->edw3 = mep->ep.dw3;
__entry->gpd = gpd;
__entry->dw0 = le32_to_cpu(gpd->dw0_info);
__entry->dw1 = le32_to_cpu(gpd->next_gpd);
@@ -190,9 +198,17 @@ DECLARE_EVENT_CLASS(mtu3_log_gpd,
__entry->dw3 = le32_to_cpu(gpd->dw3_info);
),
TP_printk("%s: gpd %p - %08x %08x %08x %08x",
-   __get_str(name), __entry->gpd,
+   __s, __entry->gpd,
__entry->dw0, __entry->dw1,
__entry->dw2, __entry->dw3
+   ),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
)
 );
 
@@ -211,41 +227,49 @@ DEFINE_EVENT(mtu3_log_gpd, mtu3_zlp_exp_gpd,
TP_ARGS(mep, gpd)
 );
 
-DECLARE_EVENT_CLASS(mtu3_log_ep,
+DECLARE_EVENT_CLASS_PRINT_INIT(mtu3_log_ep,
TP_PROTO(struct mtu3_ep *mep),
TP_ARGS(mep),
TP_STRUCT__entry(
-   __string(name, mep->name)
+   __field(u32, edw3)
__field(unsigned int, type)
__field(unsigned int, slot)
-   __field(unsigned int, maxp)
-   __field(unsigned int, mult)
-   __field(unsigned int, maxburst)
+   __field(u32, edw1)
+   __field(u32, edw2)
__field(unsigned int, flags)
__field(unsigned int, direction)
__field(struct mtu3_gpd_ring *, gpd_ring)
),
TP_fast_assign(
- 

[PATCH 6/8] usb: cdns2: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 members into trace event ring buffer and parse it for possible
bit information.

Use DECLARE_EVENT_CLASS_PRINT_INIT() related macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/gadget/udc/cdns2/cdns2-trace.h | 175 ++---
 1 file changed, 121 insertions(+), 54 deletions(-)

diff --git a/drivers/usb/gadget/udc/cdns2/cdns2-trace.h 
b/drivers/usb/gadget/udc/cdns2/cdns2-trace.h
index 61f241634ea5..f81caa12cb63 100644
--- a/drivers/usb/gadget/udc/cdns2/cdns2-trace.h
+++ b/drivers/usb/gadget/udc/cdns2/cdns2-trace.h
@@ -94,51 +94,74 @@ DEFINE_EVENT(cdns2_log_simple, cdns2_device_state,
TP_ARGS(msg)
 );
 
-TRACE_EVENT(cdns2_ep_halt,
+TRACE_EVENT_PRINT_INIT(cdns2_ep_halt,
TP_PROTO(struct cdns2_endpoint *ep_priv, u8 halt, u8 flush),
TP_ARGS(ep_priv, halt, flush),
TP_STRUCT__entry(
-   __string(name, ep_priv->name)
+   __field(u32, edw3)
__field(u8, halt)
__field(u8, flush)
),
TP_fast_assign(
-   __assign_str(name, ep_priv->name);
+   __entry->edw3 = ep_priv->endpoint.dw3;
__entry->halt = halt;
__entry->flush = flush;
),
TP_printk("Halt %s for %s: %s", __entry->flush ? " and flush" : "",
- __get_str(name), __entry->halt ? "set" : "cleared")
+ __s, __entry->halt ? "set" : "cleared"),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
-TRACE_EVENT(cdns2_wa1,
+TRACE_EVENT_PRINT_INIT(cdns2_wa1,
TP_PROTO(struct cdns2_endpoint *ep_priv, char *msg),
TP_ARGS(ep_priv, msg),
TP_STRUCT__entry(
-   __string(ep_name, ep_priv->name)
+   __field(u32, edw3)
__string(msg, msg)
),
TP_fast_assign(
-   __assign_str(ep_name, ep_priv->name);
+   __entry->edw3 = ep_priv->endpoint.dw3;
__assign_str(msg, msg);
),
-   TP_printk("WA1: %s %s", __get_str(ep_name), __get_str(msg))
+   TP_printk("WA1: %s %s", __s, __get_str(msg)),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
-DECLARE_EVENT_CLASS(cdns2_log_doorbell,
+DECLARE_EVENT_CLASS_PRINT_INIT(cdns2_log_doorbell,
TP_PROTO(struct cdns2_endpoint *pep, u32 ep_trbaddr),
TP_ARGS(pep, ep_trbaddr),
TP_STRUCT__entry(
-   __string(name, pep->num ? pep->name :
-   (pep->dir ? "ep0in" : "ep0out"))
+   __field(u32, edw3)
__field(u32, ep_trbaddr)
),
TP_fast_assign(
-   __assign_str(name, pep->name);
+   __entry->edw3 = pep->endpoint.dw3;
__entry->ep_trbaddr = ep_trbaddr;
),
-   TP_printk("%s, ep_trbaddr %08x", __get_str(name),
- __entry->ep_trbaddr)
+   TP_printk("%s, ep_trbaddr %08x", __s,
+ __entry->ep_trbaddr),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
 DEFINE_EVENT(cdns2_log_doorbell, cdns2_doorbell_ep0,
@@ -186,26 +209,34 @@ TRACE_EVENT(cdns2_dma_ep_ists,
  __entry->dma_ep_ists >> 16)
 );
 
-DECLARE_EVENT_CLASS(cdns2_log_epx_irq,
+DECLARE_EVENT_CLASS_PRINT_INIT(cdns2_log_epx_irq,
TP_PROTO(struct cdns2_device *pdev, struct cdns2_endpoint *pep),
TP_ARGS(pdev, pep),
TP_STRUCT__entry(
-   __string(ep_name, pep->name)
+   __field(u32, edw3)
__field(u32, ep_sts)
__field(u32, ep_ists)
__field(u32, ep_traddr)
),
TP_fast_assign(
-   __assign_str(ep_name, pep->name);
+   __entry->edw3 = pep->endpoint.dw3;
__entry->ep_sts = readl(>adma_regs->ep_sts);
__entry->ep_ists = readl(>adma_regs->ep_ists);
__entry->ep_traddr = readl(>adma_regs->ep_traddr);
),
TP_printk("%s, ep_traddr: %08x",
  cdns2_decode_epx_irq(__get_buf(CDNS2_MSG_MAX), CDNS2_MSG_MAX,
-  __get_str(ep_name),
+  __s,
   

[PATCH 5/8] usb: dwc3: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 members into trace event ring buffer and parse it for possible
bit information.

Use DECLARE_EVENT_CLASS_PRINT_INIT() related macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/dwc3/trace.h | 99 +---
 1 file changed, 63 insertions(+), 36 deletions(-)

diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index d2997d17cfbe..3caac180b225 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -98,35 +98,41 @@ DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req,
TP_ARGS(ctrl)
 );
 
-DECLARE_EVENT_CLASS(dwc3_log_request,
+DECLARE_EVENT_CLASS_PRINT_INIT(dwc3_log_request,
TP_PROTO(struct dwc3_request *req),
TP_ARGS(req),
TP_STRUCT__entry(
-   __string(name, req->dep->name)
+   __field(u32, edw3)
__field(struct dwc3_request *, req)
__field(unsigned int, actual)
__field(unsigned int, length)
__field(int, status)
-   __field(int, zero)
-   __field(int, short_not_ok)
-   __field(int, no_interrupt)
+   __field(u32, rdw1)
),
TP_fast_assign(
-   __assign_str(name, req->dep->name);
+   __entry->edw3 = req->dep->endpoint.dw3;
__entry->req = req;
__entry->actual = req->request.actual;
__entry->length = req->request.length;
__entry->status = req->request.status;
-   __entry->zero = req->request.zero;
-   __entry->short_not_ok = req->request.short_not_ok;
-   __entry->no_interrupt = req->request.no_interrupt;
+   __entry->rdw1 = req->request.dw1;
),
TP_printk("%s: req %p length %u/%u %s%s%s ==> %d",
-   __get_str(name), __entry->req, __entry->actual, __entry->length,
-   __entry->zero ? "Z" : "z",
-   __entry->short_not_ok ? "S" : "s",
-   __entry->no_interrupt ? "i" : "I",
+   __s, __entry->req, __entry->actual, __entry->length,
+   tr.zero ? "Z" : "z",
+   tr.short_not_ok ? "S" : "s",
+   tr.no_interrupt ? "i" : "I",
__entry->status
+   ),
+   TP_printk_init(
+   struct usb_ep te;
+   struct usb_request tr;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   tr.dw1 = __entry->rdw1;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
)
 );
 
@@ -180,12 +186,12 @@ DEFINE_EVENT(dwc3_log_generic_cmd, 
dwc3_gadget_generic_cmd,
TP_ARGS(cmd, param, status)
 );
 
-DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
+DECLARE_EVENT_CLASS_PRINT_INIT(dwc3_log_gadget_ep_cmd,
TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
struct dwc3_gadget_ep_cmd_params *params, int cmd_status),
TP_ARGS(dep, cmd, params, cmd_status),
TP_STRUCT__entry(
-   __string(name, dep->name)
+   __field(u32, edw3)
__field(unsigned int, cmd)
__field(u32, param0)
__field(u32, param1)
@@ -193,7 +199,7 @@ DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
__field(int, cmd_status)
),
TP_fast_assign(
-   __assign_str(name, dep->name);
+   __entry->edw3 = dep->endpoint.dw3;
__entry->cmd = cmd;
__entry->param0 = params->param0;
__entry->param1 = params->param1;
@@ -201,10 +207,18 @@ DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
__entry->cmd_status = cmd_status;
),
TP_printk("%s: cmd '%s' [%x] params %08x %08x %08x --> status: %s",
-   __get_str(name), dwc3_gadget_ep_cmd_string(__entry->cmd),
+   __s, dwc3_gadget_ep_cmd_string(__entry->cmd),
__entry->cmd, __entry->param0,
__entry->param1, __entry->param2,
dwc3_ep_cmd_status_string(__entry->cmd_status)
+   ),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
)
 );
 
@@ -214,11 +228,11 @@ DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd,
TP_ARGS(dep, cmd, params, cmd_status)
 );
 
-DECLARE_EVENT_CLASS(dwc3_log_trb,
+DECLARE_EVENT_CLASS_PRINT_INIT(dwc3_log_trb,
TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
TP_ARGS(dep, trb),
TP_STRUCT__entry(
-   __string(name, dep->name)
+   __field(u32, edw3)
__field(struct dwc3_trb *, trb)

[PATCH 4/8] usb: cdns3: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 members into trace event ring buffer and parse it for possible
bit information.

Use DECLARE_EVENT_CLASS_PRINT_INIT() related macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/cdns3/cdns3-trace.h | 201 ++--
 drivers/usb/cdns3/cdnsp-trace.h | 105 +++--
 2 files changed, 209 insertions(+), 97 deletions(-)

diff --git a/drivers/usb/cdns3/cdns3-trace.h b/drivers/usb/cdns3/cdns3-trace.h
index 40db89ec..9711d4b48eb6 100644
--- a/drivers/usb/cdns3/cdns3-trace.h
+++ b/drivers/usb/cdns3/cdns3-trace.h
@@ -24,49 +24,73 @@
 
 #define CDNS3_MSG_MAX  500
 
-TRACE_EVENT(cdns3_halt,
+TRACE_EVENT_PRINT_INIT(cdns3_halt,
TP_PROTO(struct cdns3_endpoint *ep_priv, u8 halt, u8 flush),
TP_ARGS(ep_priv, halt, flush),
TP_STRUCT__entry(
-   __string(name, ep_priv->name)
+   __field(u32, edw3)
__field(u8, halt)
__field(u8, flush)
),
TP_fast_assign(
-   __assign_str(name, ep_priv->name);
+   __entry->edw3 = ep_priv->endpoint.dw3;
__entry->halt = halt;
__entry->flush = flush;
),
TP_printk("Halt %s for %s: %s", __entry->flush ? " and flush" : "",
- __get_str(name), __entry->halt ? "set" : "cleared")
+ __s, __entry->halt ? "set" : "cleared"),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
-TRACE_EVENT(cdns3_wa1,
+TRACE_EVENT_PRINT_INIT(cdns3_wa1,
TP_PROTO(struct cdns3_endpoint *ep_priv, char *msg),
TP_ARGS(ep_priv, msg),
TP_STRUCT__entry(
-   __string(ep_name, ep_priv->name)
+   __field(u32, edw3)
__string(msg, msg)
),
TP_fast_assign(
-   __assign_str(ep_name, ep_priv->name);
+   __entry->edw3 = ep_priv->endpoint.dw3;
__assign_str(msg, msg);
),
-   TP_printk("WA1: %s %s", __get_str(ep_name), __get_str(msg))
+   TP_printk("WA1: %s %s", __s, __get_str(msg)),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
-TRACE_EVENT(cdns3_wa2,
+TRACE_EVENT_PRINT_INIT(cdns3_wa2,
TP_PROTO(struct cdns3_endpoint *ep_priv, char *msg),
TP_ARGS(ep_priv, msg),
TP_STRUCT__entry(
-   __string(ep_name, ep_priv->name)
+   __field(u32, edw3)
__string(msg, msg)
),
TP_fast_assign(
-   __assign_str(ep_name, ep_priv->name);
+   __entry->edw3 = ep_priv->endpoint.dw3;
__assign_str(msg, msg);
),
-   TP_printk("WA2: %s %s", __get_str(ep_name), __get_str(msg))
+   TP_printk("WA2: %s %s", __s, __get_str(msg)),
+   TP_printk_init(
+   struct usb_ep te;
+   char __s[9];
+   te.dw3 = __entry->edw3;
+   snprintf(__s, 9, "ep%d%s", te.address, \
+   (te.caps.dir_in && te.caps.dir_out) ? "" : \
+   te.caps.dir_in ? "in" : "out");
+   )
 );
 
 DECLARE_EVENT_CLASS(cdns3_log_doorbell,
@@ -114,18 +138,18 @@ DEFINE_EVENT(cdns3_log_usb_irq, cdns3_usb_irq,
TP_ARGS(priv_dev, usb_ists)
 );
 
-DECLARE_EVENT_CLASS(cdns3_log_epx_irq,
+DECLARE_EVENT_CLASS_PRINT_INIT(cdns3_log_epx_irq,
TP_PROTO(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep),
TP_ARGS(priv_dev, priv_ep),
TP_STRUCT__entry(
-   __string(ep_name, priv_ep->name)
+   __field(u32, edw3)
__field(u32, ep_sts)
__field(u32, ep_traddr)
__field(u32, ep_last_sid)
__field(u32, use_streams)
),
TP_fast_assign(
-   __assign_str(ep_name, priv_ep->name);
+   __entry->edw3 = priv_ep->endpoint.dw3;
__entry->ep_sts = readl(_dev->regs->ep_sts);
__entry->ep_traddr = readl(_dev->regs->ep_traddr);
__entry->ep_last_sid = priv_ep->last_stream_id;
@@ -133,11 +157,19 @@ DECLARE_EVENT_CLASS(cdns3_log_epx_irq,
),
TP_printk("%s, ep_traddr: %08x ep_last_sid: %08x use_streams: %d",
  cdns3_decode_epx_irq(__get_buf(CDNS3_MSG_MAX),
-  __get_str(ep_name),
+  __s,
   __entry->ep_sts),
  __entry->ep_traddr,
  

[PATCH 3/8] usb: udc: trace: reduce buffer usage of trace event

2023-09-14 Thread Linyu Yuan
Save u32 members into trace event ring buffer and parse it for possible
bit fields.

Use new DECLARE_EVENT_CLASS_PRINT_INIT() class macro for output stage.

Signed-off-by: Linyu Yuan 
---
 drivers/usb/gadget/udc/trace.h | 154 +++--
 1 file changed, 69 insertions(+), 85 deletions(-)

diff --git a/drivers/usb/gadget/udc/trace.h b/drivers/usb/gadget/udc/trace.h
index a5ed26fbc2da..e1754667f1d2 100644
--- a/drivers/usb/gadget/udc/trace.h
+++ b/drivers/usb/gadget/udc/trace.h
@@ -17,7 +17,7 @@
 #include 
 #include 
 
-DECLARE_EVENT_CLASS(udc_log_gadget,
+DECLARE_EVENT_CLASS_PRINT_INIT(udc_log_gadget,
TP_PROTO(struct usb_gadget *g, int ret),
TP_ARGS(g, ret),
TP_STRUCT__entry(
@@ -25,20 +25,7 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
__field(enum usb_device_speed, max_speed)
__field(enum usb_device_state, state)
__field(unsigned, mA)
-   __field(unsigned, sg_supported)
-   __field(unsigned, is_otg)
-   __field(unsigned, is_a_peripheral)
-   __field(unsigned, b_hnp_enable)
-   __field(unsigned, a_hnp_support)
-   __field(unsigned, hnp_polling_support)
-   __field(unsigned, host_request_flag)
-   __field(unsigned, quirk_ep_out_aligned_size)
-   __field(unsigned, quirk_altset_not_supp)
-   __field(unsigned, quirk_stall_not_supp)
-   __field(unsigned, quirk_zlp_not_supp)
-   __field(unsigned, is_selfpowered)
-   __field(unsigned, deactivated)
-   __field(unsigned, connected)
+   __field(u32, gdw1)
__field(int, ret)
),
TP_fast_assign(
@@ -46,39 +33,35 @@ DECLARE_EVENT_CLASS(udc_log_gadget,
__entry->max_speed = g->max_speed;
__entry->state = g->state;
__entry->mA = g->mA;
-   __entry->sg_supported = g->sg_supported;
-   __entry->is_otg = g->is_otg;
-   __entry->is_a_peripheral = g->is_a_peripheral;
-   __entry->b_hnp_enable = g->b_hnp_enable;
-   __entry->a_hnp_support = g->a_hnp_support;
-   __entry->hnp_polling_support = g->hnp_polling_support;
-   __entry->host_request_flag = g->host_request_flag;
-   __entry->quirk_ep_out_aligned_size = 
g->quirk_ep_out_aligned_size;
-   __entry->quirk_altset_not_supp = g->quirk_altset_not_supp;
-   __entry->quirk_stall_not_supp = g->quirk_stall_not_supp;
-   __entry->quirk_zlp_not_supp = g->quirk_zlp_not_supp;
-   __entry->is_selfpowered = g->is_selfpowered;
-   __entry->deactivated = g->deactivated;
-   __entry->connected = g->connected;
+   __entry->gdw1 = g->dw1;
__entry->ret = ret;
),
-   TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> 
%d",
+   TP_printk("speed %d/%d state %d %dmA 
[%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> %d",
__entry->speed, __entry->max_speed, __entry->state, __entry->mA,
-   __entry->sg_supported ? "sg:" : "",
-   __entry->is_otg ? "OTG:" : "",
-   __entry->is_a_peripheral ? "a_peripheral:" : "",
-   __entry->b_hnp_enable ? "b_hnp:" : "",
-   __entry->a_hnp_support ? "a_hnp:" : "",
-   __entry->hnp_polling_support ? "hnp_poll:" : "",
-   __entry->host_request_flag ? "hostreq:" : "",
-   __entry->quirk_ep_out_aligned_size ? "out_aligned:" : "",
-   __entry->quirk_altset_not_supp ? "no_altset:" : "",
-   __entry->quirk_stall_not_supp ? "no_stall:" : "",
-   __entry->quirk_zlp_not_supp ? "no_zlp" : "",
-   __entry->is_selfpowered ? "self-powered:" : "bus-powered:",
-   __entry->deactivated ? "deactivated:" : "activated:",
-   __entry->connected ? "connected" : "disconnected",
-   __entry->ret)
+   tg.sg_supported ? "sg:" : "",
+   tg.is_otg ? "OTG:" : "",
+   tg.is_a_peripheral ? "a_peripheral:" : "",
+   tg.b_hnp_enable ? "b_hnp:" : "",
+   tg.a_hnp_support ? "a_hnp:" : "",
+   tg.a_alt_hnp_support ? "a_alt_hnp:" : "",
+   tg.hnp_polling_support ? "hnp_poll:" : "",
+   tg.host_request_flag ? "hostreq:" : "",
+   tg.quirk_ep_out_aligned_size ? "out_aligned:" : "",
+   tg.quirk_altset_not_supp ? "no_altset:" : "",
+   tg.quirk_stall_not_supp ? "no_stall:" : "",
+   tg.quirk_zlp_not_supp ? "no_zlp" : "",
+   tg.quirk_avoids_skb_reserve ? "no_skb_reserve" : "",
+   tg.is_selfpowered ? "self-powered:" : "bus-powered:",
+   tg.deactivated ? "deactivated:" : "activated:",
+   tg.connected ? 

[PATCH 0/8] usb: gadget: reduce usb gadget trace event buffer usage

2023-09-14 Thread Linyu Yuan
some trace event use an interger to to save a bit field info of gadget,
also some trace save endpoint name in string forat, it all can be
chagned to other way at trace event store phase.

bit field can be replace with a union interger member which include
multiple bit fields.

ep name stringe can be replace to a interger which contaion number
and dir info.

to allow trace output stage can get bit info from save interger,
add DECLARE_EVENT_CLASS_PRINT_INIT() clas which allow user defined
operation before print.

v1: 
https://lore.kernel.org/linux-usb/20230911042843.2711-1-quic_linyy...@quicinc.com/
v2: fix two compile issues that COMPILE_TEST not covered

https://lore.kernel.org/linux-usb/2023092446.1791-1-quic_linyy...@quicinc.com/
v3: fix reviewer comments, allow bit fields work on both little and big endian

https://lore.kernel.org/linux-usb/20230912104455.7737-1-quic_linyy...@quicinc.com/
v4: add DECLARE_EVENT_CLASS_PRINT_INIT() new trace class and use it

Linyu Yuan (8):
  trace: add new DECLARE_EVENT_CLASS_PRINT_INIT class type
  usb: gadget: add anonymous definition in some struct for trace purpose
  usb: udc: trace: reduce buffer usage of trace event
  usb: cdns3: trace: reduce buffer usage of trace event
  usb: dwc3: trace: reduce buffer usage of trace event
  usb: cdns2: trace: reduce buffer usage of trace event
  usb: mtu3: trace: reduce buffer usage of trace event
  usb: musb: trace: reduce buffer usage of trace event

 drivers/usb/cdns3/cdns3-trace.h| 201 ++---
 drivers/usb/cdns3/cdnsp-trace.h| 105 +++
 drivers/usb/dwc3/trace.h   |  99 ++
 drivers/usb/gadget/udc/cdns2/cdns2-trace.h | 175 --
 drivers/usb/gadget/udc/trace.h | 154 +++-
 drivers/usb/mtu3/mtu3_trace.h  |  76 +---
 drivers/usb/musb/musb_trace.h  |  20 +-
 include/linux/tracepoint.h |  22 +++
 include/linux/usb/gadget.h | 113 +++-
 include/trace/bpf_probe.h  |   4 +
 include/trace/perf.h   |  43 +
 include/trace/stages/stage3_trace_output.h |   3 +
 include/trace/trace_events.h   | 118 
 13 files changed, 784 insertions(+), 349 deletions(-)

-- 
2.17.1



[PATCH 1/8] trace: add new DECLARE_EVENT_CLASS_PRINT_INIT class type

2023-09-14 Thread Linyu Yuan
This class almost same as DECLARE_EVENT_CLASS, it allow user add some
init operation before print at output stage.

Add a new macro TP_printk_init(), user can add operation in it.

Also add a new TRACE_EVENT_PRINT_INIT() macro.

Signed-off-by: Linyu Yuan 
---
 include/linux/tracepoint.h |  22 
 include/trace/bpf_probe.h  |   4 +
 include/trace/perf.h   |  43 
 include/trace/stages/stage3_trace_output.h |   3 +
 include/trace/trace_events.h   | 118 +
 5 files changed, 190 insertions(+)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index 88c0ba623ee6..3fd42640236a 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -551,6 +551,7 @@ static inline struct tracepoint 
*tracepoint_ptr_deref(tracepoint_ptr_t *p)
  */
 
 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
+#define DECLARE_EVENT_CLASS_PRINT_INIT(name, proto, args, tstruct, assign, 
print, init)
 #define DEFINE_EVENT(template, name, proto, args)  \
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
@@ -576,6 +577,20 @@ static inline struct tracepoint 
*tracepoint_ptr_deref(tracepoint_ptr_t *p)
DECLARE_TRACE_CONDITION(name, PARAMS(proto),\
PARAMS(args), PARAMS(cond))
 
+#define TRACE_EVENT_PRINT_INIT(name, proto, args, struct, assign, print, init) 
\
+   DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_FN_PRINT_INIT(name, proto, args, struct,   \
+   assign, print, reg, unreg, init)\
+   DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_FN_COND_PRINT_INIT(name, proto, args, cond, struct,
\
+   assign, print, reg, unreg, init)\
+   DECLARE_TRACE_CONDITION(name, PARAMS(proto),\
+   PARAMS(args), PARAMS(cond))
+#define TRACE_EVENT_CONDITION_PRINT_INIT(name, proto, args, cond,  
\
+ struct, assign, print, init)  \
+   DECLARE_TRACE_CONDITION(name, PARAMS(proto),\
+   PARAMS(args), PARAMS(cond))
+
 #define TRACE_EVENT_FLAGS(event, flag)
 
 #define TRACE_EVENT_PERF_PERM(event, expr...)
@@ -595,4 +610,11 @@ static inline struct tracepoint 
*tracepoint_ptr_deref(tracepoint_ptr_t *p)
 #define DEFINE_EVENT_NOP(template, name, proto, args)  \
DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args))
 
+#define TRACE_EVENT_NOP_PRINT_INIT(name, proto, args, struct, assign, print, 
init) \
+   DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args))
+
+#define DECLARE_EVENT_CLASS_NOP_PRINT_INIT(name, proto, args, tstruct, assign, 
print, init)
+#define DEFINE_EVENT_NOP(template, name, proto, args)  \
+   DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args))
+
 #endif /* ifdef TRACE_EVENT (see note above) */
diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h
index e609cd7da47e..99b5594a4a8e 100644
--- a/include/trace/bpf_probe.h
+++ b/include/trace/bpf_probe.h
@@ -54,6 +54,10 @@ __bpf_trace_##call(void *__data, proto)  
\
 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
 
+#undef DECLARE_EVENT_CLASS_PRINT_INIT
+#define DECLARE_EVENT_CLASS_PRINT_INIT(call, proto, args, tstruct, assign, 
print, init)\
+   __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
+
 /*
  * This part is compiled out, it is only here as a build time check
  * to make sure that if the tracepoint handling changes, the
diff --git a/include/trace/perf.h b/include/trace/perf.h
index 2c11181c82e0..bee78e8eef5d 100644
--- a/include/trace/perf.h
+++ b/include/trace/perf.h
@@ -55,6 +55,49 @@ perf_trace_##call(void *__data, proto)   
\
  head, __task);\
 }
 
+#undef DECLARE_EVENT_CLASS_PRINT_INIT
+#define DECLARE_EVENT_CLASS_PRINT_INIT(call, proto, args, tstruct, assign, 
print, init)\
+static notrace void\
+perf_trace_##call(void *__data, proto) \
+{  \
+   struct trace_event_call *event_call = __data;   \
+   struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
+   struct trace_event_raw_##call *entry;   \
+   struct pt_regs *__regs; \
+   u64 __count = 1;\
+   struct task_struct *__task = NULL;  \
+