From nobody Tue Nov 26 08:43:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709736156; cv=none; d=zohomail.com; s=zohoarc; b=Uz57sTecvD+PK6Q8LQcpsuE/y1yFYiy2Wi+L25AUV0BP3lXCkUXTx0WCZYgJh8QEpm5BOCCT1EnCBwSdiI8ZpCjfeT6wi55a0qjfLnJf79z6k6t7ykUL/UzjW7kQqTf8x4CKfAlPu3n7qp7IiDLOzVXt3Rrf0LXfXKWMsxscEg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709736156; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7HiJVoF4HTxTyfZqmxfdNDwSSt/1/19ukV8tNZkwTQ4=; b=VioDIh490z/00Lf7UL2F2O8DlTc3wx7LeoFZ7Q2gF/X28eBQp6BMEviISx1hh1udHzFhgD4+EfepNrCNwVK1kM5uAeYKBzAgRTkV4OJ61l+kSmw94sNuTv66/r02Y9k17R219f41O9uby+YMj51qSWw+5vXLFIts0e/DR3K5WbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709736156519513.2763586267132; Wed, 6 Mar 2024 06:42:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhsSH-0008F9-Ui; Wed, 06 Mar 2024 09:41:13 -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 1rhsSA-0007ny-Fv for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:41:06 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhsS2-0001Uz-Om for qemu-devel@nongnu.org; Wed, 06 Mar 2024 09:41:06 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33e151a1434so2420205f8f.2 for ; Wed, 06 Mar 2024 06:40:58 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id i10-20020adff30a000000b0033b6e26f0f9sm17781896wro.42.2024.03.06.06.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 06:40:52 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 05FFA5F9DA; Wed, 6 Mar 2024 14:40:43 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709736056; x=1710340856; 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=7HiJVoF4HTxTyfZqmxfdNDwSSt/1/19ukV8tNZkwTQ4=; b=W5Jlz7bgA1ug3WWitQJ9VZ+SfAhG8TaKjq4lu5H888Bv3U2NJKuRRmRwZJA5wJpzkR HvxyBB29CKEl+/o4/0rIEQ6Sc6vmrvAQAYXguuAP9mDPpVxsmIClMDjvkiJVOQOw8L8i 11xhewUhTM7eUFZ3UrZSDgTa2T2WpwDe76GSA2f/RaUvdOX0tia69AV6XFhTzb4T505Z ijVMeglW8xN4fb14PSmOGVGno7x37PSeJOc3O1SWBgE5d4I+xNkuRWuaRVHhCc5XTKMh cS2WO+8uhZ3DGy+e7HEONBbWF8IsqzMFgIDVgsLnbhva8UfQGDNpWwr5zQscyyJXqzvo 0mRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709736056; x=1710340856; 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=7HiJVoF4HTxTyfZqmxfdNDwSSt/1/19ukV8tNZkwTQ4=; b=t4dtUWuW1VMqH6cC00mUdggi8BeY0KZW/cSely9mWg9xT4kk5a/j5t8LugDu0fWpxq MOghM3bDKN6+T+ZJtPFvsOeOvn20TxEkpwhc3vLZoPHUfo6MkKyTw5mDFmsTOHbciUY5 A4Bg84H0JwEaY/m+YuB91IZmTkWqBht1aUymjGrXwYzoaRE5GFXptEcDWrJcKiBijelL TKa0yr33+JQ+umbBe7q82HpeGVqYNr9IMF4t5iULBC+cmDGkfwDJyOvU8iayjGm+WwRj 0xOMkEaFr1E24WeMHWIqKgF3ELSOcf2/N+Y0MKfIQyZ9XTfer+ThRJ4njV5DaGkbGBoA gsnw== X-Gm-Message-State: AOJu0YwDXcS8nQNa/3HYlK/I4MkTB4WD1YR2s7AGEitMsN41tZPafz2m 7yzRLeLRLmFZve5ZTPWHU3+R8gYlk/nSSIGqXTphmoWp49UgR243tX1jfHOp1aQ= X-Google-Smtp-Source: AGHT+IFN8t2VjrZaVQbbuC8QDjI8PuGZqOBDb6MkifpIbTkUR5kuiE/rtKD3pAr3dWymg64oFmUu5Q== X-Received: by 2002:adf:e84b:0:b0:33e:d0c:1ed0 with SMTP id d11-20020adfe84b000000b0033e0d0c1ed0mr10247148wrn.57.1709736056253; Wed, 06 Mar 2024 06:40:56 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 15/29] plugins: define qemu_plugin_u64 Date: Wed, 6 Mar 2024 14:40:27 +0000 Message-Id: <20240306144041.3787188-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240306144041.3787188-1-alex.bennee@linaro.org> References: <20240306144041.3787188-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709736158081100006 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=C3=A9e Message-Id: <20240305121005.3528075-16-alex.bennee@linaro.org> 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; =20 +/** + * 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 ent= ry, + * 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); =20 +/* 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 vc= pu + * @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_inde= x); + +/** + * 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_s= coreboard *score, char *base_ptr =3D 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 =3D 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) +=3D 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) =3D val; +} + +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) +{ + uint64_t total =3D 0; + for (int i =3D 0, n =3D qemu_plugin_num_vcpus(); i < n; ++i) { + total +=3D 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; }; --=20 2.39.2