lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5bb2eb8f-0219-4ba2-9822-dc06316b22e9@quicinc.com>
Date: Fri, 20 Dec 2024 22:37:23 +0800
From: Zhongqiu Han <quic_zhonhan@...cinc.com>
To: Jiri Slaby <jirislaby@...nel.org>, <gregkh@...uxfoundation.org>
CC: <linux-kernel@...r.kernel.org>, <linux-serial@...r.kernel.org>,
        "Zhongqiu
 Han" <quic_zhonhan@...cinc.com>
Subject: Re: [PATCH] tty: mips_ejtag_fdc: Call cpu_relax() in registers
 polling busy loops

On 12/20/2024 3:16 PM, Jiri Slaby wrote:
> On 19. 12. 24, 13:42, Zhongqiu Han wrote:
>> It is considered good practice to call cpu_relax() in busy loops, see
>> Documentation/process/volatile-considered-harmful.rst. This can lower CPU
>> power consumption or yield to a hyperthreaded twin processor, or serve as
>> a compiler barrier. 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@...cinc.com>
>> ---
>>   drivers/tty/mips_ejtag_fdc.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
>> index afbf7738c7c4..b17ead1e9698 100644
>> --- a/drivers/tty/mips_ejtag_fdc.c
>> +++ b/drivers/tty/mips_ejtag_fdc.c
>> @@ -346,7 +346,7 @@ static void mips_ejtag_fdc_console_write(struct 
>> console *c, const char *s,
>>           /* Busy wait until there's space in fifo */
>>           while (__raw_readl(regs + REG_FDSTAT) & REG_FDSTAT_TXF)
>> -            ;
>> +            cpu_relax();
>>           __raw_writel(word.word, regs + REG_FDTX(c->index));
>>       }
>>   out:
>> @@ -1233,7 +1233,7 @@ static void kgdbfdc_push_one(void)
>>       /* Busy wait until there's space in fifo */
>>       while (__raw_readl(regs + REG_FDSTAT) & REG_FDSTAT_TXF)
>> -        ;
>> +        cpu_relax();
> 
> Can this instead be switched to read_poll_timeout_atomic() or alike? 
> Those already contain cpu_relax(), of course...
> 
> thanks,

Hi Jiri,
Thanks a lot for the review!

yeah, maybe we can consider read_poll_timeout_atomic() or alike.

The implementation of read_poll_timeout_atomic() provides a precise
customization of the address busy read poll behavior by calling udelay()
and cpu_relax(), and using a timeout threshold. However, in this case,
it seems we might not need to customize the poll behavior. Since
udelay() only consumes CPU cycles, perhaps cpu_relax() is sufficient?
And if it times out, we still need to keep retrying until the data is
read. My initial thought was to call cpu_relax() to save power or act as
a memory barrier. As I mentioned before in my email to Greg, certain
MIPS-based architectures, such as Loongson-3, should requirecpu_relax().
Thanks~




-- 
Thx and BRs,
Zhongqiu Han

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ