From patchwork Mon Mar 4 13:00:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 777749 Delivered-To: patch@linaro.org Received: by 2002:a5d:4b84:0:b0:33d:f458:43ce with SMTP id b4csp502343wrt; Mon, 4 Mar 2024 05:04:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV59bS8VjXtJvmsIXWTa1rxuf1Mac/9GVr6Jlz9ClLH93W3F2Y6NGBGHNkydemRLbLoX4EznTcvysVU7M+mccfk X-Google-Smtp-Source: AGHT+IG/WfL0azEr+uLNcWZteS4U2Xx+DfEM2ohZGYJx+sIcXC3EMQJWJfWqsQodlp+D6LMzo62X X-Received: by 2002:ad4:50d2:0:b0:690:5ce8:553 with SMTP id e18-20020ad450d2000000b006905ce80553mr8002423qvq.22.1709557462516; Mon, 04 Mar 2024 05:04:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709557462; cv=none; d=google.com; s=arc-20160816; b=MA0qcGC8EL2pSHKvOd+AfmUe4o+vdqJwRBriwjzyYxqghvZBDHU4RJ9TeBxrMP5LmH cK8RHGD5ygVdtQqPcCP2AanaDrMrjPivGkOL+3qBuh5YvqzeDmQ9+AxvUaTG45vpgylg 21GlwYOGV7cVmTrndgi0/qcuqUrk9+6soK7B5e0kD/oDU6H6C8Q46jAfkZS9aKa41D6w xCUslznMb1/wnPhmxXk4MEq1H9Vq3ZQuykgnqegIVA4Y8Htpu//1FJO5G8L9xju9l8hF JAq1kB/rW/JL3ngfEvN//oB6MyEJIkBzJPobo759sYdiWBAWVE23e56G60rL5CURzvt1 j6ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=Tf1+lHjqcZCQuGZij+aDXt7N00g1XwukV+xuLoc/HBQ=; fh=iwWe/dXLTEEuIARUcSP8U5nJm4ELeL4JuDV/CtxCtRY=; b=PbQRJY06OLkS9jogAOwMJu98P23wok+JYNNGkpSuMLkyUdKrIhMFIFWycjPYN50+pK c1m8h6TtPSkR1YVLNuasNH06wkyu7Q8se3VZV/jInegE8bLTnpI9y2HjTqCsvrS4nMgo H6DGWR+5G2cBsRyJ6u0DBWs6BrPHchpF3AtnXnYu7muczVvnktxxmOPNxVDGn/BxP9Y0 LNCJiLwJJLUQtEilr1WjvTX6iH5H2fzcry3N646daeAmeSeNDN2GuRS00Ooi+b67Dyu4 iTtQ9Qp/gQJBb74Bnx1Spg9TPldvNaxZHp1IvoeoHeBZMHzUxlaspEbA1k32zkOvPq6b SWiA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gB7DXcDQ; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id eo3-20020ad45943000000b0068fe3631946si9443445qvb.387.2024.03.04.05.04.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Mar 2024 05:04:22 -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=pass header.i=@linaro.org header.s=google header.b=gB7DXcDQ; 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 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rh7xE-0002Lm-8p; Mon, 04 Mar 2024 08:02:04 -0500 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 1rh7wm-0001kn-Ow for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:01:40 -0500 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rh7wk-0000oX-IB for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:01:36 -0500 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a44cdb2d3a6so267539566b.2 for ; Mon, 04 Mar 2024 05:01:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709557293; x=1710162093; 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=Tf1+lHjqcZCQuGZij+aDXt7N00g1XwukV+xuLoc/HBQ=; b=gB7DXcDQ6GiP/3iNIL3pTxxonBlcRec0/JFiJcuFyZXq2oSROXRv6rX5XNldJk+Fym /P38qMF1jgfnxqVtuB0xqpvl6WCkW0DvWBvx4Ufoqu3bi+UPUzFRVr7vFI/CiY5zQ2/2 8NGhfGWhluX4SP8g8Qay0Ju94gBj9koOu9xtalvyCfpPWplIip4m9RzDY/G3lMRpW8NO uFLaC5RIAD7LSiOYfAwqCyihJwNi9LneNQ44iH7mBsG9GAFQD23rBicu9GHKcRMoUD4h kRAANS9YikP9iSH8eAiR22CAQQ2DPvHJ6Q0hsnB1wy6iLH//OHu+AeqWzr0j6jiYQTs+ 8aCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709557293; x=1710162093; 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=Tf1+lHjqcZCQuGZij+aDXt7N00g1XwukV+xuLoc/HBQ=; b=j/gjlfqFLf7jmXT3Vnua4h7BdjrTEP57PLlk3aZ1cKD/uzgdJrImJuUbrSojAn9TfM O9Rpw0hx3AgP0yAHjNAiluVU8ajBATVeeptyjtCVp4EN7B5yH/y+9wGCn4wqN186oGnr Dco8BPgffDw9Fv50kN/3WmWLWloKw/ampoPUm6KOuKWW8iq0hVU8UHL9Y0L2acrajUgO sA9Cxu/Cdds4w+5ZyYcD51zP0VExwxVAT8lV7klI27qQQei5NFIHTiQ3Gc2jciFLwKQR lox20T7DhBKDeNHtwf6aeuw+ogvvuP1B5xEkcBuuxpaQGsc1ZrZWxgyqFvkuoiKG6+g2 lFoQ== X-Gm-Message-State: AOJu0YyAKGozTqjOza5RGRHlEWaHOYDDusrFXcq0zc2iTlWVus2gkSNc dSeIVgOy3EuAol52Egoc0pfHCUwloF9jtBHEdjma2iuQvgbSS3SpsD/+p4FI98SKcA5rmwjPBJo 0Nak= X-Received: by 2002:a17:906:3d4:b0:a44:8c1b:8877 with SMTP id c20-20020a17090603d400b00a448c1b8877mr6708897eja.50.1709557292827; Mon, 04 Mar 2024 05:01:32 -0800 (PST) Received: from debian.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id tj7-20020a170907c24700b00a413d1eda4bsm4806136ejc.87.2024.03.04.05.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 05:01:32 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Yanan Wang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum , Paolo Bonzini , Luc Michel Subject: [PATCH v7 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Mon, 4 Mar 2024 17:00:31 +0400 Message-Id: <20240304130036.124418-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240304130036.124418-1-pierrick.bouvier@linaro.org> References: <20240304130036.124418-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=pierrick.bouvier@linaro.org; helo=mail-ej1-x633.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- tests/plugin/insn.c | 106 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 54da06fcf26..5e0aa03223e 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,25 +16,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -#define MAX_CPUS 8 /* lets not go nuts */ - -typedef struct { - uint64_t insn_count; -} InstructionCount; - -static InstructionCount counts[MAX_CPUS]; -static uint64_t inline_insn_count; +static qemu_plugin_u64 insn_count; static bool do_inline; static bool do_size; static GArray *sizes; +typedef struct { + uint64_t hits; + uint64_t last_hit; + uint64_t total_delta; +} MatchCount; + typedef struct { char *match_string; - uint64_t hits[MAX_CPUS]; - uint64_t last_hit[MAX_CPUS]; - uint64_t total_delta[MAX_CPUS]; - GPtrArray *history[MAX_CPUS]; + struct qemu_plugin_scoreboard *counts; /* MatchCount */ } Match; static GArray *matches; @@ -67,41 +63,40 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; - InstructionCount *c = &counts[i]; - - c->insn_count++; + qemu_plugin_u64_add(insn_count, cpu_index, 1); } static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; Instruction *insn = (Instruction *) udata; - Match *match = insn->match; + Match *insn_match = insn->match; + MatchCount *match = qemu_plugin_scoreboard_find(insn_match->counts, + cpu_index); + g_autoptr(GString) ts = g_string_new(""); insn->hits++; g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits", insn->vaddr, insn->disas, insn->hits); - uint64_t icount = counts[i].insn_count; - uint64_t delta = icount - match->last_hit[i]; + uint64_t icount = qemu_plugin_u64_get(insn_count, cpu_index); + uint64_t delta = icount - match->last_hit; - match->hits[i]++; - match->total_delta[i] += delta; + match->hits++; + match->total_delta += delta; g_string_append_printf(ts, - ", %"PRId64" match hits, " - "Δ+%"PRId64 " since last match," + " , cpu %u," + " %"PRId64" match hits," + " Δ+%"PRId64 " since last match," " %"PRId64 " avg insns/match\n", - match->hits[i], delta, - match->total_delta[i] / match->hits[i]); + cpu_index, + match->hits, delta, + match->total_delta / match->hits); - match->last_hit[i] = icount; + match->last_hit = icount; qemu_plugin_outs(ts->str); - - g_ptr_array_add(match->history[i], insn); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -113,8 +108,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1); } else { uint64_t vaddr = qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -136,10 +131,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) * information about the instruction which we also need to * save if there is a hit. */ - if (matches) { + if (matches->len) { char *insn_disas = qemu_plugin_insn_disas(insn); - int j; - for (j = 0; j < matches->len; j++) { + for (int j = 0; j < matches->len; j++) { Match *m = &g_array_index(matches, Match, j); if (g_str_has_prefix(insn_disas, m->match_string)) { Instruction *rec = g_new0(Instruction, 1); @@ -169,36 +163,33 @@ 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 { - 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; - } + for (i = 0; i < qemu_plugin_num_vcpus(); i++) { + g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", + i, qemu_plugin_u64_get(insn_count, i)); } g_string_append_printf(out, "total insns: %" PRIu64 "\n", - total_insns); + qemu_plugin_u64_sum(insn_count)); } qemu_plugin_outs(out->str); + + qemu_plugin_scoreboard_free(insn_count.score); + for (i = 0; i < matches->len; ++i) { + Match *m = &g_array_index(matches, Match, i); + g_free(m->match_string); + qemu_plugin_scoreboard_free(m->counts); + } + g_array_free(matches, TRUE); + g_array_free(sizes, TRUE); } /* Add a match to the array of matches */ static void parse_match(char *match) { - Match new_match = { .match_string = match }; - int i; - for (i = 0; i < MAX_CPUS; i++) { - new_match.history[i] = g_ptr_array_new(); - } - if (!matches) { - matches = g_array_new(false, true, sizeof(Match)); - } + Match new_match = { + .match_string = g_strdup(match), + .counts = qemu_plugin_scoreboard_new(sizeof(MatchCount)) }; g_array_append_val(matches, new_match); } @@ -206,6 +197,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { + matches = g_array_new(false, true, sizeof(Match)); + /* null terminated so 0 is not a special case */ + sizes = g_array_new(true, true, sizeof(unsigned long)); + for (int i = 0; i < argc; i++) { char *opt = argv[i]; g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); @@ -227,9 +222,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (do_size) { - sizes = g_array_new(true, true, sizeof(unsigned long)); - } + insn_count = qemu_plugin_scoreboard_u64( + qemu_plugin_scoreboard_new(sizeof(uint64_t))); /* Register init, translation block and exit callbacks */ qemu_plugin_register_vcpu_init_cb(id, vcpu_init);