mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de,
	yhlu.kernel@gmail.com, macro@linux-mips.org
Subject: Re: [patch 3/3] x86: io-apic - code style cleaning for setup_IO_APIC_irqs
Date: Fri, 5 Sep 2008 22:33:47 +0400	[thread overview]
Message-ID: <20080905183347.GB19334@lenovo> (raw)
In-Reply-To: <20080905181111.GG27395@elte.hu>

[Ingo Molnar - Fri, Sep 05, 2008 at 08:11:11PM +0200]
| 
| * Cyrill Gorcunov <gorcunov@gmail.com> wrote:
| 
| > [Ingo Molnar - Fri, Sep 05, 2008 at 10:04:47AM +0200]
| > | 
| > | * Cyrill Gorcunov <gorcunov@gmail.com> wrote:
| > | 
| > | > Use a nested level for 'for' cycle and break long lines.
| > | > For apic_print we should countinue using KERNEL_DEBUG if
| > | > we have started to.
| > | 
| > | > @@ -1521,32 +1521,35 @@ static void __init setup_IO_APIC_irqs(vo
| > | >  	apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
| > | >  
| > | >  	for (apic = 0; apic < nr_ioapics; apic++) {
| > | > -	for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
| > | > +		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
| > | >  
| > | > +			idx = find_irq_entry(apic, pin, mp_INT);
| > | > +			if (idx == -1) {
| > | 
| > | hm, i dont really like the super-deep nesting we do here. Could you 
| > | please split out the iterator into a separate function? That makes the 
| > | code a lot easier to understand and saves two extra tabs as well for 
| > | those ugly-looking printk lines.
| > | 
| > | 	Ingo
| > | 
| > 
| > You know it seems we use such a 'cycle on every pin on io-apics'
| > in several places for now:
| > 
| > io_apic.c
| > ---------
| > 	clear_IO_APIC
| > 	save_mask_IO_APIC_setup
| > 	restore_IO_APIC_setup
| > 	IO_APIC_irq_trigger
| > 	setup_IO_APIC_irqs
| > 
| > I've made a one-line macro for this (like for_all_ioapics_pins)
| > _but_ it looks much more ugly then this two nested for(;;) :)
| > 
| > If you meant me to make a separate iterator over the pins I think
| > it will not help a lot - this function is simple enought so the only
| > problem is too-long-printk-form - maybe just print them on separated
| > lines instead of tracking apicids? Or it was made in a sake to not
| > scroll screen too much?
| 
| hm, by iterator i meant the body itself. I.e. something like:
| 
| static void __init setup_IO_APIC_irqs(void)
| {
|         int apic, pin, notcon = 1;
| 
|         apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
| 
|         for (apic = 0; apic < nr_ioapics; apic++)
| 		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
| 			notcon = setup_ioapic_irq(apic, pin, notcon);
| 
|         if (!notcon)
|                 apic_printk(APIC_VERBOSE, " not connected.\n");
| }
| 
| this looks quite a bit cleaner, doesnt it? We lose the 'idx' and 'irq' 
| variables and we lose the curly braces as well. The flow looks a lot 
| more trivial. And the new setup_ioapic_irq() function will be simpler as 
| well - it will only have 'idx' and 'irq' as a local variable, the rest 
| comes in as a parameter. It can 'return notcon' instead of 'continue'. 
| And it will be 2 levels of tabs aligned to the left, as an added bonus.
| 
| Hm?
| 
| 	Ingo
| 

Yes Ingo it does look much cleaner _but_ the only thing which bothering
me is that we split 'logical solid' printing into several functions -
i mean we started printing in new setup_ioapic_irq function and finish
it in caller and that is much worser then having long lines printing
in single function i think (but I could be wrong :)

If we just drop original printing (just for a second to get the whole
image) we will get:

---
static void __init setup_IO_APIC_irqs(void)
{
	int apic, pin, idx, irq, first_notcon = 1;

	for (apic = 0; apic < nr_ioapics; apic++) {
		for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {

			idx = find_irq_entry(apic, pin, mp_INT);
			if (idx == -1) 
				continue;

			irq = pin_2_irq(idx, apic, pin);
#ifdef CONFIG_X86_32
			if (multi_timer_check(apic, irq))
				continue;
#endif
			add_pin_to_irq(irq, apic, pin);

			setup_IO_APIC_irq(apic, pin, irq,
					irq_trigger(idx), irq_polarity(idx));
		}
	}
---

So as you see it's more then enough self-solid :) So I wouldn't
break it 'cause of printing. If we have enough memory for bit
field - we could just mark there if pin is connected to irq and
print connection map after.
Don't get me wrong please - I just don't want to overload this function
with additional call.

According how many characters have been typed for this message I think
instead of talking I could already have done the patch you supposed :)

		- Cyrill -

  reply	other threads:[~2008-09-05 18:34 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080904183748.950151853@gmail.com>
2008-09-04 18:37 ` [patch 1/3] x86: io-apic - use ARRAY_SIZE macro Cyrill Gorcunov
2008-09-05  8:02   ` Ingo Molnar
2008-09-04 18:37 ` [patch 2/3] x86: io-apic - declare irq_cfg_lock for SPARSE_IRQ only Cyrill Gorcunov
2008-09-05  8:03   ` Ingo Molnar
2008-09-04 18:37 ` [patch 3/3] x86: io-apic - code style cleaning for setup_IO_APIC_irqs Cyrill Gorcunov
2008-09-05  8:04   ` Ingo Molnar
2008-09-05 13:49     ` Cyrill Gorcunov
2008-09-05 18:01     ` Cyrill Gorcunov
2008-09-05 18:11       ` Ingo Molnar
2008-09-05 18:33         ` Cyrill Gorcunov [this message]
2008-09-05 18:38           ` Ingo Molnar
2008-09-05 19:15             ` Cyrill Gorcunov
2008-09-06 10:15             ` Cyrill Gorcunov
2008-09-06 13:12               ` Ingo Molnar
2008-09-08  0:24                 ` Yinghai Lu
2008-09-08  4:18                   ` Cyrill Gorcunov
2008-09-08  4:20                   ` Cyrill Gorcunov
2008-09-08  4:38                     ` Yinghai Lu
2008-09-08  5:07                       ` Yinghai Lu
2008-09-08  5:17                         ` Cyrill Gorcunov
2008-09-06 18:45               ` Maciej W. Rozycki
2008-09-06 18:49                 ` Ingo Molnar
2008-09-06 20:02                   ` Maciej W. Rozycki
2008-09-07 10:00                   ` Cyrill Gorcunov
2008-09-07 15:47                     ` Ingo Molnar
2008-09-07 16:04                       ` Cyrill Gorcunov
2008-09-06 19:04                 ` Cyrill Gorcunov
2008-09-06 19:16                   ` Yinghai Lu
2008-09-06 19:19                     ` Cyrill Gorcunov
2008-09-06 19:38                     ` Cyrill Gorcunov
2008-09-06 19:44                       ` Cyrill Gorcunov
2008-09-06 20:08                         ` Maciej W. Rozycki
2008-09-06 20:13                           ` Cyrill Gorcunov

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=20080905183347.GB19334@lenovo \
    --to=gorcunov@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=macro@linux-mips.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=yhlu.kernel@gmail.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®