mbox series

[v2,00/11] usb: gadget: reduce usb gadget trace event buffer usage

Message ID 20230911112446.1791-1-quic_linyyuan@quicinc.com
Headers show
Series usb: gadget: reduce usb gadget trace event buffer usage | expand

Message

Linyu Yuan Sept. 11, 2023, 11:24 a.m. UTC
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.

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

Linyu Yuan (11):
  usb: gadget: add anonymous definition in struct usb_gadget
  usb: gadget: add anonymous definition in struct usb_request
  usb: gadget: add anonymous definition in struct usb_ep
  usb: udc: assign epnum for each usb endpoint
  usb: udc: trace: reduce buffer usage of trace event
  usb: cdns3: cdnsp: 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-gadget.c            |   1 +
 drivers/usb/cdns3/cdns3-trace.h             |  93 +++++------
 drivers/usb/cdns3/cdnsp-gadget.c            |   1 +
 drivers/usb/cdns3/cdnsp-trace.h             |  45 +++---
 drivers/usb/chipidea/udc.c                  |   1 +
 drivers/usb/dwc2/gadget.c                   |   2 +-
 drivers/usb/dwc3/gadget.c                   |   1 +
 drivers/usb/dwc3/trace.h                    |  54 +++----
 drivers/usb/fotg210/fotg210-udc.c           |   1 +
 drivers/usb/gadget/udc/aspeed-vhub/epn.c    |   1 +
 drivers/usb/gadget/udc/aspeed_udc.c         |   1 +
 drivers/usb/gadget/udc/at91_udc.c           |   1 +
 drivers/usb/gadget/udc/atmel_usba_udc.c     |   1 +
 drivers/usb/gadget/udc/bcm63xx_udc.c        |   1 +
 drivers/usb/gadget/udc/bdc/bdc_ep.c         |   1 +
 drivers/usb/gadget/udc/cdns2/cdns2-gadget.c |   2 +-
 drivers/usb/gadget/udc/cdns2/cdns2-trace.h  |  77 +++++-----
 drivers/usb/gadget/udc/dummy_hcd.c          |   1 +
 drivers/usb/gadget/udc/fsl_qe_udc.c         |   1 +
 drivers/usb/gadget/udc/fsl_udc_core.c       |   1 +
 drivers/usb/gadget/udc/fusb300_udc.c        |   1 +
 drivers/usb/gadget/udc/goku_udc.c           |   1 +
 drivers/usb/gadget/udc/gr_udc.c             |   1 +
 drivers/usb/gadget/udc/lpc32xx_udc.c        |   1 +
 drivers/usb/gadget/udc/m66592-udc.c         |   1 +
 drivers/usb/gadget/udc/max3420_udc.c        |   1 +
 drivers/usb/gadget/udc/mv_u3d_core.c        |   2 +
 drivers/usb/gadget/udc/mv_udc_core.c        |   2 +
 drivers/usb/gadget/udc/net2272.c            |   1 +
 drivers/usb/gadget/udc/net2280.c            |   2 +
 drivers/usb/gadget/udc/omap_udc.c           |   1 +
 drivers/usb/gadget/udc/pch_udc.c            |   1 +
 drivers/usb/gadget/udc/pxa25x_udc.c         |   1 +
 drivers/usb/gadget/udc/pxa27x_udc.c         |   1 +
 drivers/usb/gadget/udc/r8a66597-udc.c       |   1 +
 drivers/usb/gadget/udc/renesas_usb3.c       |   1 +
 drivers/usb/gadget/udc/renesas_usbf.c       |   1 +
 drivers/usb/gadget/udc/snps_udc_core.c      |   1 +
 drivers/usb/gadget/udc/tegra-xudc.c         |   2 +
 drivers/usb/gadget/udc/trace.h              | 106 +++++--------
 drivers/usb/gadget/udc/udc-xilinx.c         |   1 +
 drivers/usb/isp1760/isp1760-udc.c           |   1 +
 drivers/usb/mtu3/mtu3_gadget.c              |   1 +
 drivers/usb/mtu3/mtu3_trace.h               |  42 +++--
 drivers/usb/musb/musb_gadget.c              |   1 +
 drivers/usb/musb/musb_trace.h               |  14 +-
 drivers/usb/renesas_usbhs/mod_gadget.c      |   1 +
 drivers/usb/usbip/vudc_dev.c                |   1 +
 include/linux/usb/gadget.h                  | 161 +++++++++++++++-----
 49 files changed, 344 insertions(+), 295 deletions(-)

Comments

Linyu Yuan Sept. 11, 2023, 1:20 p.m. UTC | #1
On 9/11/2023 7:37 PM, Greg Kroah-Hartman wrote:
> On Mon, Sep 11, 2023 at 07:24:36PM +0800, Linyu Yuan wrote:
>> Some UDC trace event will save usb gadget information, but it will use
>> one int size buffer to save one bit information of usb gadget, so more
>> than one int buffer to save several bit fields which is not good.
>>
>> Add one anonymous union have three u32 members which can be used by trace
>> event during fast assign stage to reduce trace buffer usage, and add
>> related macro to extract bit fields from u32 members for later trace event
>> output state usage.
>>
>> Also move sg_supported and other bit fields into one anonymous struct
>> which inside anonymous union and Change bit fields from unsigned to u32
>> type, it will make sure union member have expected u32 size.
>>
>> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
>> ---
>> v2: no change
>>
>>   include/linux/usb/gadget.h | 63 ++++++++++++++++++++++++++------------
>>   1 file changed, 44 insertions(+), 19 deletions(-)
>>
>> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
>> index 75bda0783395..cdf62e7f34e7 100644
>> --- a/include/linux/usb/gadget.h
>> +++ b/include/linux/usb/gadget.h
>> @@ -357,6 +357,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 +433,49 @@ struct usb_gadget {
>>   	unsigned			mA;
>>   	struct usb_otg_caps		*otg_caps;
>>   
>> -	unsigned			sg_supported:1;
>> -	unsigned			is_otg:1;
>> -	unsigned			is_a_peripheral:1;
>> -	unsigned			b_hnp_enable:1;
>> -	unsigned			a_hnp_support:1;
>> -	unsigned			a_alt_hnp_support:1;
>> -	unsigned			hnp_polling_support:1;
>> -	unsigned			host_request_flag:1;
>> -	unsigned			quirk_ep_out_aligned_size:1;
>> -	unsigned			quirk_altset_not_supp:1;
>> -	unsigned			quirk_stall_not_supp:1;
>> -	unsigned			quirk_zlp_not_supp:1;
>> -	unsigned			quirk_avoids_skb_reserve:1;
>> -	unsigned			is_selfpowered:1;
>> -	unsigned			deactivated:1;
>> -	unsigned			connected:1;
>> -	unsigned			lpm_capable:1;
>> -	unsigned			wakeup_capable:1;
>> -	unsigned			wakeup_armed:1;
>> +	union {
>> +		struct {
>> +			u32		sg_supported:1;
>> +			u32		is_otg:1;
>> +			u32		is_a_peripheral:1;
>> +			u32		b_hnp_enable:1;
>> +			u32		a_hnp_support:1;
>> +			u32		a_alt_hnp_support:1;
>> +			u32		hnp_polling_support:1;
>> +			u32		host_request_flag:1;
>> +			u32		quirk_ep_out_aligned_size:1;
>> +			u32		quirk_altset_not_supp:1;
>> +			u32		quirk_stall_not_supp:1;
>> +			u32		quirk_zlp_not_supp:1;
>> +			u32		quirk_avoids_skb_reserve:1;
>> +			u32		is_selfpowered:1;
>> +			u32		deactivated:1;
>> +			u32		connected:1;
>> +			u32		lpm_capable:1;
>> +			u32		wakeup_capable:1;
>> +			u32		wakeup_armed:1;
>> +		} __packed;
>> +		u32			dw1;
>> +#define		USB_GADGET_SG_SUPPORTED(n)			((n) & BIT(0))
>> +#define		USB_GADGET_IS_OTG(n)				((n) & BIT(1))
>> +#define		USB_GADGET_IS_A_PERIPHERAL(n)			((n) & BIT(2))
>> +#define		USB_GADGET_B_HNP_ENABLE(n)			((n) & BIT(3))
>> +#define		USB_GADGET_A_HNP_SUPPORT(n)			((n) & BIT(4))
>> +#define		USB_GADGET_A_ALT_HNP_SUPPORT(n)			((n) & BIT(5))
>> +#define		USB_GADGET_HNP_POLLING_SUPPORT(n)		((n) & BIT(6))
>> +#define		USB_GADGET_HOST_REQUEST_FLAG(n)			((n) & BIT(7))
>> +#define		USB_GADGET_QUIRK_EP_OUT_ALIGNED_SIZE(n)		((n) & BIT(8))
>> +#define		USB_GADGET_QUIRK_ALTSET_NOT_SUPP(n)		((n) & BIT(9))
>> +#define		USB_GADGET_QUIRK_STALL_NOT_SUPP(n)		((n) & BIT(10))
>> +#define		USB_GADGET_QUIRK_ZLP_NOT_SUPP(n)		((n) & BIT(11))
>> +#define		USB_GADGET_QUIRK_AVOIDS_SKB_RESERVE(n)		((n) & BIT(12))
>> +#define		USB_GADGET_IS_SELFPOWERED(n)			((n) & BIT(13))
>> +#define		USB_GADGET_DEACTIVATED(n)			((n) & BIT(14))
>> +#define		USB_GADGET_CONNECTED(n)				((n) & BIT(15))
>> +#define		USB_GADGET_LPM_CAPABLE(n)			((n) & BIT(16))
>> +#define		USB_GADGET_WAKEUP_CAPABLE(n)			((n) & BIT(17))
>> +#define		USB_GADGET_WAKEUP_ARMED(n)			((n) & BIT(18))
> Does this actually work on both types of endian-ness?


sorry, only test little endian on ARM64, will consider big endian.


>
> thanks,
>
> greg k-h
Linyu Yuan Sept. 11, 2023, 1:44 p.m. UTC | #2
On 9/11/2023 9:32 PM, Greg Kroah-Hartman wrote:
> On Mon, Sep 11, 2023 at 07:24:35PM +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.
> Ok, but how much memory did you actually save here?  Is the memory saved
> only if tracing is enbaled, or it is always?  Is there a speed penality
> for these changes or is it the same?

yes, it is save trace ring buffer only when tracing enabled, as save 
less data, speed is higher.


it is help when enable trace for a long period.


for a single trace entry, take struct usb_gadget as example, at worst 
case, it save (19 dword  - 1 dword) / 19dword = 94% buffer.


for ep name, it only need 4 bytes/  (4bytes + 9bytes ) = 30%.


>
> You are doing a lot of code reorginization without any real explaination
> of why this is needed, nor proof about it.
>
> thanks,
>
> greg k-h