From patchwork Thu Jan 11 14:23:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 761855 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2422998wrz; Thu, 11 Jan 2024 06:26:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMMipmU2SwwmAlM2k8LkGZQRwn0l7IqazxE4cVMVxqswRuOb60ohmla6dh1MkF0Qu76eUA X-Received: by 2002:ad4:5949:0:b0:67f:c0f2:5ca6 with SMTP id eo9-20020ad45949000000b0067fc0f25ca6mr1158823qvb.99.1704983168757; Thu, 11 Jan 2024 06:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704983168; cv=none; d=google.com; s=arc-20160816; b=jCzIU62I7iMAXkZtvHn4V1CfFIN1FUthChgSn4JCI/ovj1YIy9U4eIncZIQMA7fsy3 /QvVIC2iBEsINRffHLJ+T1D7JtYrPZSXHp27umfUgoAGc9KQZm/Nc2OPHBo/mZiETK9z EgawnCD7bxGqWaoQyrGP5YtWrPCBYMDwXF2p6pPWsHGRnRsCpxSNnQGugBOryWCxi7Sw HgbI1H8+NxRA0KAK1KKoge2h1yHosmJuBWsYuMDtMaNVFK2WNq4TWvCvOevDFnQUC23H YUaTT7IuZPe8mJbby5tGDBbFCNYDwshe2AlCyePMOcmDrP8Rk+KHI+SJciUUHQG/hEEg N5+w== 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=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; fh=4xQMyYYtmbynAmJxwWPpZ6ivTwZNkSfAt6fhFI9aNBQ=; b=LIBITic0xjwlm5FfghmjSKUihR1NxIY2XhjOLknxqWAIr6dQ3gO7Rh/u/ZoesXsTK1 nZ3l+MFkv9PMhFzc2FNlZWw5RjDmby274ZQNo6JwvU6ijVus8xBm3vgLqz8TtUu38Y2k rcn3x8P7rTD3EyTxlDTpSHroioEi9ywGljn24m3d6fyRFMQuGnmzLyz11S8swTLf30gy r5/Ii79Wgbl0XVPkomzdW1vik4lGXnPNIS0EM9k9VWou0yze7CqNyVvxAzUKyYqMUhBt NNun3f5K8l0MYgw27iy/T3FkAXYOdL+Pq35K8CayOinspT8nCb8nVZDAeiC/HNVpoSSP DsFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gH8qm+1u; 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 d9-20020ac85ac9000000b004298fa9947csi1032931qtd.662.2024.01.11.06.26.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jan 2024 06:26:08 -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=gH8qm+1u; 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 1rNvyt-0004UK-VB; Thu, 11 Jan 2024 09:24:27 -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 1rNvyl-0004Q2-Ib for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyh-0002lF-8F for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:17 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-336897b6bd6so5067136f8f.2 for ; Thu, 11 Jan 2024 06:24:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983050; x=1705587850; 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=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; b=gH8qm+1uRwTu1hinB1nS2dyaevmEh3hXNsHgVzyh0R/NAt8n3ssN6VxX0I3ysmbGQD Z9P+OQwh6Zvq8nOq5rIWJQEepIcE6mTsSx/Y6g70QjXzaK4N2hzuYMla5znxYF/qrLKM EiGIatKzNX1uPJTURw869fAyt3Z1vF17vBlhpSYvpSYqhMfwYnP+40qtSiay6OpJl4+i UOSONm1ufnDY8kMSI3MreazzODI9CdyH2xQauAJvbgTTXMUq9v9H2o2bznDOze9He1DG DHrbT7D8ltMO/ppM0OckxktPM8hG1nstCzp0i7O+Bgma8YXPsolWgNJf1ZzoJN0NxC5M NOEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983050; x=1705587850; 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=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; b=tF5muU/Pg7SXS4YUPBshu7vAzT7jTqwA86Wm23ameZp68T+8ekvu0oODqV1jHPM71R lOnpRAlBlfp7sae9gIiI9ViV9NCYOQxrXZrz+P5HRRFiyTbSn2iXEFXw2zhuTMrVGnXV ssBjXaZe8St+6pjEhSGv4UWdRUAdARxckreBu8yapPloehZ4SjBaZ3sJfYzbJnWqoBvF OdJYhNxnxDQgPk1BEIzpWpmAT8ZhG6JbqzJqBc/Fh3kfaIblJXL0BFOUVd0ejm39ZF6x uPa1gpDAnwliqjeAHDCRjQLv8UW7o/MUBfWuMC55tdz/tXEbt7nefhypgxS6yE9bixbR yTLA== X-Gm-Message-State: AOJu0YzFBN9RhJ06/QrY8C5euB4QfkAIz/7ymDZTUf29bDRUSjz9FuwS ZII8/NFX6dH3P0bRo5gMPsZxkqgIn2hZcfuvf6+AF8yjUF+TIQ== X-Received: by 2002:a5d:490a:0:b0:337:3f72:3de2 with SMTP id x10-20020a5d490a000000b003373f723de2mr641930wrq.36.1704983050508; Thu, 11 Jan 2024 06:24:10 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:10 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:23 +0400 Message-ID: <20240111142326.1743444-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> References: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x430.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 Reviewed-by: Richard Henderson --- contrib/plugins/howvec.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..46230a43927 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -22,8 +22,18 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; +#define MAX_CPUS 8 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +static uint64_t count(uint64_t *arr) +{ + uint64_t res = 0; + for (int i = 0; i < MAX_CPUS; ++i) { + res += arr[i]; + } + return res; +} + typedef enum { COUNT_CLASS, COUNT_INDIVIDUAL, @@ -43,13 +53,13 @@ typedef struct { uint32_t mask; uint32_t pattern; CountType what; - uint64_t count; + uint64_t count[MAX_CPUS]; } InsnClassExecCount; typedef struct { char *insn; uint32_t opcode; - uint64_t count; + uint64_t count[MAX_CPUS]; InsnClassExecCount *class; } InsnExecCount; @@ -159,7 +169,7 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { InsnExecCount *ea = (InsnExecCount *) a; InsnExecCount *eb = (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + return count(ea->count) > count(eb->count) ? -1 : 1; } static void free_record(gpointer data) @@ -180,11 +190,11 @@ 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) { + if (count(class->count) || verbose) { g_string_append_printf(report, "Class: %-24s\t(%" PRId64 " hits)\n", class->class, - class->count); + count(class->count)); } break; case COUNT_INDIVIDUAL: @@ -212,7 +222,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, + count(rec->count), rec->opcode, rec->class ? rec->class->class : "un-categorised"); @@ -233,7 +243,7 @@ static void plugin_init(void) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { uint64_t *count = (uint64_t *) udata; - (*count)++; + count[cpu_index]++; } static uint64_t *find_counter(struct qemu_plugin_insn *insn) @@ -265,7 +275,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; case COUNT_INDIVIDUAL: { InsnExecCount *icount; @@ -285,7 +295,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) } g_mutex_unlock(&lock); - return &icount->count; + return icount->count; } default: g_assert_not_reached(); @@ -306,8 +316,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) 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, + cnt, sizeof(uint64_t), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt);