WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] xentrace: dynamic tracebuffer size allocation

To: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] xentrace: dynamic tracebuffer size allocation
From: Olaf Hering <olaf@xxxxxxxxx>
Date: Mon, 7 Feb 2011 18:55:12 +0100
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Keir Fraser <keir@xxxxxxx>
Delivery-date: Mon, 07 Feb 2011 09:55:51 -0800
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1297101317; l=1698; s=domk; d=aepfle.de; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version: References:Subject:Cc:To:From:Date:X-RZG-CLASS-ID:X-RZG-AUTH; bh=J2apX5ER+wZgd3GO4wdqaYOf65o=; b=eBSyGAxN0vDjNPEY5/AAJR+UgJxplFMIIaYcNGBYMub2hhB8kfZPXn/jsort4g9oejr qX/ox5wbSgVBIGC5RrWIcp9EDh5q1PcpYXV2UyrBAtegKKK4U3uVHoI5DmZmogzd8xSVE 0BhPJaAR+g0NJ5LEC6wY2078Ylwqlus9vTM=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <AANLkTinmsiaE7feBYSx+Zc7bUFeVGok8WrVUB2WfpP5G@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <20110205140717.GA3224@xxxxxxxxx> <C9736502.12C07%keir@xxxxxxx> <20110206133913.GA7487@xxxxxxxxx> <AANLkTinmsiaE7feBYSx+Zc7bUFeVGok8WrVUB2WfpP5G@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.20 (2009-06-14)
On Mon, Feb 07, George Dunlap wrote:

> On Sun, Feb 6, 2011 at 1:39 PM, Olaf Hering <olaf@xxxxxxxxx> wrote:
> > @@ -85,20 +100,30 @@ static void calc_tinfo_first_offset(void
> >  }
> >
> >  /**
> > - * check_tbuf_size - check to make sure that the proposed size will fit
> > + * calculate_tbuf_size - check to make sure that the proposed size will fit
> >  * in the currently sized struct t_info and allows prod and cons to
> >  * reach double the value without overflow.
> >  */
> > -static int check_tbuf_size(u32 pages)
> > +static int calculate_tbuf_size(unsigned int pages)
> >  {
> >     struct t_buf dummy;
> > -    typeof(dummy.prod) size;
> > -
> > -    size = ((typeof(dummy.prod))pages)  * PAGE_SIZE;
> > -
> > -    return (size / PAGE_SIZE != pages)
> > -           || (size + size < size)
> > -           || (num_online_cpus() * pages + t_info_first_offset > 
> > T_INFO_SIZE / sizeof(uint32_t));
> > +    typeof(dummy.prod) size = -1;
> > +
> > +    /* max size holds up to n pages */
> > +    size /= PAGE_SIZE;
> 
> size=-1, then size /= PAGE_SIZE?  Is this a clever way of finding the
> maximum buffer size able to be pointed to?  If so, it needs a comment
> explaining why it works; I'm not convinced just by looking at it this
> is will work properly.

This was a head-scratcher for me as well. The typeof() was probably
meant to make it independent from changes in t_buf. My version does not
cover signed types, and I couldnt come up with a simple way to get to
the max value of any given type. So the -1 will cover just the unsigned
types. Assuming the index values will never get a signed type, it works.


Olaf


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel