From patchwork Tue Feb 13 09:39:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 13554835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E69AEC4829A for ; Tue, 13 Feb 2024 09:41:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZpHe-0001F6-LO; Tue, 13 Feb 2024 04:40:58 -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 1rZpHc-0001Dx-4t for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:40:56 -0500 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZpHa-0000Ei-E8 for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:40:55 -0500 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2d0a4e1789cso49138081fa.3 for ; Tue, 13 Feb 2024 01:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707817252; x=1708422052; 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=0LuglNIxMpcc450MgwB+/bbbw1CGJEy0QfnhDLLQmYA=; b=Zgbr7kANLtHQLmbyRvRDAG9Rdjsts9y1KFtyQn3hcWl7dMbI33H+lQe5BXqKmkJX6L yfYVa/vWe/9DMH8MfQFBPGO0o8rKqADfy2k4P//IOUgKVK17nJ2E4reAdLAUBqzSd4rR sGj2ECE8sDLzT/KT3B4sla+MkzEtgYxpl3aY6rffcrVqJjpUZCE2TlXS1lXLD75vk9NJ 7sMuPc4Jfd2kZ1rbVrh1r+Bb7wiKeO+uKxcch4PlO61Xx+lt1AlyKEPcGSwEcypkXtzJ aPBLG0yDNVG/EhcNJUxFkI6TaEKwhLXu2fC8x693QLgwjfelLwV34k+33+EMO7OvV1oB cTKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707817252; x=1708422052; 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=0LuglNIxMpcc450MgwB+/bbbw1CGJEy0QfnhDLLQmYA=; b=emwVzVQO5Hp89wWiWXJ2EZH6rN64eeCZ57yES7LSYY4uzQCzU9Gib4kTFWfH4lE1m8 hIa+ta8U9yJbxXbCBAoDcRhH6nwkeQTyPxbho+sqsuIoj4TzxhI21lM4+RpArGF/WML4 N012OReCBTxyS42YabBCNM8pabBwiYGmBYDPH2C6sNjH4KaWDm5UbUxcCdKQFs4I14JG mthbUCxkReTqlHtFeTHLH1bd7modENKgV5zgsFkUMiQKuyyx/lJjiwbzR1pQxdqdI45U Epvemj+NPPZCkDIgQ0eFDgZ8Q03OaBL8rRLzu8Kc3HOCLfQtxyBPDLH1MBb9aPO8U5bZ Vc5Q== X-Gm-Message-State: AOJu0Yx+CFycZSCLTBy6Anvc+al0c/MmC3Ck/tfBJC1Gu224tWvbNF22 Y57Py60nGdQuNic43mPk1Sp9/ZbhHCwDLpq/C4pIB6U0XCfpVEE8CryPqH5wpzr4XkbQa/fvPr4 a X-Google-Smtp-Source: AGHT+IHb5OlReVwsqM9Ce8fBduVqUieJdWw9/dHr3FyzhnSzEjwCRlezlDmvUxRjaceFk0Y6vlysWA== X-Received: by 2002:a2e:90c3:0:b0:2d0:8eff:286a with SMTP id o3-20020a2e90c3000000b002d08eff286amr5711960ljg.40.1707817252422; Tue, 13 Feb 2024 01:40:52 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWn7y5+L/t77jcZLWD5M3etn0ob+uBjo6PBehIQV2hC4Oy5KM5+kRVqQXWcNjHFItGf3iaYhiytsdLipI3y3oRy9awFsf5BH/h7wcCGQcxWzQWZEoRDC1F8NAdKUKPHmP0A4DgKBtaB/7FDYxlphposuHpeOigm5259KuIPgnt6loIIbJImL90/arp9NypanvEDNz0uVtJBopUdwMh2qNqy79g3n/1NSDU/kYvYfPbLdVCI8Obm6PhYEt6XwLSAyGq0wDeFAmDJQtH5lCp5whvm5N/tsKKijdax00FD6iMvJXp838LIu4rDp0uHe+EyeBV31XKB2ihw/3c78bna3oPB1TUmBg== Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id cc19-20020a5d5c13000000b0033b728190c1sm8550261wrb.79.2024.02.13.01.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:40:52 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Marcel Apfelbaum , Paolo Bonzini , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Richard Henderson Subject: [PATCH v4 06/18] plugins: define qemu_plugin_u64 Date: Tue, 13 Feb 2024 13:39:56 +0400 Message-ID: <20240213094009.150349-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213094009.150349-1-pierrick.bouvier@linaro.org> References: <20240213094009.150349-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- include/qemu/qemu-plugin.h | 52 ++++++++++++++++++++++++++++++++++++ plugins/api.c | 33 +++++++++++++++++++++++ plugins/qemu-plugins.symbols | 4 +++ 3 files changed, 89 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 0994935d4a2..a48586ef0c1 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 * @@ -785,4 +796,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 76fbca685f4..15edad6769b 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -541,3 +541,36 @@ void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, 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; i < qemu_plugin_num_vcpus(); ++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; };