xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Mathieu Gagné" <mgagne@iweb.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Subject: Re: [PATCH 3 of 4] xl: add support for vif rate limiting
Date: Tue, 20 Mar 2012 14:25:26 -0400	[thread overview]
Message-ID: <4F68CB96.1060408@iweb.com> (raw)
In-Reply-To: <1332242491.9223.210.camel@zakaz.uk.xensource.com>

Forgot to reply to some comments. See below.

On 3/20/12 7:21 AM, Ian Campbell wrote:
> On Tue, 2012-03-20 at 01:28 +0000, Mathieu Gagné wrote:
>
>> +static void vif_parse_rate_bytes_per_sec(const char *bytes, uint32_t *bytes_per_sec)
>> +{
>> +    regex_t rec;
>> +    uint64_t tmp_bytes_per_sec = 0;
>> +
>> +    regcomp(&rec, vif_bytes_per_sec_re, REG_EXTENDED);
>
> It seems that you use the regex only to check the syntax and then open
> code the parsing? That strikes me as odd, if you are going to use a
> regex parser you might as well use the matches returned from it.

I originally used the matches but faced a myriad of problems and 
challenges. I not only had one problem (this patch) but two (this patch 
and the regex/matches).

After much headache, I modified my approach to use regex for validation 
purpose only which simplified my code by a huge factor. IMO, the code 
was much more complex and difficult to read when I used matches.

I'm open to modify it if someone can help me with this.


> You could also combine the parsing of rate and interval into a single
> regex and avoid the use of strtok etc in the outermost function.

The original regex used sub-matches which I didn't know how or if it was 
possible to do in C:

^([0-9]+)([GMK]?)([Bb])/s(@([0-9]+)([mu]?)s)?$


> You should return a syntax error if the string is invalid.

The original code did not bailout on error and default to unlimited. 
Should we change this behavior in libxl/xl?


>> +        const char *p = bytes;
>> +        tmp_bytes_per_sec = strtoul(p, (char**)&p, 0);
>> +        if (*p == 'G' || *p == '\0')
>> +           tmp_bytes_per_sec *= 1000 * 1000 * 1000;
>> +        else if (*p == 'M')
>> +           tmp_bytes_per_sec *= 1000 * 1000;
>> +        else if (*p == 'K')
>> +           tmp_bytes_per_sec *= 1000;
>> +        if (*p == 'b' || *(p+1) == 'b')
>> +           tmp_bytes_per_sec /= 8;

Minor optimization to do here. It's impossible to fall in the second 
case of the first condition: *p == '\0'. I'll fix it in v2.

-- 
Mathieu

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  parent reply	other threads:[~2012-03-20 18:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-20  1:28 [PATCH 0 of 4] xl: add support for vif rate limiting Mathieu Gagné
2012-03-20  1:28 ` [PATCH 1 of 4] xl: cleanup indentation Mathieu Gagné
2012-03-20 10:58   ` Ian Campbell
2012-03-20 11:07   ` Stefano Stabellini
2012-03-20  1:28 ` [PATCH 2 of 4] xl: xl network-attach -N (dry run) option Mathieu Gagné
2012-03-20 10:58   ` Ian Campbell
2012-03-20 11:09   ` Stefano Stabellini
2012-03-20  1:28 ` [PATCH 3 of 4] xl: add support for vif rate limiting Mathieu Gagné
2012-03-20 11:16   ` Stefano Stabellini
2012-03-20 11:26     ` Ian Campbell
2012-03-20 18:40       ` Mathieu Gagné
2012-03-21 10:23         ` Ian Campbell
2012-03-20 11:21   ` Ian Campbell
2012-03-20 17:58     ` Mathieu Gagné
2012-03-21 10:04       ` Ian Campbell
2012-03-20 18:25     ` Mathieu Gagné [this message]
2012-03-21 10:12       ` Ian Campbell
2012-03-20  1:28 ` [PATCH 4 of 4] xl: add "check-xl-vif-parse" test script Mathieu Gagné
2012-03-20 11:29   ` Ian Campbell
2012-03-20 11:30 ` [PATCH 0 of 4] xl: add support for vif rate limiting Ian Campbell

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=4F68CB96.1060408@iweb.com \
    --to=mgagne@iweb.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=Stefano.Stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).