From patchwork Mon Feb 26 09:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775842 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233715wrt; Mon, 26 Feb 2024 01:15:59 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXkjtJlCx2aKLVa2L/HDuGKzgHxl5y7cfK7r//MdREgFGwPteo8jDmUKJJp32T8wd+Y1jX0cUqpWimSsNULJjxZ X-Google-Smtp-Source: AGHT+IHMvFNwKuzo5LA8j6uMbcXY8vN9qeTFFThj/ve45OKttmH96xjyguTrnTWV7UjPLMcMcBka X-Received: by 2002:ac8:5e0c:0:b0:42e:8ce6:c293 with SMTP id h12-20020ac85e0c000000b0042e8ce6c293mr880900qtx.32.1708938959614; Mon, 26 Feb 2024 01:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708938959; cv=none; d=google.com; s=arc-20160816; b=cd5cT5wb7soS6zCViKH/oW1NQ4VGN6Mk6CMAok2kQYidV85Lo3zoh/YaSQb74yTPu2 7Jx5MJq+t2yunihhmtJPebMl4HijSdSBvGz1E4TfaIbGU+B6MLwf5UxsyhyImOJ8c0IL CZa3OGa2WD3GR6b9etEscpPRJLdB//BoV92tLiwR77DvFI3iE7je0BHAltMgTjK2aQ0s LBpkTQL6KnnVds+y6QsYmrYClOrd2yg1zlbUs8UOI9qrlI25/32bj/ZwB7t+kIvYt9Nu PS/ePJsQbB7nxETPJ3Jnarj0jrSMSEb2Pww/lhn/4vtZlke+O7nZVUgxobfXlzEH+Xqg bI1A== 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=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=c5CnVZHKIdzn09ElH5AKvaSl6RFvxx+yOi0Q8lmQJfrruWmClkrvHIzLpWiGexcYWb d39MLR72ETaKKhOtbAe+ktJVjW51Ue4ZHklTdhkK2XXbaRt2BFps2sjmPyxIwT9+8M/D yFNkcx3+H0FWdUCt+wmxbD4b5SJ3cuaUgcJPm2f5hqqdVcd0QhVj3J0onUI8ZvSUPBVQ yjZMzVnSVy2NcFYmVPBecmtLNcCzGhtHDpHCZp5ZQEvh2xMkXb+lVwqGDJYRVFOl4Q6M ndOZbVaj+kCls8pQ2VL3dWfj0/jKLsOzAxYfTwGNAg5EgGrvnodwg8TWwZqv1h32sWPK ciLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mEoSVDdu; 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 w11-20020ac857cb000000b0042dfd040b70si5030070qta.110.2024.02.26.01.15.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:15:59 -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=mEoSVDdu; 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 1reX4n-0003NC-0f; Mon, 26 Feb 2024 04:15:09 -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 1reX4l-0003MV-F9 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:07 -0500 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4j-00058r-Ja for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:07 -0500 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2d24a727f78so40475351fa.0 for ; Mon, 26 Feb 2024 01:15:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938903; x=1709543703; 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=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; b=mEoSVDduxsZJrg7cphVxDu3n9gZ6uIcLevJmTR2Op15uxuRPm/RBCqaBOAtdzvsejl woCcNvZRXs2GFjfUMETLelcpTFTs1cTjvF4eyI22R6hA82ivLWaGq5dXD1aU4DlbiTDN ceCzuK3agoZuYjLH4w6jft4aHM4rlYEjplT4K6iGvqRRfFVCmczccGmTKWkoqcOhrB78 lAQHS4q7mRrfbVkA7abftHXwmNvT32sWJqtqGZEQFzQBU0/XjLOwEz9193F2tNESz9Nt Qq5W4Py9HHQp3PqmZxG2d928XVBV4k4KcOd9PhjyAq0chc7URNyMm9jRdhXNFKUEV8/T BpZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938903; x=1709543703; 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=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; b=S2Uw+7lwpcFOYnPzEYj1dfdkQ2+ske5eTZeRTT03M3zC+21e/q6F+jCuBIkboXlzfq NSZ7pfYk8hOKhWMMJJn2eqllXXAGSVA+1CxKC88zht95hYCG0B3w+sey31BtxmNUtNgl z2lvcM9CMbUT1NWPTVY+B8yMiGJjmMpnhUCGTKupI7Xpljo6tIcIw8jJtyhNDyDjFM27 5AUjfMIFh4uHiYkJQzQUYvFB3oSARUQCouWLmBTklEE5Bf900RwT9lit4Ea002kbufON J16F1c8VkL7JTuTDIpGhqXMjPBLtpqs9Vaagx3Ntstb4E/ZyV8tdXCtJbtwddZlqq4Ii qMYA== X-Gm-Message-State: AOJu0YyHsemu2VqP8x4JhZD66DNnga1If7tbL9kZyRR5z1KrKVnBM43w kUgshsH+hV5AG2NFW5aaOo8mPmIevxn1h7Zy81CullLje17Ke9NH8XSUI63cXj/4ZLQCX++GrOU R634G5Q== X-Received: by 2002:a2e:9902:0:b0:2d2:3a2b:7ad3 with SMTP id v2-20020a2e9902000000b002d23a2b7ad3mr3581633lji.26.1708938903522; Mon, 26 Feb 2024 01:15:03 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:03 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 02/12] plugins: define qemu_plugin_u64 Date: Mon, 26 Feb 2024 13:14:34 +0400 Message-ID: <20240226091446.479436-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::229; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x229.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 Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- 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 f0c26827e04..6442ab041be 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 * @@ -782,4 +793,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 2dfc3ce4eaf..579fe4a6e54 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -517,3 +517,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; };