From nobody Fri Dec 19 06:58:51 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1747846015; cv=none; d=zohomail.com; s=zohoarc; b=lMbAvf2IkvnPKyKbqzg5rtp9BF0jSCJ8JKlKZ6P8S3NNQvS9Sj3QEJO+/G+Shj944JrR8nb3qWzNQr/Wjnz80Az8CVLfI42gx/PtQUYkMs0010qWmg61Qk2X5ad7NiVh81p4lvZ4Ord9clM1UJ9bHxYP/SW5e4F8P61OE8ISqVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747846015; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bk8FpSTvxiM/NAT/RHs0cdgY5o8m/myin/sCjff0MlQ=; b=A0P2RwPpk9sNK8ybnmVeR037pDy0AdVcJCzBvC8sY8Zoisg4rEd9r8lWn6Za7wqTWeUryGN8uwqTyaYYatKohZg5GY3s43g8CwjSi8CM+Og5ARj8e7p3D8dyIOQvICDBzcvRBdGi/C960vzA0B9CPaGuw9e7AESFGIp8zmVOK3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747846015394241.54196460865887; Wed, 21 May 2025 09:46:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHmXE-0000Z5-Bj; Wed, 21 May 2025 12:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uHmX8-0000Vj-IC for qemu-devel@nongnu.org; Wed, 21 May 2025 12:43:11 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uHmX0-0006Ad-MY for qemu-devel@nongnu.org; Wed, 21 May 2025 12:43:10 -0400 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-601ed5e97e9so6523314a12.2 for ; Wed, 21 May 2025 09:43:01 -0700 (PDT) Received: from draig.lan ([185.126.160.19]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad52d490910sm929266466b.135.2025.05.21.09.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 09:42:55 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id BB1FA5F9FA; Wed, 21 May 2025 17:42:50 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1747845780; x=1748450580; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bk8FpSTvxiM/NAT/RHs0cdgY5o8m/myin/sCjff0MlQ=; b=ai4Z0MBNkOIQqVT6FHvgQGC2NVvmlBMDuQsfUe4PWehb6CUWBnRIbZ6S+YUC8aV9Jj h2Q0Pez48xv4fFZypspXmSNvZQK7izoBHNMMiOj+l2kNHa3e9VHT8D6/WtLBwecaQ+iw iniedxKYXO/1bWVj1t9G9pIBnSS4VAXro10uhX0BssNpkvU7nMg3+uwYfPOULnz23vUY t5X7M0c6i1L/PWOrXIGQmvhQq0DBWi0s1y18KvGapsNwV6/jr6bRgUr9n6HHQJ+QwxdR wziMHjXrqNZ///C2V+Y/ezVEultboy2+W/FoC4PPq6s/hnuu/21RT6TNAzMXH7VneBPQ BVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747845780; x=1748450580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bk8FpSTvxiM/NAT/RHs0cdgY5o8m/myin/sCjff0MlQ=; b=jX6GpA71VcmyddYOUk4gQvLq9cuegbYnuV8tAHZl8CkJ9xmNyZ3nxSKeCztIEM1Eag OP8q0jfMSAllAmxLy2YUGU97VLkG/038v2RdG3bzdwf16PyiLly1S3UR8lhcRrDs3eA9 G6K6K5sJIHST1ALbTIy1vbYod4UzgkeZlzT8XCldP1g3X1gRFNknrMVC4nwcga4rF1kd JSxQ3ItTGMp2FOa/iyj52bjFpn0Qwc0w7bvoolpiexDcwS6lk2kQFwk8/2TAxm//4W7z BOycB3jnd9BcS4npMiBYk86vI9mM0mGedoyhIdKigPwUT5ejv5GxjjiW7BmiYxh0SwWt Zlag== X-Gm-Message-State: AOJu0YwR2Qu5ucwk/kmfhSedQdoe7XT2us4TErDmfCZDFq1Fv8oGnpDs dcVjMRyLG3WKmV3FKTVqSQfQ/k2ssHkY1Qh1VGcmgQJcFSVHFRmNpuwDCDyiYYVUPXk= X-Gm-Gg: ASbGncvaA0vRB+A1QDeBiFs++ge/2GgEqDjjeEYkonBLsiyPLHKVLRyL2sKEi1BTb5M VEzoYnoAvS6YAquKs3eYJvYYXYjEWB0NdWBRsFqSCDnYZ4LibTN9yR09F0dbwc8qoEM2PgnLEZT ijSatisGUBdWPc5Nk5104D9+ceJlgByD1Bg+9LqIiNiEENjHTDjCHHhccbIPAcGRm+Iza4pxzkX +NElp79cvx09oDvybsqcXbQv/6T3t6kWcU2g+wylvehWdAzLO+z5VEz4d/YacyLT+IpsSmh5/VM TX69MLdMC8hHggzSQ6Y9LcgHIRycptsE9fRQ0KIhaS8lpL7E83lT X-Google-Smtp-Source: AGHT+IH9NN0WLJSVJmueJBQ2QgSM0o2wAFE4QqB5up/xqwzVXs6hiazGIO04dYNoK2VuFDqnMkyNmw== X-Received: by 2002:a17:907:2d1f:b0:ad2:23b6:149c with SMTP id a640c23a62f3a-ad536dcd710mr1664944866b.43.1747845779769; Wed, 21 May 2025 09:42:59 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Paolo Bonzini , Akihiko Odaki , John Snow , Fabiano Rosas , Peter Xu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Alexandre Iooss , Markus Armbruster , David Hildenbrand , Laurent Vivier , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Maydell , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Mahmoud Mandour , Sriram Yagnaraman , Dmitry Osipenko , Gustavo Romero , "Michael S. Tsirkin" Subject: [PATCH v3 07/20] contrib/plugins: add a scaling factor to the ips arg Date: Wed, 21 May 2025 17:42:37 +0100 Message-Id: <20250521164250.135776-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250521164250.135776-1-alex.bennee@linaro.org> References: <20250521164250.135776-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52d.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1747846017414116600 It's easy to get lost in zeros while setting the numbers of instructions per second. Add a scaling suffix to make things simpler. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Pierrick Bouvier --- v2 - normalise the suffix before a full strcmp0 - check endptr actually set - fix checkpatch - scale_entry -> ScaleEntry - drop hz from suffix --- contrib/plugins/ips.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c index e5297dbb01..eb4418c25b 100644 --- a/contrib/plugins/ips.c +++ b/contrib/plugins/ips.c @@ -129,6 +129,18 @@ static void plugin_exit(qemu_plugin_id_t id, void *uda= ta) qemu_plugin_scoreboard_free(vcpus); } =20 +typedef struct { + const char *suffix; + unsigned long multipler; +} ScaleEntry; + +/* a bit like units.h but not binary */ +static ScaleEntry scales[] =3D { + { "k", 1000 }, + { "m", 1000 * 1000 }, + { "g", 1000 * 1000 * 1000 }, +}; + QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int ar= gc, char **argv) @@ -137,12 +149,32 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugi= n_id_t id, char *opt =3D argv[i]; g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); if (g_strcmp0(tokens[0], "ips") =3D=3D 0) { - max_insn_per_second =3D g_ascii_strtoull(tokens[1], NULL, 10); + char *endptr =3D NULL; + max_insn_per_second =3D g_ascii_strtoull(tokens[1], &endptr, 1= 0); if (!max_insn_per_second && errno) { fprintf(stderr, "%s: couldn't parse %s (%s)\n", __func__, tokens[1], g_strerror(errno)); return -1; } + + if (endptr && *endptr !=3D 0) { + g_autofree gchar *lower =3D g_utf8_strdown(endptr, -1); + unsigned long scale =3D 0; + + for (int j =3D 0; j < G_N_ELEMENTS(scales); j++) { + if (g_strcmp0(lower, scales[j].suffix) =3D=3D 0) { + scale =3D scales[j].multipler; + break; + } + } + + if (scale) { + max_insn_per_second *=3D scale; + } else { + fprintf(stderr, "bad suffix: %s\n", endptr); + return -1; + } + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; --=20 2.39.5