x86: avoid redundant loop in io_apic_level_ack_pending()
PATCH 1/9 x86: avoid redundant loop in io_apic_level_ack_pending()
In reply to a message not in the archiveIf one can find an ack pending pin, there is no need to check the rest of them.
--- arch/x86/kernel/io_apic_64.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/kernel/io_apic_64.c +7 -4
@@ -155,11 +155,10 @@ static inline void io_apic_modify(unsignwritel (value, &io_apic->data); } -static int io_apic_level_ack_pending (unsigned int irq) +static bool io_apic_level_ack_pending (unsigned int irq) {struct irq_pin_list *entry;unsigned long flags; -int pending =0 ;spin_lock_irqsave (&ioapic_lock, flags); entry = irq_2_pin + irq;
@@ -172,13 +171,17 @@ static int io_apic_level_ack_pending(unsbreak ; reg =io_apic_read (entry->apic,0x10 + pin*2 );/* Is the remote IRR bit set? */ - pending |= (reg >>14 ) &1 ; +if ((reg >>14 ) &1 ) { +spin_unlock_irqrestore (&ioapic_lock, flags); +return true; + }if (!entry->next)break ; entry = irq_2_pin + entry->next; }spin_unlock_irqrestore (&ioapic_lock, flags); -return pending; + +return false; }/*
PATCH 2/9 x86: use ioapic_read_entry() and ioapic_write_entry()
In reply to a message not in the archiveRemove duplicate code by using ioapic_read_entry() and ioapic_write_entry() in io_apic_{32,64}.c
--- arch/x86/kernel/io_apic_32.c | 10 ++-------- arch/x86/kernel/io_apic_64.c | 25 ++++++------------------- 2 files changed, 8 insertions(+), 27 deletions(-)
arch/x86/kernel/io_apic_64.c +6 -19
@@ -905,9 +905,8 @@ static void __init setup_IO_APIC_irqs(vostatic void __init setup_ExtINT_IRQ0_pin (unsigned int apic,unsigned int pin,int vector) {struct IO_APIC_route_entry entry; -unsigned long flags; -memset (&entry,0 ,sizeof (entry)); +memset (&entry,0 ,sizeof (entry));disable_8259A_irq (0 );
@@ -935,10 +934,7 @@ static void __init setup_ExtINT_IRQ0_pin/* * Add it to the IO-APIC irq-routing table: */ -spin_lock_irqsave (&ioapic_lock, flags); -io_apic_write (apic,0x11 +2 *pin, *(((int *)&entry)+1 )); -io_apic_write (apic,0x10 +2 *pin, *(((int *)&entry)+0 )); -spin_unlock_irqrestore (&ioapic_lock, flags); +ioapic_write_entry (apic, pin, entry);enable_8259A_irq (0 ); }
@@ -1600,17 +1596,14 @@ static inline void unlock_ExtINT_logic(vint apic, pin, i;struct IO_APIC_route_entry entry0, entry1;unsigned char save_control, save_freq_select; -unsigned long flags; pin =find_isa_irq_pin (8 , mp_INT); apic =find_isa_irq_apic (8 , mp_INT);if (pin ==-1 )return ; -spin_lock_irqsave (&ioapic_lock, flags); - *(((int *)&entry0) +1 ) =io_apic_read (apic,0x11 +2 * pin); - *(((int *)&entry0) +0 ) =io_apic_read (apic,0x10 +2 * pin); -spin_unlock_irqrestore (&ioapic_lock, flags); + entry0 =ioapic_read_entry (apic, pin); +clear_IO_APIC_pin (apic, pin);memset (&entry1,0 ,sizeof (entry1));
@@ -1623,10 +1616,7 @@ static inline void unlock_ExtINT_logic(v entry1.trigger =0 ; entry1.vector =0 ; -spin_lock_irqsave (&ioapic_lock, flags); -io_apic_write (apic,0x11 +2 * pin, *(((int *)&entry1) +1 )); -io_apic_write (apic,0x10 +2 * pin, *(((int *)&entry1) +0 )); -spin_unlock_irqrestore (&ioapic_lock, flags); +ioapic_write_entry (apic, pin, entry1); save_control =CMOS_READ (RTC_CONTROL ); save_freq_select =CMOS_READ (RTC_FREQ_SELECT );
@@ -1645,10 +1635,7 @@ static inline void unlock_ExtINT_logic(vCMOS_WRITE (save_freq_select,RTC_FREQ_SELECT );clear_IO_APIC_pin (apic, pin); -spin_lock_irqsave (&ioapic_lock, flags); -io_apic_write (apic,0x11 +2 * pin, *(((int *)&entry0) +1 )); -io_apic_write (apic,0x10 +2 * pin, *(((int *)&entry0) +0 )); -spin_unlock_irqrestore (&ioapic_lock, flags); +ioapic_write_entry (apic, pin, entry0); }/*
arch/x86/kernel/io_apic_32.c +2 -8
@@ -1260,7 +1260,6 @@ static void __init setup_IO_APIC_irqs(vo {struct IO_APIC_route_entry entry;int apic, pin, idx, irq, first_notcon =1 , vector; -unsigned long flags;apic_printk (APIC_VERBOSE ,KERN_DEBUG "init IO_APIC IRQs\n" );
@@ -1326,9 +1325,7 @@ static void __init setup_IO_APIC_irqs(voif (!apic && (irq <16 ))disable_8259A_irq (irq); } -spin_lock_irqsave (&ioapic_lock, flags); -__ioapic_write_entry (apic, pin, entry); -spin_unlock_irqrestore (&ioapic_lock, flags); +ioapic_write_entry (apic, pin, entry); } }
@@ -2789,7 +2786,6 @@ int __init io_apic_get_redir_entries (inint io_apic_set_pci_routing (int ioapic,int pin,int irq,int edge_level,int active_high_low) {struct IO_APIC_route_entry entry; -unsigned long flags;if (!IO_APIC_IRQ (irq)) { printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
@@ -2830,9 +2826,7 @@ int io_apic_set_pci_routing (int ioapic,if (!ioapic && (irq <16 ))disable_8259A_irq (irq); -spin_lock_irqsave (&ioapic_lock, flags); -__ioapic_write_entry (ioapic, pin, entry); -spin_unlock_irqrestore (&ioapic_lock, flags); +ioapic_write_entry (ioapic, pin, entry);return 0 ; }
PATCH 3/9 x86: remove unnecessary memset()
In reply to a message not in the archiveNo need to clear the memory allocated by alloc_bootmem(). It is already filled with zero.
--- arch/x86/kernel/io_apic_64.c | 1 - 1 file changed, 1 deletion(-)
arch/x86/kernel/io_apic_64.c +0 -1
@@ -2304,7 +2304,6 @@ static struct resource * __init ioapic_s res = (void *)mem;if (mem !=NULL ) { -memset (mem,0 , n); mem +=sizeof (struct resource ) * nr_ioapics;for (i =0 ; i < nr_ioapics; i++) {
PATCH 4/9 x86: remove unnecessary tmp local variable
In reply to a message not in the archiveThere is no reason to use obscurer name.
--- arch/x86/kernel/io_apic_32.c | 3 +-- arch/x86/kernel/io_apic_64.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/io_apic_32.c +1 -2
@@ -2028,8 +2028,7 @@ static inline void init_IO_APIC_traps(vo* 0x80, because int 0x80 is hm, kind of importantish. ;) */ for (irq =0 ; irq <NR_IRQS ; irq++) { -int tmp = irq; -if (IO_APIC_IRQ (tmp) && !irq_vector[tmp]) { +if (IO_APIC_IRQ (irq) && !irq_vector[irq]) {/* * Hmm.. We don't have an entry for this, * so default to an old-fashioned 8259
arch/x86/kernel/io_apic_64.c +1 -2
@@ -1516,8 +1516,7 @@ static inline void init_IO_APIC_traps(vo* 0x80, because int 0x80 is hm, kind of importantish. ;) */ for (irq =0 ; irq <NR_IRQS ; irq++) { -int tmp = irq; -if (IO_APIC_IRQ (tmp) && !irq_cfg[tmp].vector) { +if (IO_APIC_IRQ (irq) && !irq_cfg[irq].vector) {/* * Hmm.. We don't have an entry for this, * so default to an old-fashioned 8259
PATCH 5/9 x86: use cpumask_of_cpu()
In reply to a message not in the archiveUse cpumask_of_cpu() rather than the pair of cpus_clear() and cpu_set().
--- arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 4 ++-- arch/x86/kernel/genapic_flat_64.c | 5 +---- arch/x86/kernel/io_apic_64.c | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-)
arch/x86/kernel/genapic_flat_64.c +1 -4
@@ -138,12 +138,9 @@ static cpumask_t physflat_target_cpus(vostatic cpumask_t physflat_vector_allocation_domain (int cpu) { -cpumask_t domain =CPU_MASK_NONE ; -cpu_set (cpu, domain); -return domain; +return cpumask_of_cpu (cpu); } -static void physflat_send_IPI_mask (cpumask_t cpumask,int vector) {send_IPI_mask_sequence (cpumask, vector);
arch/x86/kernel/cpu/mcheck/mce_amd_64.c +2 -2
@@ -254,8 +254,8 @@ struct threshold_attr {static cpumask_t affinity_set (unsigned int cpu) {cpumask_t oldmask = current->cpus_allowed; -cpumask_t newmask =CPU_MASK_NONE ; -cpu_set (cpu, newmask); +cpumask_t newmask =cpumask_of_cpu (cpu); +set_cpus_allowed (current, newmask);return oldmask; }
arch/x86/kernel/io_apic_64.c +1 -3
@@ -1351,9 +1351,7 @@ static int ioapic_retrigger_irq(unsignedunsigned long flags;spin_lock_irqsave (&vector_lock, flags); -cpus_clear (mask); -cpu_set (first_cpu (cfg->domain), mask); - + mask =cpumask_of_cpu (first_cpu (cfg->domain));send_IPI_mask (mask, cfg->vector);spin_unlock_irqrestore (&vector_lock, flags);
PATCH 6/9 x86: use cpu_online()
In reply to a message not in the archive--- arch/x86/kernel/reboot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/reboot.c +2 -2
@@ -412,12 +412,12 @@ static void native_machine_shutdown(void#ifdef CONFIG_X86_32 /* See if there has been given a command line override */ if ((reboot_cpu !=-1 ) && (reboot_cpu <NR_CPUS ) && -cpu_isset (reboot_cpu, cpu_online_map)) +cpu_online (reboot_cpu)) reboot_cpu_id = reboot_cpu;#endif /* Make certain the cpu I'm about to reboot on is online */ -if (!cpu_isset (reboot_cpu_id, cpu_online_map)) +if (!cpu_online (reboot_cpu_id)) reboot_cpu_id =smp_processor_id ();/* Make certain I only run on the appropriate processor */
PATCH 7/9 use BUILD_BUG_ON() for the size of struct intel_mp_floating
In reply to a message not in the archiveUse BUILD_BUG_ON() rather than runtime diagnosis (in i386) or compile-time error technology with extern non-exsistent function (in x86_64)
--- arch/x86/kernel/mpparse_32.c | 7 +++---- arch/x86/kernel/mpparse_64.c | 8 +++----- 2 files changed, 6 insertions(+), 9 deletions(-)
arch/x86/kernel/mpparse_32.c +3 -4
@@ -716,14 +716,13 @@ void __init get_smp_config (void)*/ } -static int __init smp_scan_config (unsigned long base,unsigned long length) +static int __init smp_scan_config (unsigned long base,unsigned long length) {unsigned long *bp =phys_to_virt (base);struct intel_mp_floating *mpf; -printk (KERN_INFO "Scan SMP from %p for %ld bytes.\n" , bp,length); -if (sizeof (*mpf) !=16 ) -printk ("Error: MPF size\n" ); +printk (KERN_INFO "Scan SMP from %p for %ld bytes.\n" , bp, length); +BUILD_BUG_ON (sizeof (*mpf) !=16 );while (length >0 ) { mpf = (struct intel_mp_floating *)bp;
arch/x86/kernel/mpparse_64.c +3 -5
@@ -534,15 +534,13 @@ void __init get_smp_config (void)*/ } -static int __init smp_scan_config (unsigned long base,unsigned long length) +static int __init smp_scan_config (unsigned long base,unsigned long length) { -extern void __bad_mpf_size (void );unsigned int *bp =phys_to_virt (base);struct intel_mp_floating *mpf; -Dprintk ("Scan SMP from %p for %ld bytes.\n" , bp,length); -if (sizeof (*mpf) !=16 ) -__bad_mpf_size (); +Dprintk ("Scan SMP from %p for %ld bytes.\n" , bp, length); +BUILD_BUG_ON (sizeof (*mpf) !=16 );while (length >0 ) { mpf = (struct intel_mp_floating *)bp;
PATCH 8/9 x86_64: use MP_intsrc_info()
In reply to a message not in the archiveRemove duplicate code by using MP_intsrc_info() in mpparse_{32,64}.c
--- arch/x86/kernel/mpparse_32.c | 23 ++++------------------- arch/x86/kernel/mpparse_64.c | 23 ++++------------------- 2 files changed, 8 insertions(+), 38 deletions(-)
arch/x86/kernel/mpparse_64.c +4 -19
@@ -193,9 +193,9 @@ static void __init MP_ioapic_info (struc nr_ioapics++; } -static void __init MP_intsrc_info (struct mpc_config_intsrc *m) +static void __init MP_intsrc_info (struct mpc_config_intsrc *m) { - mp_irqs [mp_irq_entries] = *m; + mp_irqs[mp_irq_entries] = *m; Dprintk("Int: type %d, pol %d, trig %d, bus %d," " IRQ %02x, APIC ID %x, APIC INT %02x\n", m->mpc_irqtype, m->mpc_irqflag & 3,
@@ -741,14 +741,7 @@ mp_override_legacy_irq(u8 bus_irq, u8 po intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;/* APIC ID */ intsrc.mpc_dstirq = pin;/* INTIN# */ -Dprintk ("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n" , - intsrc.mpc_irqtype, intsrc.mpc_irqflag &3 , - (intsrc.mpc_irqflag >>2 ) &3 , intsrc.mpc_srcbus, - intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq); - - mp_irqs[mp_irq_entries] = intsrc; -if (++mp_irq_entries ==MAX_IRQ_SOURCES ) -panic ("Max # of irq sources exceeded!\n" ); +MP_intsrc_info (&intsrc); }void __init mp_config_acpi_legacy_irqs (void )
@@ -803,15 +796,7 @@ void __init mp_config_acpi_legacy_irqs(v intsrc.mpc_srcbusirq = i;/* Identity mapped */ intsrc.mpc_dstirq = i; -Dprintk ("Int: type %d, pol %d, trig %d, bus %d, irq %d, " -"%d-%d\n" , intsrc.mpc_irqtype, intsrc.mpc_irqflag &3 , - (intsrc.mpc_irqflag >>2 ) &3 , intsrc.mpc_srcbus, - intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, - intsrc.mpc_dstirq); - - mp_irqs[mp_irq_entries] = intsrc; -if (++mp_irq_entries ==MAX_IRQ_SOURCES ) -panic ("Max # of irq sources exceeded!\n" ); +MP_intsrc_info (&intsrc); } }
arch/x86/kernel/mpparse_32.c +4 -19
@@ -274,9 +274,9 @@ static void __init MP_ioapic_info (struc nr_ioapics++; } -static void __init MP_intsrc_info (struct mpc_config_intsrc *m) +static void __init MP_intsrc_info (struct mpc_config_intsrc *m) { - mp_irqs [mp_irq_entries] = *m; + mp_irqs[mp_irq_entries] = *m; Dprintk("Int: type %d, pol %d, trig %d, bus %d," " IRQ %02x, APIC ID %x, APIC INT %02x\n", m->mpc_irqtype, m->mpc_irqflag & 3,
@@ -960,14 +960,7 @@ mp_override_legacy_irq(u8 bus_irq, u8 po intsrc.mpc_dstapic = mp_ioapics[ioapic].mpc_apicid;/* APIC ID */ intsrc.mpc_dstirq = pin;/* INTIN# */ -Dprintk ("Int: type %d, pol %d, trig %d, bus %d, irq %d, %d-%d\n" , - intsrc.mpc_irqtype, intsrc.mpc_irqflag &3 , - (intsrc.mpc_irqflag >>2 ) &3 , intsrc.mpc_srcbus, - intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, intsrc.mpc_dstirq); - - mp_irqs[mp_irq_entries] = intsrc; -if (++mp_irq_entries ==MAX_IRQ_SOURCES ) -panic ("Max # of irq sources exceeded!\n" ); +MP_intsrc_info (&intsrc); }void __init mp_config_acpi_legacy_irqs (void )
@@ -1029,15 +1022,7 @@ void __init mp_config_acpi_legacy_irqs ( intsrc.mpc_srcbusirq = i;/* Identity mapped */ intsrc.mpc_dstirq = i; -Dprintk ("Int: type %d, pol %d, trig %d, bus %d, irq %d, " -"%d-%d\n" , intsrc.mpc_irqtype, intsrc.mpc_irqflag &3 , - (intsrc.mpc_irqflag >>2 ) &3 , intsrc.mpc_srcbus, - intsrc.mpc_srcbusirq, intsrc.mpc_dstapic, - intsrc.mpc_dstirq); - - mp_irqs[mp_irq_entries] = intsrc; -if (++mp_irq_entries ==MAX_IRQ_SOURCES ) -panic ("Max # of irq sources exceeded!\n" ); +MP_intsrc_info (&intsrc); } }
PATCH 9/9 x86: use bitmap library for pin_programmed
In reply to a message not in the archiveUse bitmap library for pin_programmed rather than reinvent bitmaps.
--- arch/x86/kernel/mpparse_32.c | 15 ++++++--------- arch/x86/kernel/mpparse_64.c | 16 +++++++--------- 2 files changed, 13 insertions(+), 18 deletions(-)
arch/x86/kernel/mpparse_64.c +7 -9
@@ -21,6 +21,7 @@#include <linux/mc146818rtc.h> #include <linux/acpi.h> #include <linux/module.h> +#include <linux/bitmap.h> #include <asm/smp.h> #include <asm/mtrr.h>
@@ -643,7 +644,7 @@ static struct mp_ioapic_routing {int apic_id;int gsi_start;int gsi_end; -u32 pin_programmed[4 ]; +DECLARE_BITMAP (pin_programmed,MP_MAX_IOAPIC_PIN +1 ); } mp_ioapic_routing[MAX_IO_APICS ];static int mp_find_ioapic (int gsi)
@@ -802,9 +803,8 @@ void __init mp_config_acpi_legacy_irqs(vint mp_register_gsi (u32 gsi,int triggering,int polarity) { -int ioapic =-1 ; -int ioapic_pin =0 ; -int idx, bit =0 ; +int ioapic; +int ioapic_pin;if (acpi_irq_model !=ACPI_IRQ_MODEL_IOAPIC )return gsi;
@@ -826,21 +826,19 @@ int mp_register_gsi(u32 gsi, int trigger* with redundant pin->gsi mappings (but unique PCI devices); * we only program the IOAPIC on the first. */ - bit = ioapic_pin %32 ; - idx = (ioapic_pin <32 ) ?0 : (ioapic_pin /32 ); -if (idx >3 ) { +if (ioapic_pin >MP_MAX_IOAPIC_PIN ) {printk (KERN_ERR "Invalid reference to IOAPIC pin " "%d-%d\n" , mp_ioapic_routing[ioapic].apic_id, ioapic_pin);return gsi; } -if ((1 <<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) { +if (test_bit (ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {Dprintk (KERN_DEBUG "Pin %d-%d already programmed\n" , mp_ioapic_routing[ioapic].apic_id, ioapic_pin);return gsi; } - mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 <<bit); +set_bit (ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed); io_apic_set_pci_routing(ioapic, ioapic_pin, gsi, triggering == ACPI_EDGE_SENSITIVE ? 0 : 1,
arch/x86/kernel/mpparse_32.c +6 -9
@@ -859,7 +859,7 @@ static struct mp_ioapic_routing {int apic_id;int gsi_base;int gsi_end; -u32 pin_programmed[4 ]; +DECLARE_BITMAP (pin_programmed,MP_MAX_IOAPIC_PIN +1 ); } mp_ioapic_routing[MAX_IO_APICS ];static int mp_find_ioapic (int gsi)
@@ -1031,9 +1031,8 @@ void __init mp_config_acpi_legacy_irqs (int mp_register_gsi (u32 gsi,int triggering,int polarity) { -int ioapic =-1 ; -int ioapic_pin =0 ; -int idx, bit =0 ; +int ioapic; +int ioapic_pin;static int pci_irq =IRQ_COMPRESSION_START ;/* * Mapping between Global System Interrupts, which
@@ -1062,21 +1061,19 @@ int mp_register_gsi(u32 gsi, int trigger* with redundant pin->gsi mappings (but unique PCI devices); * we only program the IOAPIC on the first. */ - bit = ioapic_pin %32 ; - idx = (ioapic_pin <32 ) ?0 : (ioapic_pin /32 ); -if (idx >3 ) { +if (ioapic_pin >MP_MAX_IOAPIC_PIN ) {printk (KERN_ERR "Invalid reference to IOAPIC pin " "%d-%d\n" , mp_ioapic_routing[ioapic].apic_id, ioapic_pin);return gsi; } -if ((1 <<bit) & mp_ioapic_routing[ioapic].pin_programmed[idx]) { +if (test_bit (ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed)) {Dprintk (KERN_DEBUG "Pin %d-%d already programmed\n" , mp_ioapic_routing[ioapic].apic_id, ioapic_pin);return (gsi <IRQ_COMPRESSION_START ? gsi : gsi_to_irq[gsi]); } - mp_ioapic_routing[ioapic].pin_programmed[idx] |= (1 <<bit); +set_bit (ioapic_pin, mp_ioapic_routing[ioapic].pin_programmed);/* * For GSI >= 64, use IRQ compression