From patchwork Thu Jan 18 03:23:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 763602 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e5d:0:b0:337:62d3:c6d5 with SMTP id j29csp589656wrz; Wed, 17 Jan 2024 19:25:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFb2P4kpzB9L23gUDE38vpxk9Kfq3GM5DtiY2pZ/21u71Ev9tlfaq5MCLRdjerGI52FJ2cv X-Received: by 2002:a05:620a:ec7:b0:783:692b:ce02 with SMTP id x7-20020a05620a0ec700b00783692bce02mr145710qkm.74.1705548318078; Wed, 17 Jan 2024 19:25:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705548318; cv=none; d=google.com; s=arc-20160816; b=oqRXCIBFCNZB9o3wZybMPDIvy2KsW/vr9kn9To0MDhrOv6qNq/wWCTJEwut772iz7v 2Tpdxdf+wSErKUGTmttlX4s8y1rPn0/DIoMDPPyL/j2zZTe/gXbHP1ElXcfID756gAcD 2bZAdtV/yRPnFfrvFM4Ifggz8g5mGiVFFoA3pvaJ5wLqKVGpY82ctUWOAEpxkfxLPk+U Jj1rX4abZK/T9uSDeE3KbyANDtaEN9CaTt0RAiE8sP3S4qTt8POf9m9EfVfjOlYv+nQJ U5oVahvhYBeGomUaluubFFy89rR7EQ7ct3+lQ3GAWmt49Qkc30gDhwPSMQ0M6c9DbG0W 2jFw== 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=8IOrVF2ci3KA0n859H758KBpLzvdBx7y6KGSkBugi9k=; fh=2e6Nkd059oxyN734d2Q7Nq9y1HEjPsJBCkEwQXCC3ww=; b=f6eumQyzBC8sBBAaQNpDiT5LXZmozM5fOW0U06JWe1AGcuXJy2NkOwnagJ76LdWrEh F3g2mAZY2grR74OCTXU1rDM2fM+ro9eY/oa6T2pz6k15sHoNPFnhXzplWEN28kDde7jy k3TANURQMIj0NC61uCJ9IY+Wn3Y2bRH5sepFY+XqAhBDjJUZTR06JAtGeloo3pAO7vBP GucrRmoN0JIJnm1rC/HJ05m2VZZ7ouHd6/HQh7z7uCCGFUjoxHOggS2R3a4dB0/sOSVc oaMjkz3rBVTYcyyjlR27n2s1ItgxLiePrUh46Ar5+Sic6Sji3HCS+fquKLYozK0HFbTg etVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GR2MnKuP; 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 f7-20020a37ad07000000b0078316faf794si12740573qkm.441.2024.01.17.19.25.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Jan 2024 19:25: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=GR2MnKuP; 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 1rQJ1J-0003lW-QF; Wed, 17 Jan 2024 22:24:45 -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 1rQJ1I-0003lN-QI for qemu-devel@nongnu.org; Wed, 17 Jan 2024 22:24:44 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rQJ1G-0002yy-WB for qemu-devel@nongnu.org; Wed, 17 Jan 2024 22:24:44 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-337cf4eabc9so132820f8f.3 for ; Wed, 17 Jan 2024 19:24:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705548281; x=1706153081; 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=8IOrVF2ci3KA0n859H758KBpLzvdBx7y6KGSkBugi9k=; b=GR2MnKuPRD/VWdAenUG5AO/k050Dt7L6o4t0jC1OoakfDsvmScYqxFaUmz5yIgc+pb jVicqy2iHYT0C/WcZVM6AzHnDVx2TbwZMJ4xrB4iUpCELz+WIQgA6K03dS1+vBOMc+P7 wRVnzA9wbJyXRSuAeJq/mYeH67dqDjuzbuF5CuTnhe4v0IY4n90GKIQrzJ8vdWu8DOri 0BQwkm4keb9XnPrgC1Ip/g+G7pF4pdkBinFn2xO7SKbDH9amE3Gr16FEneExtG6i19Rx SRYSg6lrH/sX+mJ041O/xnXTNSV45jh/YzxeFogP8Q+unyPxWvefvnd0pqSvkZN0BjMD W5MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705548281; x=1706153081; 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=8IOrVF2ci3KA0n859H758KBpLzvdBx7y6KGSkBugi9k=; b=GIUSIHC3pi+U65vIZmVs7nQSpJwfBOAXL47Jhl5iGcWhOTpQ7lJvUNhGkxsm3TDSXa +vxvSWzdhprwf60EXbxQbRWWesL01EpPsphK+cXmaEX0lTX0pbNO0IkW2/YwixmOfgP2 h32FaI6L2F/iEZkVZGRLaC2NAiev2VVO4vEob/fkdf5HtzVJD4cgbHVdFAUf6oSGbl5S f3rH7rgPU+MVAZkhxUr194PKIBG8QEFYyNH86xLYJnR5G0xVzNBrbWvOiDBfJgHoOn2g 49KFSNfYAwwCkKQaJCC9z9KKdYBh5IfBdFavtGvhUBro46JKxND2ZXUAPFeRUpvEA/aB yZqg== X-Gm-Message-State: AOJu0YxYyOpKEZa2x92w+bf9sGdMWV8CvoJbWxXkFamUbP6SSBU5taYO 91sWJ+qrx+zEggRALU7IE9n1OLrBX8sEYTSeCb3RbIus7/RxxE+23a7cHNYxhJ03TgrZqe/lsu0 ORa0= X-Received: by 2002:a5d:4646:0:b0:337:2aa3:ac83 with SMTP id j6-20020a5d4646000000b003372aa3ac83mr89211wrs.61.1705548280959; Wed, 17 Jan 2024 19:24:40 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id i2-20020adff302000000b0033788e357e1sm2894292wro.108.2024.01.17.19.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 19:24:40 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , Alexandre Iooss Subject: [PATCH v2 10/14] contrib/plugins/howvec: migrate to new per_vcpu API Date: Thu, 18 Jan 2024 07:23:55 +0400 Message-ID: <20240118032400.3762658-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118032400.3762658-1-pierrick.bouvier@linaro.org> References: <20240118032400.3762658-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x434.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 --- contrib/plugins/howvec.c | 50 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..497b86fcd6b 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_t count; } InsnClassExecCount; typedef struct { char *insn; uint32_t opcode; - uint64_t count; + qemu_plugin_u64_t 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_get(qemu_plugin_u64(score), cpu_index))++; } -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,15 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) icount->opcode = opcode; icount->insn = qemu_plugin_insn_disas(insn); icount->class = class; + icount->count = + qemu_plugin_u64(qemu_plugin_scoreboard_new(sizeof(uint64_t))); 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 +314,13 @@ 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_u64(cnt), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt); @@ -322,6 +335,13 @@ 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) { + class_tables[i].table[j].count = + qemu_plugin_u64(qemu_plugin_scoreboard_new(sizeof(uint64_t))); + } + } + /* Select a class table appropriate to the guest architecture */ for (i = 0; i < ARRAY_SIZE(class_tables); i++) { ClassSelector *entry = &class_tables[i];