From patchwork Wed May 21 16:42:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 891545 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2221458wrm; Wed, 21 May 2025 09:46:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUoSCgaRsGxT6cf0UMFz3xmWKVYQDQiDbV1GcG8FkX4euzTtRbt3rxWLsDTx/zXB5xMV6N7ZA==@linaro.org X-Google-Smtp-Source: AGHT+IEXm5Wq0S76hOdt31WUoe5Fl8juoDUDOGW4IY9w8YUEI6WqGtpH4ZyDCB5usLWYovAyJxN3 X-Received: by 2002:a05:6e02:3307:b0:3dc:8a53:c9c4 with SMTP id e9e14a558f8ab-3dc8a53ca8fmr15646835ab.6.1747846015471; Wed, 21 May 2025 09:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747846015; cv=none; d=google.com; s=arc-20240605; b=EhX0MfT3kQysmojs3ohrkZq5ismq8u51a7XX/zcuMZBAnYlL4sNfHlIS4Zdd80UXYS M1hTlfQjT83CC6caPVERRYlTygs96UYhILSVYNPb+dogL7qo0ajp4hU/rCYP7uwDKGOu Z1lge8VMlf9YcFHwbOGDkWBZ4syKMo5yNaul4WzpbLOZ9DJ3n+veRwPhNZadnXHmynuZ RY9cO6/sqtWbH0BecvSqEjO9SWO+MjewZ4XW1QnCYEg5R2GiY5EKbYTpgrC3jQUiWBeM rGCmXownfqMg0uT/m1hdUfTX6mXNC/Ms86QnHMPezYcEDM9EfmVKxExSEiJa1dlk0qQQ 0iiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bk8FpSTvxiM/NAT/RHs0cdgY5o8m/myin/sCjff0MlQ=; fh=bRO1MF9VSOWVIGjbYXUTHO3COe2aRRAcNw1LSvnzoWs=; b=NtAJ2PF5f3QgJjonSUlCdy6JUV9YY3wXr3IC5+hNKOI8Nc2dmRnSS0HU8Uzo0fJdhy ugStPqg0SVEsUMYD0/lcv8iX0Oa3mi1+gh2oYifrSYGgWhHQfOyHyoACSDK3RgWl1//f rSFg1H0vww30NRnY3IEKc2sCge1L/wNAdMXV1SIp18QInelOCKUg7J+vBLN7g36kNFZG /hLtLB0YBsURzsDmMlvXxiGtwI+CUgbRArCHN5oGloaiaAIvXNMNEQGOj8PNReg31DeA C25xC9YkRROFo7gJvUatL4FsoYTNE6iUkRCqDvg61SptvMJrW2F+9g1Br3KNOhC5z1B4 ghwg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ai4Z0MBN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e9e14a558f8ab-3dc76de918bsi62184415ab.153.2025.05.21.09.46.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 May 2025 09:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ai4Z0MBN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Thomas Huth , Paolo Bonzini , Akihiko Odaki , John Snow , Fabiano Rosas , Peter Xu , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= , Alexandre Iooss , Markus Armbruster , David Hildenbrand , Laurent Vivier , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Peter Maydell , qemu-arm@nongnu.org, =?utf-8?q?Ph?= =?utf-8?q?ilippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée 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 *udata) qemu_plugin_scoreboard_free(vcpus); } +typedef struct { + const char *suffix; + unsigned long multipler; +} ScaleEntry; + +/* a bit like units.h but not binary */ +static ScaleEntry scales[] = { + { "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 argc, char **argv) @@ -137,12 +149,32 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, char *opt = argv[i]; g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "ips") == 0) { - max_insn_per_second = g_ascii_strtoull(tokens[1], NULL, 10); + char *endptr = NULL; + max_insn_per_second = g_ascii_strtoull(tokens[1], &endptr, 10); 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 != 0) { + g_autofree gchar *lower = g_utf8_strdown(endptr, -1); + unsigned long scale = 0; + + for (int j = 0; j < G_N_ELEMENTS(scales); j++) { + if (g_strcmp0(lower, scales[j].suffix) == 0) { + scale = scales[j].multipler; + break; + } + } + + if (scale) { + max_insn_per_second *= scale; + } else { + fprintf(stderr, "bad suffix: %s\n", endptr); + return -1; + } + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1;