From patchwork Mon Jan 24 20:16:05 2022 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: 534533 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp3156839imr; Mon, 24 Jan 2022 12:48:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNK+JLDf7wzga8w9JRU7+JaalPrCH/LCVLAtPiQH4oX0kPJdQl7XEtiB2bOwW+J4W5rqJo X-Received: by 2002:a25:7e46:: with SMTP id z67mr24588423ybc.595.1643057306812; Mon, 24 Jan 2022 12:48:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057306; cv=none; d=google.com; s=arc-20160816; b=dfmDU+0SToXTnDK3FoalipsWdArIqJ4URiOyn2cha/gLEd8SEdZ0DJUkn1MjSTuRuW tH0xmeP9ChzSFQDmcGIm0qzlazNysWyPKnT847SD1nKtFf7K1ddEHO4qjj62Tdh/Siox 3cml5y3QYm2iDNqYSNzvmX/nhHqZpCDU6FSZWfWz/95aAoY2LIu2Q1jhoH0r9d5VSXxK LoCxztuQ1TTwu+qE+W0t8hbMKWZk66vWRPQp67LrqVGGeBcdkZdPRwVzLtNFJSpekp5y s1MDkgCbz/fQ0NCCsGrRYD099YPEtAFpMFpbw2k+2TZlk/n/PcyW+o2Vze1p1X69xNTo DXtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=Aw9//rMqmIasQm/iGFUqITI+tDFIlD0DW72eVqm7DkE=; b=f6oJ9st877f29z0Oh05Nh8mpayzEnAw+T8rvRI1xBzzSkStRQzKQUjs7yY8EQsmRLg Ca6b6Y4CyVeNglrxPqQEgDsBXCtGUbG5+djYKoAsTIIR7jXEVnA7H1pzNd+ky1akYNzL jEpiVcVNFHO75FlVTHvUk8Wd9CJB0mammnhHiQ13M44h8gIO/arCApF42Hp1EQtwsnHR +3FlulJ4sQqiLcmkImEVNjFqmxzfsXzS24C1IjWPKgwz0g6m5amS6Wv8aMGIUbPdKh73 iAlEUGF7aevt0DddxCbEbas6Jdm+tZlpOR/XpHh9qrPFBabJYFzIfvLlw1tWm5Q3pmPB B+mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HYLqfquS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 3si15640289ybu.614.2022.01.24.12.48.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jan 2022 12:48:26 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=HYLqfquS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nC6GI-0007gD-AM for patch@linaro.org; Mon, 24 Jan 2022 15:48:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nC5rm-0005Bj-Ll for qemu-devel@nongnu.org; Mon, 24 Jan 2022 15:23:06 -0500 Received: from [2a00:1450:4864:20::62b] (port=35648 helo=mail-ej1-x62b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nC5rk-0004JK-TZ for qemu-devel@nongnu.org; Mon, 24 Jan 2022 15:23:06 -0500 Received: by mail-ej1-x62b.google.com with SMTP id s5so24634781ejx.2 for ; Mon, 24 Jan 2022 12:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Aw9//rMqmIasQm/iGFUqITI+tDFIlD0DW72eVqm7DkE=; b=HYLqfquScx/h8wnEQ3Mw7hSkylcYU0FQ8CCpAUf6h/z1ukEByh+QCt0gVgDcq1D24s hjDgyF0wQmPrcF943sMNgvLmsDkgc/Jr0Oqfdx+1We3UHtTZiN1qJflgXxT5I6ZdtVfu KIBwKqeYgzDHLWPwUc3RHsUaMaWuLt/4u7YVUEhBVly6QtXL2s0B16+t8FrMxKNoNsvc QkM0Pg/y5dr8N3M/yAYAImyl2jp73j9AHkDBuTXuBLir18ubRwX9a84CMRg5HtWtDvOw PEOFOHoKkb/fB7EB9K+w8CKsJtko4dmbqijyV/KceEPnJWNIwjosFByZPzTlKQrdylJ4 6aUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Aw9//rMqmIasQm/iGFUqITI+tDFIlD0DW72eVqm7DkE=; b=ZLypNnLIVRCJAfZ9FqE/d6PCffMSGtLFpmNOBqfnGJYq5ezWSyoPkDllz1L1ftpSne sv1if6qVK/M344nUR085sftmyzu714MQlkg2R5KSHdX6oqBt9lfumj/BAxaEumMifvvx YbU3Jzye8aVsxu4uadt991nsCwEN4hPHyfWUuK/icXv9oK9HauHHoN77UJU4tzPMY4P0 UCTydGKIzRv5gWp1rsrlPJYq7oPJB49dNT50Do87C8HhxSj+lvPp0dWM1b3YK3SQDqBb 2WJ+RlXCYpzGzt4sYfQ2/Dozwyxx082th4OZ/SvVkS5kXhoSPT0Lz7q2WXzMhr66SrNu 1FSg== X-Gm-Message-State: AOAM533XPvc0C9uTzNe8I4S4euPJTK4n5nUesPzbdv3tIVYiCu/Fof+g nhwYQ6mGJeGwqG5NiTyZp1sztg== X-Received: by 2002:a17:907:2d06:: with SMTP id gs6mr4361974ejc.765.1643055783444; Mon, 24 Jan 2022 12:23:03 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id uz30sm5303096ejb.61.2022.01.24.12.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 12:22:58 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 91D0C1FFCA; Mon, 24 Jan 2022 20:16:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 19/22] tests/plugin: allow libinsn.so per-CPU counts Date: Mon, 24 Jan 2022 20:16:05 +0000 Message-Id: <20220124201608.604599-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124201608.604599-1-alex.bennee@linaro.org> References: <20220124201608.604599-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::62b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, 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: , Cc: aaron@os.amperecomputing.com, robhenry@microsoft.com, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Luke.Craig@ll.mit.edu, Alexandre Iooss , kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We won't go fully flexible but for most system emulation 8 vCPUs resolution should be enough for anybody ;-) Signed-off-by: Alex Bennée --- tests/plugin/insn.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index d229fdc001..d5a0a08cb4 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,22 +16,33 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t insn_count; +#define MAX_CPUS 8 /* lets not go nuts */ + +typedef struct { + uint64_t last_pc; + uint64_t insn_count; +} InstructionCount; + +static InstructionCount counts[MAX_CPUS]; +static uint64_t inline_insn_count; + static bool do_inline; static bool do_size; +static bool do_frequency; static GArray *sizes; static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - static uint64_t last_pc; + unsigned int i = cpu_index % MAX_CPUS; + InstructionCount *c = &counts[i]; uint64_t this_pc = GPOINTER_TO_UINT(udata); - if (this_pc == last_pc) { + if (this_pc == c->last_pc) { g_autofree gchar *out = g_strdup_printf("detected repeat execution @ 0x%" PRIx64 "\n", this_pc); qemu_plugin_outs(out); } - last_pc = this_pc; - insn_count++; + c->last_pc = this_pc; + c->insn_count++; } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -44,7 +55,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) if (do_inline) { qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &insn_count, 1); + insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); } else { uint64_t vaddr = qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -66,9 +77,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out = g_string_new(NULL); + int i; if (do_size) { - int i; for (i = 0; i <= sizes->len; i++) { unsigned long *cnt = &g_array_index(sizes, unsigned long, i); if (*cnt) { @@ -76,8 +87,20 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "len %d bytes: %ld insns\n", i, *cnt); } } + } else if (do_inline) { + g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_count); } else { - g_string_append_printf(out, "insns: %" PRIu64 "\n", insn_count); + uint64_t total_insns = 0; + for (i = 0; i < MAX_CPUS; i++) { + InstructionCount *c = &counts[i]; + if (c->insn_count) { + g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", + i, c->insn_count); + total_insns += c->insn_count; + } + } + g_string_append_printf(out, "total insns: %" PRIu64 "\n", + total_insns); } qemu_plugin_outs(out->str); }