mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Guan-Yu Lin <guanyulin@google.com>
Cc: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com,
	mathias.nyman@intel.com, perex@perex.cz, tiwai@suse.com,
	sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com,
	ricardo@marliere.net, lijiayi@kylinos.cn,
	quic_jjohnson@quicinc.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org
Subject: Re: [PATCH v7 3/5] usb: add apis for offload usage tracking
Date: Thu, 9 Jan 2025 10:04:34 -0500	[thread overview]
Message-ID: <69a4ae28-dbdc-48eb-b77b-147f58739913@rowland.harvard.edu> (raw)
In-Reply-To: <20250109035605.1486717-4-guanyulin@google.com>

On Thu, Jan 09, 2025 at 03:55:07AM +0000, Guan-Yu Lin wrote:
> Introduce offload_usage and corresponding apis to track offload usage
> on each USB device. Offload denotes that there is another co-processor
> accessing the USB device via the same USB host controller. To optimize
> power usage, it's essential to monitor whether the USB device is
> actively used by other co-processor. This information is vital when
> determining if a USB device can be safely suspended during system power
> state transitions.
> 
> Signed-off-by: Guan-Yu Lin <guanyulin@google.com>
> ---
>  drivers/usb/core/driver.c | 108 ++++++++++++++++++++++++++++++++++++++
>  drivers/usb/core/usb.c    |   4 ++
>  include/linux/usb.h       |  19 +++++++
>  3 files changed, 131 insertions(+)
> 
> diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
> index f203fdbfb6f6..01f6287cf73f 100644
> --- a/drivers/usb/core/driver.c
> +++ b/drivers/usb/core/driver.c
> @@ -2037,6 +2037,114 @@ int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
>  
>  #endif /* CONFIG_PM */
>  
> +#ifdef CONFIG_USB_XHCI_SIDEBAND
> +
> +/**
> + * usb_offload_get - increment the offload_usage of a USB device
> + * @udev: the USB device to increment its offload_usage
> + *
> + * Incrementing the offload_usage of a usb_device indicates that offload is
> + * enabled on this usb_device; that is, another entity is actively handling USB
> + * transfers. This information allows the USB driver to adjust its power
> + * management policy based on offload activity.
> + *
> + * The caller must hold @udev's device lock.
> + *
> + * Return: 0 on success. A negative error code otherwise.
> + */
> +int usb_offload_get(struct usb_device *udev)
> +{
> +	int ret;
> +
> +	if (udev->state == USB_STATE_NOTATTACHED ||
> +			udev->state == USB_STATE_SUSPENDED)
> +		return -EAGAIN;
> +
> +	/*
> +	 * offload_usage could only be modified when the device is active, since
> +	 * it will alter the suspend flow of the device.
> +	 */
> +	ret = pm_runtime_get_sync(&udev->dev);

Note that this function will increment the runtime PM reference count 
even if it returns an error.  You probably want to call 
pm_runtime_resume_and_get() instead.  Likewise in usb_offload_put().

> +
> +	if (ret < 0)
> +		return ret;
> +
> +	refcount_inc(&udev->offload_usage);
> +	pm_runtime_put_sync(&udev->dev);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_offload_get);

Alan Stern

  reply	other threads:[~2025-01-09 15:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09  3:55 [PATCH v7 0/5] Support system sleep with offloaded usb transfers Guan-Yu Lin
2025-01-09  3:55 ` [PATCH v7 1/5] usb: dwc3: separate dev_pm_ops for each pm_event Guan-Yu Lin
2025-01-09  3:55 ` [PATCH v7 2/5] usb: xhci-plat: " Guan-Yu Lin
2025-01-09  3:55 ` [PATCH v7 3/5] usb: add apis for offload usage tracking Guan-Yu Lin
2025-01-09 15:04   ` Alan Stern [this message]
2025-01-13  9:19     ` Guan-Yu Lin
2025-01-09  3:55 ` [PATCH v7 4/5] xhci: sideband: add api to trace sideband usage Guan-Yu Lin
2025-01-09  3:55 ` [PATCH v7 5/5] usb: host: enable USB offload during system sleep Guan-Yu Lin
2025-01-09 15:08   ` Alan Stern
2025-01-13 16:14     ` Guan-Yu Lin

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=69a4ae28-dbdc-48eb-b77b-147f58739913@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=guanyulin@google.com \
    --cc=kekrby@gmail.com \
    --cc=lijiayi@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=oneukum@suse.com \
    --cc=perex@perex.cz \
    --cc=quic_jjohnson@quicinc.com \
    --cc=ricardo@marliere.net \
    --cc=sumit.garg@linaro.org \
    --cc=tiwai@suse.com \
    /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®