From patchwork Tue Mar 5 12:09:51 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: 777997 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c8:0:b0:33e:474f:8c56 with SMTP id p8csp399801wrs; Tue, 5 Mar 2024 04:18:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVQVNWEIEjgUsCP7E19d2L45UZdcYKcsn0+j8jWOKZuaomNJdbLr/2Pczq6udTc89qkPobOa/eoQ0cGtYKizOzq X-Google-Smtp-Source: AGHT+IHzlJM6H/+3PQNNeuy1Vq08VV9JMefUANPkgwk7cBkfaBs1YDTNQeZlZuu8kxxsN8gTyFsA X-Received: by 2002:ad4:4e49:0:b0:690:89ce:9344 with SMTP id eb9-20020ad44e49000000b0069089ce9344mr1638764qvb.8.1709641120803; Tue, 05 Mar 2024 04:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709641120; cv=none; d=google.com; s=arc-20160816; b=hVpDNwZfxj6jKlwtvMMA1QPyD0Cd4CIxDpURnY2p5rlkvIHW6f2QOzPpeiQhenli6V 0kq14XfQE0xxCgEn2kSV8HaETATN6e6ympT761NBfjbJeFwgSc7J43S3QjYfzLezx0jT eyYReFye84dXb5XkwsS6Fo/lnh/lXy6LYnAfii9VPO2CwLYd8FxW1oFzUfSl5B2yvo5b ZhOHWacDLM3DA9jkyd0iLwwniWg87uM3rQfnNMHfgLQmOt1whwPuZBCE3ideKSLGrx6o eyc89RT8f4KQZDzeiQ17FiYs3Mt4rYY+vcMfd8Y+Bz70+gY7TssCKc+fnTcHIqo4SpZj iYUQ== 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=UqNj0COIQuCCXg0hZT7WW42rxn79Q0Rei6wd0zzibZM=; fh=f6avZL29XgA8xpJjruaeiY/t2FUw83MgiNvVXs1rDYg=; b=l0nrQzDC9jEIWu2Q1H+9iHBDUoANmwLDA5bgQoCLXpybcNL/iqOTQ+oKeRouDGQOCc YHwkvDor+AeRJT3TmtHfU1dJcsJzGEfB5qja9/I079ygjC/rwn4O3PlXr7Syas52fP3Q EKO15F2NGZgOEAv2Zpmt45U2HP57KOE94n/SGHqeWmJRDLBAIdoT+CXPh82Q9h8SEqOE nte6mIAb8XBi8pDtT5/p1CXLeTbCknIv9qql5dUeoKOAvW/MiSHk5xFRC81UtoSUkHmx Zs4eGEX4x8H2silBpyBoCFw0GTP7mhWVVjFe8tIXspp0RpmEABtkxIV8VPj2/CPNVcXW kJgQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QEiKOBRz; 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-20020a0562143a0100b0068cbd994768si11772618qvb.566.2024.03.05.04.18.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Mar 2024 04:18:40 -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=QEiKOBRz; 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 1rhTeu-0006FW-Bm; Tue, 05 Mar 2024 07:12:36 -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 1rhTdh-0002gy-Uk for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:11:22 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhTcr-0001VG-Fg for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:11:20 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-412de18edcaso17025045e9.3 for ; Tue, 05 Mar 2024 04:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709640620; x=1710245420; 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=UqNj0COIQuCCXg0hZT7WW42rxn79Q0Rei6wd0zzibZM=; b=QEiKOBRz+cu1icMi/mXn8vteHRi2/VIxGbfHCbDcSSFWUcPDqZJh/Mt2dC5fNZ9r/2 u5fMltc7OApY5sHa/d4FEw4GoYkRP4BlV6JRvmgRE3vMFuW4PdNL/bv2AtPyXVDasTD/ /ndXSaCQkh22Z1j2u94i7BJ/EuaabAZb1MajmT8oP1EOXbNtBMITTgRBeRmbgulz8SVk ygJ0sX4cZ2nhi0AZ84HQUvFgNkvaiE7ijOiNJhYVP++ObuXkNx88nvdfue1mw5jvLlhC o8Qy5dH1ZzyjUBGsn3wJSKPvC4HJsiC86vuoUPAtdbyRwzyfsCoYyseacCCrSB0VeH7t 46rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709640620; x=1710245420; 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=UqNj0COIQuCCXg0hZT7WW42rxn79Q0Rei6wd0zzibZM=; b=ECONR1wCMzXzEPIotWRhT+tsqXyT58X22QKycDsOLZypo/CUVEQ5BsdiqpS/a9Q0S0 Czpjrs/H47wvFqCzpVfXVbE6fajpFzXh8+VDLjOOK1eL/8qdQJonUuJRh0FsgtT4FcWJ g0FdtGqDoHAVcIpDQDq60Rm1nuNazaLgANZGkzzegZduNgqAmDGzwI7zexYRi5Qab6W9 xop5lrwaqomZjpGzLEFzDHyuTw2u8O7CMmGGGzUGEdWbGwH8bBtQlLn2Iy44YnJBrXvy MmCN2v56XUcXg6BLhxyaA8u0oztOA9MDalU/9dZIk0ARwDXqg/+faffprbFluSWbNdl0 zI5Q== X-Gm-Message-State: AOJu0Yy7p0IUxP7MMlu5URD51aBXVx+YiSGyufKKGsb4pBobKpVV4EWS QS6zEC4ub4gNi6UlPnjtr1MfrMaB6znZ8jZXjfjrL4oTijNKmp2Xp7TwpskykzE= X-Received: by 2002:a05:600c:1546:b0:412:e7e1:b5c with SMTP id f6-20020a05600c154600b00412e7e10b5cmr2930430wmg.15.1709640620050; Tue, 05 Mar 2024 04:10:20 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b00412b643b5a3sm17627256wms.11.2024.03.05.04.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:10:16 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E54B75F9DF; Tue, 5 Mar 2024 12:10:06 +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 Subject: [PATCH 15/29] plugins: define qemu_plugin_u64 Date: Tue, 5 Mar 2024 12:09:51 +0000 Message-Id: <20240305121005.3528075-16-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::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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, 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 Additionally to the scoreboard, we define a qemu_plugin_u64, which is a simple struct holding a pointer to a scoreboard, and a given offset. This allows to have a scoreboard containing structs, without having to bring offset to operate on a specific field. Since most of the plugins are simply collecting a sum of per-cpu values, qemu_plugin_u64 directly support this operation as well. All inline operations defined later will use a qemu_plugin_u64 as input. New functions: - qemu_plugin_u64_add - qemu_plugin_u64_get - qemu_plugin_u64_set - qemu_plugin_u64_sum New macros: - qemu_plugin_scoreboard_u64 - qemu_plugin_scoreboard_u64_in_struct Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240304130036.124418-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- include/qemu/qemu-plugin.h | 52 ++++++++++++++++++++++++++++++++++++ plugins/api.c | 34 +++++++++++++++++++++++ plugins/qemu-plugins.symbols | 4 +++ 3 files changed, 90 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 31c468ddb2c..ebf9a645e15 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -225,6 +225,17 @@ struct qemu_plugin_insn; /** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ struct qemu_plugin_scoreboard; +/** + * typedef qemu_plugin_u64 - uint64_t member of an entry in a scoreboard + * + * This field allows to access a specific uint64_t member in one given entry, + * located at a specified offset. Inline operations expect this as entry. + */ +typedef struct { + struct qemu_plugin_scoreboard *score; + size_t offset; +} qemu_plugin_u64; + /** * enum qemu_plugin_cb_flags - type of callback * @@ -784,4 +795,45 @@ QEMU_PLUGIN_API void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, unsigned int vcpu_index); +/* Macros to define a qemu_plugin_u64 */ +#define qemu_plugin_scoreboard_u64(score) \ + (qemu_plugin_u64) {score, 0} +#define qemu_plugin_scoreboard_u64_in_struct(score, type, member) \ + (qemu_plugin_u64) {score, offsetof(type, member)} + +/** + * qemu_plugin_u64_add() - add a value to a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + * @added: value to add + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added); + +/** + * qemu_plugin_u64_get() - get value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, unsigned int vcpu_index); + +/** + * qemu_plugin_u64_set() - set value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + * @val: new value + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val); + +/** + * qemu_plugin_u64_sum() - return sum of all vcpu entries in a scoreboard + * @entry: entry to sum + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 76b2e652b9c..8910cbb2c46 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -484,3 +484,37 @@ void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, char *base_ptr = score->data->data; return base_ptr + vcpu_index * g_array_get_element_size(score->data); } + +static uint64_t *plugin_u64_address(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + char *ptr = qemu_plugin_scoreboard_find(entry.score, vcpu_index); + return (uint64_t *)(ptr + entry.offset); +} + +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added) +{ + *plugin_u64_address(entry, vcpu_index) += added; +} + +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + return *plugin_u64_address(entry, vcpu_index); +} + +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val) +{ + *plugin_u64_address(entry, vcpu_index) = val; +} + +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) +{ + uint64_t total = 0; + for (int i = 0, n = qemu_plugin_num_vcpus(); i < n; ++i) { + total += qemu_plugin_u64_get(entry, i); + } + return total; +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 3f93e7d6b13..6204453d0fd 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -44,6 +44,10 @@ qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr; + qemu_plugin_u64_add; + qemu_plugin_u64_get; + qemu_plugin_u64_set; + qemu_plugin_u64_sum; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; };