From: "Jan Beulich" Subject: [PATCH 3/4] x86/HPET: use dynamic allocation for hpet_events[] Date: Fri, 11 Mar 2011 15:34:37 +0000 Message-ID: <4D7A4F1D0200007800035EB8@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part032F391D.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. --=__Part032F391D.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Typically there are far less than 32 counters available, and hence there's no use in wasting the memory on (almost) every system. Signed-off-by: Jan Beulich --- 2011-03-09.orig/xen/arch/x86/hpet.c +++ 2011-03-09/xen/arch/x86/hpet.c @@ -21,8 +21,6 @@ #define MAX_DELTA_NS MILLISECS(10*1000) #define MIN_DELTA_NS MICROSECS(20) =20 -#define MAX_HPET_NUM 32 - #define HPET_EVT_USED_BIT 0 #define HPET_EVT_USED (1 << HPET_EVT_USED_BIT) #define HPET_EVT_DISABLE_BIT 1 @@ -56,8 +54,7 @@ struct hpet_event_channel int irq; /* msi irq */ unsigned int flags; /* HPET_EVT_x */ } __cacheline_aligned; -static struct hpet_event_channel hpet_events[MAX_HPET_NUM] =3D=20 - { [0 ... MAX_HPET_NUM-1].irq =3D -1 }; +static struct hpet_event_channel *__read_mostly hpet_events; =20 /* msi hpet channels used for broadcast */ static unsigned int __read_mostly num_hpets_used; @@ -426,6 +423,11 @@ static int __init hpet_fsb_cap_lookup(vo num_chs =3D ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT); num_chs++; /* Value read out starts from 0 */ =20 + hpet_events =3D xmalloc_array(struct hpet_event_channel, num_chs); + if ( !hpet_events ) + return 0; + memset(hpet_events, 0, num_chs * sizeof(*hpet_events)); + num_chs_used =3D 0; for ( i =3D 0; i < num_chs; i++ ) { @@ -585,10 +587,16 @@ void __init hpet_broadcast_init(void) if ( !(hpet_id & HPET_ID_LEGSUP) ) return; =20 + if ( !hpet_events ) + hpet_events =3D xmalloc(struct hpet_event_channel); + if ( !hpet_events ) + return; + memset(hpet_events, 0, sizeof(*hpet_events)); + hpet_events->irq =3D -1; + /* Start HPET legacy interrupts */ cfg |=3D HPET_CFG_LEGACY; n =3D 1; - hpet_events->idx =3D 0; =20 if ( !force_hpet_broadcast ) pv_rtc_handler =3D handle_rtc_once; @@ -627,6 +635,9 @@ void hpet_broadcast_resume(void) u32 cfg; unsigned int i, n; =20 + if ( !hpet_events ) + return; + hpet_resume(); =20 cfg =3D hpet_read32(HPET_CFG); @@ -668,7 +679,7 @@ void hpet_disable_legacy_broadcast(void) u32 cfg; unsigned long flags; =20 - if ( !(hpet_events->flags & HPET_EVT_LEGACY) ) + if ( !hpet_events || !(hpet_events->flags & HPET_EVT_LEGACY) ) return; =20 spin_lock_irqsave(&hpet_events->lock, flags); @@ -751,7 +762,7 @@ void hpet_broadcast_exit(void) =20 int hpet_broadcast_is_available(void) { - return ((hpet_events->flags & HPET_EVT_LEGACY) + return ((hpet_events && (hpet_events->flags & HPET_EVT_LEGACY)) || num_hpets_used > 0); } =20 @@ -759,7 +770,8 @@ int hpet_legacy_irq_tick(void) { this_cpu(irq_count)--; =20 - if ( (hpet_events->flags & (HPET_EVT_DISABLE|HPET_EVT_LEGACY)) !=3D + if ( !hpet_events || + (hpet_events->flags & (HPET_EVT_DISABLE|HPET_EVT_LEGACY)) !=3D HPET_EVT_LEGACY ) return 0; hpet_events->event_handler(hpet_events); --=__Part032F391D.1__= Content-Type: text/plain; name="x86-hpet-alloc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-hpet-alloc.patch" Typically there are far less than 32 counters available, and hence=0Athere'= s no use in wasting the memory on (almost) every system.=0A=0ASigned-off-by= : Jan Beulich =0A=0A--- 2011-03-09.orig/xen/arch/x86/h= pet.c=0A+++ 2011-03-09/xen/arch/x86/hpet.c=0A@@ -21,8 +21,6 @@=0A #define = MAX_DELTA_NS MILLISECS(10*1000)=0A #define MIN_DELTA_NS MICROSECS(20)=0A = =0A-#define MAX_HPET_NUM 32=0A-=0A #define HPET_EVT_USED_BIT 0=0A = #define HPET_EVT_USED (1 << HPET_EVT_USED_BIT)=0A #define HPET_EVT_DI= SABLE_BIT 1=0A@@ -56,8 +54,7 @@ struct hpet_event_channel=0A int irq; = /* msi irq */=0A unsigned int flags; /* HPET_EVT_x */=0A } = __cacheline_aligned;=0A-static struct hpet_event_channel hpet_events[MAX_HP= ET_NUM] =3D =0A- { [0 ... MAX_HPET_NUM-1].irq =3D -1 };=0A+static = struct hpet_event_channel *__read_mostly hpet_events;=0A =0A /* msi hpet = channels used for broadcast */=0A static unsigned int __read_mostly = num_hpets_used;=0A@@ -426,6 +423,11 @@ static int __init hpet_fsb_cap_looku= p(vo=0A num_chs =3D ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT);=0A= num_chs++; /* Value read out starts from 0 */=0A =0A+ hpet_events = =3D xmalloc_array(struct hpet_event_channel, num_chs);=0A+ if ( = !hpet_events )=0A+ return 0;=0A+ memset(hpet_events, 0, num_chs = * sizeof(*hpet_events));=0A+=0A num_chs_used =3D 0;=0A for ( i =3D = 0; i < num_chs; i++ )=0A {=0A@@ -585,10 +587,16 @@ void __init = hpet_broadcast_init(void)=0A if ( !(hpet_id & HPET_ID_LEGSUP) )=0A = return;=0A =0A+ if ( !hpet_events )=0A+ = hpet_events =3D xmalloc(struct hpet_event_channel);=0A+ if ( = !hpet_events )=0A+ return;=0A+ memset(hpet_events, 0, = sizeof(*hpet_events));=0A+ hpet_events->irq =3D -1;=0A+=0A = /* Start HPET legacy interrupts */=0A cfg |=3D HPET_CFG_LEGACY;=0A = n =3D 1;=0A- hpet_events->idx =3D 0;=0A =0A if ( = !force_hpet_broadcast )=0A pv_rtc_handler =3D handle_rtc_once;= =0A@@ -627,6 +635,9 @@ void hpet_broadcast_resume(void)=0A u32 cfg;=0A = unsigned int i, n;=0A =0A+ if ( !hpet_events )=0A+ return;=0A= +=0A hpet_resume();=0A =0A cfg =3D hpet_read32(HPET_CFG);=0A@@ = -668,7 +679,7 @@ void hpet_disable_legacy_broadcast(void)=0A u32 = cfg;=0A unsigned long flags;=0A =0A- if ( !(hpet_events->flags & = HPET_EVT_LEGACY) )=0A+ if ( !hpet_events || !(hpet_events->flags & = HPET_EVT_LEGACY) )=0A return;=0A =0A spin_lock_irqsave(&hpet_ev= ents->lock, flags);=0A@@ -751,7 +762,7 @@ void hpet_broadcast_exit(void)=0A= =0A int hpet_broadcast_is_available(void)=0A {=0A- return ((hpet_events= ->flags & HPET_EVT_LEGACY)=0A+ return ((hpet_events && (hpet_events->fla= gs & HPET_EVT_LEGACY))=0A || num_hpets_used > 0);=0A }=0A = =0A@@ -759,7 +770,8 @@ int hpet_legacy_irq_tick(void)=0A {=0A = this_cpu(irq_count)--;=0A =0A- if ( (hpet_events->flags & (HPET_EVT_DISA= BLE|HPET_EVT_LEGACY)) !=3D=0A+ if ( !hpet_events ||=0A+ = (hpet_events->flags & (HPET_EVT_DISABLE|HPET_EVT_LEGACY)) !=3D=0A = HPET_EVT_LEGACY )=0A return 0;=0A hpet_events->event_handler(hp= et_events);=0A --=__Part032F391D.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 --=__Part032F391D.1__=--