All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, Keir Fraser <keir@xen.org>
Subject: Re: [PATCH] xentrace: dynamic tracebuffer size allocation
Date: Mon, 7 Feb 2011 18:55:12 +0100	[thread overview]
Message-ID: <20110207175512.GA13123@aepfle.de> (raw)
In-Reply-To: <AANLkTinmsiaE7feBYSx+Zc7bUFeVGok8WrVUB2WfpP5G@mail.gmail.com>

On Mon, Feb 07, George Dunlap wrote:

> On Sun, Feb 6, 2011 at 1:39 PM, Olaf Hering <olaf@aepfle.de> 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

  reply	other threads:[~2011-02-07 17:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-05 14:07 [PATCH] xentrace: dynamic tracebuffer size allocation Olaf Hering
2011-02-05 16:32 ` Olaf Hering
2011-02-05 20:35 ` Keir Fraser
2011-02-06 13:39   ` Olaf Hering
2011-02-07 17:38     ` George Dunlap
2011-02-07 17:55       ` Olaf Hering [this message]
2011-03-14 17:33       ` Olaf Hering
2011-03-16 11:32         ` George Dunlap
2011-03-16 13:05           ` Olaf Hering
2011-03-16 14:18             ` George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110207175512.GA13123@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.