mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Thomas Gleixner' <tglx@linutronix.de>,
	Bart Van Assche <bvanassche@acm.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Russell King <linux@armlinux.org.uk>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Clemens Ladisch <clemens@ladisch.de>
Subject: RE: [PATCH 07/21] hpet: Switch to number_of_interrupts()
Date: Mon, 7 Oct 2024 13:00:02 +0000	[thread overview]
Message-ID: <18b139e4a0674892ba69d00e5f170b7f@AcuMS.aculab.com> (raw)
In-Reply-To: <874j5oun7x.ffs@tglx>

From: Thomas Gleixner <tglx@linutronix.de>
> Sent: 07 October 2024 13:12
> 
> On Sun, Oct 06 2024 at 17:45, Bart Van Assche wrote:
> > On 10/6/24 10:13 AM, David Laight wrote:
> >> From: Bart Van Assche
> >>> Sent: 30 September 2024 19:16
> >>> --- a/drivers/char/hpet.c
> >>> +++ b/drivers/char/hpet.c
> >>> @@ -195,7 +195,7 @@ static void hpet_timer_set_irq(struct hpet_dev *devp)
> >>>   		v &= ~0xffff;
> >>>
> >>>   	for_each_set_bit(irq, &v, HPET_MAX_IRQ) {
> >>> -		if (irq >= nr_irqs) {
> >>> +		if (irq >= number_of_interrupts()) {
> >>>   			irq = HPET_MAX_IRQ;
> >>>   			break;
> >>>   		}
> >>
> >> This is horrid.
> >> You've replaced the read of a global variable (which, in some cases the
> >> compiler might be able to pull outside the loop) with a real function
> >> call in every loop iteration.
> >>
> >> With all the mitigations for cpu speculative execution 'issues' you
> >> pretty much don't want trivial function calls.
> >>
> >> If you are worried about locals shadowing globals just change one of the names.
> >
> > Since HPET_MAX_IRQ == 32 and since the lower 16 bits of 'v' are cleared
> > on modern systems, would it be such a big deal if number_of_interrupts()
> > is called 16 times?
> 
> No. The context is open() which is a slow path operation.

This was one example of that code loop - and probably not the best
to have picked.
Indeed, it is using a long[] bitmap designed for 'big' bitmaps
for one that fits in 32 bits and (probably) coding a 'find first bit'
function using the impossible HPET_NAX_IRQ value as an error exit.

In any case 'accessor functions' just move the global symbol from
being a data symbol to a code symbol while obfuscating the
code and making it harder to find where values are set and used.

	David

> 
> > Since number_of_interrupts() has been marked as __pure, and since the
> > kernel is built with -O2, do you agree that this should be sufficient to
> > let the compiler CSE optimization step move function calls like the
> > above from inside a loop out of the loop?
> 
> It could do so.
> 
> Thanks,
> 
>         tglx

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2024-10-07 13:01 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 18:15 [PATCH 00/21] Reduce the scope of 'nr_irqs' Bart Van Assche
2024-09-30 18:15 ` [PATCH 01/21] genirq: Introduce number_of_interrupts() and set_number_of_interrupts() Bart Van Assche
2024-10-01 12:33   ` Thomas Gleixner
2024-10-01 20:12     ` Bart Van Assche
2024-10-02 15:49       ` Thomas Gleixner
2024-10-03 21:01         ` Bart Van Assche
2024-10-06 19:58           ` Thomas Gleixner
2024-09-30 18:15 ` [PATCH 02/21] ARM: Switch to number_of_interrupts() / set_number_of_interrupts() Bart Van Assche
2024-09-30 18:15 ` [PATCH 03/21] LoongArch: Switch to set_number_of_interrupts() Bart Van Assche
2024-09-30 18:15 ` [PATCH 04/21] powerpc/cell: Switch to number_of_interrupts() Bart Van Assche
2024-09-30 18:15 ` [PATCH 05/21] s390/irq: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 06/21] x86/acpi: Switch to number_of_interrupts() / set_number_of_interrupts() Bart Van Assche
2024-09-30 18:15 ` [PATCH 07/21] hpet: Switch to number_of_interrupts() Bart Van Assche
2024-10-06 17:13   ` David Laight
2024-10-07  0:45     ` Bart Van Assche
2024-10-07 12:11       ` Thomas Gleixner
2024-10-07 13:00         ` David Laight [this message]
2024-10-07 15:27           ` Thomas Gleixner
2024-09-30 18:15 ` [PATCH 08/21] net: 3com: 3c59x: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 09/21] net: hamradio: baycom_ser_fdx: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 10/21] scsi: aha152x: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 11/21] serial: core: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 12/21] serial: 8250: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 13/21] serial: amba-pl010: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 14/21] serial: amba-pl011: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 15/21] serial: cpm_uart: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 16/21] serial: ucc_uart: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 17/21] sh: intc: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 18/21] xen/events: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 19/21] fs/procfs: " Bart Van Assche
2024-09-30 18:15 ` [PATCH 20/21] genirq: " Bart Van Assche
2024-10-07 16:26   ` Bart Van Assche
2024-09-30 18:16 ` [PATCH 21/21] genirq: Unexport nr_irqs Bart Van Assche

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=18b139e4a0674892ba69d00e5f170b7f@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bvanassche@acm.org \
    --cc=clemens@ladisch.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome