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: 772275 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp169076wre; Tue, 13 Feb 2024 01:41:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXH3YhfK8H3/bu9+d+LiKRYCTRDZ1lMHOn/sjI8FDto4z3yOM7y5s+m/5j+7ssdkBkc+P3YNyjqIGfUvUVrPiyQ X-Google-Smtp-Source: AGHT+IFQQHfr02PelFRtfs3cLJziiJl9wbjRKWgsp4HbGIAb90feKJz4A3uF2hiofrxVtgv5L3DW X-Received: by 2002:a05:622a:254:b0:42c:7bef:c3bc with SMTP id c20-20020a05622a025400b0042c7befc3bcmr5204446qtx.53.1707817288845; Tue, 13 Feb 2024 01:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707817288; cv=none; d=google.com; s=arc-20160816; b=mugUiEjASWsj/mY5J2pwuvkv62vTp2LQ10H2hr2bpeJ8BnkqlI3OUGhR6Mi2ZghmMF RUtmmz0AnvJ7fS9YAK8bEKsYT+cGJ3V0060+bH3x1nnt9N4A1l/FzN0Wzr3NCLUodImU s+jAAvru7AQ5WDRtDrHJVhQHxWO3KlekUXXsyEauFN7EeQlXpdY7NinmYgI2T2I6wJ2B qj4T5LCoBMeTXjw0A0yoaq6s0+UAtI8VPEratq6Yn1J/D238ptwU/9e15RLvNrNbyCIa Y72TARtAbguns0wfhzj96PkHKI2dEzUxA6FYhbISacNH6u4hP7oP2C/+Vr365GvDQrx0 mrbg== 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=0LuglNIxMpcc450MgwB+/bbbw1CGJEy0QfnhDLLQmYA=; fh=+oRXYNonfPPZ9W0YxBXGbRVBnjQ/dkVYPQhScNZMRss=; b=m7MTPlmBPO4xEagW9YM3ByWEB0Znsrl0RM+bKPxW9twmCxhGAlDPicpmiri2Lcp1gC lM5B+ZYw51aSyLcGVgyCdOb/I5JeYcCmoFTYGroTm9FkYuEfbZDL8BnTgBaXAA/IOp/C a2JXgD4hT9j6gZ14XjkcWP/akSkzXJ0mKjf28wiYq2xFT0pTVQESoKAGSjna5WgxNDtH WmLATfr35fVSOYCxVFMnxWi8nV0gEawe+B4jFR/4IUfofoV3Nv472bfk6jFQXCQXxAJU CrEg+obEA8nnBaNhyaNx3AB02woOu9acrTDVXhT1Nlrr/dq+dreztfEbIlGJXWE5q47D miVg==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Zgbr7kAN; 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 X-Forwarded-Encrypted: i=1; AJvYcCVNbJtzwpppAmHCVhclOHHVh7JqXgMiciG7bgMGUQbO/DUrxrTakDE74RGOIrgs6odL7BcyWsGP3/XwECKfC716 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f9-20020ac859c9000000b0042c7c277572si2641150qtf.517.2024.02.13.01.41.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Feb 2024 01:41:28 -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=Zgbr7kAN; 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 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-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.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; };