From: George Dunlap <george.dunlap@eu.citrix.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>,
Hanweidong <hanweidong@huawei.com>,
xen-devel@lists.xen.org,
Stefano Stabellini <stefano.stabellini@citrix.com>,
Jan Beulich <JBeulich@suse.com>,
Ian Jackson <ian.jackson@citrix.com>
Subject: Re: [PATCH v2 5/5] libxl, hvmloader: Don't relocate memory for MMIO hole
Date: Thu, 20 Jun 2013 12:01:58 +0100 [thread overview]
Message-ID: <51C2E126.4090304@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1306201126470.4548@kaball.uk.xensource.com>
On 20/06/13 11:29, Stefano Stabellini wrote:
> On Thu, 20 Jun 2013, George Dunlap wrote:
>> On 20/06/13 11:12, Jan Beulich wrote:
>>>>>> On 20.06.13 at 11:22, George Dunlap <george.dunlap@eu.citrix.com>
>>>>>> wrote:
>>>> On 19/06/13 18:18, Stefano Stabellini wrote:
>>>>> On Tue, 18 Jun 2013, George Dunlap wrote:
>>>>>> + s = xenstore_read(HVM_XS_ALLOW_MEMORY_RELOCATE, NULL);
>>>>>> + if ( s )
>>>>>> + allow_memory_relocate = (bool)strtoll(s, NULL, 0);
>>>>>> + printf("Relocating guest memory for lowmem MMIO space %s\n",
>>>>>> + allow_memory_relocate?"enabled":"disabled");
>>>>> It doesn't take a strtoll to parse a boolean.
>>>> As discussed in v1, strtoll is the only "XtoY" function available in
>>>> hvmloader. :-) The only other option would be to explicitly compare for
>>>> "1" or "0" (or do some half-baked *s-'0' thing).
>>>>
>>>> This does make me think though -- what is the semantics of casting to a
>>>> bool? Is it !!, or will it essentially clip off the high bits? (e.g.,
>>>> would "2" become "1", or "0"?)
>>> If bool is a typedef or #define of _Bool, and _Bool is a complier
>>> supplied type, then the cast will do the right thing. But doing the
>>> assignment without the cast would too, i.e. the cast is pointless
>>> (as I think IanJ had already pointed out).
>> Thanks for the info.
>>
>> It may be pointless from a functionality perspective, but it's also harmless.
>> It won't add a single byte to the compiled code, but the 6 characters will
>> remind a developer reading the source that there is a cast being done here,
>> just in case it should ever become important. Not super important, but I'd
>> rather leave it in.
>>
>>> However, if we want to be on the safe side and also make the
>>> code work with a compiler that doesn't have a built-in _Bool, I'd
>>> think
>>>
>>> allow_memory_relocate = !s || strtoll(s, NULL, 0);
>>>
>>> would be the better statement (without any if() surrounding it,
>>> and without the variable declaration having an initializer.
>> Doing this would effectively hide the "default" value. This is bad because 1)
>> it's not clear what the default is to someone just scanning the code, 2) it's
>> hard to change. (Consider how you'd modify the above statement if you wanted
>> to default to 0 instead.)
> I would avoid the strtoll altogether:
>
> if (s != NULL && s[0] != '0')
> allow_memory_relocate = 1;
> else
> allow_memory_relocate = 0;
I think I'd be more inclined to do allow_memory_relocate = strcmp(s,
"0"); That will have more predictable results (e.g., 0 is false,
anything else at all is true).
-George
next prev parent reply other threads:[~2013-06-20 11:01 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-18 16:46 [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-18 16:46 ` [PATCH v2 2/5] hvmloader: Load large devices into high MMIO space as needed George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 9:23 ` George Dunlap
2013-06-20 9:47 ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 3/5] hvmloader: Remove minimum size for BARs to relocate to 64-bit space George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-19 21:14 ` Wei Liu
2013-06-20 9:01 ` George Dunlap
2013-06-20 9:48 ` Jan Beulich
2013-06-18 16:46 ` [PATCH v2 4/5] hvmloader: Fix check for needing a 64-bit bar George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 10:01 ` Jan Beulich
2013-06-20 10:21 ` George Dunlap
2013-06-18 16:46 ` [PATCH v2 5/5] libxl, hvmloader: Don't relocate memory for MMIO hole George Dunlap
2013-06-18 17:16 ` George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 9:22 ` George Dunlap
2013-06-20 10:12 ` Jan Beulich
2013-06-20 10:20 ` George Dunlap
2013-06-20 10:29 ` Stefano Stabellini
2013-06-20 10:56 ` Jan Beulich
2013-06-20 10:59 ` George Dunlap
2013-06-20 11:01 ` George Dunlap [this message]
2013-06-20 13:35 ` Ian Jackson
2013-06-20 14:06 ` George Dunlap
2013-06-20 10:37 ` Ian Jackson
2013-06-20 10:44 ` George Dunlap
2013-06-20 10:52 ` Jan Beulich
2013-06-20 10:49 ` Stefano Stabellini
2013-06-25 9:56 ` Ian Campbell
2013-06-25 10:15 ` George Dunlap
2013-06-18 16:53 ` [PATCH v2 1/5] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-19 17:18 ` Stefano Stabellini
2013-06-20 8:56 ` George Dunlap
2013-06-20 10:40 ` Stefano Stabellini
2013-06-20 10:43 ` George Dunlap
2013-06-20 9:36 ` Jan Beulich
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=51C2E126.4090304@eu.citrix.com \
--to=george.dunlap@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=hanweidong@huawei.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=stefano.stabellini@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).