From patchwork Mon Feb 26 09:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775839 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233720wrt; Mon, 26 Feb 2024 01:16:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW1VSf7qBwUa27mYrrbxrniLz6PMn7RjB2fOWNCKlEVTabFxJ2HNsmhpOBcc7FeB3FphMy3j7vSU0kumtZVw3vM X-Google-Smtp-Source: AGHT+IFgL4soNXyF5tGZrqvktj8EkJtXzKGL5TzWFvZ1gnZc77Rk1jJgpd9KjcsVoIYlca9hwZa8 X-Received: by 2002:ac8:7f0d:0:b0:42e:8e2a:4e18 with SMTP id f13-20020ac87f0d000000b0042e8e2a4e18mr580119qtk.17.1708938959837; Mon, 26 Feb 2024 01:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708938959; cv=none; d=google.com; s=arc-20160816; b=B9l3pyDe9NDt0SU1cEOpFFLm4XfuMXNRDblJTw2212cKVLQFEXdUKIDFxBRIhL5vY4 29EMv0Bvuw8E75BwP1HJpVcUFngn+0AHPAVXhrK1xCwck02Rn/cwgQSsW3eiTH8x8UXB HnZsClwH62cv8taskE2ilStKLTitOaviDKYYCRlgGP6qYE/lZDrOnZJhFQJN8nltcITW isPATbUmSulKRNrey6ul8qcfimqPUhM6Z8kgYMaKzmv9DdVszlbOhnz6jbVQ8v+6rIi3 hSOPjcgEA8+d0tAOwPua5kIunINedif4LBEvBlpULAHqXOwPTCaXe/YVKuOL6KAraaCz O9Rg== 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=VrrxeNLA6gdIIRboBxDqxtycrixqBs+uk7TOLQzL5/zbHurOiNQUsxTaToxoM+1Mf9 5trM+fIZjgi7iIhJFYgF1EY/BiUS0ErMnQ0mrXTIddTg2YgZg6SZKaWgHpH8BxzHufTO K43WkkRvJVYJcufRzvMXzF4MwRastS/x0AoOCCR56jN/z6Yx9swimobatN0gQsVWTn2Y Q4NANyfAotDVLjQPhcoGTfSySDjM4frVfMP0NQu7dN8tygzPAqZlvX6FJQbC/Q0ZQdic oER8mBKyFEayJ06SiELpSVShKo4lw7gcWdDu/J8HNidc/0LXSTipnQyeM63wlMjhf653 KIRw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jCTjBQJ6; 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 i7-20020ac84887000000b0042e5a313367si4571309qtq.175.2024.02.26.01.15.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:15:59 -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=jCTjBQJ6; 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 1reX5O-0004Xv-V0; Mon, 26 Feb 2024 04:15:47 -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 1reX5M-0004X7-NU for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5E-0005DR-HK for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-412a3eba4dcso6888865e9.2 for ; Mon, 26 Feb 2024 01:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938932; x=1709543732; 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=jCTjBQJ6Wg9S1DSraCK8f0/d2+vml46XQpWGRHOQL24uBK3JiOD66mZDV7/RcOPNB3 NjX68+9k9ri6X3eqzc//Cd09ZQ+7K5Yy3wJp3RuAYl36GNmtopfr4WpeIMC5U43NztF3 UijLtzvL7wKFSYcBI4+BpVgK+ZidofOynfyJaRFg0Cp0bwwroJd0nyCQas0Q1zRmuETC HD2RnJY0KYbwsjQzfyn0q8OG7Ox8Rb/GkJSrt9CDWo6za3/5PyU7W9WvK5HnraanIoLw Xh1LdFdTVxRckItbkWD5lrRuRcTepaduo/OBb2BZHEAAERxxR2FyUd7/Rz17ZRN77r1w vm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938932; x=1709543732; 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=ahmlYvaSXVrZfy+/gFuYEPPZanOy2iJ7j4GIaYS1SjZWLgZdFVpe5Y++zhJOK5GY4N 8yyOZ2YQE/5NaMUAyUXphloa/TADHdIBXJlSoOB6GVDWlmclDJGB5ZBXH+YLbx1YLZns bKNbeSN6/MriOnX/5Y9ZMB07cxq9E/0PvGSg/rF4qLVyK90HoPbNkbq4eDCzyW50rDe6 a4iLkrUvOhoJbKCSItNzk8rIHEi4QxOuM6/ImQdW04BSkhVmICrm/mTVaSJ/7sv+U+g6 ZSBdV4uoWERned1edm+/Zl4ZfrSHIUZVtN02f1Jrez+h3Hlr2ZmWRWnvgD309MrBL7R3 Fuzw== X-Gm-Message-State: AOJu0Yx8ob/H/bdHmjiK8OiHnAB6aF2A7iH7CUZGyKqko7UohXs0BEaD WYoAC0fQEuH7FMWzU9F+ynJjTIR7veHYW4PWq2520yXYH8vwKfDAQbXJADAcxiXD1c043GsXd7W ymkqQLA== X-Received: by 2002:a05:600c:41c2:b0:412:9018:74ca with SMTP id t2-20020a05600c41c200b00412901874camr5016399wmh.35.1708938932471; Mon, 26 Feb 2024 01:15:32 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:32 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:42 +0400 Message-ID: <20240226091446.479436-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x335.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=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 Reviewed-by: Alex Bennée Tested-by: Alex Bennée Reviewed-by: Alex Bennée --- 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];