From patchwork Tue Feb 13 09:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 772287 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp169509wre; Tue, 13 Feb 2024 01:43:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVoIFRzpn5OVnk8Re3p4P4HyvHCIb3AArEvIk7JDsZ+ta+T/tvwFajdE9An0vTGCDKKJovbIDtNxCJZYfs+i235 X-Google-Smtp-Source: AGHT+IF+wby2hM3SSCBe3jBPQTBXp19ZeUduXShiforR+ijfHkPX19YYG0PpbX3Q3bAl0zBhg6NM X-Received: by 2002:a0c:db05:0:b0:68d:18b8:a13b with SMTP id d5-20020a0cdb05000000b0068d18b8a13bmr2806961qvk.11.1707817385037; Tue, 13 Feb 2024 01:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707817385; cv=none; d=google.com; s=arc-20160816; b=vN6844U/pZ6mgDD+7vBGCTkOfe7TkD47N0M8G5iSgVz1yKXlavbI6ul0Vfv9C+Xomm LQF9H5aIKV5lvM9zAEfeZL9/Bv9wri0KHbP7QWyFHQzHJgjNifrmWDMLXKvVBUjU9jp3 z91qOkw5j5mT9vW8oqDrxqQl+4evikpR7EI7xWnIMK7EUi56s5wCtwrrSGKeE0MDFb5b olararWSwgUTOI6YI/tnJKzDWUdZJ6O2V/jKJmdXPIxNv1hVbU/hDcpcsHcDK50ODqr9 N88tKCC9A8iOEG4/Kaa3cpgaVdsfzp0tnJJMyCgUrMjzCyPsKGZ7P5B62nPXZy5somes Cj/Q== 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=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; fh=bKGm/G5WL8czAb8NnxzMNzum3jOtE7pN3+veZPHMZu0=; b=e7ynUEGOqklFmLHiiYSfPf39MunAFPKjlolUa3LGXjhCYPLqZeEBSLyR4ic3pHh8/i J6qYlolWuu6J2oq+4Rzu2emLMsgLCzN6n36OZSElsoz5SHQDzFmQhVz8DlVl+cp7A9YI UpSyEZixJ7qMViHiHi/mxhDLHyVihApzIU6/iq8qlVZVMxAmXiHj7NVIJAzxDLm1ryTu trEtSb0fbZ4ANHLEyR+VybxeMTPcRe5+S8uw/92kCfllULicaGH4B4Nzuy9nvTreH1cJ h5ozb0LPKuCdQB+D009thoF6cwkWDQAnLxbGNUGkba7iaAoKPZCNAJHUq6LV7749WLGr +h8w==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TkKK4sqR; 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 X-Forwarded-Encrypted: i=1; AJvYcCVWUWPtA/lfIVCQJtuRTVx6A2vbIPIKw9bUaNtYGKFygTmlvquz68kEqW4FANgZ85Ypczs5YeHVc6pxWSPvbV09 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fn3-20020ad45d63000000b0068cd9f35a23si2371844qvb.542.2024.02.13.01.43.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Feb 2024 01:43:05 -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=TkKK4sqR; 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 1rZpI0-0001RM-TJ; Tue, 13 Feb 2024 04:41:21 -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 1rZpHx-0001PA-VK for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:41:17 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZpHw-0000Gi-1l for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:41:17 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-339289fead2so2658838f8f.3 for ; Tue, 13 Feb 2024 01:41:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707817273; x=1708422073; 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=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; b=TkKK4sqRaIOH1fAS3Ai9NKvp/u46JIwA/JjOLGq29YL46vJBOWoh3jd1wlFl+uwfWF 2SjEnhm4mHZKguA/iA6U2SyruvBQQYPQrU+qaxjbh4RuaFFjfzsVk5W39dBYzsj/D6ee vzPZnze84hDIceW6sRjgL8z4UrkF/d/nU+Ol4DIKi8ZLYqU8CEUiW4JIu/tNoSzfxpqC RGnmb5EhNEnpu2v41qneusLOx9mqQkt2jvsGj81yGW/jcXSTkbA0ARkqK+GmhCLbVa04 6Hd6Ecrf0mRj/ojaiwW+jJx3jD5ypjZVktGHkiJkhboAzb+EZ3s3VXSR+EKKutdWodLB mOTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707817273; x=1708422073; 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=jIM1lNqnf5XAacffBXN4ljIlTpT3DH/ZoqvjHNJUJG4=; b=voN7aEVSGQ+sDODPOLwtnzOx6yXm84jl+iMhlvdziBcKXvDStomI8X0Hzc19wC+HEZ 0DX5OvCEdcv0yo+/WSGMfJDtz0PlnF+/cZnBMAy1BwZDwpAj+dMbOfusYY6HyDjn7Q6I WuONrp6Rsbdr8XBkhmkbwW5jL+UMDj3mMSiIqEYXUOFNiZyqg9qM/K0KV0GJPJGTRf8X Ou/Pey4fI1ihLZS4xy1c5tFNX1Fh5bK1uXSYJVSdytOSk8RvHmnca77rvZ6LPbSflRq/ PxUho524g0HPL/kNePaOq+AdP5s3VVZGYu1isoCorTbG/7kZ/E5MFWBLVgOGx1ArD0aO KrGA== X-Gm-Message-State: AOJu0YwDTmgm83h954R7IZz8ka4ZzmTWe1byFvrKbLT5Xg2YEiRcLJyP /OExct3huIDombMVhc73GxGSGt7OLhqtLfAZu5m6AJVNyau+zkZSarn48lyspKPdYLVe21RobML a X-Received: by 2002:a5d:490d:0:b0:33b:4e38:b878 with SMTP id x13-20020a5d490d000000b0033b4e38b878mr6567177wrq.26.1707817273326; Tue, 13 Feb 2024 01:41:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXjpnVkbtq4yK7B9CkAVcwuCAxUXuqGyYMRMkN4dR+hlI8wlp3nKUZ9eEuR8nZCIkTDuqGOiC+SUPCmQBOjlBP4xpdyKayf41zujppD6p1bnXUSYXKwjopz/83tMDP1D8qS/OMrJiA7ylTX2vOjh6w/bJ/E9co44/2NtcZjgqcE/9aTf5rel6GLcPCNlUgWJ1EqBLUDg5dbXbtVdbYdxdxwieeZBu3zXeqMIf5rAiToz8zKjb2J7p4C+yRmdDQSFM75TIOaJ7j5D2fxISPKkOasrzjRRMiL0Rw03mHDcuaJQHolTDrJHgi+OO/JSlH/770PBGQn5xm2B6HFOfl9EO+hh8QR5g== Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id cc19-20020a5d5c13000000b0033b728190c1sm8550261wrb.79.2024.02.13.01.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:41:12 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Marcel Apfelbaum , Paolo Bonzini , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Richard Henderson Subject: [PATCH v4 12/18] tests/plugin/insn: migrate to new per_vcpu API Date: Tue, 13 Feb 2024 13:40:02 +0400 Message-ID: <20240213094009.150349-13-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213094009.150349-1-pierrick.bouvier@linaro.org> References: <20240213094009.150349-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x433.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 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 5fd3017c2b3..0d0a4cd1c34 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; @@ -48,41 +44,40 @@ typedef struct { 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) @@ -94,8 +89,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( @@ -117,10 +112,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); @@ -150,36 +144,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); } @@ -187,6 +178,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); @@ -208,9 +203,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))); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);