mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Zhongqiu Han <quic_zhonhan@quicinc.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"mathias.nyman@intel.com" <mathias.nyman@intel.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] usb: dwc3: core: Call cpu_relax() in registers polling busy loops
Date: Tue, 20 Aug 2024 22:05:41 +0000	[thread overview]
Message-ID: <20240820220536.lgxvvbfboheknyll@synopsys.com> (raw)
In-Reply-To: <20240820121501.3593245-2-quic_zhonhan@quicinc.com>

On Tue, Aug 20, 2024, Zhongqiu Han wrote:
> Busy loops that poll on a register should call cpu_relax(). On some
> architectures, it can lower CPU power consumption or yield to a
> hyperthreaded twin processor. It also serves as a compiler barrier,
> see Documentation/process/volatile-considered-harmful.rst. In addition,
> if something goes wrong in the busy loop at least it can prevent things
> from getting worse.
> 
> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
> ---
>  drivers/usb/dwc3/core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 734de2a8bd21..498f08dbbdb5 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -2050,6 +2050,8 @@ static int dwc3_get_num_ports(struct dwc3 *dwc)
>  		if (!offset)
>  			break;
>  
> +		cpu_relax();
> +
>  		val = readl(base + offset);
>  		major_revision = XHCI_EXT_PORT_MAJOR(val);
>  
> -- 
> 2.25.1
> 

We're not polling on a register here. We're just traversing and reading
the next port capability. The loop in dwc3_get_num_ports() should not be
more than DWC3_USB2_MAX_PORTS + DWC3_USB3_MAX_PORTS.

What's really causing this busy loop you found?

If polling for a register is really a problem, then we would have that
problem everywhere else in dwc3. But why here?

Thanks,
Thinh

  reply	other threads:[~2024-08-20 22:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-20 12:14 [PATCH 0/2] usb: Call cpu_relax() when polling registers Zhongqiu Han
2024-08-20 12:15 ` [PATCH 1/2] usb: dwc3: core: Call cpu_relax() in registers polling busy loops Zhongqiu Han
2024-08-20 22:05   ` Thinh Nguyen [this message]
2024-08-21 13:59     ` Zhongqiu Han
2024-08-20 12:15 ` [PATCH 2/2] usb: xhci: ext-caps: Use cpu_relax() when polling registers Zhongqiu Han
2024-08-21  9:40   ` Mathias Nyman
2024-08-21 14:04     ` Zhongqiu Han

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=20240820220536.lgxvvbfboheknyll@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=quic_zhonhan@quicinc.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®