From: "Jan Beulich" Subject: [PATCH] linux/xenoprof: dynamic buffer array allocation Date: Tue, 05 Jan 2010 12:54:38 +0000 Message-ID: <4B43449E0200007800028416@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC8E2CD9E.0__=" 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 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. --=__PartC8E2CD9E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The recent change to locally define MAX_VIRT_CPUS wasn't really appropriate - with there not being a hard limit on the number of vCPU-s anymore, these arrays should be allocated dynamically. As usual, written against 2.6.32.2 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich --- head-2010-01-04.orig/drivers/xen/xenoprof/xenoprofile.c 2010-01-04 = 13:31:29.000000000 +0100 +++ head-2010-01-04/drivers/xen/xenoprof/xenoprofile.c 2010-01-04 = 16:51:11.000000000 +0100 @@ -32,15 +32,14 @@ #include "../../../drivers/oprofile/event_buffer.h" =20 #define MAX_XENOPROF_SAMPLES 16 -#define MAX_VIRT_CPUS 128 =20 /* sample buffers shared with Xen */ -static xenoprof_buf_t *xenoprof_buf[MAX_VIRT_CPUS]; +static xenoprof_buf_t **__read_mostly xenoprof_buf; /* Shared buffer area */ static struct xenoprof_shared_buffer shared_buffer; =20 /* Passive sample buffers shared with Xen */ -static xenoprof_buf_t *p_xenoprof_buf[MAX_OPROF_DOMAINS][MAX_VIRT_CPUS]; +static xenoprof_buf_t **__read_mostly p_xenoprof_buf[MAX_OPROF_DOMAINS]; /* Passive shared buffer area */ static struct xenoprof_shared_buffer p_shared_buffer[MAX_OPROF_DOMAINS]; =20 @@ -250,11 +249,32 @@ static int bind_virq(void) } =20 =20 +static xenoprof_buf_t **get_buffer_array(unsigned int nbuf) +{ + size_t size =3D nbuf * sizeof(xenoprof_buf_t); + + if (size <=3D PAGE_SIZE) + return kmalloc(size, GFP_KERNEL); + return vmalloc(size); +} + +static void release_buffer_array(xenoprof_buf_t **buf, unsigned int nbuf) +{ + if (nbuf * sizeof(xenoprof_buf_t) <=3D PAGE_SIZE) + kfree(buf); + else + vfree(buf); +} + + static void unmap_passive_list(void) { int i; - for (i =3D 0; i < pdomains; i++) + for (i =3D 0; i < pdomains; i++) { xenoprof_arch_unmap_shared_buffer(&p_shared_buffer[i]); + release_buffer_array(p_xenoprof_buf[i], + passive_domains[i].nbuf); + } pdomains =3D 0; } =20 @@ -274,10 +294,16 @@ static int map_xenoprof_buffer(int max_s return ret; nbuf =3D get_buffer.nbuf; =20 + xenoprof_buf =3D get_buffer_array(nbuf); + if (!xenoprof_buf) { + xenoprof_arch_unmap_shared_buffer(&shared_buffer); + return -ENOMEM; + } + for (i=3D0; i< nbuf; i++) { buf =3D (struct xenoprof_buf*)=20 &shared_buffer.buffer[i * get_buffer.bufsize]; - BUG_ON(buf->vcpu_id >=3D MAX_VIRT_CPUS); + BUG_ON(buf->vcpu_id >=3D nbuf); xenoprof_buf[buf->vcpu_id] =3D buf; } =20 @@ -292,8 +318,10 @@ static int xenoprof_setup(void) if ( (ret =3D map_xenoprof_buffer(MAX_XENOPROF_SAMPLES)) ) return ret; =20 - if ( (ret =3D bind_virq()) ) + if ( (ret =3D bind_virq()) ) { + release_buffer_array(xenoprof_buf, nbuf); return ret; + } =20 if (xenoprof_is_primary) { /* Define dom0 as an active domain if not done yet */ @@ -336,6 +364,7 @@ static int xenoprof_setup(void) return 0; err: unbind_virq(); + release_buffer_array(xenoprof_buf, nbuf); return ret; } =20 @@ -357,6 +386,7 @@ static void xenoprof_shutdown(void) xenoprof_arch_unmap_shared_buffer(&shared_buffer); if (xenoprof_is_primary) unmap_passive_list(); + release_buffer_array(xenoprof_buf, nbuf); } =20 =20 @@ -449,11 +479,19 @@ static int xenoprof_set_passive(int * p_ &p_shared_buffer[i]); if (ret) goto out; + + p_xenoprof_buf[i] =3D get_buffer_array(passive_domains[i].n= buf); + if (!p_xenoprof_buf[i]) { + ++i; + ret =3D -ENOMEM; + goto out; + } + for (j =3D 0; j < passive_domains[i].nbuf; j++) { buf =3D (struct xenoprof_buf *) &p_shared_buffer[i].buffer[ j * passive_domains[i].bufsize]; - BUG_ON(buf->vcpu_id >=3D MAX_VIRT_CPUS); + BUG_ON(buf->vcpu_id >=3D passive_domains[i].nbuf); p_xenoprof_buf[i][buf->vcpu_id] =3D buf; } } @@ -462,8 +500,11 @@ static int xenoprof_set_passive(int * p_ return 0; =20 out: - for (j =3D 0; j < i; j++) + for (j =3D 0; j < i; j++) { xenoprof_arch_unmap_shared_buffer(&p_shared_buffer[i]); + release_buffer_array(p_xenoprof_buf[i], + passive_domains[i].nbuf); + } =20 return ret; } --=__PartC8E2CD9E.0__= Content-Type: text/plain; name="xenlinux-oprofile-buffer-alloc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xenlinux-oprofile-buffer-alloc.patch" Subject: xenoprof: dynamic buffer array allocation=0A=0AThe recent change = to locally define MAX_VIRT_CPUS wasn't really=0Aappropriate - with there = not being a hard limit on the number of=0AvCPU-s anymore, these arrays = should be allocated dynamically.=0A=0AAs usual, written against 2.6.32.2 = and made apply to the 2.6.18=0Atree without further testing.=0A=0ASigned-of= f-by: Jan Beulich =0A=0A--- head-2010-01-04.orig/drive= rs/xen/xenoprof/xenoprofile.c 2010-01-04 13:31:29.000000000 +0100=0A+++ = head-2010-01-04/drivers/xen/xenoprof/xenoprofile.c 2010-01-04 = 16:51:11.000000000 +0100=0A@@ -32,15 +32,14 @@=0A #include "../../../driver= s/oprofile/event_buffer.h"=0A =0A #define MAX_XENOPROF_SAMPLES 16=0A-#defin= e MAX_VIRT_CPUS 128=0A =0A /* sample buffers shared with Xen */=0A-static = xenoprof_buf_t *xenoprof_buf[MAX_VIRT_CPUS];=0A+static xenoprof_buf_t = **__read_mostly xenoprof_buf;=0A /* Shared buffer area */=0A static struct = xenoprof_shared_buffer shared_buffer;=0A =0A /* Passive sample buffers = shared with Xen */=0A-static xenoprof_buf_t *p_xenoprof_buf[MAX_OPROF_DOMAI= NS][MAX_VIRT_CPUS];=0A+static xenoprof_buf_t **__read_mostly p_xenoprof_buf= [MAX_OPROF_DOMAINS];=0A /* Passive shared buffer area */=0A static struct = xenoprof_shared_buffer p_shared_buffer[MAX_OPROF_DOMAINS];=0A =0A@@ = -250,11 +249,32 @@ static int bind_virq(void)=0A }=0A =0A =0A+static = xenoprof_buf_t **get_buffer_array(unsigned int nbuf)=0A+{=0A+ size_t = size =3D nbuf * sizeof(xenoprof_buf_t);=0A+=0A+ if (size <=3D PAGE_SIZE)=0A= + return kmalloc(size, GFP_KERNEL);=0A+ return vmalloc(size= );=0A+}=0A+=0A+static void release_buffer_array(xenoprof_buf_t **buf, = unsigned int nbuf)=0A+{=0A+ if (nbuf * sizeof(xenoprof_buf_t) <=3D = PAGE_SIZE)=0A+ kfree(buf);=0A+ else=0A+ vfree(buf);= =0A+}=0A+=0A+=0A static void unmap_passive_list(void)=0A {=0A int i;=0A- = for (i =3D 0; i < pdomains; i++)=0A+ for (i =3D 0; i < pdomains; i++) = {=0A xenoprof_arch_unmap_shared_buffer(&p_shared_buffer[i]);=0A+= release_buffer_array(p_xenoprof_buf[i],=0A+ = passive_domains[i].nbuf);=0A+ }=0A pdomains =3D 0;=0A = }=0A =0A@@ -274,10 +294,16 @@ static int map_xenoprof_buffer(int max_s=0A = return ret;=0A nbuf =3D get_buffer.nbuf;=0A =0A+ xenoprof_bu= f =3D get_buffer_array(nbuf);=0A+ if (!xenoprof_buf) {=0A+ = xenoprof_arch_unmap_shared_buffer(&shared_buffer);=0A+ return = -ENOMEM;=0A+ }=0A+=0A for (i=3D0; i< nbuf; i++) {=0A = buf =3D (struct xenoprof_buf*) =0A &shared_buffer.buff= er[i * get_buffer.bufsize];=0A- BUG_ON(buf->vcpu_id >=3D MAX_VIRT_C= PUS);=0A+ BUG_ON(buf->vcpu_id >=3D nbuf);=0A = xenoprof_buf[buf->vcpu_id] =3D buf;=0A }=0A =0A@@ -292,8 +318,10 @@ = static int xenoprof_setup(void)=0A if ( (ret =3D map_xenoprof_buffer(M= AX_XENOPROF_SAMPLES)) )=0A return ret;=0A =0A- if ( (ret = =3D bind_virq()) )=0A+ if ( (ret =3D bind_virq()) ) {=0A+ = release_buffer_array(xenoprof_buf, nbuf);=0A return ret;=0A+ = }=0A =0A if (xenoprof_is_primary) {=0A /* Define dom0 as = an active domain if not done yet */=0A@@ -336,6 +364,7 @@ static int = xenoprof_setup(void)=0A return 0;=0A err:=0A unbind_virq();=0A+ = release_buffer_array(xenoprof_buf, nbuf);=0A return ret;=0A }=0A =0A@@ = -357,6 +386,7 @@ static void xenoprof_shutdown(void)=0A xenoprof_ar= ch_unmap_shared_buffer(&shared_buffer);=0A if (xenoprof_is_primary)=0A= unmap_passive_list();=0A+ release_buffer_array(xenopr= of_buf, nbuf);=0A }=0A =0A =0A@@ -449,11 +479,19 @@ static int xenoprof_set= _passive(int * p_=0A &p_shared_b= uffer[i]);=0A if (ret)=0A goto out;=0A+=0A+ = p_xenoprof_buf[i] =3D get_buffer_array(passive_domains[i].nbuf);=0A= + if (!p_xenoprof_buf[i]) {=0A+ ++i;=0A+ = ret =3D -ENOMEM;=0A+ goto out;=0A+ = }=0A+=0A for (j =3D 0; j < passive_domains[i].nbuf; j++) = {=0A buf =3D (struct xenoprof_buf *)=0A = &p_shared_buffer[i].buffer[=0A j * = passive_domains[i].bufsize];=0A- BUG_ON(buf->vcpu_id= >=3D MAX_VIRT_CPUS);=0A+ BUG_ON(buf->vcpu_id >=3D = passive_domains[i].nbuf);=0A p_xenoprof_buf[i][buf->vcpu= _id] =3D buf;=0A }=0A }=0A@@ -462,8 +500,11 @@ static = int xenoprof_set_passive(int * p_=0A return 0;=0A =0A out:=0A- = for (j =3D 0; j < i; j++)=0A+ for (j =3D 0; j < i; j++) {=0A = xenoprof_arch_unmap_shared_buffer(&p_shared_buffer[i]);=0A+ = release_buffer_array(p_xenoprof_buf[i],=0A+ = passive_domains[i].nbuf);=0A+ }=0A =0A return ret;=0A }=0A --=__PartC8E2CD9E.0__= 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 --=__PartC8E2CD9E.0__=--