From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: Joerg Roedel <joerg.roedel@amd.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 1/3] qemu: Add strtosz_suffix_unit function
Date: Thu, 7 Jul 2011 16:13:11 +0200 [thread overview]
Message-ID: <1310047993-7649-2-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1310047993-7649-1-git-send-email-joerg.roedel@amd.com>
This function does the same as the strtosz_suffix function
except that it allows to specify the unit to which the
k/M/B/T suffixes apply. This function will be used later to
parse the tsc-frequency from the command-line.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
cutils.c | 16 +++++++++++-----
qemu-common.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/cutils.c b/cutils.c
index f9a7e36..28049e0 100644
--- a/cutils.c
+++ b/cutils.c
@@ -322,7 +322,8 @@ int fcntl_setfl(int fd, int flag)
* value must be terminated by whitespace, ',' or '\0'. Return -1 on
* error.
*/
-int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+int64_t strtosz_suffix_unit(const char *nptr, char **end,
+ const char default_suffix, int64_t unit)
{
int64_t retval = -1;
char *endptr;
@@ -362,20 +363,20 @@ int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
}
break;
case STRTOSZ_DEFSUFFIX_KB:
- mul = 1 << 10;
+ mul = unit;
break;
case 0:
if (mul_required) {
goto fail;
}
case STRTOSZ_DEFSUFFIX_MB:
- mul = 1ULL << 20;
+ mul = unit * unit;
break;
case STRTOSZ_DEFSUFFIX_GB:
- mul = 1ULL << 30;
+ mul = unit * unit * unit;
break;
case STRTOSZ_DEFSUFFIX_TB:
- mul = 1ULL << 40;
+ mul = unit * unit * unit * unit;
break;
default:
goto fail;
@@ -405,6 +406,11 @@ fail:
return retval;
}
+int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)
+{
+ return strtosz_suffix_unit(nptr, end, default_suffix, 1024);
+}
+
int64_t strtosz(const char *nptr, char **end)
{
return strtosz_suffix(nptr, end, STRTOSZ_DEFSUFFIX_MB);
diff --git a/qemu-common.h b/qemu-common.h
index 109498d..854031a 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -186,6 +186,8 @@ int fcntl_setfl(int fd, int flag);
#define STRTOSZ_DEFSUFFIX_B 'B'
int64_t strtosz(const char *nptr, char **end);
int64_t strtosz_suffix(const char *nptr, char **end, const char default_suffix);
+int64_t strtosz_suffix_unit(const char *nptr, char **end,
+ const char default_suffix, int64_t unit);
/* path.c */
void init_paths(const char *prefix);
--
1.7.4.1
next prev parent reply other threads:[~2011-07-07 14:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-07 14:13 [Qemu-devel] [PATCH 0/3][uq/master] Basic TSC-Scaling support v2 Joerg Roedel
2011-07-07 14:13 ` Joerg Roedel [this message]
2011-07-08 8:00 ` [Qemu-devel] [PATCH 1/3] qemu: Add strtosz_suffix_unit function Markus Armbruster
2011-07-07 14:13 ` [Qemu-devel] [PATCH 2/3] qemu-x86: Add tsc_freq option to -cpu Joerg Roedel
2011-07-19 11:46 ` Marcelo Tosatti
2011-07-19 12:20 ` Avi Kivity
2011-07-19 12:56 ` Marcelo Tosatti
2011-07-19 13:30 ` Joerg Roedel
2011-07-19 13:54 ` Avi Kivity
2011-07-19 13:55 ` Avi Kivity
2011-07-19 14:14 ` Joerg Roedel
2011-07-19 15:55 ` Avi Kivity
2011-07-07 14:13 ` [Qemu-devel] [PATCH 3/3] qemu-x86: Set tsc_khz in kvm when supported Joerg Roedel
2011-07-19 11:48 ` Marcelo Tosatti
2011-07-19 17:03 ` Jan Kiszka
2011-07-19 13:04 ` [Qemu-devel] [PATCH 0/3][uq/master] Basic TSC-Scaling support v2 Marcelo Tosatti
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=1310047993-7649-2-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.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).