From patchwork Thu Jul 7 14:13:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 103671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 164F3B6F67 for ; Fri, 8 Jul 2011 00:22:19 +1000 (EST) Received: from localhost ([::1]:41958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QepT5-0000gk-6u for incoming@patchwork.ozlabs.org; Thu, 07 Jul 2011 10:22:15 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QepKg-0007jt-T5 for qemu-devel@nongnu.org; Thu, 07 Jul 2011 10:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QepKe-0001bF-Mr for qemu-devel@nongnu.org; Thu, 07 Jul 2011 10:13:34 -0400 Received: from ch1ehsobe001.messaging.microsoft.com ([216.32.181.181]:55324 helo=CH1EHSOBE006.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QepKe-0001b3-BU for qemu-devel@nongnu.org; Thu, 07 Jul 2011 10:13:32 -0400 Received: from mail116-ch1-R.bigfish.com (216.32.181.171) by CH1EHSOBE006.bigfish.com (10.43.70.56) with Microsoft SMTP Server id 14.1.225.22; Thu, 7 Jul 2011 14:13:29 +0000 Received: from mail116-ch1 (localhost.localdomain [127.0.0.1]) by mail116-ch1-R.bigfish.com (Postfix) with ESMTP id 0D468608314; Thu, 7 Jul 2011 14:13:29 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzz8275bhz32i668h839h61h) X-Forefront-Antispam-Report: CIP:163.181.249.109; KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp02.amd.com; RD:none; EFVD:NLI Received: from mail116-ch1 (localhost.localdomain [127.0.0.1]) by mail116-ch1 (MessageSwitch) id 1310048008869310_15858; Thu, 7 Jul 2011 14:13:28 +0000 (UTC) Received: from CH1EHSMHS023.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.249]) by mail116-ch1.bigfish.com (Postfix) with ESMTP id C6B2DA2004B; Thu, 7 Jul 2011 14:13:28 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by CH1EHSMHS023.bigfish.com (10.43.70.23) with Microsoft SMTP Server id 14.1.225.22; Thu, 7 Jul 2011 14:13:28 +0000 X-WSS-ID: 0LNYVIC-02-FW7-02 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Axway MailGate 3.8.1) with ESMTP id 213F5C8115; Thu, 7 Jul 2011 09:13:24 -0500 (CDT) Received: from SAUSEXDAG01.amd.com (163.181.3.36) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.106.1; Thu, 7 Jul 2011 09:14:05 -0500 Received: from storexhtp01.amd.com (172.24.4.3) by sausexdag01.amd.com (163.181.3.36) with Microsoft SMTP Server (TLS) id 14.1.289.1; Thu, 7 Jul 2011 09:13:27 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Thu, 7 Jul 2011 10:13:17 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 8D3DA49C5EA; Thu, 7 Jul 2011 15:13:16 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 7987A100277; Thu, 7 Jul 2011 16:13:16 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti Date: Thu, 7 Jul 2011 16:13:11 +0200 Message-ID: <1310047993-7649-2-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1310047993-7649-1-git-send-email-joerg.roedel@amd.com> References: <1310047993-7649-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP2+, XP SP1+ (seldom 98) X-Received-From: 216.32.181.181 Cc: Joerg Roedel , qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 1/3] qemu: Add strtosz_suffix_unit function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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);