From patchwork Mon Mar 4 13:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 777753 Delivered-To: patch@linaro.org Received: by 2002:a5d:4b84:0:b0:33d:f458:43ce with SMTP id b4csp503416wrt; Mon, 4 Mar 2024 05:06:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWYFjQdkXwIBHZjmEC0ULTblO09W/dvyQf7D1szjtL10J0ChulVtRxZ88A2LK5cF3T4xbsANJTjDkoxlrMKR4Fy X-Google-Smtp-Source: AGHT+IHzZdW47cldhIpUMsy/BUtCkYpdSdd+mi1UQPbT5PFmftVLwkMcvlzTjZX/lMFzxzFsdjmx X-Received: by 2002:ad4:4b64:0:b0:690:71c6:4dea with SMTP id m4-20020ad44b64000000b0069071c64deamr3092495qvx.56.1709557578756; Mon, 04 Mar 2024 05:06:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709557578; cv=none; d=google.com; s=arc-20160816; b=muQ1EoJOnT9jH9hEPs3GPjYNrgtoRwt7yKlh2Ajf37757GuL4o27rfYK0IIDV2N5Pz euZejvch27kQvkwcKGhAyuz5dsoPBsvWz7Y8jFRgqItFfD+q1MJ39DnccIdNL+SgGzqq IZGZm33qeTky374zuDHcTv0XkkPurPmX8ZAKazRV615dR/O1ueT7n1erwc5UdiAI8fA4 WUJngH1TllZHhCWpon4CWyaaIUkD2+5hBxPEwEFKGnETaqQCTvprYtLv/JcIIxdvCMVi pk9zHcK6u2HB8MszsSozR+si4kcr/WMuoLHmTx45t3F/qO9lFqYdx9vaANv0goGm651Z XGlg== 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=/2IiUkHopV2kqQ50xbiRbR5fNcCFrzYMY0qVpPsgzH8=; fh=MDSJphmAaz7z3HiU8dJnBqogMR5Yd8Y7OcCVYt+ujgE=; b=cNb/mAfN9irV61etupXk1h1Zyb+lz2y6PBMdggPysT7QVhtxB8Mm9Y1ZLtqyRHeHBq dVW0ndRzQxOzp5OSVTr61bwJhE2U0DhrfewX1X6WfYVjBetlx8ZpWM2Yddtjdwkotq13 0/Nk5UCldG5+R99odibvwXYKfiK3VoqnziQFo9L/7Uj5QAh2crHkvZIR0UY27q1w7wam V8wH0hEuN191Qce4fIg4hFT3ljKbRjXXhq3iho4gjTExwDeguOZrQ76vrFVau430vAtq nuts2IO+p08CZ+2JN5KvkhkU2h3pH6nEuMJ5sYvbwdj+vT8kFt/qqvb7byqM4tCcQha4 6g4A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEshOLyt; 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 nw1-20020a0562143a0100b006903c85415dsi9162985qvb.126.2024.03.04.05.06.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Mar 2024 05:06:18 -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=wEshOLyt; 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 1rh7xH-0002lA-Jk; Mon, 04 Mar 2024 08:02:07 -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 1rh7xA-0002Ew-4o for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:02:03 -0500 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rh7x4-0000rB-DA for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:01:56 -0500 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-566adfeced4so4561989a12.1 for ; Mon, 04 Mar 2024 05:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709557311; x=1710162111; 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=/2IiUkHopV2kqQ50xbiRbR5fNcCFrzYMY0qVpPsgzH8=; b=wEshOLytLsF/L4rWlQz8PTn+S4mo6DhN7PNpxCGhFUb5ZUlsnN4tI4LadHzLx5p8/s +UR9UULJfhy7CFLGiiW7FWdwJMNEiZr/yzPva6NlYBtlLfymLNolwa1uFJdxKlmMkJ9P BRAkMcPBFEIcWxV53UU8NAbqq7tzZCQ98RHgSGzUX7EhRK6JjOaEDJD9mpjmIHy4nMaS 9l1w3AmCZYE/leW9RYwavAGVfIVhu6dKSymLyIluJYR/39lAs3xSs0WZtVW2VHUSuyz/ yy7MalRcl+y5sZXpDuXGUSoTkOAGnOPee2z2VnnNV8R6VRqK3c6T4OCl6LISI20cPBKI SRYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709557311; x=1710162111; 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=/2IiUkHopV2kqQ50xbiRbR5fNcCFrzYMY0qVpPsgzH8=; b=oTtMhtq6ARIxollxaYEf2SoCBM1ESX25wYWYfhnt/s9bkCnxYx5Uf7Fb0VM1fnwTYh +tqToSkTwiT+zV6TwCWIUjqK8p0K9TGt8cJz/8uX85LBbUnKI7bXjaI4RU8V7ljIXoiJ MAS9Ir/EzkJ1GNmiSngwUmnDP67Uxn6YYayHEcyFLkgnP1SmsYNJJAnsbYMqNifxVJyk Brb3X4M1v7xrUP0Ga8QnIkjyTOXwtGqFopmG2RWuOU4NE3uv+Rg+oYacCA3sJXmSXfTA ISpIsqmSf7TAVx7WcB8/0TI56yYqZd6AqRNbs0ypsC+wj+34QyleIJm7vStskAZ4UMCc VvkQ== X-Gm-Message-State: AOJu0Yx0xmB7gn4najx7OfPWJkE8a4z2vUzwZSGO8e0SS7BTo6HikDuH lbgv5ZzLVT/9XdrSdY6Nxg070kmU6nW45PB2lC4aqOumevSGGuaWsipz/AyEoFEFpc5clqCbBJj uc3w= X-Received: by 2002:a17:906:ae55:b0:a44:4a94:a6d5 with SMTP id lf21-20020a170906ae5500b00a444a94a6d5mr5008138ejb.27.1709557311061; Mon, 04 Mar 2024 05:01:51 -0800 (PST) Received: from debian.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id tj7-20020a170907c24700b00a413d1eda4bsm4806136ejc.87.2024.03.04.05.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 05:01:50 -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 Subject: [PATCH v7 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Mon, 4 Mar 2024 17:00:34 +0400 Message-Id: <20240304130036.124418-11-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::52c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-ed1-x52c.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: Alex Bennée Tested-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- contrib/plugins/howvec.c | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..2d10c87e0fb 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -43,13 +43,13 @@ typedef struct { uint32_t mask; uint32_t pattern; CountType what; - uint64_t count; + qemu_plugin_u64 count; } InsnClassExecCount; typedef struct { char *insn; uint32_t opcode; - uint64_t count; + qemu_plugin_u64 count; InsnClassExecCount *class; } InsnExecCount; @@ -159,7 +159,9 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { InsnExecCount *ea = (InsnExecCount *) a; InsnExecCount *eb = (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + uint64_t count_a = qemu_plugin_u64_sum(ea->count); + uint64_t count_b = qemu_plugin_u64_sum(eb->count); + return count_a > count_b ? -1 : 1; } static void free_record(gpointer data) @@ -167,12 +169,14 @@ static void free_record(gpointer data) InsnExecCount *rec = (InsnExecCount *) data; g_free(rec->insn); g_free(rec); + qemu_plugin_scoreboard_free(rec->count.score); } static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new("Instruction Classes:\n"); int i; + uint64_t total_count; GList *counts; InsnClassExecCount *class = NULL; @@ -180,11 +184,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) class = &class_table[i]; switch (class->what) { case COUNT_CLASS: - if (class->count || verbose) { + total_count = qemu_plugin_u64_sum(class->count); + if (total_count || verbose) { g_string_append_printf(report, "Class: %-24s\t(%" PRId64 " hits)\n", class->class, - class->count); + total_count); } break; case COUNT_INDIVIDUAL: @@ -212,7 +217,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "Instr: %-24s\t(%" PRId64 " hits)" "\t(op=0x%08x/%s)\n", rec->insn, - rec->count, + qemu_plugin_u64_sum(rec->count), rec->opcode, rec->class ? rec->class->class : "un-categorised"); @@ -221,6 +226,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) } g_hash_table_destroy(insns); + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + qemu_plugin_scoreboard_free(class_tables[i].table[j].count.score); + } + } + qemu_plugin_outs(report->str); } @@ -232,11 +243,12 @@ static void plugin_init(void) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - uint64_t *count = (uint64_t *) udata; - (*count)++; + struct qemu_plugin_scoreboard *score = udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(score), cpu_index, 1); } -static uint64_t *find_counter(struct qemu_plugin_insn *insn) +static struct qemu_plugin_scoreboard *find_counter( + struct qemu_plugin_insn *insn) { int i; uint64_t *cnt = NULL; @@ -265,7 +277,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) case COUNT_NONE: return NULL; case COUNT_CLASS: - return &class->count; + return class->count.score; case COUNT_INDIVIDUAL: { InsnExecCount *icount; @@ -279,13 +291,16 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) icount->opcode = opcode; icount->insn = qemu_plugin_insn_disas(insn); icount->class = class; + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + icount->count = qemu_plugin_scoreboard_u64(score); g_hash_table_insert(insns, GUINT_TO_POINTER(opcode), (gpointer) icount); } g_mutex_unlock(&lock); - return &icount->count; + return icount->count.score; } default: g_assert_not_reached(); @@ -300,14 +315,14 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t i; for (i = 0; i < n; i++) { - uint64_t *cnt; struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); - cnt = find_counter(insn); + struct qemu_plugin_scoreboard *cnt = find_counter(insn); if (cnt) { if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + qemu_plugin_scoreboard_u64(cnt), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt); @@ -322,6 +337,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, { int i; + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + class_tables[i].table[j].count = qemu_plugin_scoreboard_u64(score); + } + } + /* Select a class table appropriate to the guest architecture */ for (i = 0; i < ARRAY_SIZE(class_tables); i++) { ClassSelector *entry = &class_tables[i];