From patchwork Wed Nov 3 17:05:53 2021 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: 516789 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp902846iml; Wed, 3 Nov 2021 10:20:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR4Bc6PIC8pvd8ybYqUgA0/hMcSw6EDh0InOwuWDHIKFJrjb/F1uOzYnrwAxaKjwiIx0ZE X-Received: by 2002:a05:6830:2463:: with SMTP id x35mr17082286otr.246.1635960047313; Wed, 03 Nov 2021 10:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635960047; cv=none; d=google.com; s=arc-20160816; b=BYEAZa1IzVfyaSopPyxg4aEslVcGu9nXz1NuawsH8z6NQ5/wq2f7D2QxHB1IBfCZze 0kSqctJfwmCDSEnktTt/+9hux8bnijceb4vwqU48uf669nT41evJBi9kG15TUpn7kjXJ Wmzfuz7a+Cb0tIUuh5gdGm4UWlM+9p2/GDtm25PZWt7dhBFQrkIcdMT4XhhwE6eKrSw1 NhvMyO21RFhx7of6BGWj/xPBD0p5mBsQ61WtQnePHlFannzKagabrvzXdKE6vxmbaYgV 8ypNBQBY7KhCdkY0p3XRUMu8d60paOwK6fOXQNdiOe7MjqO1u7BQNkZ+CFVc1GJ44JN2 vULw== 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=yyRfS3iCiw1/tG9HJBOoGZjbjgeiOJQ9Q/Je/hZdaRg=; b=lIbmo3e1jGXw9ofmhtw5PIM5z+Fptz4jVXMYqM6tQMaTNgdMJ5q7gTOvKct8nnyVb7 OyEPJvyrqYqpAhPCqGRFlXol20PLS53FHZmTcPA+jn5oAsCGlK46eXQFt3w1iAQI7MUR pNRYPJXYFOkFi53bL7tUamI8qdKfj1wIs/cJ0Ff142ncnSvdgns/7L8ka+bv51VvGbQR scQ0N0Vu7eZukYmqXkfRxtQeT2YSNfQtFs1k43xRt63gnjH1oDOSR1x/5d59R1M2ZL2/ hNnSkkQ++PR1he9HxZw0oN3Z9MWZ82/Avw4oJa5bTGHw/dHjD/eotg4KzbgGc5cAAgjE j49Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cqoV8aek; 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 l2si4087998otl.322.2021.11.03.10.20.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Nov 2021 10:20:47 -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=fail header.i=@linaro.org header.s=google header.b=cqoV8aek; 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]:33422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miJwM-0005jX-Ow for patch@linaro.org; Wed, 03 Nov 2021 13:20:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miJoF-0005N9-1f for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:12:23 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:34762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miJoD-00074T-3q for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:12:22 -0400 Received: by mail-wm1-x336.google.com with SMTP id o4-20020a1c7504000000b0032cab7473caso3787876wmc.1 for ; Wed, 03 Nov 2021 10:12:20 -0700 (PDT) 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=yyRfS3iCiw1/tG9HJBOoGZjbjgeiOJQ9Q/Je/hZdaRg=; b=cqoV8aekGmrLmeADR2FQU9Opie4UHv44PCSmpdKoYNsOxgUL97i5txKIrHKtVhDkl8 cAH6Bwwn3diZhcpuyiTAzLYmUpbLYK99COevWvU+wGRTWpVp4Bji6b/b3crDVpwEwf9C zgSp1UFNa1NpT+DgVBivGIvT64FNthZZtueQp336mTl6JwVH00S3kkjjTJ69OzjwJf64 /uTCe22IyUjZH5NBnuv0SC3MZ35zbFyhq+yVfInjVEjTRueuMMRrROg6xj+6oTh04gJt auaWwXvYIRu/7D1nbmFy/E9loELlnxwpscg1dYyLBDdIquPpAm3kcUolKHtPgxvvT3Ne nl+Q== 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=yyRfS3iCiw1/tG9HJBOoGZjbjgeiOJQ9Q/Je/hZdaRg=; b=u+C25FuKD699DhFzSNG3FAI/FTv83dnPlSTuPdQRdej4NHLZ7u94LuFrR59kC0dZDt htlwN+RAF98a/iUJ6p886g/kUxcGzlKGXhKMX+Mp1wOwvOuWyAv+CCfolvbilW6y1ZB1 3jAaF/aQF5XWC4bHsJ+1t2MBp6azc9mxP14zzmxmra1YDiDoSUy2UQs5/oDbUnMc6kQe K0ob5lh+XwDJqeNDmpQ2IXTGOSGmx60E+A4v/56Fes721OY1JmKBeOswpZ7FMqh3bF3I 2mon0E4aaap0qqO+rXEOtaQW0X6msW7Xo2TQNLzRF9whF9XqjkZvV+9WHiouHIRS7RU1 JOFw== X-Gm-Message-State: AOAM532m/uYl0lpyxF2wYf23VE8aOFYPk/16MvBsWCCiraC/KlmKeAo+ c6OEjUzXR+9hu/Q4W4YSln7mbQ== X-Received: by 2002:a1c:4681:: with SMTP id t123mr16849867wma.83.1635959539731; Wed, 03 Nov 2021 10:12:19 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z11sm2529620wrt.58.2021.11.03.10.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 10:12:18 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D8A161FFAF; Wed, 3 Nov 2021 17:05:59 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 16/21] tests/plugins: extend the insn plugin to track opcode sizes Date: Wed, 3 Nov 2021 17:05:53 +0000 Message-Id: <20211103170558.717981-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211103170558.717981-1-alex.bennee@linaro.org> References: <20211103170558.717981-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , richard.henderson@linaro.org, qemu-devel@nongnu.org, Alexandre Iooss Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is mostly a convenience feature for identifying frontends that do multiple repeat loads so I can test changes to the instruction tracking interface. Signed-off-by: Alex Bennée Message-Id: <20211026102234.3961636-20-alex.bennee@linaro.org> -- 2.30.2 diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 0f6a1938c1..d229fdc001 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -18,6 +18,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; static uint64_t insn_count; static bool do_inline; +static bool do_size; +static GArray *sizes; static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { @@ -49,13 +51,35 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, GUINT_TO_POINTER(vaddr)); } + + if (do_size) { + size_t sz = qemu_plugin_insn_size(insn); + if (sz > sizes->len) { + g_array_set_size(sizes, sz); + } + unsigned long *cnt = &g_array_index(sizes, unsigned long, sz); + (*cnt)++; + } } } static void plugin_exit(qemu_plugin_id_t id, void *p) { - g_autofree gchar *out = g_strdup_printf("insns: %" PRIu64 "\n", insn_count); - qemu_plugin_outs(out); + g_autoptr(GString) out = g_string_new(NULL); + + if (do_size) { + int i; + for (i = 0; i <= sizes->len; i++) { + unsigned long *cnt = &g_array_index(sizes, unsigned long, i); + if (*cnt) { + g_string_append_printf(out, + "len %d bytes: %ld insns\n", i, *cnt); + } + } + } else { + g_string_append_printf(out, "insns: %" PRIu64 "\n", insn_count); + } + qemu_plugin_outs(out->str); } QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, @@ -70,12 +94,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "sizes") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_size)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; } } + if (do_size) { + sizes = g_array_new(true, true, sizeof(unsigned long)); + } + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0;