From patchwork Tue Mar 5 12:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 778007 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c8:0:b0:33e:474f:8c56 with SMTP id p8csp401099wrs; Tue, 5 Mar 2024 04:22:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUYaJ0RkT24Z+EIJrA6HL4BIiTwg4kal2RjB3G4AfYv4j6/Kb7WO+a98+/i8UGS7J/jHy05JURp4I4UFpCMAWcI X-Google-Smtp-Source: AGHT+IH/KRFxICM0Y7cjc5wtIssi0WqdunV3CN/bkQoVdRq3ys5K/BlQHOvvo5RF+GYXD4dzkeY+ X-Received: by 2002:ac8:5ac1:0:b0:42e:ce2c:ff2f with SMTP id d1-20020ac85ac1000000b0042ece2cff2fmr2056649qtd.65.1709641320611; Tue, 05 Mar 2024 04:22:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709641320; cv=none; d=google.com; s=arc-20160816; b=zj5wUdyLNn9vrT+urH2EdpCrwlSzXdCFOk+mteggPPbU/hQG3kUoGfT6jxs1Rim3HU tOgEL8qdOr/h6IOEfnm2TGw2DxMzlBvHIbCo35TIn/kVXAXOYYLfSW9gG2rYAYsh2JOo ah0XqycPJMy1C7pU9v8/67rVLS9VnyubZ2afJrv6xRNOUm3Yj0YO9hg3LxijZsWzwWA2 qcA3A0E2DA8Spn3hVGLeYGIAgvKVA5cy/1RnUnAK2Wkipm4QH26KVTOdc773NFRhMC+m B/Hs689c87oFrXnc5j3UfSgA4T/KvzraF9u/Buziw8oqUk/b7h7JHEepLE8n693nIMfk ubcg== 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=Jva0UhCUVM5PrwiNrRfr0W8ZD8H77VctOx99a/dGefo=; fh=0plVVyIIm9S3azloeI1ZUuIkQnwpDkyGGtr6f6xmokE=; b=h7lgIe2cVkk+Q9VJ+HagW4duVxV4Ajq93mN7D9seNTQCVJ1N5xpWIqtkqaEcA33pCV GUMS0wZvPrX7QkZ3M8CUGs6vTl7m6B5DKAg1Z+nDz7a9s5vW4YC68PFL7k8GwE68RRs/ jQ2FYhE9MwfJT4YToGZH/3k0lCtnr89ESKZK5PUw1iHGIlIYRx+AyKFluE2ImgA/xbtD TbfjkR/3Ls2ZrxJ/D+SPMVAy4KBxA+DvUNfULqf/v4SD9tw/+WK+Bl3Bb06JY8tcUzN3 Idr0TLJBc88JAnWuKa+cXRcvjgewKC8lJjjYNVxufUJylzv288YDoYLDjs0nN+FPQ6HJ dFVg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dnl08MoI; 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 od17-20020a0562142f1100b0068ee3b2faeasi12018301qvb.182.2024.03.05.04.22.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Mar 2024 04:22:00 -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=dnl08MoI; 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 1rhTnO-0004yR-Gy; Tue, 05 Mar 2024 07:21:24 -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 1rhTlJ-0000lh-By for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:19:13 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhTky-0003Gr-K9 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:19:13 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33e4d36f288so243459f8f.1 for ; Tue, 05 Mar 2024 04:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709641129; x=1710245929; 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=Jva0UhCUVM5PrwiNrRfr0W8ZD8H77VctOx99a/dGefo=; b=dnl08MoI3lEFJ66xmrtGAPwl6c0WgbVa6CIGWJuFRRHJxF1T3z4H0j36DmCH+DhuNm AEgeuUHHB5iKdVJ5BkD+WWrt6cbjcctNrBHVaBt0W635xLyVj83wHwKbac0dhLC4ve3p RjVEVS3ufPPXtCwccmGwuVsmiL2UL3IBWVa/eEGumHQmIsS28/kHcvE9Kha2GpMVqf6B 93DxPZKYDjDeLdjBkpa6YDaX610LA4crv6W0RffRydr6tsKREEMsEueHN+MYurXHqjGp 7O6x+wMcJFc8xj5uVk677dESZ/8bskmaPJEDS06rF5pDIz0bQCLcIk9NEtFZfftphVta HcIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709641129; x=1710245929; 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=Jva0UhCUVM5PrwiNrRfr0W8ZD8H77VctOx99a/dGefo=; b=wdysPdStj71EelG7o3cYVLG5FeDCmqs5xIs+2pE5+P5fWQobEiUAWwePthWjj2xFmu 1DK2FC66xlGq1BtR5CpVDBIW6PuXTrIsqDWOMi6UnS1+t5jfxO4CjDtWXDD+39HYSiub dYG6Oi5A2EiZOYz7+SlrPOQR+SH04nO7WBfYZOKVAauSKO2+ZS5U6kDIpg2K5+LC6Kmw QgZIBSQc9S9bWLXOie3Nkbu7/PjOf5YxG0cmnJbR8YWexV3y78wjQjVhIvoD/+IA2kIp eMl52QMOz6sXqsR7s50bE9rUvxQCoasf1pNd/1pnozUgRlrurMSp2jXrm7mCMILVvyKS 1rlQ== X-Gm-Message-State: AOJu0YwDI3O7lLZCR4ulnzK2m064gCK8LaCMwvJn8GXl2tagj0l0ZHBz KHrQv2PvSUPzjpu3xWw7ImxKK4FTX0vXP+ouqoMZBe93bA1OOKXIhNSEaVI0A1E= X-Received: by 2002:a05:6000:1e11:b0:33e:47fa:912a with SMTP id bj17-20020a0560001e1100b0033e47fa912amr2968670wrb.27.1709641129428; Tue, 05 Mar 2024 04:18:49 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id bi25-20020a05600c3d9900b00412e84e96ffsm3912412wmb.40.2024.03.05.04.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:18:47 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 4CC305F9E6; Tue, 5 Mar 2024 12:10:07 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Alistair Francis , Nicholas Piggin , Liu Zhiwei , Richard Henderson , Yanan Wang , qemu-s390x@nongnu.org, "Edgar E. Iglesias" , Eduardo Habkost , Daniel Henrique Barboza , Michael Rolnik , Daniel Henrique Barboza , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , Yoshinori Sato , Laurent Vivier , Thomas Huth , Peter Maydell , Mahmoud Mandour , Brad Smith , Alistair Francis , Brian Cain , Cleber Rosa , John Snow , Marcel Apfelbaum , Pierrick Bouvier , Palmer Dabbelt , Riku Voipio , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Weiwei Li , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Beraldo Leal , Kyle Evans , David Hildenbrand , Song Gao , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Alexandre Iooss , Warner Losh , qemu-riscv@nongnu.org, Ilya Leoshkevich , Luc Michel Subject: [PATCH 19/29] tests/plugin/mem: migrate to new per_vcpu API Date: Tue, 5 Mar 2024 12:09:55 +0000 Message-Id: <20240305121005.3528075-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305121005.3528075-1-alex.bennee@linaro.org> References: <20240305121005.3528075-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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=unavailable 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 From: Pierrick Bouvier Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier Message-Id: <20240304130036.124418-7-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- tests/plugin/mem.c | 46 ++++++++++++++++++++++++++------------- tests/tcg/Makefile.target | 2 +- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..b650dddcce1 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,9 +16,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t inline_mem_count; -static uint64_t cb_mem_count; -static uint64_t io_count; +typedef struct { + uint64_t mem_count; + uint64_t io_count; +} CPUCount; + +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 mem_count; +static qemu_plugin_u64 io_count; static bool do_inline, do_callback; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; @@ -27,16 +32,16 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out = g_string_new(""); - if (do_inline) { - g_string_printf(out, "inline mem accesses: %" PRIu64 "\n", inline_mem_count); - } - if (do_callback) { - g_string_append_printf(out, "callback mem accesses: %" PRIu64 "\n", cb_mem_count); + if (do_inline || do_callback) { + g_string_printf(out, "mem accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(mem_count)); } if (do_haddr) { - g_string_append_printf(out, "io accesses: %" PRIu64 "\n", io_count); + g_string_append_printf(out, "io accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(io_count)); } qemu_plugin_outs(out->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, @@ -46,12 +51,12 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, struct qemu_plugin_hwaddr *hwaddr; hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); if (qemu_plugin_hwaddr_is_io(hwaddr)) { - io_count++; + qemu_plugin_u64_add(io_count, cpu_index, 1); } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } @@ -64,9 +69,10 @@ 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_mem_inline(insn, rw, - QEMU_PLUGIN_INLINE_ADD_U64, - &inline_mem_count, 1); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, rw, + QEMU_PLUGIN_INLINE_ADD_U64, + mem_count, 1); } if (do_callback) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, @@ -117,6 +123,16 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } + if (do_inline && do_callback) { + fprintf(stderr, + "can't enable inline and callback counting at the same time\n"); + return -1; + } + + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + mem_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, mem_count); + io_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, io_count); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0; diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index a4c25908fb7..f21be50d3b2 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -168,7 +168,7 @@ RUN_TESTS+=$(EXTRA_RUNS) # Some plugins need additional arguments above the default to fully # exercise things. We can define them on a per-test basis here. -run-plugin-%-with-libmem.so: PLUGIN_ARGS=$(COMMA)inline=true$(COMMA)callback=true +run-plugin-%-with-libmem.so: PLUGIN_ARGS=$(COMMA)inline=true ifeq ($(filter %-softmmu, $(TARGET)),) run-%: %