From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Dunlap Subject: Re: [PATCH 4 of 4] xentrace: allocate non-contiguous per-cpu trace buffers Date: Thu, 26 May 2011 11:06:15 +0100 Message-ID: References: <7f6a118d237e60ca6f30.1305037959@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <7f6a118d237e60ca6f30.1305037959@localhost> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Olaf Hering Cc: xen-devel@lists.xensource.com, George Dunlap List-Id: xen-devel@lists.xenproject.org Acked-by: George Dunlap On Tue, May 10, 2011 at 3:32 PM, Olaf Hering wrote: > # HG changeset patch > # User Olaf Hering > # Date 1305037567 -7200 > # Node ID 7f6a118d237e60ca6f30723db687b06a8ef3c3e9 > # Parent =A01a45e40add8b407532374c34f20bad51707808cf > xentrace: allocate non-contiguous per-cpu trace buffers > > Signed-off-by: Olaf Hering > > diff -r 1a45e40add8b -r 7f6a118d237e xen/common/trace.c > --- a/xen/common/trace.c =A0 =A0 =A0 =A0Tue May 10 16:25:39 2011 +0200 > +++ b/xen/common/trace.c =A0 =A0 =A0 =A0Tue May 10 16:26:07 2011 +0200 > @@ -166,7 +166,7 @@ static int calculate_tbuf_size(unsigned > =A0*/ > =A0static int alloc_trace_bufs(unsigned int pages) > =A0{ > - =A0 =A0int i, cpu, order; > + =A0 =A0int i, cpu; > =A0 =A0 /* Start after a fixed-size array of NR_CPUS */ > =A0 =A0 uint32_t *t_info_mfn_list; > =A0 =A0 uint16_t t_info_first_offset; > @@ -182,34 +182,11 @@ static int alloc_trace_bufs(unsigned int > =A0 =A0 t_info_first_offset =3D calc_tinfo_first_offset(); > > =A0 =A0 pages =3D calculate_tbuf_size(pages, t_info_first_offset); > - =A0 =A0order =3D get_order_from_pages(pages); > > =A0 =A0 t_info =3D alloc_xenheap_pages(get_order_from_pages(t_info_pages)= , 0); > =A0 =A0 if ( t_info =3D=3D NULL ) > - =A0 =A0 =A0 =A0goto out_dealloc; > + =A0 =A0 =A0 =A0goto out_dealloc_t_info; > > - =A0 =A0/* > - =A0 =A0 * First, allocate buffers for all of the cpus. =A0If any > - =A0 =A0 * fails, deallocate what you have so far and exit. > - =A0 =A0 */ > - =A0 =A0for_each_online_cpu(cpu) > - =A0 =A0{ > - =A0 =A0 =A0 =A0void *rawbuf; > - =A0 =A0 =A0 =A0struct t_buf *buf; > - > - =A0 =A0 =A0 =A0if ( (rawbuf =3D alloc_xenheap_pages( > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0order, MEMF_bits(32 + PAGE_SHIFT))) =3D= =3D NULL ) > - =A0 =A0 =A0 =A0{ > - =A0 =A0 =A0 =A0 =A0 =A0printk(XENLOG_INFO "xentrace: memory allocation = failed " > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "on cpu %d\n", cpu); > - =A0 =A0 =A0 =A0 =A0 =A0goto out_dealloc; > - =A0 =A0 =A0 =A0} > - > - =A0 =A0 =A0 =A0per_cpu(t_bufs, cpu) =3D buf =3D rawbuf; > - =A0 =A0 =A0 =A0buf->cons =3D buf->prod =3D 0; > - =A0 =A0} > - > - =A0 =A0offset =3D t_info_first_offset; > =A0 =A0 t_info_mfn_list =3D (uint32_t *)t_info; > > =A0 =A0 for(i =3D 0; i < t_info_pages; i++) > @@ -219,27 +196,53 @@ static int alloc_trace_bufs(unsigned int > =A0 =A0 t_info->tbuf_size =3D pages; > > =A0 =A0 /* > - =A0 =A0 * Now share the pages so xentrace can map them, and write them = in > - =A0 =A0 * the global t_info structure. > + =A0 =A0 * Allocate buffers for all of the cpus. > + =A0 =A0 * If any fails, deallocate what you have so far and exit. > =A0 =A0 =A0*/ > =A0 =A0 for_each_online_cpu(cpu) > =A0 =A0 { > - =A0 =A0 =A0 =A0void *rawbuf =3D per_cpu(t_bufs, cpu); > - =A0 =A0 =A0 =A0struct page_info *p =3D virt_to_page(rawbuf); > - =A0 =A0 =A0 =A0uint32_t mfn =3D virt_to_mfn(rawbuf); > + =A0 =A0 =A0 =A0offset =3D t_info_first_offset + (cpu * pages); > + =A0 =A0 =A0 =A0t_info->mfn_offset[cpu] =3D offset; > > =A0 =A0 =A0 =A0 for ( i =3D 0; i < pages; i++ ) > =A0 =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 =A0 =A0share_xen_page_with_privileged_guests(p + i, XEN= SHARE_writable); > + =A0 =A0 =A0 =A0 =A0 =A0void *p =3D alloc_xenheap_pages(0, MEMF_bits(32 = + PAGE_SHIFT)); > + =A0 =A0 =A0 =A0 =A0 =A0if ( !p ) > + =A0 =A0 =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(XENLOG_INFO "xentrace: memory all= ocation failed " > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "on cpu %d after %d pages\n= ", cpu, i); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0t_info_mfn_list[offset + i] =3D 0; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto out_dealloc; > + =A0 =A0 =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 =A0 =A0 =A0t_info_mfn_list[offset + i] =3D virt_to_mfn(p); > + =A0 =A0 =A0 =A0} > + =A0 =A0} > > - =A0 =A0 =A0 =A0 =A0 =A0t_info_mfn_list[offset + i]=3Dmfn + i; > - =A0 =A0 =A0 =A0} > - =A0 =A0 =A0 =A0t_info->mfn_offset[cpu]=3Doffset; > - =A0 =A0 =A0 =A0printk(XENLOG_INFO "xentrace: p%d mfn %"PRIx32" offset %= d\n", > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 cpu, mfn, offset); > - =A0 =A0 =A0 =A0offset+=3Di; > + =A0 =A0/* > + =A0 =A0 * Initialize buffers for all of the cpus. > + =A0 =A0 */ > + =A0 =A0for_each_online_cpu(cpu) > + =A0 =A0{ > + =A0 =A0 =A0 =A0struct t_buf *buf; > + =A0 =A0 =A0 =A0struct page_info *pg; > > =A0 =A0 =A0 =A0 spin_lock_init(&per_cpu(t_lock, cpu)); > + > + =A0 =A0 =A0 =A0offset =3D t_info->mfn_offset[cpu]; > + > + =A0 =A0 =A0 =A0/* Initialize the buffer metadata */ > + =A0 =A0 =A0 =A0per_cpu(t_bufs, cpu) =3D buf =3D mfn_to_virt(t_info_mfn_= list[offset]); > + =A0 =A0 =A0 =A0buf->cons =3D buf->prod =3D 0; > + > + =A0 =A0 =A0 =A0printk(XENLOG_INFO "xentrace: p%d mfn %x offset %u\n", > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 cpu, t_info_mfn_list[offset], offse= t); > + > + =A0 =A0 =A0 =A0/* Now share the trace pages */ > + =A0 =A0 =A0 =A0for ( i =3D 0; i < pages; i++ ) > + =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 =A0 =A0pg =3D mfn_to_page(t_info_mfn_list[offset + i]); > + =A0 =A0 =A0 =A0 =A0 =A0share_xen_page_with_privileged_guests(pg, XENSHA= RE_writable); > + =A0 =A0 =A0 =A0} > =A0 =A0 } > > =A0 =A0 data_size =A0=3D (pages * PAGE_SIZE - sizeof(struct t_buf)); > @@ -255,14 +258,19 @@ static int alloc_trace_bufs(unsigned int > =A0out_dealloc: > =A0 =A0 for_each_online_cpu(cpu) > =A0 =A0 { > - =A0 =A0 =A0 =A0void *rawbuf =3D per_cpu(t_bufs, cpu); > - =A0 =A0 =A0 =A0per_cpu(t_bufs, cpu) =3D NULL; > - =A0 =A0 =A0 =A0if ( rawbuf ) > + =A0 =A0 =A0 =A0offset =3D t_info->mfn_offset[cpu]; > + =A0 =A0 =A0 =A0if ( !offset ) > + =A0 =A0 =A0 =A0 =A0 =A0continue; > + =A0 =A0 =A0 =A0for ( i =3D 0; i < pages; i++ ) > =A0 =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 =A0 =A0ASSERT(!(virt_to_page(rawbuf)->count_info & PGC_= allocated)); > - =A0 =A0 =A0 =A0 =A0 =A0free_xenheap_pages(rawbuf, order); > + =A0 =A0 =A0 =A0 =A0 =A0uint32_t mfn =3D t_info_mfn_list[offset + i]; > + =A0 =A0 =A0 =A0 =A0 =A0if ( !mfn ) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > + =A0 =A0 =A0 =A0 =A0 =A0ASSERT(!(mfn_to_page(mfn)->count_info & PGC_allo= cated)); > + =A0 =A0 =A0 =A0 =A0 =A0free_xenheap_pages(mfn_to_virt(mfn), 0); > =A0 =A0 =A0 =A0 } > =A0 =A0 } > +out_dealloc_t_info: > =A0 =A0 free_xenheap_pages(t_info, get_order_from_pages(t_info_pages)); > =A0 =A0 t_info =3D NULL; > =A0 =A0 printk(XENLOG_WARNING "xentrace: allocation failed! Tracing disab= led.\n"); > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel >