From: "Jan Beulich" Subject: [PATCH 4/4] x86/HPET: adjust types Date: Fri, 11 Mar 2011 15:35:14 +0000 Message-ID: <4D7A4F420200007800035EBC@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part3C100622.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" Cc: Gang Wei List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part3C100622.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 'unsigned int' is better suited as an array index on x86-64. 'u32' produces better code than 'unsigned long' on x86-64, so use the former for storing 32-bit values read from the hardware. this_cpu() uses an implicit smp_processor_id(), and hence using per_cpu() when the result of smp_processor_id() is already available is more efficient. Fold one case of cpu_isset()+cpu_clear() into cpu_test_and_clear(). Drop the unused return value of evt_do_broadcast(). Signed-off-by: Jan Beulich --- 2011-03-09.orig/xen/arch/x86/hpet.c +++ 2011-03-09/xen/arch/x86/hpet.c @@ -50,7 +50,7 @@ struct hpet_event_channel void (*event_handler)(struct hpet_event_channel *); =20 unsigned int idx; /* physical channel idx */ - int cpu; /* msi target */ + unsigned int cpu; /* msi target */ int irq; /* msi irq */ unsigned int flags; /* HPET_EVT_x */ } __cacheline_aligned; @@ -61,7 +61,7 @@ static unsigned int __read_mostly num_hp =20 DEFINE_PER_CPU(struct hpet_event_channel *, cpu_bc_channel); =20 -static int *__read_mostly irq_channel; +static unsigned int *__read_mostly irq_channel; #define irq_to_channel(irq) irq_channel[irq] =20 unsigned long __read_mostly hpet_address; @@ -166,32 +166,24 @@ static int reprogram_hpet_evt_channel( return ret; } =20 -static int evt_do_broadcast(cpumask_t mask) +static void evt_do_broadcast(cpumask_t mask) { - int ret =3D 0, cpu =3D smp_processor_id(); + unsigned int cpu =3D smp_processor_id(); =20 - if ( cpu_isset(cpu, mask) ) - { - cpu_clear(cpu, mask); + if ( cpu_test_and_clear(cpu, mask) ) raise_softirq(TIMER_SOFTIRQ); - ret =3D 1; - } =20 cpuidle_wakeup_mwait(&mask); =20 if ( !cpus_empty(mask) ) - { cpumask_raise_softirq(mask, TIMER_SOFTIRQ); - ret =3D 1; - } - return ret; } =20 static void handle_hpet_broadcast(struct hpet_event_channel *ch) { cpumask_t mask; s_time_t now, next_event; - int cpu; + unsigned int cpu; =20 spin_lock_irq(&ch->lock); =20 @@ -253,12 +245,11 @@ static void hpet_interrupt_handler(int i =20 static void hpet_msi_unmask(unsigned int irq) { - unsigned long cfg; - int ch_idx =3D irq_to_channel(irq); - struct hpet_event_channel *ch; + u32 cfg; + unsigned int ch_idx =3D irq_to_channel(irq); + struct hpet_event_channel *ch =3D hpet_events + ch_idx; =20 - BUG_ON(ch_idx < 0); - ch =3D &hpet_events[ch_idx]; + BUG_ON(ch_idx >=3D num_hpets_used); =20 cfg =3D hpet_read32(HPET_Tn_CFG(ch->idx)); cfg |=3D HPET_TN_FSB; @@ -267,12 +258,11 @@ static void hpet_msi_unmask(unsigned int =20 static void hpet_msi_mask(unsigned int irq) { - unsigned long cfg; - int ch_idx =3D irq_to_channel(irq); - struct hpet_event_channel *ch; + u32 cfg; + unsigned int ch_idx =3D irq_to_channel(irq); + struct hpet_event_channel *ch =3D hpet_events + ch_idx; =20 - BUG_ON(ch_idx < 0); - ch =3D &hpet_events[ch_idx]; + BUG_ON(ch_idx >=3D num_hpets_used); =20 cfg =3D hpet_read32(HPET_Tn_CFG(ch->idx)); cfg &=3D ~HPET_TN_FSB; @@ -281,11 +271,10 @@ static void hpet_msi_mask(unsigned int i =20 static void hpet_msi_write(unsigned int irq, struct msi_msg *msg) { - int ch_idx =3D irq_to_channel(irq); - struct hpet_event_channel *ch; + unsigned int ch_idx =3D irq_to_channel(irq); + struct hpet_event_channel *ch =3D hpet_events + ch_idx; =20 - BUG_ON(ch_idx < 0); - ch =3D &hpet_events[ch_idx]; + BUG_ON(ch_idx >=3D num_hpets_used); =20 hpet_write32(msg->data, HPET_Tn_ROUTE(ch->idx)); hpet_write32(msg->address_lo, HPET_Tn_ROUTE(ch->idx) + 4); @@ -293,11 +282,10 @@ static void hpet_msi_write(unsigned int=20 =20 static void hpet_msi_read(unsigned int irq, struct msi_msg *msg) { - int ch_idx =3D irq_to_channel(irq); - struct hpet_event_channel *ch; + unsigned int ch_idx =3D irq_to_channel(irq); + struct hpet_event_channel *ch =3D hpet_events + ch_idx; =20 - BUG_ON(ch_idx < 0); - ch =3D &hpet_events[ch_idx]; + BUG_ON(ch_idx >=3D num_hpets_used); =20 msg->data =3D hpet_read32(HPET_Tn_ROUTE(ch->idx)); msg->address_lo =3D hpet_read32(HPET_Tn_ROUTE(ch->idx) + 4); @@ -404,11 +392,10 @@ static int __init hpet_assign_irq(unsign return irq; } =20 -static int __init hpet_fsb_cap_lookup(void) +static unsigned int __init hpet_fsb_cap_lookup(void) { - unsigned int id; - unsigned int num_chs, num_chs_used; - int i; + u32 id; + unsigned int i, num_chs, num_chs_used; =20 /* TODO. */ if ( iommu_intremap ) @@ -432,7 +419,7 @@ static int __init hpet_fsb_cap_lookup(vo for ( i =3D 0; i < num_chs; i++ ) { struct hpet_event_channel *ch =3D &hpet_events[num_chs_used]; - unsigned long cfg =3D hpet_read32(HPET_Tn_CFG(i)); + u32 cfg =3D hpet_read32(HPET_Tn_CFG(i)); =20 /* Only consider HPET timer with MSI support */ if ( !(cfg & HPET_TN_FSB_CAP) ) @@ -447,20 +434,17 @@ static int __init hpet_fsb_cap_lookup(vo num_chs_used++; } =20 - printk(XENLOG_INFO - "HPET: %d timers in total, %d timers will be used for = broadcast\n", + printk(XENLOG_INFO "HPET: %u timers (%u will be used for broadcast)\n"= , num_chs, num_chs_used); =20 return num_chs_used; } =20 -static int next_channel; -static spinlock_t next_lock =3D SPIN_LOCK_UNLOCKED; - -static struct hpet_event_channel *hpet_get_channel(int cpu) +static struct hpet_event_channel *hpet_get_channel(unsigned int cpu) { - int i; - int next; + static unsigned int next_channel; + static spinlock_t next_lock =3D SPIN_LOCK_UNLOCKED; + unsigned int i, next; struct hpet_event_channel *ch; =20 if ( num_hpets_used =3D=3D 0 ) @@ -489,7 +473,8 @@ static struct hpet_event_channel *hpet_g return ch; } =20 -static void hpet_attach_channel(int cpu, struct hpet_event_channel *ch) +static void hpet_attach_channel(unsigned int cpu, + struct hpet_event_channel *ch) { ASSERT(spin_is_locked(&ch->lock)); =20 @@ -507,7 +492,8 @@ static void hpet_attach_channel(int cpu, set_affinity(ch->irq, cpumask_of_cpu(ch->cpu)); } =20 -static void hpet_detach_channel(int cpu, struct hpet_event_channel *ch) +static void hpet_detach_channel(unsigned int cpu, + struct hpet_event_channel *ch) { ASSERT(spin_is_locked(&ch->lock)); ASSERT(ch =3D=3D per_cpu(cpu_bc_channel, cpu)); @@ -564,7 +550,7 @@ void __init hpet_broadcast_init(void) if ( hpet_rate =3D=3D 0 ) return; =20 - irq_channel =3D xmalloc_array(int, nr_irqs); + irq_channel =3D xmalloc_array(unsigned int, nr_irqs); BUG_ON(irq_channel =3D=3D NULL); for ( i =3D 0; i < nr_irqs; i++ ) irq_channel[i] =3D -1; @@ -703,10 +689,10 @@ void hpet_disable_legacy_broadcast(void) =20 void hpet_broadcast_enter(void) { - int cpu =3D smp_processor_id(); + unsigned int cpu =3D smp_processor_id(); struct hpet_event_channel *ch =3D per_cpu(cpu_bc_channel, cpu); =20 - if ( this_cpu(timer_deadline) =3D=3D 0 ) + if ( per_cpu(timer_deadline, cpu) =3D=3D 0 ) return; =20 if ( !ch ) @@ -727,17 +713,17 @@ void hpet_broadcast_enter(void) =20 spin_lock(&ch->lock); /* reprogram if current cpu expire time is nearer */ - if ( this_cpu(timer_deadline) < ch->next_event ) - reprogram_hpet_evt_channel(ch, this_cpu(timer_deadline), NOW(), = 1); + if ( per_cpu(timer_deadline, cpu) < ch->next_event ) + reprogram_hpet_evt_channel(ch, per_cpu(timer_deadline, cpu), = NOW(), 1); spin_unlock(&ch->lock); } =20 void hpet_broadcast_exit(void) { - int cpu =3D smp_processor_id(); + unsigned int cpu =3D smp_processor_id(); struct hpet_event_channel *ch =3D per_cpu(cpu_bc_channel, cpu); =20 - if ( this_cpu(timer_deadline) =3D=3D 0 ) + if ( per_cpu(timer_deadline, cpu) =3D=3D 0 ) return; =20 if ( !ch ) @@ -745,7 +731,7 @@ void hpet_broadcast_exit(void) =20 /* Reprogram the deadline; trigger timer work now if it has passed. = */ enable_APIC_timer(); - if ( !reprogram_timer(this_cpu(timer_deadline)) ) + if ( !reprogram_timer(per_cpu(timer_deadline, cpu)) ) raise_softirq(TIMER_SOFTIRQ); =20 read_lock_irq(&ch->cpumask_lock); --=__Part3C100622.1__= Content-Type: text/plain; name="x86-hpet-types.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-hpet-types.patch" 'unsigned int' is better suited as an array index on x86-64.=0A=0A'u32' = produces better code than 'unsigned long' on x86-64, so use the=0Aformer = for storing 32-bit values read from the hardware.=0A=0Athis_cpu() uses an = implicit smp_processor_id(), and hence using=0Aper_cpu() when the result = of smp_processor_id() is already available=0Ais more efficient.=0A=0AFold = one case of cpu_isset()+cpu_clear() into cpu_test_and_clear().=0A=0ADrop = the unused return value of evt_do_broadcast().=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- 2011-03-09.orig/xen/arch/x86/hpet.c= =0A+++ 2011-03-09/xen/arch/x86/hpet.c=0A@@ -50,7 +50,7 @@ struct hpet_event= _channel=0A void (*event_handler)(struct hpet_event_channel = *);=0A =0A unsigned int idx; /* physical channel idx */=0A- int = cpu; /* msi target */=0A+ unsigned int cpu; /* msi target = */=0A int irq; /* msi irq */=0A unsigned int flags; /* = HPET_EVT_x */=0A } __cacheline_aligned;=0A@@ -61,7 +61,7 @@ static = unsigned int __read_mostly num_hp=0A =0A DEFINE_PER_CPU(struct hpet_event_c= hannel *, cpu_bc_channel);=0A =0A-static int *__read_mostly irq_channel;=0A= +static unsigned int *__read_mostly irq_channel;=0A #define irq_to_channel(= irq) irq_channel[irq]=0A =0A unsigned long __read_mostly hpet_address;=0A= @@ -166,32 +166,24 @@ static int reprogram_hpet_evt_channel(=0A return = ret;=0A }=0A =0A-static int evt_do_broadcast(cpumask_t mask)=0A+static = void evt_do_broadcast(cpumask_t mask)=0A {=0A- int ret =3D 0, cpu =3D = smp_processor_id();=0A+ unsigned int cpu =3D smp_processor_id();=0A = =0A- if ( cpu_isset(cpu, mask) )=0A- {=0A- cpu_clear(cpu, = mask);=0A+ if ( cpu_test_and_clear(cpu, mask) )=0A raise_softirq= (TIMER_SOFTIRQ);=0A- ret =3D 1;=0A- }=0A =0A cpuidle_wakeup_m= wait(&mask);=0A =0A if ( !cpus_empty(mask) )=0A- {=0A = cpumask_raise_softirq(mask, TIMER_SOFTIRQ);=0A- ret =3D 1;=0A- = }=0A- return ret;=0A }=0A =0A static void handle_hpet_broadcast(struct = hpet_event_channel *ch)=0A {=0A cpumask_t mask;=0A s_time_t now, = next_event;=0A- int cpu;=0A+ unsigned int cpu;=0A =0A spin_lock_i= rq(&ch->lock);=0A =0A@@ -253,12 +245,11 @@ static void hpet_interrupt_handl= er(int i=0A =0A static void hpet_msi_unmask(unsigned int irq)=0A {=0A- = unsigned long cfg;=0A- int ch_idx =3D irq_to_channel(irq);=0A- = struct hpet_event_channel *ch;=0A+ u32 cfg;=0A+ unsigned int ch_idx = =3D irq_to_channel(irq);=0A+ struct hpet_event_channel *ch =3D = hpet_events + ch_idx;=0A =0A- BUG_ON(ch_idx < 0);=0A- ch =3D = &hpet_events[ch_idx];=0A+ BUG_ON(ch_idx >=3D num_hpets_used);=0A =0A = cfg =3D hpet_read32(HPET_Tn_CFG(ch->idx));=0A cfg |=3D HPET_TN_FSB;=0A= @@ -267,12 +258,11 @@ static void hpet_msi_unmask(unsigned int=0A =0A = static void hpet_msi_mask(unsigned int irq)=0A {=0A- unsigned long = cfg;=0A- int ch_idx =3D irq_to_channel(irq);=0A- struct hpet_event_ch= annel *ch;=0A+ u32 cfg;=0A+ unsigned int ch_idx =3D irq_to_channel(ir= q);=0A+ struct hpet_event_channel *ch =3D hpet_events + ch_idx;=0A =0A- = BUG_ON(ch_idx < 0);=0A- ch =3D &hpet_events[ch_idx];=0A+ = BUG_ON(ch_idx >=3D num_hpets_used);=0A =0A cfg =3D hpet_read32(HPET_Tn_= CFG(ch->idx));=0A cfg &=3D ~HPET_TN_FSB;=0A@@ -281,11 +271,10 @@ = static void hpet_msi_mask(unsigned int i=0A =0A static void hpet_msi_write(= unsigned int irq, struct msi_msg *msg)=0A {=0A- int ch_idx =3D = irq_to_channel(irq);=0A- struct hpet_event_channel *ch;=0A+ unsigned = int ch_idx =3D irq_to_channel(irq);=0A+ struct hpet_event_channel *ch = =3D hpet_events + ch_idx;=0A =0A- BUG_ON(ch_idx < 0);=0A- ch =3D = &hpet_events[ch_idx];=0A+ BUG_ON(ch_idx >=3D num_hpets_used);=0A =0A = hpet_write32(msg->data, HPET_Tn_ROUTE(ch->idx));=0A hpet_write32(msg->= address_lo, HPET_Tn_ROUTE(ch->idx) + 4);=0A@@ -293,11 +282,10 @@ static = void hpet_msi_write(unsigned int =0A =0A static void hpet_msi_read(unsigned= int irq, struct msi_msg *msg)=0A {=0A- int ch_idx =3D irq_to_channel(ir= q);=0A- struct hpet_event_channel *ch;=0A+ unsigned int ch_idx =3D = irq_to_channel(irq);=0A+ struct hpet_event_channel *ch =3D hpet_events = + ch_idx;=0A =0A- BUG_ON(ch_idx < 0);=0A- ch =3D &hpet_events[ch_idx]= ;=0A+ BUG_ON(ch_idx >=3D num_hpets_used);=0A =0A msg->data =3D = hpet_read32(HPET_Tn_ROUTE(ch->idx));=0A msg->address_lo =3D hpet_read32= (HPET_Tn_ROUTE(ch->idx) + 4);=0A@@ -404,11 +392,10 @@ static int __init = hpet_assign_irq(unsign=0A return irq;=0A }=0A =0A-static int __init = hpet_fsb_cap_lookup(void)=0A+static unsigned int __init hpet_fsb_cap_lookup= (void)=0A {=0A- unsigned int id;=0A- unsigned int num_chs, num_chs_us= ed;=0A- int i;=0A+ u32 id;=0A+ unsigned int i, num_chs, num_chs_us= ed;=0A =0A /* TODO. */=0A if ( iommu_intremap )=0A@@ -432,7 +419,7 = @@ static int __init hpet_fsb_cap_lookup(vo=0A for ( i =3D 0; i < = num_chs; i++ )=0A {=0A struct hpet_event_channel *ch =3D = &hpet_events[num_chs_used];=0A- unsigned long cfg =3D hpet_read32(HP= ET_Tn_CFG(i));=0A+ u32 cfg =3D hpet_read32(HPET_Tn_CFG(i));=0A =0A = /* Only consider HPET timer with MSI support */=0A if ( = !(cfg & HPET_TN_FSB_CAP) )=0A@@ -447,20 +434,17 @@ static int __init = hpet_fsb_cap_lookup(vo=0A num_chs_used++;=0A }=0A =0A- = printk(XENLOG_INFO=0A- "HPET: %d timers in total, %d timers will = be used for broadcast\n",=0A+ printk(XENLOG_INFO "HPET: %u timers (%u = will be used for broadcast)\n",=0A num_chs, num_chs_used);=0A = =0A return num_chs_used;=0A }=0A =0A-static int next_channel;=0A-static= spinlock_t next_lock =3D SPIN_LOCK_UNLOCKED;=0A-=0A-static struct = hpet_event_channel *hpet_get_channel(int cpu)=0A+static struct hpet_event_c= hannel *hpet_get_channel(unsigned int cpu)=0A {=0A- int i;=0A- int = next;=0A+ static unsigned int next_channel;=0A+ static spinlock_t = next_lock =3D SPIN_LOCK_UNLOCKED;=0A+ unsigned int i, next;=0A = struct hpet_event_channel *ch;=0A =0A if ( num_hpets_used =3D=3D 0 = )=0A@@ -489,7 +473,8 @@ static struct hpet_event_channel *hpet_g=0A = return ch;=0A }=0A =0A-static void hpet_attach_channel(int cpu, struct = hpet_event_channel *ch)=0A+static void hpet_attach_channel(unsigned int = cpu,=0A+ struct hpet_event_channel *ch)=0A = {=0A ASSERT(spin_is_locked(&ch->lock));=0A =0A@@ -507,7 +492,8 @@ = static void hpet_attach_channel(int cpu,=0A set_affinity(ch->irq, = cpumask_of_cpu(ch->cpu));=0A }=0A =0A-static void hpet_detach_channel(int = cpu, struct hpet_event_channel *ch)=0A+static void hpet_detach_channel(unsi= gned int cpu,=0A+ struct hpet_event_channel = *ch)=0A {=0A ASSERT(spin_is_locked(&ch->lock));=0A ASSERT(ch = =3D=3D per_cpu(cpu_bc_channel, cpu));=0A@@ -564,7 +550,7 @@ void __init = hpet_broadcast_init(void)=0A if ( hpet_rate =3D=3D 0 )=0A = return;=0A =0A- irq_channel =3D xmalloc_array(int, nr_irqs);=0A+ = irq_channel =3D xmalloc_array(unsigned int, nr_irqs);=0A BUG_ON(irq_cha= nnel =3D=3D NULL);=0A for ( i =3D 0; i < nr_irqs; i++ )=0A = irq_channel[i] =3D -1;=0A@@ -703,10 +689,10 @@ void hpet_disable_legacy_bro= adcast(void)=0A =0A void hpet_broadcast_enter(void)=0A {=0A- int cpu = =3D smp_processor_id();=0A+ unsigned int cpu =3D smp_processor_id();=0A = struct hpet_event_channel *ch =3D per_cpu(cpu_bc_channel, cpu);=0A = =0A- if ( this_cpu(timer_deadline) =3D=3D 0 )=0A+ if ( per_cpu(timer_= deadline, cpu) =3D=3D 0 )=0A return;=0A =0A if ( !ch )=0A@@ = -727,17 +713,17 @@ void hpet_broadcast_enter(void)=0A =0A spin_lock(&ch= ->lock);=0A /* reprogram if current cpu expire time is nearer */=0A- = if ( this_cpu(timer_deadline) < ch->next_event )=0A- reprogram_hpet= _evt_channel(ch, this_cpu(timer_deadline), NOW(), 1);=0A+ if ( = per_cpu(timer_deadline, cpu) < ch->next_event )=0A+ reprogram_hpet_e= vt_channel(ch, per_cpu(timer_deadline, cpu), NOW(), 1);=0A spin_unlock(= &ch->lock);=0A }=0A =0A void hpet_broadcast_exit(void)=0A {=0A- int cpu = =3D smp_processor_id();=0A+ unsigned int cpu =3D smp_processor_id();=0A = struct hpet_event_channel *ch =3D per_cpu(cpu_bc_channel, cpu);=0A = =0A- if ( this_cpu(timer_deadline) =3D=3D 0 )=0A+ if ( per_cpu(timer_= deadline, cpu) =3D=3D 0 )=0A return;=0A =0A if ( !ch )=0A@@ = -745,7 +731,7 @@ void hpet_broadcast_exit(void)=0A =0A /* Reprogram = the deadline; trigger timer work now if it has passed. */=0A enable_API= C_timer();=0A- if ( !reprogram_timer(this_cpu(timer_deadline)) )=0A+ = if ( !reprogram_timer(per_cpu(timer_deadline, cpu)) )=0A raise_soft= irq(TIMER_SOFTIRQ);=0A =0A read_lock_irq(&ch->cpumask_lock);=0A --=__Part3C100622.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part3C100622.1__=--