* [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max
@ 2010-05-18 0:41 Jeremy Fitzhardinge
2010-05-18 1:45 ` Yang Hongyang
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fitzhardinge @ 2010-05-18 0:41 UTC (permalink / raw)
To: Xen-devel; +Cc: Ian Jackson, Vincent Hanquez, Stefano Stabellini
Allow mem-set and mem-max to take 'b', 'k', 'm', 'g' and 't' as scaling
suffixes for bytes, kilobytes, mega, etc. An unadorned number is still
treated as kilobytes so no existing users should be affected.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon May 17 17:37:56 2010 -0700
@@ -1200,16 +1200,40 @@
}
}
+static long long int parse_mem_size_kb(char *mem)
+{
+ char *endptr;
+ long long int bytes;
+ long long int scale = 1024;
+
+ bytes = strtoll(mem, &endptr, 10);
+
+ if (strlen(endptr) > 1)
+ return -1;
+
+ switch (*endptr) {
+ case '\0': break;
+ case 'b': scale = 1; break;
+ case 'k': scale = 1024ll; break;
+ case 'm': scale = 1024ll * 1024; break;
+ case 'g': scale = 1024ll * 1024 * 1024; break;
+ case 't': scale = 1024ll * 1024 * 1024 * 1024; break;
+ default:
+ return -1;
+ }
+
+ return (bytes * scale) / 1024;
+}
+
int set_memory_max(char *p, char *mem)
{
- char *endptr;
- uint32_t memorykb;
+ long long int memorykb;
int rc;
find_domain(p);
- memorykb = strtoul(mem, &endptr, 10);
- if (*endptr != '\0') {
+ memorykb = parse_mem_size_kb(mem);
+ if (memorykb == -1) {
fprintf(stderr, "invalid memory size: %s\n", mem);
exit(3);
}
@@ -1255,17 +1279,18 @@
void set_memory_target(char *p, char *mem)
{
- char *endptr;
- uint32_t memorykb;
+ long long int memorykb;
find_domain(p);
- memorykb = strtoul(mem, &endptr, 10);
- if (*endptr != '\0') {
- fprintf(stderr, "invalid memory size: %s\n", mem);
- exit(3);
+ memorykb = parse_mem_size_kb(mem);
+
+ if (memorykb == -1) {
+ fprintf(stderr, "invalid memory size: %s\n", mem);
+ exit(3);
}
- printf("setting domid %d memory to : %d\n", domid, memorykb);
+
+ printf("setting domid %d memory to : %lld\n", domid, memorykb);
libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1);
}
diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Mon May 17 17:37:56 2010 -0700
@@ -110,12 +110,12 @@
},
{ "mem-max",
&main_memmax,
- "Set the maximum amount reservation for a domain",
+ "Set the maximum amount reservation for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
"<Domain> <MemKB>",
},
{ "mem-set",
&main_memset,
- "Set the current memory usage for a domain",
+ "Set the current memory usage for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
"<Domain> <MemKB>",
},
{ "button-press",
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max
2010-05-18 0:41 [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max Jeremy Fitzhardinge
@ 2010-05-18 1:45 ` Yang Hongyang
2010-05-18 17:04 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 4+ messages in thread
From: Yang Hongyang @ 2010-05-18 1:45 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Vincent Hanquez, Xen-devel, Ian Jackson, Stefano Stabellini
Hi jeremy,
On 05/18/2010 08:41 AM, Jeremy Fitzhardinge wrote:
> Allow mem-set and mem-max to take 'b', 'k', 'm', 'g' and 't' as scaling
> suffixes for bytes, kilobytes, mega, etc. An unadorned number is still
> treated as kilobytes so no existing users should be affected.
>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
>
> diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
> --- a/tools/libxl/xl_cmdimpl.c Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdimpl.c Mon May 17 17:37:56 2010 -0700
> @@ -1200,16 +1200,40 @@
> }
> }
>
> +static long long int parse_mem_size_kb(char *mem)
I think here should use 'uint64_t' which is 'unsigned long long'
instead of 'long long int'.
> +{
> + char *endptr;
> + long long int bytes;
> + long long int scale = 1024;
> +
> + bytes = strtoll(mem, &endptr, 10);
> +
> + if (strlen(endptr) > 1)
> + return -1;
> +
> + switch (*endptr) {
> + case '\0': break;
> + case 'b': scale = 1; break;
> + case 'k': scale = 1024ll; break;
> + case 'm': scale = 1024ll * 1024; break;
> + case 'g': scale = 1024ll * 1024 * 1024; break;
> + case 't': scale = 1024ll * 1024 * 1024 * 1024; break;
> + default:
> + return -1;
> + }
> +
> + return (bytes * scale) / 1024;
> +}
> +
> int set_memory_max(char *p, char *mem)
> {
> - char *endptr;
> - uint32_t memorykb;
> + long long int memorykb;
> int rc;
>
> find_domain(p);
>
> - memorykb = strtoul(mem, &endptr, 10);
> - if (*endptr != '\0') {
> + memorykb = parse_mem_size_kb(mem);
> + if (memorykb == -1) {
> fprintf(stderr, "invalid memory size: %s\n", mem);
> exit(3);
> }
> @@ -1255,17 +1279,18 @@
>
> void set_memory_target(char *p, char *mem)
> {
> - char *endptr;
> - uint32_t memorykb;
> + long long int memorykb;
>
> find_domain(p);
>
> - memorykb = strtoul(mem, &endptr, 10);
> - if (*endptr != '\0') {
> - fprintf(stderr, "invalid memory size: %s\n", mem);
> - exit(3);
> + memorykb = parse_mem_size_kb(mem);
> +
> + if (memorykb == -1) {
> + fprintf(stderr, "invalid memory size: %s\n", mem);
> + exit(3);
> }
> - printf("setting domid %d memory to : %d\n", domid, memorykb);
> +
> + printf("setting domid %d memory to : %lld\n", domid, memorykb);
> libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1);
> }
>
> diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
> --- a/tools/libxl/xl_cmdtable.c Fri May 14 08:05:05 2010 +0100
> +++ b/tools/libxl/xl_cmdtable.c Mon May 17 17:37:56 2010 -0700
> @@ -110,12 +110,12 @@
> },
> { "mem-max",
> &main_memmax,
> - "Set the maximum amount reservation for a domain",
> + "Set the maximum amount reservation for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
> "<Domain> <MemKB>",
> },
> { "mem-set",
> &main_memset,
> - "Set the current memory usage for a domain",
> + "Set the current memory usage for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
> "<Domain> <MemKB>",
> },
> { "button-press",
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
>
--
Regards
Yang Hongyang
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max
2010-05-18 1:45 ` Yang Hongyang
@ 2010-05-18 17:04 ` Jeremy Fitzhardinge
2010-05-21 10:40 ` Ian Jackson
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fitzhardinge @ 2010-05-18 17:04 UTC (permalink / raw)
To: Yang Hongyang; +Cc: Vincent Hanquez, Xen-devel, Ian Jackson, Stefano Stabellini
On 05/17/2010 06:45 PM, Yang Hongyang wrote:
> Hi jeremy,
>
> On 05/18/2010 08:41 AM, Jeremy Fitzhardinge wrote:
>
>> Allow mem-set and mem-max to take 'b', 'k', 'm', 'g' and 't' as scaling
>> suffixes for bytes, kilobytes, mega, etc. An unadorned number is still
>> treated as kilobytes so no existing users should be affected.
>>
>> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
>>
>> diff -r baccadfd9418 tools/libxl/xl_cmdimpl.c
>> --- a/tools/libxl/xl_cmdimpl.c Fri May 14 08:05:05 2010 +0100
>> +++ b/tools/libxl/xl_cmdimpl.c Mon May 17 17:37:56 2010 -0700
>> @@ -1200,16 +1200,40 @@
>> }
>> }
>>
>> +static long long int parse_mem_size_kb(char *mem)
>>
> I think here should use 'uint64_t' which is 'unsigned long long'
> instead of 'long long int'.
>
I want it to be signed so I can use -1 as an error indicator. And I
want it to be "long long int" rather than int64_t so that the format
specifier for printf is unambiguous (since int64_t can be just "long" on
a 64-bit machine).
J
>
>> +{
>> + char *endptr;
>> + long long int bytes;
>> + long long int scale = 1024;
>> +
>> + bytes = strtoll(mem, &endptr, 10);
>> +
>> + if (strlen(endptr) > 1)
>> + return -1;
>> +
>> + switch (*endptr) {
>> + case '\0': break;
>> + case 'b': scale = 1; break;
>> + case 'k': scale = 1024ll; break;
>> + case 'm': scale = 1024ll * 1024; break;
>> + case 'g': scale = 1024ll * 1024 * 1024; break;
>> + case 't': scale = 1024ll * 1024 * 1024 * 1024; break;
>> + default:
>> + return -1;
>> + }
>> +
>> + return (bytes * scale) / 1024;
>> +}
>> +
>> int set_memory_max(char *p, char *mem)
>> {
>> - char *endptr;
>> - uint32_t memorykb;
>> + long long int memorykb;
>> int rc;
>>
>> find_domain(p);
>>
>> - memorykb = strtoul(mem, &endptr, 10);
>> - if (*endptr != '\0') {
>> + memorykb = parse_mem_size_kb(mem);
>> + if (memorykb == -1) {
>> fprintf(stderr, "invalid memory size: %s\n", mem);
>> exit(3);
>> }
>> @@ -1255,17 +1279,18 @@
>>
>> void set_memory_target(char *p, char *mem)
>> {
>> - char *endptr;
>> - uint32_t memorykb;
>> + long long int memorykb;
>>
>> find_domain(p);
>>
>> - memorykb = strtoul(mem, &endptr, 10);
>> - if (*endptr != '\0') {
>> - fprintf(stderr, "invalid memory size: %s\n", mem);
>> - exit(3);
>> + memorykb = parse_mem_size_kb(mem);
>> +
>> + if (memorykb == -1) {
>> + fprintf(stderr, "invalid memory size: %s\n", mem);
>> + exit(3);
>> }
>> - printf("setting domid %d memory to : %d\n", domid, memorykb);
>> +
>> + printf("setting domid %d memory to : %lld\n", domid, memorykb);
>> libxl_set_memory_target(&ctx, domid, memorykb, /* enforce */ 1);
>> }
>>
>> diff -r baccadfd9418 tools/libxl/xl_cmdtable.c
>> --- a/tools/libxl/xl_cmdtable.c Fri May 14 08:05:05 2010 +0100
>> +++ b/tools/libxl/xl_cmdtable.c Mon May 17 17:37:56 2010 -0700
>> @@ -110,12 +110,12 @@
>> },
>> { "mem-max",
>> &main_memmax,
>> - "Set the maximum amount reservation for a domain",
>> + "Set the maximum amount reservation for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
>> "<Domain> <MemKB>",
>> },
>> { "mem-set",
>> &main_memset,
>> - "Set the current memory usage for a domain",
>> + "Set the current memory usage for a domain. Units default to kilobytes, but can be suffixed with 'b' (bytes), 'k' (KB), 'm' (MB), 'g' (GB) or 't' (TB)",
>> "<Domain> <MemKB>",
>> },
>> { "button-press",
>>
>>
>>
>> _______________________________________________
>> Xen-devel mailing list
>> Xen-devel@lists.xensource.com
>> http://lists.xensource.com/xen-devel
>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max
2010-05-18 17:04 ` Jeremy Fitzhardinge
@ 2010-05-21 10:40 ` Ian Jackson
0 siblings, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2010-05-21 10:40 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Yang Hongyang, Vincent Hanquez, Xen-devel, Stefano Stabellini
Jeremy Fitzhardinge writes ("Re: [Xen-devel] [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max"):
> I want it to be signed so I can use -1 as an error indicator. And I
> want it to be "long long int" rather than int64_t so that the format
> specifier for printf is unambiguous (since int64_t can be just "long" on
> a 64-bit machine).
You can use int64_t and as a format write "%"PRIi64
Ian.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-21 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-18 0:41 [PATCH] xl: allow scaling suffix on memory sizes in mem-set and mem-max Jeremy Fitzhardinge
2010-05-18 1:45 ` Yang Hongyang
2010-05-18 17:04 ` Jeremy Fitzhardinge
2010-05-21 10:40 ` Ian Jackson
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.