From patchwork Mon Feb 26 09:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775838 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233657wrt; Mon, 26 Feb 2024 01:15:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVL3b2umPTOCYmX+Q/akwBLpZYxHsuG0UpgfdZ9WUWJrXx4BGv76cj8CbgSgRZXgUkT/cHDNXoW3SlMDVfGQSCF X-Google-Smtp-Source: AGHT+IFm5p4hVmI9v5Jwu+1zP2Vu5jvrFNWX9M/sioaE1Fy/EbcVhxDT5SzFlEq7UUqSxB32Qpgn X-Received: by 2002:a05:6102:3185:b0:470:3da4:1a3a with SMTP id c5-20020a056102318500b004703da41a3amr4238643vsh.6.1708938948605; Mon, 26 Feb 2024 01:15:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708938948; cv=none; d=google.com; s=arc-20160816; b=gnxlOC2KoIl3oDI4Q4EYqZYaGV3vVyefm1luZSoUw7bVHjXtWiMMNnEax6RKsD9dny 1h4XxO1U54VwN6dFGr3olDmvqZb1ksR4Bko0GS6UMoJdTLgmt7sKCekemtOeocpj0NF1 0Wt1nnSdAYIVjIhnjGYYGuC5oW0e/+eFll0XNdmHwb+IfV0SFb2sW89GyzEBiZDKPHYb I4U9LjRrMoGy+Ecb7kZfSQZu5rAHWpVJu91eWmknrx/A0B6XUjvgUFEA75P7Ld99svAN DtYJI8AqJeIm7bLDkxaG4uPaCa4U3fowbzjL+GdFcfIeXfYPtVLURQL2MxkgWwPxFFk9 DAhg== 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=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=e9oH7zZk50PQFIjZBAIvSkIelzdXNhXBUVCUZFYkPw7gvOVZgAKwNQWA4MtZq4LhrF cGM956D+ZlpDUluHCMc80EcLXckfqoZnhwDIOH2vkY0yUMRGaUFmnCLws3AHlmVSVp9i vUbVNm7IMa4pXf5HLCSrva5BgsmEg+V3qMM4USNSgGsbJmUjcE71jiTVuQvChrqeMsIN TWm4Yk5cQDv4FAOHbbydcbACJTl/XgSVccDFXr34DUqR7bUBUdIh6Zq7e8THpxKr7E+9 5WwtRTt5xw63UPMD1LKBn5k6dB9m14jrYwXodaz+u9CVfu8l66ZDp9XByaLLzCRRHrQz Fngw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PUn6mks+; 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 f3-20020ac859c3000000b0042c3d3abcd1si4987432qtf.120.2024.02.26.01.15.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:15:48 -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=PUn6mks+; 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 1reX4j-0003M5-Re; Mon, 26 Feb 2024 04:15:05 -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 1reX4i-0003Ld-Dt for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:04 -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 1reX4g-0004xk-6c for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:04 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-412a3ebad2aso6233975e9.1 for ; Mon, 26 Feb 2024 01:15:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938900; x=1709543700; 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=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; b=PUn6mks+iuxlxJqPVpN+afSdrfQ24p3qhZycCqpt1huoqU75LZsqxFFrnXvxfLc62b F4ICArEThL+pdj9jIMLbRKFLCmrKepSUtyjE1zPx/9aXKR6ZVcXqNi+664MxbFQQmwPn T1E2TP4lYWhpvFV4lhlwhyQdzY77rNgQv2dLdF2MHRNttWuOCktIDHz2j9LT88VCi8Wb d/8ZRoZ03Sy3C97kh6stH0gvu0GtmIpZdbceZOdUvxvcxIiP+EyHqO2OkySTztO7uCd6 bcQ5tXrfJ0DkGJbNuft7+3aqrX6oUOkVNV35vJ1mHx8Dsdkxc2gi4/PBVvqEcDBnbElp eTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938900; x=1709543700; 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=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; b=eSzAHGG4KzKtGut1fxMX7DtdpYONRUBpmB3pnAfPG7aUDAev+W8NmL96sgUtAgwg7c 5a3ima775cAGUVA0TrtWySFCJiNqVYx3x88HwowqqARaFDLTxocK7HJfP4PF8r1rqo7V wGI73t8PgK1SjTtN8gycoxqcmLNTp6KEHXDgj/ivunvc7r2am7EpOsOoxJvXxYdCohvA SiTbeZcjaohmPNg2DUpqWWPja9YGv1nxj2INyND8VoEnXDfYN94mvrCEncwVSBTY0hQd gSeyoMmSxTNNLqbjNxcFSSlKvIbfYcZuZbyvq/hQGfeAYohAyrnmv8l5wxW6mXQloTyP abag== X-Gm-Message-State: AOJu0Yw7woYordqLiLHjD3vxcSHUnSMKkLTQLbPDqXOcrkrZconr17eG WsS9cJYd+CefuKP0a4UmqjuwzFS19AKhVkXbnO2FlyYBeK2lwhUECHQY5QClbyUZ887yXGJ9s7I QNy5PTA== X-Received: by 2002:a05:600c:5114:b0:412:9687:493b with SMTP id o20-20020a05600c511400b004129687493bmr4899413wms.8.1708938900038; Mon, 26 Feb 2024 01:15:00 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:14:59 -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 01/12] plugins: scoreboard API Date: Mon, 26 Feb 2024 13:14:33 +0400 Message-ID: <20240226091446.479436-2-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::32a; envelope-from=pierrick.bouvier@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, 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 We introduce a cpu local storage, automatically managed (and extended) by QEMU itself. Plugin allocate a scoreboard, and don't have to deal with how many cpus are launched. This API will be used by new inline functions but callbacks can benefit from this as well. This way, they can operate without a global lock for simple operations. At any point during execution, any scoreboard will be dimensioned with at least qemu_plugin_num_vcpus entries. New functions: - qemu_plugin_scoreboard_find - qemu_plugin_scoreboard_free - qemu_plugin_scoreboard_new Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/plugin.h | 6 ++++ include/qemu/qemu-plugin.h | 31 ++++++++++++++++++++ plugins/plugin.h | 6 ++++ plugins/api.c | 19 ++++++++++++ plugins/core.c | 57 ++++++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 3 ++ 6 files changed, 122 insertions(+) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 64fb425fb0b..53d80341a8c 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -112,6 +112,12 @@ struct qemu_plugin_insn { bool mem_only; }; +/* A scoreboard is an array of values, indexed by vcpu_index */ +struct qemu_plugin_scoreboard { + GArray *data; + QLIST_ENTRY(qemu_plugin_scoreboard) entry; +}; + /* * qemu_plugin_insn allocate and cleanup functions. We don't expect to * cleanup many of these structures. They are reused for each fresh diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 3b6b18058d2..f0c26827e04 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -222,6 +222,8 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, struct qemu_plugin_tb; /** struct qemu_plugin_insn - Opaque handle for a translated instruction */ struct qemu_plugin_insn; +/** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ +struct qemu_plugin_scoreboard; /** * enum qemu_plugin_cb_flags - type of callback @@ -750,5 +752,34 @@ GArray *qemu_plugin_get_registers(void); int qemu_plugin_read_register(struct qemu_plugin_register *handle, GByteArray *buf); +/** + * qemu_plugin_scoreboard_new() - alloc a new scoreboard + * + * @element_size: size (in bytes) for one entry + * + * Returns a pointer to a new scoreboard. It must be freed using + * qemu_plugin_scoreboard_free. + */ +QEMU_PLUGIN_API +struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_size); + +/** + * qemu_plugin_scoreboard_free() - free a scoreboard + * @score: scoreboard to free + */ +QEMU_PLUGIN_API +void qemu_plugin_scoreboard_free(struct qemu_plugin_scoreboard *score); + +/** + * qemu_plugin_scoreboard_find() - get pointer to an entry of a scoreboard + * @score: scoreboard to query + * @vcpu_index: entry index + * + * Returns address of entry of a scoreboard matching a given vcpu_index. This + * address can be modified later if scoreboard is resized. + */ +QEMU_PLUGIN_API +void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, + unsigned int vcpu_index); #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/plugin.h b/plugins/plugin.h index 00b3509f708..043c740067d 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -31,6 +31,8 @@ struct qemu_plugin_state { * but with the HT we avoid adding a field to CPUState. */ GHashTable *cpu_ht; + QLIST_HEAD(, qemu_plugin_scoreboard) scoreboards; + size_t scoreboard_alloc_size; DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX); /* * @lock protects the struct as well as ctx->uninstalling. @@ -101,4 +103,8 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb); int plugin_num_vcpus(void); +struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size); + +void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score); + #endif /* PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index f6c3ba2366f..2dfc3ce4eaf 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -498,3 +498,22 @@ int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray *buf) return gdb_read_register(current_cpu, buf, reg->gdb_reg_num); } + +struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_size) +{ + return plugin_scoreboard_new(element_size); +} + +void qemu_plugin_scoreboard_free(struct qemu_plugin_scoreboard *score) +{ + plugin_scoreboard_free(score); +} + +void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, + unsigned int vcpu_index) +{ + g_assert(vcpu_index < qemu_plugin_num_vcpus()); + /* we can't use g_array_index since entry size is not statically known */ + char *base_ptr = score->data->data; + return base_ptr + vcpu_index * g_array_get_element_size(score->data); +} diff --git a/plugins/core.c b/plugins/core.c index 83745663f32..12ec6911d5e 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -18,6 +18,7 @@ #include "qemu/lockable.h" #include "qemu/option.h" #include "qemu/plugin.h" +#include "qemu/queue.h" #include "qemu/rcu_queue.h" #include "qemu/xxhash.h" #include "qemu/rcu.h" @@ -214,6 +215,35 @@ CPUPluginState * qemu_plugin_create_vcpu_state(void) return g_new0(CPUPluginState, 1); } +static void plugin_grow_scoreboards__locked(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.scoreboard_alloc_size) { + return; + } + + bool need_realloc = FALSE; + while (cpu->cpu_index >= plugin.scoreboard_alloc_size) { + plugin.scoreboard_alloc_size *= 2; + need_realloc = TRUE; + } + + + if (!need_realloc || QLIST_EMPTY(&plugin.scoreboards)) { + /* nothing to do, we just updated sizes for future scoreboards */ + return; + } + + /* cpus must be stopped, as tb might still use an existing scoreboard. */ + start_exclusive(); + struct qemu_plugin_scoreboard *score; + QLIST_FOREACH(score, &plugin.scoreboards, entry) { + g_array_set_size(score->data, plugin.scoreboard_alloc_size); + } + /* force all tb to be flushed, as scoreboard pointers were changed. */ + tb_flush(cpu); + end_exclusive(); +} + void qemu_plugin_vcpu_init_hook(CPUState *cpu) { bool success; @@ -224,6 +254,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu) success = g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index, &cpu->cpu_index); g_assert(success); + plugin_grow_scoreboards__locked(cpu); qemu_rec_mutex_unlock(&plugin.lock); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT); @@ -577,6 +608,8 @@ static void __attribute__((__constructor__)) plugin_init(void) qemu_rec_mutex_init(&plugin.lock); plugin.id_ht = g_hash_table_new(g_int64_hash, g_int64_equal); plugin.cpu_ht = g_hash_table_new(g_int_hash, g_int_equal); + QLIST_INIT(&plugin.scoreboards); + plugin.scoreboard_alloc_size = 16; /* avoid frequent reallocation */ QTAILQ_INIT(&plugin.ctxs); qht_init(&plugin.dyn_cb_arr_ht, plugin_dyn_cb_arr_cmp, 16, QHT_MODE_AUTO_RESIZE); @@ -587,3 +620,27 @@ int plugin_num_vcpus(void) { return plugin.num_vcpus; } + +struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size) +{ + struct qemu_plugin_scoreboard *score = + g_malloc0(sizeof(struct qemu_plugin_scoreboard)); + score->data = g_array_new(FALSE, TRUE, element_size); + g_array_set_size(score->data, plugin.scoreboard_alloc_size); + + qemu_rec_mutex_lock(&plugin.lock); + QLIST_INSERT_HEAD(&plugin.scoreboards, score, entry); + qemu_rec_mutex_unlock(&plugin.lock); + + return score; +} + +void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score) +{ + qemu_rec_mutex_lock(&plugin.lock); + QLIST_REMOVE(score, entry); + qemu_rec_mutex_unlock(&plugin.lock); + + g_array_free(score->data, TRUE); + g_free(score); +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 27fe97239be..3f93e7d6b13 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -37,6 +37,9 @@ qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; + qemu_plugin_scoreboard_free; + qemu_plugin_scoreboard_find; + qemu_plugin_scoreboard_new; qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; 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; }; From patchwork Mon Feb 26 09:14:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775840 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233713wrt; Mon, 26 Feb 2024 01:15:59 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXZTS24Dnob0HNX9qEUlh+/v3kPPsevi3rt+hA4WYdlqYGUZ/6/YXEugCT5sN24BX/NZkvDeZrJERV1r/Sa9hIf X-Google-Smtp-Source: AGHT+IF945KNpdIxProhYw7KjwTK/PTzniKT4dzf053Xf+TWTA4ko0plNaZ2l5+JgSYNeDVMhTa5 X-Received: by 2002:a0c:ca83:0:b0:68f:e7c6:a48a with SMTP id a3-20020a0cca83000000b0068fe7c6a48amr5374919qvk.58.1708938959509; 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=ZEqAqNHZZcM1X0yO3cmik7ytTpGszZ5jHDIvtIFw65O3kY0IbRe0h2DlPfvvgHHMN2 iRMD763KUb8Z5fn4j+W2k6ibKWaH452LPdDykVy4hFeXROt5+cNtt4v7LQRtr0GFbo62 90Phndud7LDA7x/qyLPUjLRPRQ8bNXqU7SzDW/y8vlLLzAOwbfYTuhgXp33UWqWq/GCJ bspm9oB23yg/m56WPyGT9EfyM5buQ6ShQ/0RCW49puJvb1R4LmignCwB9Wb4JPj1Lp/s KE3tLFxX1JU7WaXq/93q69Lex4nPXRymGgo7m2UlE/OtCqtZJySmE7UoGdnUMgXzOq8M wr8A== 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=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=xkSutqXSegtHHReL5D0vfWkRKTR6SeCrZZoFC72V/qN5MAQh1jvqEFMg7dc9DFQZIB SSffF4t5d6tSHVMfkZgKQVslRRNqIMaOASIBPq60XlaCE4aXs6ADSiq4InCWyqi47asW hXYs4zHT7zkoLjjRcdl4l83ygOLE+O04o2s4VrF9Hc8aBYEG/ibYtM6snZ7vSxgO1SRL wDEBtUCpydR3p1Ti/0vN7Hx0NF67Mdu7Dkk84h0viEFTYhAuHGQbyYHog0Jd6f4ZyMDm gwNakW2wQSAGUwTSXRO82ieCCba1OmQ3fjN35F9EJ06Pq3al/BhsGVL7mEKMMIWlx80E qN5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DUmYNaIm; 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 hf9-20020a0562140e8900b0068ce329b12bsi4699165qvb.408.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=DUmYNaIm; 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 1reX4x-0003kF-6J; Mon, 26 Feb 2024 04:15:20 -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 1reX4q-0003XM-Ov for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:16 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4m-00059d-Ty for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:11 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33d6f26ff33so1989745f8f.0 for ; Mon, 26 Feb 2024 01:15:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938907; x=1709543707; 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=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; b=DUmYNaImplbViz27f5RiVrIP8J5luh1e7NNeyXW1iHy7jSz1E6nDnP/OQs88qSyhlx 1+oIXYftTTKqEIRIeGuWao74CnhqzEV9txmGnyQUbpPI5VXse344VVmQjypeFT5IzZda u4mfiQj8MVWPh2eOs61Y9l4XOu51c0m1EGYWPgb7i25uO2u1j70L/Ih+rnduGJX/i0Kf Qt8TIB90KeCVxFXmgsViUF801UNCJL5904x4/2GU6GvjXfXV4XzK3RuHr3QinFk/zKpn SgRy9B7LdOB1vkCD+CEI6gnEBSgkv1lBXj7DmytN3g15Yiypm025sTDKXLn28+emABn6 S9Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938907; x=1709543707; 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=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; b=J6OJEiNULQ6yVeq5ONml1jKSCkRmN9ujbVzMu1Ytu2GqeKOn38jR8OZDOdrLiAGRII yuTGTiWZc3/uYKtk8c4ZY5/iZtP9pGCut226pL3mI9nClQAAIntlO4PQvcVAhPgEJsxD 5lrYVi3Pyth1MKvTNupysvY+30sk5e73tFcdg2bPtx3++TmUIlIHiJeVTBimhp7K8VR1 zIWAouNiLac5GUcZyj8xdqNGmVuhRoNw4V4c8mcmnOhZf3TeK+66OMVmNdRrJLQ7EzMk BJZEbIzc1xNw4qwwgtaHcn6RxEMc8b8SYXC477pMBEjKBGR+FzUDCbzj1dGkpDHpE/uG wvAg== X-Gm-Message-State: AOJu0Yz4AT/nzQhG+IQlURmcX8g88kfjoGXxEoedx8qRJ0hXl87wXoBs scJcsbDR2fC9YL05MwtOfANBvRtiiHTKNg4gUkUljwQVumhvQhyhvxGoAYQRfSnorQjwcKBWn41 4jq180g== X-Received: by 2002:a05:6000:9:b0:33d:5484:e451 with SMTP id h9-20020a056000000900b0033d5484e451mr4186713wrx.34.1708938907158; Mon, 26 Feb 2024 01:15:07 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:06 -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 03/12] plugins: implement inline operation relative to cpu_index Date: Mon, 26 Feb 2024 13:14:35 +0400 Message-ID: <20240226091446.479436-4-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::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42f.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 Instead of working on a fixed memory location, allow to address it based on cpu_index, an element size and a given offset. Result address: ptr + offset + cpu_index * element_size. With this, we can target a member in a struct array from a base pointer. Current semantic is not modified, thus inline operation still targets always the same memory location. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- plugins/plugin.h | 2 +- accel/tcg/plugin-gen.c | 69 ++++++++++++++++++++++++++++++++++-------- plugins/api.c | 3 +- plugins/core.c | 12 +++++--- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/plugins/plugin.h b/plugins/plugin.h index 043c740067d..3bf1aaf5c2d 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -99,7 +99,7 @@ void plugin_register_vcpu_mem_cb(GArray **arr, enum qemu_plugin_mem_rw rw, void *udata); -void exec_inline_op(struct qemu_plugin_dyn_cb *cb); +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index); int plugin_num_vcpus(void); diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index ac6b52b9ec9..0f8be53d394 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -133,16 +133,28 @@ static void gen_empty_udata_cb_no_rwg(void) */ static void gen_empty_inline_cb(void) { + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); + TCGv_ptr cpu_index_as_ptr = tcg_temp_ebb_new_ptr(); TCGv_i64 val = tcg_temp_ebb_new_i64(); TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); + tcg_gen_ld_i32(cpu_index, tcg_env, + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); + /* second operand will be replaced by immediate value */ + tcg_gen_mul_i32(cpu_index, cpu_index, cpu_index); + tcg_gen_ext_i32_ptr(cpu_index_as_ptr, cpu_index); + tcg_gen_movi_ptr(ptr, 0); + tcg_gen_add_ptr(ptr, ptr, cpu_index_as_ptr); tcg_gen_ld_i64(val, ptr, 0); - /* pass an immediate != 0 so that it doesn't get optimized away */ - tcg_gen_addi_i64(val, val, 0xdeadface); + /* second operand will be replaced by immediate value */ + tcg_gen_add_i64(val, val, val); + tcg_gen_st_i64(val, ptr, 0); tcg_temp_free_ptr(ptr); tcg_temp_free_i64(val); + tcg_temp_free_ptr(cpu_index_as_ptr); + tcg_temp_free_i32(cpu_index); } static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info) @@ -290,12 +302,37 @@ static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr) return op; } +static TCGOp *copy_ld_i32(TCGOp **begin_op, TCGOp *op) +{ + return copy_op(begin_op, op, INDEX_op_ld_i32); +} + +static TCGOp *copy_ext_i32_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + op = copy_op(begin_op, op, INDEX_op_mov_i32); + } else { + op = copy_op(begin_op, op, INDEX_op_ext_i32_i64); + } + return op; +} + +static TCGOp *copy_add_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + op = copy_op(begin_op, op, INDEX_op_add_i32); + } else { + op = copy_op(begin_op, op, INDEX_op_add_i64); + } + return op; +} + static TCGOp *copy_ld_i64(TCGOp **begin_op, TCGOp *op) { if (TCG_TARGET_REG_BITS == 32) { /* 2x ld_i32 */ - op = copy_op(begin_op, op, INDEX_op_ld_i32); - op = copy_op(begin_op, op, INDEX_op_ld_i32); + op = copy_ld_i32(begin_op, op); + op = copy_ld_i32(begin_op, op); } else { /* ld_i64 */ op = copy_op(begin_op, op, INDEX_op_ld_i64); @@ -331,6 +368,13 @@ static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op, uint64_t v) return op; } +static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) +{ + op = copy_op(begin_op, op, INDEX_op_mul_i32); + op->args[2] = tcgv_i32_arg(tcg_constant_i32(v)); + return op; +} + static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) { if (UINTPTR_MAX == UINT32_MAX) { @@ -396,18 +440,17 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - /* const_ptr */ - op = copy_const_ptr(&begin_op, op, cb->userp); - - /* ld_i64 */ + char *ptr = cb->userp; + size_t elem_size = 0; + size_t offset = 0; + op = copy_ld_i32(&begin_op, op); + op = copy_mul_i32(&begin_op, op, elem_size); + op = copy_ext_i32_ptr(&begin_op, op); + op = copy_const_ptr(&begin_op, op, ptr + offset); + op = copy_add_ptr(&begin_op, op); op = copy_ld_i64(&begin_op, op); - - /* add_i64 */ op = copy_add_i64(&begin_op, op, cb->inline_insn.imm); - - /* st_i64 */ op = copy_st_i64(&begin_op, op); - return op; } diff --git a/plugins/api.c b/plugins/api.c index 579fe4a6e54..af4b98a1127 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -106,7 +106,8 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, void *ptr, uint64_t imm) { if (!tb->mem_only) { - plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], 0, op, ptr, imm); + plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], + 0, op, ptr, imm); } } diff --git a/plugins/core.c b/plugins/core.c index 12ec6911d5e..e3ec68ec286 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -317,7 +317,8 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) void plugin_register_inline_op(GArray **arr, enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, + enum qemu_plugin_op op, + void *ptr, uint64_t imm) { struct qemu_plugin_dyn_cb *dyn_cb; @@ -473,9 +474,12 @@ void qemu_plugin_flush_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); } -void exec_inline_op(struct qemu_plugin_dyn_cb *cb) +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - uint64_t *val = cb->userp; + char *ptr = cb->userp; + size_t elem_size = 0; + size_t offset = 0; + uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) { case QEMU_PLUGIN_INLINE_ADD_U64: @@ -508,7 +512,7 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, vaddr, cb->userp); break; case PLUGIN_CB_INLINE: - exec_inline_op(cb); + exec_inline_op(cb, cpu->cpu_index); break; default: g_assert_not_reached(); From patchwork Mon Feb 26 09:14:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775841 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233719wrt; Mon, 26 Feb 2024 01:16:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWdF73gU+LNtGKqPQ44H9TDeQqhiqOzK31QjsrxHuEdl0Z8lMK5++s0EyVzLdBfC1ldypG0Dk+S9rOrHIbxFEjn X-Google-Smtp-Source: AGHT+IG5t9yBZ50uFegq1zfjDGy7VFwcBjxLwC0PspJKtQfJFU54BsM5Vfk7AxUiTD0aPKee9jF9 X-Received: by 2002:ae9:e515:0:b0:787:b846:4598 with SMTP id w21-20020ae9e515000000b00787b8464598mr7317405qkf.16.1708938959825; 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=EjGT/hFuSERGPSrD9RaFBQLmcnx7C2/FLSsBpSuyAAPlafn42W42sQeuiK0hLB37jR xkbPTx3HQfhsyBM8XG3FdbfiQ93whdQ4/rJjrhotEK0HM7EFNesuCoh7dk8fSYKqQau5 0YnBLc0jWgdOH5hKN20j3Ak5C1dG7q0TuQ3G2K+W2BeVYnCpv2zt7qDDwj84udu6DRTW Gt67GM7ClJ2QVJMMjxrwJ502M0E668jG0ITnuBv/UPjqyfLNntsgd4JuP2WV/EJYe4Uh MEHqmAXYkY4tIThv6ocRxKkqqCfvkf3728I+FHQ6CLclviTeUkp9y7vIHaBz2z1a1afd 6vww== 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=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=DFdt+kv7TwjtBsfaOBQK0Eio1nrg4vHlACFLNHpdG/gJF9+3/sOMkZqkcSUmviv1Xc VzHYvKoWgk2E6z1C23OVOQj5CY8EqlN1U9EhMF+vRIFf0/8ZACEhVLI40Z+GoonEyuw3 XquM9f5MvLYeSFR3cSwSZUg8VSX7aOgdwtRTIYu/63Wqe6jCdvULZOas5MAgJAM6jQib g2/RkS1A3x7WaUHizSeoq/ipxLhUkz5PyMHSdSwthbaraS0gi+AMHM4o9+QFiA8ynAIX K9Ufp3WQH2KUJtSo9WPIirBR1r3nO1sY4yW21Rp0cGk/a2+L8b6qrrI3Ein4wfGwqOCL Nrsg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ys/WGGmu"; 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 f7-20020a05620a408700b0078790ff4921si4758575qko.75.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="ys/WGGmu"; 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 1reX4z-0003vo-G6; Mon, 26 Feb 2024 04:15:21 -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 1reX4w-0003k7-Qq for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:19 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4t-0005A4-MG for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:18 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33de4d3483eso53632f8f.3 for ; Mon, 26 Feb 2024 01:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938911; x=1709543711; 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=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; b=ys/WGGmuWY6d0VjfauyQUy4IO6KlCYC65pvY6cUuH4nPRCxw+j7753Zw5knz0Zd5S0 mpsVcnT0UWeZmumcZ1qssxGDOdDPd8r2B79ID4gx1yPTKqiZAaF3IdR6oDOz6fnhjsJO HIDPmXZU+sKOaucLMVLqWD1UFxwe5BE2FKOdqEPfN/LAsLgqYilDSzR9VoUOaoDXwV89 SFKkRJaZRLQZeShJPRlneI1YZf5/zrwBXUYOWaAKVqvzIOcmvTCEV2TNDPzimTY+jZHG HLkMsVFjzhQoUdeGbdQRL1VSB4zAFVQ20cip5IMP+xoGo+xxA7pcG9kCczTG47wQKs1Q +LNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938911; x=1709543711; 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=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; b=ZIyJOtvXpXO8dJSLBkYjTd9Q4unkLikfn3ee+Xdx+13pYzVEsjpBnt3F5Xld2jNqzI MIowxATqxen7HmAouxdw3XJk1NJ4lP++tLi0Lh3xnJ/tvrTrUn2fHk9OHIWkOTZkKi5f NWTEXG61+QhLgsv8GL9nKVig4Aht6gwXwdhEaabLYP0GwsSh/bW/yNzg5DuryntZU2FV VDJx6U+jUi/redQ38jSE8WByjWCTDTqgEuV0JWzwxLLqjfV7xn5hkYPCJi5ZHwnhfTbQ v0ZoCx9SSZw2Lltca8nLr8v4eB4BPWrBRf2G3Ubl4v3mVdaYqH5nPUl3xRFBv6JhD3Jl 0ZGQ== X-Gm-Message-State: AOJu0YyWX663nK1lt7llu0AddhIbjbWXdCHyVfV1ygP3E0/GUuBpzYGh 8IWTTh0cpUnrkgwfSurYsqqIItKDGADl++Im9HDULcFJLFTCckqQt4dMCaqzS6vQgq+XWLXZL1+ aGzSHsw== X-Received: by 2002:adf:e546:0:b0:33d:6edc:99af with SMTP id z6-20020adfe546000000b0033d6edc99afmr4745593wrm.34.1708938911524; Mon, 26 Feb 2024 01:15:11 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:11 -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 04/12] plugins: add inline operation per vcpu Date: Mon, 26 Feb 2024 13:14:36 +0400 Message-ID: <20240226091446.479436-5-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::42d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42d.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 Extends API with three new functions: qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline_per_vcpu(). Those functions takes a qemu_plugin_u64 as input. This allows to have a thread-safe and type-safe version of inline operations. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/plugin.h | 1 + include/qemu/qemu-plugin.h | 51 +++++++++++++++++++++++++++++++++++- plugins/plugin.h | 6 +++++ accel/tcg/plugin-gen.c | 7 +++++ plugins/api.c | 37 +++++++++++++++++++++++++- plugins/core.c | 23 ++++++++++++++++ plugins/qemu-plugins.symbols | 3 +++ 7 files changed, 126 insertions(+), 2 deletions(-) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 53d80341a8c..378fea77b5f 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -92,6 +92,7 @@ struct qemu_plugin_dyn_cb { /* fields specific to each dyn_cb type go here */ union { struct { + qemu_plugin_u64 entry; enum qemu_plugin_op op; uint64_t imm; } inline_insn; diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 6442ab041be..7c33e2a5887 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -328,6 +328,22 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, enum qemu_plugin_op op, void *ptr, uint64_t imm); +/** + * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline op + * @tb: the opaque qemu_plugin_tb handle for the translation + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @entry: entry to run op + * @imm: the op data (e.g. 1) + * + * Insert an inline op on a given scoreboard entry. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + /** * qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -358,6 +374,22 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); +/** + * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inline op + * @insn: the opaque qemu_plugin_insn handle for an instruction + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @entry: entry to run op + * @imm: the op data (e.g. 1) + * + * Insert an inline op to every time an instruction executes. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + /** * qemu_plugin_tb_n_insns() - query helper for number of insns in TB * @tb: opaque handle to TB passed to callback @@ -583,7 +615,24 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); - +/** + * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem access + * @insn: handle for instruction to instrument + * @rw: apply to reads, writes or both + * @op: the op, of type qemu_plugin_op + * @entry: entry to run op + * @imm: immediate data for @op + * + * This registers a inline op every memory access generated by the + * instruction. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, diff --git a/plugins/plugin.h b/plugins/plugin.h index 3bf1aaf5c2d..f6fa10a0f56 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -73,6 +73,12 @@ void plugin_register_inline_op(GArray **arr, enum qemu_plugin_op op, void *ptr, uint64_t imm); +void plugin_register_inline_op_on_entry(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + void plugin_reset_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb, bool reset); diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 0f8be53d394..47e05ec6347 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -443,6 +443,13 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, char *ptr = cb->userp; size_t elem_size = 0; size_t offset = 0; + if (!ptr) { + /* use inline entry */ + ptr = cb->inline_insn.entry.score->data->data; + elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); + offset = cb->inline_insn.entry.offset; + } + op = copy_ld_i32(&begin_op, op); op = copy_mul_i32(&begin_op, op, elem_size); op = copy_ext_i32_ptr(&begin_op, op); diff --git a/plugins/api.c b/plugins/api.c index af4b98a1127..5fed50d9b09 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -111,6 +111,18 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, } } +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + if (!tb->mem_only) { + plugin_register_inline_op_on_entry( + &tb->cbs[PLUGIN_CB_INLINE], 0, op, entry, imm); + } +} + void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, qemu_plugin_vcpu_udata_cb_t cb, enum qemu_plugin_cb_flags flags, @@ -136,6 +148,18 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, } } +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + if (!insn->mem_only) { + plugin_register_inline_op_on_entry( + &insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], 0, op, entry, imm); + } +} + /* * We always plant memory instrumentation because they don't finalise until @@ -148,7 +172,7 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, void *udata) { plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], - cb, flags, rw, udata); + cb, flags, rw, udata); } void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, @@ -160,6 +184,17 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, rw, op, ptr, imm); } +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + plugin_register_inline_op_on_entry( + &insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], rw, op, entry, imm); +} + void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_tb_trans_cb_t cb) { diff --git a/plugins/core.c b/plugins/core.c index e3ec68ec286..4b428dc25b1 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -331,6 +331,23 @@ void plugin_register_inline_op(GArray **arr, dyn_cb->inline_insn.imm = imm; } +void plugin_register_inline_op_on_entry(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + struct qemu_plugin_dyn_cb *dyn_cb; + + dyn_cb = plugin_get_dyn_cb(arr); + dyn_cb->userp = NULL; + dyn_cb->type = PLUGIN_CB_INLINE; + dyn_cb->rw = rw; + dyn_cb->inline_insn.entry = entry; + dyn_cb->inline_insn.op = op; + dyn_cb->inline_insn.imm = imm; +} + void plugin_register_dyn_cb__udata(GArray **arr, qemu_plugin_vcpu_udata_cb_t cb, enum qemu_plugin_cb_flags flags, @@ -479,6 +496,12 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) char *ptr = cb->userp; size_t elem_size = 0; size_t offset = 0; + if (!ptr) { + /* use inline entry */ + ptr = cb->inline_insn.entry.score->data->data; + elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); + offset = cb->inline_insn.entry.offset; + } uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) { diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 6204453d0fd..0d8141b85f1 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -28,13 +28,16 @@ qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_insn_exec_cb; qemu_plugin_register_vcpu_insn_exec_inline; + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu; qemu_plugin_register_vcpu_mem_cb; qemu_plugin_register_vcpu_mem_inline; + qemu_plugin_register_vcpu_mem_inline_per_vcpu; qemu_plugin_register_vcpu_resume_cb; qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; qemu_plugin_scoreboard_free; From patchwork Mon Feb 26 09:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775846 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233999wrt; Mon, 26 Feb 2024 01:16:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUMtqQOtUuKbZtxAeLO9jo2ADjqCbrtIIgdNyC104cFqxRZBYdfpIWKSZ2vgHGiQ9yYw8226xIIhrRxiKxlqo9x X-Google-Smtp-Source: AGHT+IHoj7E3OSO7tpBD07bFKQK6TNyZwoSauIhlCa2TTJURB+K+AkNNYFeMF6ipRqNL2tdR2WVd X-Received: by 2002:ac8:5a06:0:b0:42e:8c42:e7ab with SMTP id n6-20020ac85a06000000b0042e8c42e7abmr682036qta.65.1708939010674; Mon, 26 Feb 2024 01:16:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708939010; cv=none; d=google.com; s=arc-20160816; b=v5yfbD5WlJMR5Zx8irBeHZ0lROX2sqpIt6shWrO+wppdTOhdfmTr1lyqM+XXAk8q7N tmzBvSLtUcXZyV2ORhmsRwvYCpDCyvivdcdIbQNCXmy6l+DAruiP2aH+A+XHQUhMiX5k mV2Yn/PXeA9fHM6fG2HfBbqpBBr7pCxAKUC8OILPviBUP9D4kbgFUU9febJ/BIM/wdKK QWd11zL+UahqGm0OTtobCFKkiFGboLncKPD2UYpyj/3j6D7/mr3hvqL8dOfZ7GGJLpYy znHGvvUvtY+svsRuSb2ibv7jZx3HyeHg4UsrZqX7XOPdpSSMZbk0gjYf6R+5VK5aeBia CwzQ== 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=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=GcSoPjyA4k1kJVRWlRk0InYc3S9Ke0YXIcr+ya+omi3MV8WPDdNhZET20Haw+kdekg CyupqOZH/e+PYCHgktWr7Iyi3+NW196KGl/MLK5S7v9CrZ00FpvUphlv8YOKAMqg4boS TEGbQ5EqyuqUBdtIBl8vmc8vvbNg0rdHPq5w+ft9fvxvxePdrwzgqVAZKQkpnUV/fsmE 623mtCQIsjX/YS8W9OdmXjMjnvhlT4fO9sXlWkX0DgKBtsmUKFUW1yUvQN2+w9dmLPj5 J5fkkuJFqimKj91lowwuSgA5aYx+cIxaGZExkxWiOO0x+HKdyVYbOoQNG0gCcJnBTbo0 Zpgg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uEBVZLct; 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 l25-20020a05620a211900b007873fa993e8si4640757qkl.619.2024.02.26.01.16.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:16:50 -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=uEBVZLct; 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 1reX52-0004Bg-Q6; Mon, 26 Feb 2024 04:15:24 -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 1reX4z-0003wG-Fm for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:21 -0500 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4x-0005Bb-97 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:21 -0500 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2d220e39907so47810931fa.1 for ; Mon, 26 Feb 2024 01:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938915; x=1709543715; 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=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=uEBVZLctK/CzRN7ZBB6J9ouzBGg1UzwYcXq+BCi+doGchBvz74GLcTq2PEbGs4c2RQ b+/n/t36j92FIMbEf7Q4h6JbZ1Be5ROJHZ6F4uWa70MWkMGCLwFU3d9zk6pfpNpRxeY1 CsfcmfTA8U/wthjFjSeIshnf2B4ew/BmIxpSoUHJjUN8BTOPuTnZPyGM62yQFYn9kaIq H8Pg93gqcThg+dI5zSTt56xFjTwM3KeZ4nFCYXfrfksNwYhOTDQQ0nojpmyM2e4UqxAu jumpfvnSSjLokX1cxizUred5CFKf3umORNzgUlRlEkg1yw+DoWhQMq1VZkczl2akWqCq XXnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938915; x=1709543715; 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=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=NPtGBj/vqDtd/TibiX9VBHA3D6H7gs4AsR8oT2ALQO5MRD3SELFCRZd+izarsyHXNM SlhGQ83eZMlQwrr2BOE9LjTISc6f5muGEb2MQfMwDcwIU7EFRYjUTrTxsq2p0TV3o48E OFEwg18iOoWzVnMzXRakvM2N62i6fZsWJwidwc6kkqtQ1Z+VM7I8AB/ZsOxajPLth7fb 5G8gMUmfgrqVTHiFep2gjuV7gsFc2O1ahdRM2ToNJkutKXZlMc1VmsI8EcJ4HaXjU0wF XP/YwKnx3Vawiwn3ZvqtWgr1jf8vQmQkK3JUKoakxKjEpvTSRYpzKs08tiAeXT5tBuiq hxZg== X-Gm-Message-State: AOJu0YywFU1ViBO/Bd+mEa0bINaobiJURjs8vx83yFpmT44/nt/KJOC4 Vu7zGgpvsI/wG5JBHyN6oKUlU91j5dpyriEPIrZMFlfMS/CpOEnDb35rM/LMhepyOGAKLTI7B5F sUf7bOg== X-Received: by 2002:a05:651c:2112:b0:2d2:892a:62 with SMTP id a18-20020a05651c211200b002d2892a0062mr2485405ljq.46.1708938914998; Mon, 26 Feb 2024 01:15:14 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:14 -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 05/12] tests/plugin: add test plugin for inline operations Date: Mon, 26 Feb 2024 13:14:37 +0400 Message-ID: <20240226091446.479436-6-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::22a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22a.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 For now, it simply performs instruction, bb and mem count, and ensure that inline vs callback versions have the same result. Later, we'll extend it when new inline operations are added. Use existing plugins to test everything works is a bit cumbersome, as different events are treated in different plugins. Thus, this new one. Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- tests/plugin/inline.c | 186 +++++++++++++++++++++++++++++++++++++++ tests/plugin/meson.build | 2 +- 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/inline.c diff --git a/tests/plugin/inline.c b/tests/plugin/inline.c new file mode 100644 index 00000000000..0163e9b51c5 --- /dev/null +++ b/tests/plugin/inline.c @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2023, Pierrick Bouvier + * + * Demonstrates and tests usage of inline ops. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include + +#include + +typedef struct { + uint64_t count_tb; + uint64_t count_tb_inline; + uint64_t count_insn; + uint64_t count_insn_inline; + uint64_t count_mem; + uint64_t count_mem_inline; +} CPUCount; + +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 count_tb; +static qemu_plugin_u64 count_tb_inline; +static qemu_plugin_u64 count_insn; +static qemu_plugin_u64 count_insn_inline; +static qemu_plugin_u64 count_mem; +static qemu_plugin_u64 count_mem_inline; + +static uint64_t global_count_tb; +static uint64_t global_count_insn; +static uint64_t global_count_mem; +static unsigned int max_cpu_index; +static GMutex tb_lock; +static GMutex insn_lock; +static GMutex mem_lock; + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +static void stats_insn(void) +{ + const uint64_t expected = global_count_insn; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_insn); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_insn_inline); + printf("insn: %" PRIu64 "\n", expected); + printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void stats_tb(void) +{ + const uint64_t expected = global_count_tb; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_tb); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_tb_inline); + printf("tb: %" PRIu64 "\n", expected); + printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void stats_mem(void) +{ + const uint64_t expected = global_count_mem; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_mem); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_mem_inline); + printf("mem: %" PRIu64 "\n", expected); + printf("mem: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + const unsigned int num_cpus = qemu_plugin_num_vcpus(); + g_assert(num_cpus == max_cpu_index + 1); + + for (int i = 0; i < num_cpus ; ++i) { + const uint64_t tb = qemu_plugin_u64_get(count_tb, i); + const uint64_t tb_inline = qemu_plugin_u64_get(count_tb_inline, i); + const uint64_t insn = qemu_plugin_u64_get(count_insn, i); + const uint64_t insn_inline = qemu_plugin_u64_get(count_insn_inline, i); + const uint64_t mem = qemu_plugin_u64_get(count_mem, i); + const uint64_t mem_inline = qemu_plugin_u64_get(count_mem_inline, i); + printf("cpu %d: tb (%" PRIu64 ", %" PRIu64 ") | " + "insn (%" PRIu64 ", %" PRIu64 ") | " + "mem (%" PRIu64 ", %" PRIu64 ")" + "\n", + i, tb, tb_inline, insn, insn_inline, mem, mem_inline); + g_assert(tb == tb_inline); + g_assert(insn == insn_inline); + g_assert(mem == mem_inline); + } + + stats_tb(); + stats_insn(); + stats_mem(); + + qemu_plugin_scoreboard_free(counts); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + qemu_plugin_u64_add(count_tb, cpu_index, 1); + g_mutex_lock(&tb_lock); + max_cpu_index = MAX(max_cpu_index, cpu_index); + global_count_tb++; + g_mutex_unlock(&tb_lock); +} + +static void vcpu_insn_exec(unsigned int cpu_index, void *udata) +{ + qemu_plugin_u64_add(count_insn, cpu_index, 1); + g_mutex_lock(&insn_lock); + global_count_insn++; + g_mutex_unlock(&insn_lock); +} + +static void vcpu_mem_access(unsigned int cpu_index, + qemu_plugin_meminfo_t info, + uint64_t vaddr, + void *userdata) +{ + qemu_plugin_u64_add(count_mem, cpu_index, 1); + g_mutex_lock(&mem_lock); + global_count_mem++; + g_mutex_unlock(&mem_lock); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + qemu_plugin_register_vcpu_tb_exec_cb( + tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, count_tb_inline, 1); + + for (int idx = 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, idx); + qemu_plugin_register_vcpu_insn_exec_cb( + insn, vcpu_insn_exec, QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, count_insn_inline, 1); + qemu_plugin_register_vcpu_mem_cb(insn, &vcpu_mem_access, + QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_MEM_RW, 0); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, QEMU_PLUGIN_MEM_RW, + QEMU_PLUGIN_INLINE_ADD_U64, + count_mem_inline, 1); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + count_tb = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb); + count_insn = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn); + count_mem = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_mem); + count_tb_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb_inline); + count_insn_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn_inline); + count_mem_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_mem_inline); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/tests/plugin/meson.build b/tests/plugin/meson.build index e18183aaeda..9eece5bab51 100644 --- a/tests/plugin/meson.build +++ b/tests/plugin/meson.build @@ -1,6 +1,6 @@ t = [] if get_option('plugins') - foreach i : ['bb', 'empty', 'insn', 'mem', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall'] if host_os == 'windows' t += shared_module(i, files(i + '.c') + '../../contrib/plugins/win32_linker.c', include_directories: '../../include/qemu', From patchwork Mon Feb 26 09:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775849 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp234188wrt; Mon, 26 Feb 2024 01:17:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhbEFPUvH7Ws4LpzxGtt/8jmbh1HxJVNm5mFmsmghGhSGZuFiQQLeNXOR+Xxoa097qQMXlHxDcQ6TbqShaCwkz X-Google-Smtp-Source: AGHT+IHUQxaYK+Zs7Yb1qz3J0qgw/HOEC7ipvrt8Szw7fIkFokGa/zzujxTw6J7K0LMBRp174d5v X-Received: by 2002:a1f:df04:0:b0:4c0:6406:ee62 with SMTP id w4-20020a1fdf04000000b004c06406ee62mr2915451vkg.13.1708939042758; Mon, 26 Feb 2024 01:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708939042; cv=none; d=google.com; s=arc-20160816; b=CHZJlYKbgvll7w1F4Dc/e35IIhizq16qi12Yvo3Fpa7tiYY2J9lJxr+RhOXgQxxcC+ p569e+p1LRj3DuK1sk4CTpRlVUfwQmH7NRQP7Y3to4WQ5jmjrLfeDyoijSRHKVizChQj TgQ7U8zmmwFeJGESWyO0asSRK9AuJU0bUjPPgWQoSoZuQ7LI0jRDbSnEo9K3XhoU6I2x 4MxlQ9L+4vxmPlHsba/FNDLLu/ecyVFpQO75I7f0Lfj4Rp6/d3iAiobLzLAeknhcQEsV as4ihoW8Kxn7lZBp0B7toxBeF9ynQXgdkOsMXnXpz+d2/NnVf6iwayaua3SCOAdgV69b 9wIg== 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=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=zXXUejlc38FbHIsLhTbdrmtpAjALFi7aKWOgx33pJ3PFCn74yxIsc2B5gmpbjBcJaO dansnLw7Hc//w0ALbNyl4qXNO7RGYsUhEYmLlFgFcLsH/l/J9UXzewU1y/oiLvfk8+Iu 9bnKIJH2LE6DgQ5GVZXnPNZ+AMwvmhBTpNw+cWe5xFQBtsrLqKSEKhkEDUE01jVfJKHk 5nFxb9sNOejQTC9nle9g/X2uCQOHVkUcm/GWaA5RQKUBf+kPaP9ukb4zE2WSE3+S6lyh EHPrR+Q1NPxFN32Fala3ej1/y/94Tugxjj1WyDv3EbfHKBvb3sr7jeSHeF7jKTrWWWFv 1lVQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UG4prCl3; 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 gw4-20020a0562140f0400b0068fb764232bsi4664577qvb.224.2024.02.26.01.17.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:17:22 -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=UG4prCl3; 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 1reX55-0004IH-6R; Mon, 26 Feb 2024 04:15:27 -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 1reX50-00040J-Bg for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:22 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4y-0005Bs-KS for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:22 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33d6f26ff33so1989923f8f.0 for ; Mon, 26 Feb 2024 01:15:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938918; x=1709543718; 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=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; b=UG4prCl3ubyr7SIGfLItQxpg+qmenGLWDqjU5fDxkKUpunNvFm08isf4FlYo16mZWN BKvYZQzoqdugS6aKAkkTML4pRjYv4FqRUuaGula25Z1XLy1/b9UPP561+OjJNRnQxEYm I8+LUc4xdge/4m3o14kUD4SKgUvjeOWkLNeamlWiy0tjKvjR9nC4D42/vYiFkVm9KNKI Y/I3au7yEoxX9dFUf0yBzwlHWYmQMUgSd0M7u1YVbTby0CTOUG8Pzo3Rr7eB/qUM/+Kj 9hDDmOxhjHIZp9/tiqkaow4m+LXw7MqVa2WX3xmT0Z5wk6AR45FdOaP1yr7uNF1vuhcw p4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938918; x=1709543718; 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=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; b=EeI3ENsoGL3DDFog4hFpi/gxZjpsCgzsfsmmxCFma1DBG4w9cTDcTD0s2sOC+UK/1V o1SKFVMzeMjC8x3OchsfxrlZbJy7bZcTz7qcznlXIH2JaSxInlPXeqo+/O25zXnUeM04 J5K7RanNwF5vUSoDLwFi7g6IWhWW2a5b6AspOeyxNcDUFyBilGTAMYG7LScCNYdz/Nir QLyrD8B89JRqV3mzVRMT083RihPJBQVVohZ6o54hGjOwInHTMoUdX7FIsojIrBPP6sUq yN0agDXVY19qbor1pVWCyS4KF9dvcYhOblHzq3kl5nyXJWVDtsJusURrxe8d+t6hLzeX Mk3A== X-Gm-Message-State: AOJu0YzXSs47Oj5KlcKuf3Dv4pbVgPxOk1JKdSV4U9oBTZdCSbiQyBkZ Yleazfium5fYURGs1ysXIixgV0nXAt4InTK6hRypJsmQj6VQ4lr5iYEWQocy8TyrP/nK5J5oKkE I95OXxg== X-Received: by 2002:a5d:4a88:0:b0:33d:4fca:a47f with SMTP id o8-20020a5d4a88000000b0033d4fcaa47fmr5084130wrq.18.1708938918435; Mon, 26 Feb 2024 01:15:18 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:18 -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 06/12] tests/plugin/mem: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:38 +0400 Message-ID: <20240226091446.479436-7-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::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x430.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Luc Michel --- tests/plugin/mem.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..d4729f5e015 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,9 +16,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t inline_mem_count; -static uint64_t cb_mem_count; -static uint64_t io_count; +typedef struct { + uint64_t mem_count; + uint64_t io_count; +} CPUCount; + +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 mem_count; +static qemu_plugin_u64 io_count; static bool do_inline, do_callback; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; @@ -27,16 +32,16 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out = g_string_new(""); - if (do_inline) { - g_string_printf(out, "inline mem accesses: %" PRIu64 "\n", inline_mem_count); - } - if (do_callback) { - g_string_append_printf(out, "callback mem accesses: %" PRIu64 "\n", cb_mem_count); + if (do_inline || do_callback) { + g_string_printf(out, "mem accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(mem_count)); } if (do_haddr) { - g_string_append_printf(out, "io accesses: %" PRIu64 "\n", io_count); + g_string_append_printf(out, "io accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(io_count)); } qemu_plugin_outs(out->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, @@ -46,12 +51,12 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, struct qemu_plugin_hwaddr *hwaddr; hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); if (qemu_plugin_hwaddr_is_io(hwaddr)) { - io_count++; + qemu_plugin_u64_add(io_count, cpu_index, 1); } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } @@ -64,9 +69,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); if (do_inline) { - qemu_plugin_register_vcpu_mem_inline(insn, rw, - QEMU_PLUGIN_INLINE_ADD_U64, - &inline_mem_count, 1); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, rw, + QEMU_PLUGIN_INLINE_ADD_U64, + mem_count, 1); } if (do_callback) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, @@ -117,6 +123,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + mem_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, mem_count); + io_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, io_count); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0; From patchwork Mon Feb 26 09:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775848 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp234129wrt; Mon, 26 Feb 2024 01:17:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUIh6iSZXOtgvv1fkNAjz2EB+svRfrYVUxJfNFi8iBUCK9pYQUBTVUq4TeJO5W+BYtPYrNA7XC5jViXasYdgSm9 X-Google-Smtp-Source: AGHT+IHQB5NizDmp9EUb/lRpsU9FKcxNB9iEos+PKZxMeNRnaU9/k6H/Tc4tdyYlcKlxq0f1DP8k X-Received: by 2002:ac8:7d49:0:b0:42e:2955:4645 with SMTP id h9-20020ac87d49000000b0042e29554645mr8047256qtb.21.1708939033293; Mon, 26 Feb 2024 01:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708939033; cv=none; d=google.com; s=arc-20160816; b=pQ8OUkyW03oJ8Vn6Hx4WD29iLkIKOMgbHv1geNGOg1I1fCVjnNFYTgoJ58uuImst6Z nl3PU+/hxVBWEcl0iqJCaMsdOhl2jp1HrWkWLbAXmjxaGnMfEFc8y4cgrTjOVUYEs/QV rwMLmdRfeqFi00jOk8MErtNUMRmWkUt3IgtJovflVNV/REGWVlkVwJwt7wHkW0sHKTn1 z7gpnKbGBcw7ywb7XGmGK5O7kxhArtYrLPatY2PrMwh2aqTqOBx8KVPKp9BzKTTN1TTv TvsA4YW4RKx1cr8It55ZMzzJuAg+MxuxLyrbs9jBZssGBzcZLU184CooUbMlZju3MTBV 0c0g== 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=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=HJFLJTuORiRPwNtOjPF+MlYdSEnm4B700LlVMdT4x89K6mJuwCHzlYt+kkTvM0k4sY q+wkr2bmo1u5MD6sfDqHFi0cEa1GZ4rkbZhv3FkegM2jmYmzuozBUtWT1qc5kUKw3ahb rlDdG+Pl0skaXb7+0x9NlcHPr6c4iK2Gq1pH7y5hG2zaGETm8GTowYB4hYlFSt91Z0es h41swQBMOZwvfrk1GELArFSV9FYZPcAScJQmnL9h+EkbMyB62Cwyvbth5tcwRPHyeZWh fELIRT8GwqLOJ2i6L/N2Uu390AiDzjAU5kXMbpYxeQ/Y0REnUcqEWnOXXv8PUixgBMgg oiNQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nx27Wjxp; 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 j24-20020ac85518000000b0042e6e3730a2si4456922qtq.221.2024.02.26.01.17.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:17:13 -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=Nx27Wjxp; 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 1reX55-0004I8-3i; Mon, 26 Feb 2024 04:15:27 -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 1reX53-0004EZ-LO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:25 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX51-0005CT-NO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:25 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33d8739ddd4so2256325f8f.2 for ; Mon, 26 Feb 2024 01:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938922; x=1709543722; 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=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; b=Nx27Wjxpe9DyaWO++l0nRjR8hbNxD5P+EB7iVFL/3/xngfScU5nA62Pt6PqL2X3eVP ZFY6Y2ICYs8Qetj9FsjQOifMxS9e1MVJpNxMQtXvLszHE92kyXGOl9n+grFSCSLhKW+i hQp98qjSIL+bAf5ow8TA47X2jvQutGNPruOUwbWXtG5L82G79quVcWKRT+NIuVuVUVUb TIGiXjN+S3IUYoBM78TGC3WWWwAQMeR69NNlRlfNuO/i7boD/idIEZaCoMPAwg4ivvZu iXRiM6v1E2hRBHwgDi8Lnf7spEN392R9zbriKOrcYhaqXVLfXcP6okx/uZ2fkKt+2Kw1 QgAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938922; x=1709543722; 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=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; b=fF5b/CdLcA4BZj9VJXd6c0zmAER7Ysmnk4MzRLscPYEVxClc089uuyPtCVs+4ScRLi wX1zS4P72WNCgyDN9Q6zvPd0FlPMrM2dBbA7uvSdy8igYfSC7lR5fw8Xdwn2xNpNKf2I nSGjstD7IPyG3nkaFzAjJxjJfftXLkHa1KhELovyXV9ni7+WGoCzS0Kc9Tnk1i8I9QgL 7KP/8LDqLIcXN2eNzRnRmQNEbPg396lXT3KBwNxixp2AiL0Bnn5lX+yklNWK/5y1fK95 ii39m57RKD37bt3yIELt3hKGZQQae3FLn5+CXvo/5YtzA/Q3qbnj7kRKuelKJ8AeTyT5 RtcQ== X-Gm-Message-State: AOJu0YyxyBBSoRGP9+4PATO71ND55GyBtwTxFWUCmkcb0JXvHAsKXFM/ 3ODTtpW+SqctSE9WLaAauUmNB1VkNeRKPXWzgU2GdnX1dc8gyP+AoW4mnvmR4UMgYVDWAuMac50 n4FBd7Q== X-Received: by 2002:a5d:6346:0:b0:33b:302:c08 with SMTP id b6-20020a5d6346000000b0033b03020c08mr4182825wrw.43.1708938921887; Mon, 26 Feb 2024 01:15:21 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:21 -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 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:39 +0400 Message-ID: <20240226091446.479436-8-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::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x436.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Luc Michel --- tests/plugin/insn.c | 106 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 54da06fcf26..5e0aa03223e 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,25 +16,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -#define MAX_CPUS 8 /* lets not go nuts */ - -typedef struct { - uint64_t insn_count; -} InstructionCount; - -static InstructionCount counts[MAX_CPUS]; -static uint64_t inline_insn_count; +static qemu_plugin_u64 insn_count; static bool do_inline; static bool do_size; static GArray *sizes; +typedef struct { + uint64_t hits; + uint64_t last_hit; + uint64_t total_delta; +} MatchCount; + typedef struct { char *match_string; - uint64_t hits[MAX_CPUS]; - uint64_t last_hit[MAX_CPUS]; - uint64_t total_delta[MAX_CPUS]; - GPtrArray *history[MAX_CPUS]; + struct qemu_plugin_scoreboard *counts; /* MatchCount */ } Match; static GArray *matches; @@ -67,41 +63,40 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; - InstructionCount *c = &counts[i]; - - c->insn_count++; + qemu_plugin_u64_add(insn_count, cpu_index, 1); } static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; Instruction *insn = (Instruction *) udata; - Match *match = insn->match; + Match *insn_match = insn->match; + MatchCount *match = qemu_plugin_scoreboard_find(insn_match->counts, + cpu_index); + g_autoptr(GString) ts = g_string_new(""); insn->hits++; g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits", insn->vaddr, insn->disas, insn->hits); - uint64_t icount = counts[i].insn_count; - uint64_t delta = icount - match->last_hit[i]; + uint64_t icount = qemu_plugin_u64_get(insn_count, cpu_index); + uint64_t delta = icount - match->last_hit; - match->hits[i]++; - match->total_delta[i] += delta; + match->hits++; + match->total_delta += delta; g_string_append_printf(ts, - ", %"PRId64" match hits, " - "Δ+%"PRId64 " since last match," + " , cpu %u," + " %"PRId64" match hits," + " Δ+%"PRId64 " since last match," " %"PRId64 " avg insns/match\n", - match->hits[i], delta, - match->total_delta[i] / match->hits[i]); + cpu_index, + match->hits, delta, + match->total_delta / match->hits); - match->last_hit[i] = icount; + match->last_hit = icount; qemu_plugin_outs(ts->str); - - g_ptr_array_add(match->history[i], insn); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -113,8 +108,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1); } else { uint64_t vaddr = qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -136,10 +131,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) * information about the instruction which we also need to * save if there is a hit. */ - if (matches) { + if (matches->len) { char *insn_disas = qemu_plugin_insn_disas(insn); - int j; - for (j = 0; j < matches->len; j++) { + for (int j = 0; j < matches->len; j++) { Match *m = &g_array_index(matches, Match, j); if (g_str_has_prefix(insn_disas, m->match_string)) { Instruction *rec = g_new0(Instruction, 1); @@ -169,36 +163,33 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "len %d bytes: %ld insns\n", i, *cnt); } } - } else if (do_inline) { - g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_count); } else { - uint64_t total_insns = 0; - for (i = 0; i < MAX_CPUS; i++) { - InstructionCount *c = &counts[i]; - if (c->insn_count) { - g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", - i, c->insn_count); - total_insns += c->insn_count; - } + for (i = 0; i < qemu_plugin_num_vcpus(); i++) { + g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", + i, qemu_plugin_u64_get(insn_count, i)); } g_string_append_printf(out, "total insns: %" PRIu64 "\n", - total_insns); + qemu_plugin_u64_sum(insn_count)); } qemu_plugin_outs(out->str); + + qemu_plugin_scoreboard_free(insn_count.score); + for (i = 0; i < matches->len; ++i) { + Match *m = &g_array_index(matches, Match, i); + g_free(m->match_string); + qemu_plugin_scoreboard_free(m->counts); + } + g_array_free(matches, TRUE); + g_array_free(sizes, TRUE); } /* Add a match to the array of matches */ static void parse_match(char *match) { - Match new_match = { .match_string = match }; - int i; - for (i = 0; i < MAX_CPUS; i++) { - new_match.history[i] = g_ptr_array_new(); - } - if (!matches) { - matches = g_array_new(false, true, sizeof(Match)); - } + Match new_match = { + .match_string = g_strdup(match), + .counts = qemu_plugin_scoreboard_new(sizeof(MatchCount)) }; g_array_append_val(matches, new_match); } @@ -206,6 +197,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { + matches = g_array_new(false, true, sizeof(Match)); + /* null terminated so 0 is not a special case */ + sizes = g_array_new(true, true, sizeof(unsigned long)); + for (int i = 0; i < argc; i++) { char *opt = argv[i]; g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); @@ -227,9 +222,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (do_size) { - sizes = g_array_new(true, true, sizeof(unsigned long)); - } + insn_count = qemu_plugin_scoreboard_u64( + qemu_plugin_scoreboard_new(sizeof(uint64_t))); /* Register init, translation block and exit callbacks */ qemu_plugin_register_vcpu_init_cb(id, vcpu_init); From patchwork Mon Feb 26 09:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775847 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp234119wrt; Mon, 26 Feb 2024 01:17:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWFz8wDYNIqowA61HXeDTCTohX7MYCe3VASvxLQdoeKqQdGnTpLQG2WTk/X5dxmQ/wHPukh2NUVV5WSbPXs6w09 X-Google-Smtp-Source: AGHT+IGCgRouNS/NuQtOusKDTVNVsWUeGm8YI7eKEDRYssJC7VV9nMJ1Yg1zL2ZVP6nLHOAbgaa8 X-Received: by 2002:a05:6214:3d0d:b0:68f:f9a8:45e2 with SMTP id ol13-20020a0562143d0d00b0068ff9a845e2mr7044808qvb.24.1708939032558; Mon, 26 Feb 2024 01:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708939032; cv=none; d=google.com; s=arc-20160816; b=QVccBw56WIq+0iveRp88P0ZmjqEM1ZCr1ARERlnnzmBwvD/n/eSVM7YLYPwbtXafIM mJAL8vB05JONzas26obhXgn99zaQnlv9yq8AN6NgqaSTTK6luKRGOc28l23kAUBBgLeH hrTGceDVR9oIqaT9U0HuCaRZZwIKrIZhq1ivD38NUWwW40ygLG4pPdkfVXISbCkXcRht YuWEehhh8iJFpYluqWCLvt85ymeVCybkGass5M4Y/iAPmnVSLEP9a0kVGRAMggyEVx6q 3gmRY7JYQgfkLCuvN8MNvN0SwcAILa0m45eVeZ/AMGn9WX0KYJDmuQRXpF+oIIhtEfD8 pztw== 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=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=G9dI1oiv+gUCuWKuBeoXs01Ts1GylJr7OeiRK7XokqTle6gR+RM+Gfw7w216LW5ZlR Yg5fUVUevyoTiSjIQfs1kbIbD761CUxiAPkQV/QEsQIzUlx6CItUzaTXMfDaJCBjcQxn bPTw29tJOl2yAHhhLUK/NW/jRBR7YGLlJOl6CVG2OHKuO+2mZS4C/3n+Dypd0lwEn3Hp zLZFTanxi5nVgXoWw+UxkbiFEkN8UeeSLiNq1iZLWvdDZh9npCuGUE4WKKRoE3RxlwPC 1YxVrN//wwpIdKN8RJMR+dwgtZ6/Yk4z6BjBWY3Bw/FAh7gPn7pAXjwEV2fkMuuFyPpy vQyg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C6bPY0mk; 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 gg5-20020a056214252500b0068ed5f45265si4728801qvb.475.2024.02.26.01.17.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:17:12 -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=C6bPY0mk; 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 1reX5A-0004LA-9Z; Mon, 26 Feb 2024 04:15:32 -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 1reX57-0004KH-Au for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:29 -0500 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX55-0005DC-Ld for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:29 -0500 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2d21a68dd3bso37996661fa.1 for ; Mon, 26 Feb 2024 01:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938925; x=1709543725; 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=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; b=C6bPY0mkiSMBrJ/QRKxCECQiF36DK6zJg2ufLh4BH7tFAEo6n2Xure9AnQfEaUk3Bw sg6gaphAZOFu7nowS88kX2PubG/sgqq+id7oO61PNjRWlSraX40hvtS2yGchGfVYgWPQ S+48WcROCPefo4C7NzhVGD7vvZFMkvXFuGzSQRJFb2TkHZpa65h+WzmAXInItWPBzaBl 9ZTry/T+C8WqNxqe7FRXOiaKrv4pR5Cq85AOEVKzfaBmFoSF7oOij+45mm8+hM0r7rlo zwsxdsziHwN7VdjufvtVJWh/lnLAhWmGO++WtiZpnwQVcqKWEgsmKBpYY9NvAvDstiKA pu6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938925; x=1709543725; 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=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; b=SVoLrDR1sbgprSQWlh42hsLazTYQJUCbzKq7iUAteYxBpSCv6PDhrjgQREr3jMeSge oWuS2piOXIQKW4ChPzDhrI6fjgLRELLhCMl7+AGQ7vWW03rJu6QE6zBh9e8DxjZP/nm7 I8JByH1IxrQW/yjEwcQFZrHjSActc9yxUUcrmVouyLxdij+SdqQTKNkyG1Z/cSngq5cl thwOwtvGNH9KMLniXrnQ3ZYd3sqnkgk30nMAxFGA8G32MT4p0U9/bjKfvKF/TzzNJkgt fjc/IP9MnZUdUirtX/47IldJcL+eb0/YhOEr5Nr7sstVZbjsP/mWYgL707oOIpc8YEXJ RZcg== X-Gm-Message-State: AOJu0YzYnkQXYaZkDHeF/9OMpUmeGJ+JfphUgO+Yg5dsonm0x3INny4T tIAeeeqSjwr1Js8M9s/XVl8hVlq5594vdjVUeqaLeid3Bcdl2H1s8/bnGEkGJwtyfFnMD3Pd+FI 0dYZ5jw== X-Received: by 2002:a2e:b170:0:b0:2d2:4cb2:59e4 with SMTP id a16-20020a2eb170000000b002d24cb259e4mr3894689ljm.31.1708938925534; Mon, 26 Feb 2024 01:15:25 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:25 -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 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:40 +0400 Message-ID: <20240226091446.479436-9-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::236; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x236.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Luc Michel Reviewed-by: Alex Bennée --- tests/plugin/bb.c | 63 +++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index df50d1fd3bc..36776dee1e1 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -17,27 +17,25 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; typedef struct { - GMutex lock; - int index; uint64_t bb_count; uint64_t insn_count; } CPUCount; -/* Used by the inline & linux-user counts */ +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 bb_count; +static qemu_plugin_u64 insn_count; + static bool do_inline; -static CPUCount inline_count; - /* Dump running CPU total on idle? */ static bool idle_report; -static GPtrArray *counts; -static int max_cpus; -static void gen_one_cpu_report(CPUCount *count, GString *report) +static void gen_one_cpu_report(CPUCount *count, GString *report, + unsigned int cpu_index) { if (count->bb_count) { g_string_append_printf(report, "CPU%d: " "bb's: %" PRIu64", insns: %" PRIu64 "\n", - count->index, + cpu_index, count->bb_count, count->insn_count); } } @@ -46,20 +44,23 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new(""); - if (do_inline || !max_cpus) { - g_string_printf(report, "bb's: %" PRIu64", insns: %" PRIu64 "\n", - inline_count.bb_count, inline_count.insn_count); - } else { - g_ptr_array_foreach(counts, (GFunc) gen_one_cpu_report, report); + for (int i = 0; i < qemu_plugin_num_vcpus(); ++i) { + CPUCount *count = qemu_plugin_scoreboard_find(counts, i); + gen_one_cpu_report(count, report, i); } + g_string_append_printf(report, "Total: " + "bb's: %" PRIu64", insns: %" PRIu64 "\n", + qemu_plugin_u64_sum(bb_count), + qemu_plugin_u64_sum(insn_count)); qemu_plugin_outs(report->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count = g_ptr_array_index(counts, cpu_index); + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); g_autoptr(GString) report = g_string_new(""); - gen_one_cpu_report(count, report); + gen_one_cpu_report(count, report, cpu_index); if (report->len > 0) { g_string_prepend(report, "Idling "); @@ -69,14 +70,11 @@ static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - CPUCount *count = max_cpus ? - g_ptr_array_index(counts, cpu_index) : &inline_count; + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); uintptr_t n_insns = (uintptr_t)udata; - g_mutex_lock(&count->lock); count->insn_count += n_insns; count->bb_count++; - g_mutex_unlock(&count->lock); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -84,11 +82,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t n_insns = qemu_plugin_tb_n_insns(tb); if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.bb_count, 1); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.insn_count, - n_insns); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, bb_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, n_insns); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -121,18 +118,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (info->system_emulation && !do_inline) { - max_cpus = info->system.max_vcpus; - counts = g_ptr_array_new(); - for (i = 0; i < max_cpus; i++) { - CPUCount *count = g_new0(CPUCount, 1); - g_mutex_init(&count->lock); - count->index = i; - g_ptr_array_add(counts, count); - } - } else if (!do_inline) { - g_mutex_init(&inline_count.lock); - } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + bb_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, bb_count); + insn_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, insn_count); if (idle_report) { qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle); From patchwork Mon Feb 26 09:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775844 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233911wrt; Mon, 26 Feb 2024 01:16:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVcPka3Aa8mZpfRknOKdx0fO4B1DC/107kvaZ4FTG92JTzRzD75TqdJtHfBbjS60xeVnx3KcyVGEOocrUObR6ng X-Google-Smtp-Source: AGHT+IHcLwwotjXEnZdBIoqkt4fvT6wS71Ez7kt2slC84smAuBQAjRDW0+dG3y69zZx2iH00HZyo X-Received: by 2002:a05:620a:2993:b0:787:da49:28f5 with SMTP id r19-20020a05620a299300b00787da4928f5mr567908qkp.57.1708938991485; Mon, 26 Feb 2024 01:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708938991; cv=none; d=google.com; s=arc-20160816; b=RRh/cxciPkrjblx/Ahw0g4q+NKTYxivLB1D21GBOPgrISzg01CEAYR3jOIYkl02Ezz 4LA/7OCJTAif/50nQSsn1Ik8DmvCl2wKIYO/DgDlT5C3sDzsus+WQptsZycW/9aH1UO+ Wxsyyb9HZ6/876u/Qo3Q5xLTMGUcvhmelQ4GbH7z6Xdla0GJmTqR/GQY2wjGzNw6xpAH 44ONbcrTI0sSjtLZsw2I4GatqmMmj7Q2ZYYXNOL/dWiYO6WBfpbTRenzUxEYjZ2Lyulu Me4qoCX3h4zIqVZJ+vyGvKA5XLVPQ7ALOoxFiZIejoNebhpqJzTBnewuT/ZnbPvFqRQv wr9Q== 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=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=h85+NISpyjWtToSCk3io4gwaw591SPyt/IusHtdEfoppsp+jC6GbByNZBQTjcTHNEz +ycRQpCQBYCmik811LuOhZAukYk/A5u/zPatn5wcVtB7n52dSLQMauS7+94DvNkIQoz5 oUvy6f2qZab26jxlyXZNXmDV/72TFD0POqumfC4hrkshLG08WbCsKIkwnXJQbpXn9KBM LFdm09FRKVu4awUSbl7WSEb8wC6yvWxiusFMXgA8DUNGUKI1BfvZurl12THFO4LP1gYd s9trABCYyk5+54hayg7Xs5chCCgkLn+wBDgirbiHdWFu8Rc2cffCFlrmJafBskhLoBWz 8++g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cCw1Pwfu; 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 p21-20020a05620a113500b007871b8aed2fsi4543537qkk.715.2024.02.26.01.16.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:16:31 -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=cCw1Pwfu; 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 1reX5L-0004W5-63; Mon, 26 Feb 2024 04:15:43 -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 1reX5I-0004UY-2h for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:40 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5B-0005DP-Sz for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:38 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33dcd8dec88so654874f8f.1 for ; Mon, 26 Feb 2024 01:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938929; x=1709543729; 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=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=cCw1Pwfud3hGF7uAydYs7LOsTS3aDpX0i52AGLlShFBhbT03nSFErBRjvD5r5v/QZC cajN/S0lzidbexwWA3yJ77haRhJhaDvmM1BY5nVZctUwMAX8LXM1h5kinKak9LQoEguj fLbTaDdHyxl6OqTZi7m4LPGmL8mmxSYSawGEKZqUjRqS/l8x/AaVWdUXGiDOvBvJBS0h tjL36otWM5W3LFmCoQv1/i/O4Zi0YhePY5VEl1+XHUyAddOleYm7Bq8E6bpitbkO2Z30 oWaKjMXaBJ9nfJ62kMrB8UnwASTiZEpUsD9osumbJfCgZByptg4z2dD5VHLuITlQ+ACF cxyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938929; x=1709543729; 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=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=KkqtCF2GqhD8yesP+T0/SQbOiTTkUnkYMAGLcs+HYoY5BH7NmQJ7YRMjtIzL5fNuLF 61T2fLaWfgf+aAso7blxKekOaJjpxHoxmcD0jAFWwG5Zx3sfFwTgAEseq7KH2D5Rq715 x2yL8u2IyFizmvnYXpUbV/lbAmrvriwFK+AImUznQODwhRjzeS7f1tL9oOeI/D3bv6Fw /Kn+9K9IC2/WhXeUBn613fFiRFr/TWUj1KwUoSrAyyE4WANKZBotfByydcVDy8rUIrjb eQw/c4377sG8BseFM8aWlez8RyM/OwZHC1Nilb0AYwEwF+F4ML4d5Ow9Vzu0ljHdqCT/ QXNQ== X-Gm-Message-State: AOJu0Yzagtja7hOuxiRvsuhFYcDSgNuTC4B1RRuBD/NT6L0/SQwCz1FH JnvilhzT3Z8QKR8lbRAzCoWnLjE/wCEf3PjM+94RrnOxP9XtAuTCqsigJ+cSDp2gdomhlr3epXg PEHcFpA== X-Received: by 2002:a05:6000:1243:b0:33d:b32a:8acb with SMTP id j3-20020a056000124300b0033db32a8acbmr4350659wrx.23.1708938929000; Mon, 26 Feb 2024 01:15:29 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:28 -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 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:41 +0400 Message-ID: <20240226091446.479436-10-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::429; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x429.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 Signed-off-by: Pierrick Bouvier --- contrib/plugins/hotblocks.c | 50 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 4de1b134944..02bc5078bdd 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -34,8 +34,8 @@ static guint64 limit = 20; */ typedef struct { uint64_t start_addr; - uint64_t exec_count; - int trans_count; + struct qemu_plugin_scoreboard *exec_count; + int trans_count; unsigned long insns; } ExecCount; @@ -43,7 +43,17 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { ExecCount *ea = (ExecCount *) a; ExecCount *eb = (ExecCount *) b; - return ea->exec_count > eb->exec_count ? -1 : 1; + uint64_t count_a = + qemu_plugin_u64_sum(qemu_plugin_scoreboard_u64(ea->exec_count)); + uint64_t count_b = + qemu_plugin_u64_sum(qemu_plugin_scoreboard_u64(eb->exec_count)); + return count_a > count_b ? -1 : 1; +} + +static void exec_count_free(gpointer key, gpointer value, gpointer user_data) +{ + ExecCount *cnt = value; + qemu_plugin_scoreboard_free(cnt->exec_count); } static void plugin_exit(qemu_plugin_id_t id, void *p) @@ -52,7 +62,6 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) GList *counts, *it; int i; - g_mutex_lock(&lock); g_string_append_printf(report, "%d entries in the hash table\n", g_hash_table_size(hotblocks)); counts = g_hash_table_get_values(hotblocks); @@ -63,16 +72,21 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) for (i = 0; i < limit && it->next; i++, it = it->next) { ExecCount *rec = (ExecCount *) it->data; - g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", - rec->start_addr, rec->trans_count, - rec->insns, rec->exec_count); + g_string_append_printf( + report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", + rec->start_addr, rec->trans_count, + rec->insns, + qemu_plugin_u64_sum( + qemu_plugin_scoreboard_u64(rec->exec_count))); } g_list_free(it); } - g_mutex_unlock(&lock); qemu_plugin_outs(report->str); + + g_hash_table_foreach(hotblocks, exec_count_free, NULL); + g_hash_table_destroy(hotblocks); } static void plugin_init(void) @@ -82,15 +96,9 @@ static void plugin_init(void) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - ExecCount *cnt; - uint64_t hash = (uint64_t) udata; - - g_mutex_lock(&lock); - cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); - /* should always succeed */ - g_assert(cnt); - cnt->exec_count++; - g_mutex_unlock(&lock); + ExecCount *cnt = (ExecCount *)udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(cnt->exec_count), + cpu_index, 1); } /* @@ -114,18 +122,20 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) cnt->start_addr = pc; cnt->trans_count = 1; cnt->insns = insns; + cnt->exec_count = qemu_plugin_scoreboard_new(sizeof(uint64_t)); g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt); } g_mutex_unlock(&lock); if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &cnt->exec_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + qemu_plugin_scoreboard_u64(cnt->exec_count), 1); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, - (void *)hash); + (void *)cnt); } } From patchwork Mon Feb 26 09:14:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775839 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233720wrt; Mon, 26 Feb 2024 01:16:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW1VSf7qBwUa27mYrrbxrniLz6PMn7RjB2fOWNCKlEVTabFxJ2HNsmhpOBcc7FeB3FphMy3j7vSU0kumtZVw3vM X-Google-Smtp-Source: AGHT+IFgL4soNXyF5tGZrqvktj8EkJtXzKGL5TzWFvZ1gnZc77Rk1jJgpd9KjcsVoIYlca9hwZa8 X-Received: by 2002:ac8:7f0d:0:b0:42e:8e2a:4e18 with SMTP id f13-20020ac87f0d000000b0042e8e2a4e18mr580119qtk.17.1708938959837; 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=B9l3pyDe9NDt0SU1cEOpFFLm4XfuMXNRDblJTw2212cKVLQFEXdUKIDFxBRIhL5vY4 29EMv0Bvuw8E75BwP1HJpVcUFngn+0AHPAVXhrK1xCwck02Rn/cwgQSsW3eiTH8x8UXB HnZsClwH62cv8taskE2ilStKLTitOaviDKYYCRlgGP6qYE/lZDrOnZJhFQJN8nltcITW isPATbUmSulKRNrey6ul8qcfimqPUhM6Z8kgYMaKzmv9DdVszlbOhnz6jbVQ8v+6rIi3 hSOPjcgEA8+d0tAOwPua5kIunINedif4LBEvBlpULAHqXOwPTCaXe/YVKuOL6KAraaCz O9Rg== 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=VrrxeNLA6gdIIRboBxDqxtycrixqBs+uk7TOLQzL5/zbHurOiNQUsxTaToxoM+1Mf9 5trM+fIZjgi7iIhJFYgF1EY/BiUS0ErMnQ0mrXTIddTg2YgZg6SZKaWgHpH8BxzHufTO K43WkkRvJVYJcufRzvMXzF4MwRastS/x0AoOCCR56jN/z6Yx9swimobatN0gQsVWTn2Y Q4NANyfAotDVLjQPhcoGTfSySDjM4frVfMP0NQu7dN8tygzPAqZlvX6FJQbC/Q0ZQdic oER8mBKyFEayJ06SiELpSVShKo4lw7gcWdDu/J8HNidc/0LXSTipnQyeM63wlMjhf653 KIRw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jCTjBQJ6; 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 i7-20020ac84887000000b0042e5a313367si4571309qtq.175.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=jCTjBQJ6; 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 1reX5O-0004Xv-V0; Mon, 26 Feb 2024 04:15:47 -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 1reX5M-0004X7-NU for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5E-0005DR-HK for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-412a3eba4dcso6888865e9.2 for ; Mon, 26 Feb 2024 01:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938932; x=1709543732; 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=jCTjBQJ6Wg9S1DSraCK8f0/d2+vml46XQpWGRHOQL24uBK3JiOD66mZDV7/RcOPNB3 NjX68+9k9ri6X3eqzc//Cd09ZQ+7K5Yy3wJp3RuAYl36GNmtopfr4WpeIMC5U43NztF3 UijLtzvL7wKFSYcBI4+BpVgK+ZidofOynfyJaRFg0Cp0bwwroJd0nyCQas0Q1zRmuETC HD2RnJY0KYbwsjQzfyn0q8OG7Ox8Rb/GkJSrt9CDWo6za3/5PyU7W9WvK5HnraanIoLw Xh1LdFdTVxRckItbkWD5lrRuRcTepaduo/OBb2BZHEAAERxxR2FyUd7/Rz17ZRN77r1w vm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938932; x=1709543732; 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=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=ahmlYvaSXVrZfy+/gFuYEPPZanOy2iJ7j4GIaYS1SjZWLgZdFVpe5Y++zhJOK5GY4N 8yyOZ2YQE/5NaMUAyUXphloa/TADHdIBXJlSoOB6GVDWlmclDJGB5ZBXH+YLbx1YLZns bKNbeSN6/MriOnX/5Y9ZMB07cxq9E/0PvGSg/rF4qLVyK90HoPbNkbq4eDCzyW50rDe6 a4iLkrUvOhoJbKCSItNzk8rIHEi4QxOuM6/ImQdW04BSkhVmICrm/mTVaSJ/7sv+U+g6 ZSBdV4uoWERned1edm+/Zl4ZfrSHIUZVtN02f1Jrez+h3Hlr2ZmWRWnvgD309MrBL7R3 Fuzw== X-Gm-Message-State: AOJu0Yx8ob/H/bdHmjiK8OiHnAB6aF2A7iH7CUZGyKqko7UohXs0BEaD WYoAC0fQEuH7FMWzU9F+ynJjTIR7veHYW4PWq2520yXYH8vwKfDAQbXJADAcxiXD1c043GsXd7W ymkqQLA== X-Received: by 2002:a05:600c:41c2:b0:412:9018:74ca with SMTP id t2-20020a05600c41c200b00412901874camr5016399wmh.35.1708938932471; Mon, 26 Feb 2024 01:15:32 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:32 -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 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:42 +0400 Message-ID: <20240226091446.479436-11-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::335; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x335.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=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 Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Bennée Tested-by: Alex Bennée Reviewed-by: Alex Bennée --- contrib/plugins/howvec.c | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..2d10c87e0fb 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -43,13 +43,13 @@ typedef struct { uint32_t mask; uint32_t pattern; CountType what; - uint64_t count; + qemu_plugin_u64 count; } InsnClassExecCount; typedef struct { char *insn; uint32_t opcode; - uint64_t count; + qemu_plugin_u64 count; InsnClassExecCount *class; } InsnExecCount; @@ -159,7 +159,9 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { InsnExecCount *ea = (InsnExecCount *) a; InsnExecCount *eb = (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + uint64_t count_a = qemu_plugin_u64_sum(ea->count); + uint64_t count_b = qemu_plugin_u64_sum(eb->count); + return count_a > count_b ? -1 : 1; } static void free_record(gpointer data) @@ -167,12 +169,14 @@ static void free_record(gpointer data) InsnExecCount *rec = (InsnExecCount *) data; g_free(rec->insn); g_free(rec); + qemu_plugin_scoreboard_free(rec->count.score); } static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new("Instruction Classes:\n"); int i; + uint64_t total_count; GList *counts; InsnClassExecCount *class = NULL; @@ -180,11 +184,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) class = &class_table[i]; switch (class->what) { case COUNT_CLASS: - if (class->count || verbose) { + total_count = qemu_plugin_u64_sum(class->count); + if (total_count || verbose) { g_string_append_printf(report, "Class: %-24s\t(%" PRId64 " hits)\n", class->class, - class->count); + total_count); } break; case COUNT_INDIVIDUAL: @@ -212,7 +217,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "Instr: %-24s\t(%" PRId64 " hits)" "\t(op=0x%08x/%s)\n", rec->insn, - rec->count, + qemu_plugin_u64_sum(rec->count), rec->opcode, rec->class ? rec->class->class : "un-categorised"); @@ -221,6 +226,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) } g_hash_table_destroy(insns); + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + qemu_plugin_scoreboard_free(class_tables[i].table[j].count.score); + } + } + qemu_plugin_outs(report->str); } @@ -232,11 +243,12 @@ static void plugin_init(void) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - uint64_t *count = (uint64_t *) udata; - (*count)++; + struct qemu_plugin_scoreboard *score = udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(score), cpu_index, 1); } -static uint64_t *find_counter(struct qemu_plugin_insn *insn) +static struct qemu_plugin_scoreboard *find_counter( + struct qemu_plugin_insn *insn) { int i; uint64_t *cnt = NULL; @@ -265,7 +277,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) case COUNT_NONE: return NULL; case COUNT_CLASS: - return &class->count; + return class->count.score; case COUNT_INDIVIDUAL: { InsnExecCount *icount; @@ -279,13 +291,16 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) icount->opcode = opcode; icount->insn = qemu_plugin_insn_disas(insn); icount->class = class; + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + icount->count = qemu_plugin_scoreboard_u64(score); g_hash_table_insert(insns, GUINT_TO_POINTER(opcode), (gpointer) icount); } g_mutex_unlock(&lock); - return &icount->count; + return icount->count.score; } default: g_assert_not_reached(); @@ -300,14 +315,14 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t i; for (i = 0; i < n; i++) { - uint64_t *cnt; struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); - cnt = find_counter(insn); + struct qemu_plugin_scoreboard *cnt = find_counter(insn); if (cnt) { if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + qemu_plugin_scoreboard_u64(cnt), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt); @@ -322,6 +337,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, { int i; + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + class_tables[i].table[j].count = qemu_plugin_scoreboard_u64(score); + } + } + /* Select a class table appropriate to the guest architecture */ for (i = 0; i < ARRAY_SIZE(class_tables); i++) { ClassSelector *entry = &class_tables[i]; From patchwork Mon Feb 26 09:14:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775845 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233990wrt; Mon, 26 Feb 2024 01:16:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWotMsm0pyy+VSHLBa2SuJ5w8+NTebwvzwagsdJ1gfbfq2CkmqcMjeI0DkA6vOZt9x2ejnRJuDmqk7czokJ2V8r X-Google-Smtp-Source: AGHT+IGGe0V8AioTL68BwKEmTLI8UCsRDeotfXCKDfzlB1PZ0DSvId8YdY1J99w1c4i9omTvD0pV X-Received: by 2002:a05:620a:51d3:b0:787:a9c0:f7f with SMTP id cx19-20020a05620a51d300b00787a9c00f7fmr6916472qkb.3.1708939009671; Mon, 26 Feb 2024 01:16:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708939009; cv=none; d=google.com; s=arc-20160816; b=kw6Z22rE7jWERlyCg3rJTC5wlijeUaNabW8skGe09tZQ8jPit5sEuP1SD+0RqnxNG4 FCJBmMQu0Uxs8rxQyDLwV32PNKLMsCZOrPvWDa2apXDkO2cmvxaEqQi2upY0rJXKLZtv AIs76t39i1dvJozFXnY9B4k6n4Dcwafa8vrexw7LLy3Q6m4mJBvQzS16y9+mHiqDYZCC 3Ejgpv4dMFEWqRD0GBWmTPpzozpiDLQgH36HtXHk4/2dzlnVQdX9S5Il3VQHsA6dij+8 AONBhZT6+uvA5IwQaFpWcX/vk1sJIzmtn6/51g9Sni5ypvupexizicvPvfvSshGJQ5lN afQQ== 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=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=PUqe5XZnV6KcURELZ7wqPjCuqruelgeVPKzFJzyvZboH6gn/gf0oHv83vFv1BPg61h j0EWnJItKawv1rgPxdWAxJ9woDQWQUFvbpnFR6cxIzVa38QypY/rq+cGOJMclfmcaQOV bGxX/TTJ5R0UTLlt08eDJXUfoqOMD+d18u61basAI5KrX0y2txbhQi11xDaHGuL9SPKj ychq8uqOIXX/EbyJIBArmD8OyU1x9y4WFcFBDgafSH4/vzJNOd6Gd1lNivSAQZULdWhc SuYrndl+u2Vk1vqDFgaV/pPtHq9ESCtOTkjg3jjygbrRdd0g3aVAVBeylZmZSq4X9Xgs +y1A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g9Utxd1l; 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 u8-20020a05620a454800b00787d6677545si891470qkp.79.2024.02.26.01.16.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:16:49 -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=g9Utxd1l; 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 1reX5N-0004XB-17; Mon, 26 Feb 2024 04:15:45 -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 1reX5K-0004WU-OI for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:42 -0500 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5I-0005DX-EI for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:42 -0500 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d204e102a9so33230521fa.0 for ; Mon, 26 Feb 2024 01:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938936; x=1709543736; 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=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; b=g9Utxd1lUFyfiIhCpMtPezXa2u7fmMyiNaKtd/Xwern8V8WJepDid8wFT1uya8/bVJ VTd+qzGQttML9Ahfcb3hBhi43ZL4RbTW885ZEDSEwRLHQkCj6oahwhPiIVXX/NiZOKBe 28ukjmkVmai5Mx9Zv+NmBxJUuThHum45kvkktlxfd3O4XU4CStisDzeRFJIadrFPK8x2 JhwWEzHU61rhRr/JCtBIQ6IoalfVC4U7QSGU6pIRBQVTGtCX4TQT6/irgZKU0PzNtqQQ RteIdpWUUxp6ChyadrzXk1Iq2YebPAymss/182qi1639I7dUmi3E8lYwmSflqXhlFQwi 00JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938936; x=1709543736; 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=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; b=CQlj68ASqgGqfcTVtWiK2OYIn0e0Wwo63fbMLrRcvvuAtKrbxI2e86FRX95jJ70Br8 5CjbPhBGaaKP4CEIyQgRm1BSN7LMqBSKgLFpSRCXGrl0X9p4yP0GPpETLeJZt+W2oFgb Z7PfG/BE+1kPH0+NqLsyG4/evRtvkvZbHWMJ5m/d8hq3UmeQ1dgEz928FvOFFfkqEf0x x9ibQqjiN9/DxZRVcsEO78fgVyH0V2c8whWJaPPTEMldDFj41bBXVyCARTbE2ykVQN92 238U57n0nCMsTXq9S33uk9XaLHiRMvgZR1UO3j5V31GO7oBe31lCnL+avovSlQYg6aW/ 6ilA== X-Gm-Message-State: AOJu0YzwA2xLngxF6ljFLUaLApVYJkk5xkAh/Z55wenRoxs/CnAQ0kwt 1orefDtEEbnbHYUl4PvrVyzhYq/1EDsZw3PoRcw2kb3PPRuffUOk8TryzKjBW1i4aCEMzstIpOb YOkGMUw== X-Received: by 2002:a05:651c:11cf:b0:2d2:2bd2:78e8 with SMTP id z15-20020a05651c11cf00b002d22bd278e8mr3125899ljo.47.1708938935937; Mon, 26 Feb 2024 01:15:35 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:35 -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 11/12] plugins: remove non per_vcpu inline operation from API Date: Mon, 26 Feb 2024 13:14:43 +0400 Message-ID: <20240226091446.479436-12-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::22b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22b.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 Now we have a thread-safe equivalent of inline operation, and that all plugins were changed to use it, there is no point to keep the old API. In more, it will help when we implement more functionality (conditional callbacks), as we can assume that we operate on a scoreboard. API version bump was already done as part of this series. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Bennée --- include/qemu/qemu-plugin.h | 58 ++++-------------------------------- plugins/api.c | 29 ------------------ plugins/qemu-plugins.symbols | 3 -- 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 7c33e2a5887..1044fa7b14f 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -52,7 +52,11 @@ typedef uint64_t qemu_plugin_id_t; * The plugins export the API they were built against by exposing the * symbol qemu_plugin_version which can be checked. * - * version 2: removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * version 2: + * - removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * - Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline. + * Those functions are replaced by *_per_vcpu variants, which guarantee + * thread-safety for operations. */ extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; @@ -309,25 +313,6 @@ enum qemu_plugin_op { QEMU_PLUGIN_INLINE_ADD_U64, }; -/** - * qemu_plugin_register_vcpu_tb_exec_inline() - execution inline op - * @tb: the opaque qemu_plugin_tb handle for the translation - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time a translated unit executes. - * Useful if you just want to increment a single counter somewhere in - * memory. - * - * Note: ops are not atomic so in multi-threaded/multi-smp situations - * you will get inexact results. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline op * @tb: the opaque qemu_plugin_tb handle for the translation @@ -359,21 +344,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, enum qemu_plugin_cb_flags flags, void *userdata); -/** - * qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op - * @insn: the opaque qemu_plugin_insn handle for an instruction - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time an instruction executes. Useful - * if you just want to increment a single counter somewhere in memory. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inline op * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -597,24 +567,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, void *userdata); -/** - * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any memory access - * @insn: handle for instruction to instrument - * @rw: apply to reads, writes or both - * @op: the op, of type qemu_plugin_op - * @ptr: pointer memory for the op - * @imm: immediate data for @op - * - * This registers a inline op every memory access generated by the - * instruction. This provides for a lightweight but not thread-safe - * way of counting the number of operations done. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm); - /** * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem access * @insn: handle for instruction to instrument diff --git a/plugins/api.c b/plugins/api.c index 5fed50d9b09..e0af3c4a9e3 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -101,16 +101,6 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, } } -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - if (!tb->mem_only) { - plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], - 0, op, ptr, imm); - } -} - void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( struct qemu_plugin_tb *tb, enum qemu_plugin_op op, @@ -138,16 +128,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, } } -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - if (!insn->mem_only) { - plugin_register_inline_op(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], - 0, op, ptr, imm); - } -} - void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_op op, @@ -175,15 +155,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, cb, flags, rw, udata); } -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm) -{ - plugin_register_inline_op(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], - rw, op, ptr, imm); -} - void qemu_plugin_register_vcpu_mem_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 0d8141b85f1..a9fac056c7f 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -27,16 +27,13 @@ qemu_plugin_register_vcpu_idle_cb; qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_insn_exec_cb; - qemu_plugin_register_vcpu_insn_exec_inline; qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu; qemu_plugin_register_vcpu_mem_cb; - qemu_plugin_register_vcpu_mem_inline; qemu_plugin_register_vcpu_mem_inline_per_vcpu; qemu_plugin_register_vcpu_resume_cb; qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_vcpu_tb_exec_cb; - qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; From patchwork Mon Feb 26 09:14:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 775843 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp233899wrt; Mon, 26 Feb 2024 01:16:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU3yjckaM4DxYW7fal/g23Mkvjhf7tF73W4m8k6kPb0f9LRTS1333aWb0s21YN+TWj75cqKpUXKCKYbJjYMr1Lu X-Google-Smtp-Source: AGHT+IGJh8SkbGRGmnuKLc6yPwIzd91U6pp7WLCSjaOILhmiZ5GqQ8oBkRPlI7XMe5hPm3gwRTl/ X-Received: by 2002:a05:6214:20a7:b0:68f:e35e:da68 with SMTP id 7-20020a05621420a700b0068fe35eda68mr9212141qvd.1.1708938989131; Mon, 26 Feb 2024 01:16:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708938989; cv=none; d=google.com; s=arc-20160816; b=Y6BYEeR/DXKEbIrj9517Y2D3q8iamWCVtSa1ToHy/keUPi5IZoSWvD/RmecF0eOtY5 c49S+OaQtOxCKKGA59QdSWrMzO/h49DxA64Ys+8uiBQyXWy1RFJZ1yzPCPlLFrI11bV0 YG61j1X5HltPvY1cYGk13xDP04aj8agNx9nP8DJpMhgRfm0V0V55Q79XwBENr6HJNawt 1CitvDmcoNzUaeqB7CwQNVp1JxNw8GV8VLvTNBLnaQ8WTMNqR2YJkFNxn2G8kY883owT QHCyvZZPBxkA8AT8J2lEFg6JeicsPg96isxYOXXkUU5pyTXiORtzEtaLWFkGrWAe9PiE dk9A== 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=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; fh=l9WWdDUrM2GgKqlI4LjrMx7cGq7hKMPQ4FaYC0/RjNA=; b=edkaQH49QzbnnOS6M1qK5iVWycwKcxUCNQLbOo/fcJM1roRGhxEyrhHg7Fa1ePx5gG XtA9//mdzkWFO20auTWDispymF3BaFecuHrX4JPV09C+cocn9HwgIbzO/Zf5/3o3uFTQ J/oBIvtdriJh5qg2BAqDgVE1RtiSQVtN26HpuKMPFQwj2sRP53abZ+Sata6e6x2SiX8a cVZrwKf0WT6Mso9wudDEQoIr1vtd+WTGMfcEDknxzSdGZhGvNmlQQZaHI8mUPkqYik1K 9CWu4MpR+yClXWlGYrBFQyHOq8UgYRy4KtcL3MrKhOnN9xypn9fKU1bIIyZ/HqUecydi Oxww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AVADNh4G; 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 jr2-20020a0562142a8200b0068fa4b5ec4asi4659438qvb.350.2024.02.26.01.16.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 01:16:29 -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=AVADNh4G; 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 1reX5S-0004c1-Pa; Mon, 26 Feb 2024 04:15:50 -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 1reX5R-0004bV-KC for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:49 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5J-0005Dj-D3 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:49 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33dcd8dec88so654933f8f.1 for ; Mon, 26 Feb 2024 01:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938939; x=1709543739; 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=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; b=AVADNh4GfA+Ax15dyNFHnDuxHBCYZcNjUgUfWZUvcFKytXa9VjOluygN2L+uN1vXVa 7/ZUec01JI0ErVCIxeeRD/PGwewZUHpDeVml8co1zD1UiV3uFj5KewSZwa5hQgZEdmCB AEQoSspNqumPUPBj6gNByNdDF59IiTcVk5EOh6OuSaE3e1NGd2X8kwRTFQgXB3DQrXYt 3eCYyU1lap8KtktBjKLKH8Cdb6oAc6XJNlVwRrgsTN9KVXrAquTud7LfMmYuCWc7AjwY +xfUy4QNGICJqmbpeKEfqUFhqsTPSMjW8rkx+ZYZS+qIutHnUDdIv1XKem2CwIZgtMyv /dwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938939; x=1709543739; 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=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; b=cUS/x1HaLlxXUQNuloVEmowgXoOkMJ9ZXP4wDr03JLIzeYA6LI2xzrQFRDRyG3Hyp4 iMnLts1YWckKhblt/8xpW76kbenO8js41EFkzXnYGIfN1pXzZAZ/gCsD7o/VV7BE55at u4FOfAR25pYb5HXmHemxLJwqMLJAQTJsxWJOywHl3OkqUGTqjFTABCeW9TabiEJ1t4FA pPQ6a8Yq3gM8bU5gLj+kHp1hBPBnc1TCb0zNSpgUKAiqaT0pqwAKHG7AAl/WRS5ninXj fTvAHf8e0wflCfHu00sHHT0G+q7QcM5Uqlh3LL3xkk0N80RY2i7G8mCbSyUf/FRX7FI3 k74w== X-Gm-Message-State: AOJu0Yzm64ZubbQVvBruHLcr5hIkmN6LDp6ozkaxHU+ZgSJRn3gQ814+ xKpPqCQS2BxltAzridv4dPEh8niNUATISzoelZTEEmHlOYKN3UEBA2a/+09cQTRmBugl80LIWYy yk93sfg== X-Received: by 2002:adf:e78f:0:b0:33d:38cf:aa76 with SMTP id n15-20020adfe78f000000b0033d38cfaa76mr4572454wrm.46.1708938939398; Mon, 26 Feb 2024 01:15:39 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:39 -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 12/12] plugins: cleanup codepath for previous inline operation Date: Mon, 26 Feb 2024 13:14:44 +0400 Message-ID: <20240226091446.479436-13-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::42b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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 Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Bennée --- plugins/plugin.h | 5 ----- accel/tcg/plugin-gen.c | 13 ++++--------- plugins/core.c | 29 ++++------------------------- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/plugins/plugin.h b/plugins/plugin.h index f6fa10a0f56..7c34f23cfcb 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -68,11 +68,6 @@ struct qemu_plugin_ctx { struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id); -void plugin_register_inline_op(GArray **arr, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm); - void plugin_register_inline_op_on_entry(GArray **arr, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 47e05ec6347..8028786c7bb 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -440,15 +440,10 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - char *ptr = cb->userp; - size_t elem_size = 0; - size_t offset = 0; - if (!ptr) { - /* use inline entry */ - ptr = cb->inline_insn.entry.score->data->data; - elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); - offset = cb->inline_insn.entry.offset; - } + char *ptr = cb->inline_insn.entry.score->data->data; + size_t elem_size = g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset = cb->inline_insn.entry.offset; op = copy_ld_i32(&begin_op, op); op = copy_mul_i32(&begin_op, op, elem_size); diff --git a/plugins/core.c b/plugins/core.c index 4b428dc25b1..c0f06d6bcf9 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -315,22 +315,6 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) return &g_array_index(cbs, struct qemu_plugin_dyn_cb, cbs->len - 1); } -void plugin_register_inline_op(GArray **arr, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, - void *ptr, - uint64_t imm) -{ - struct qemu_plugin_dyn_cb *dyn_cb; - - dyn_cb = plugin_get_dyn_cb(arr); - dyn_cb->userp = ptr; - dyn_cb->type = PLUGIN_CB_INLINE; - dyn_cb->rw = rw; - dyn_cb->inline_insn.op = op; - dyn_cb->inline_insn.imm = imm; -} - void plugin_register_inline_op_on_entry(GArray **arr, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, @@ -493,15 +477,10 @@ void qemu_plugin_flush_cb(void) void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - char *ptr = cb->userp; - size_t elem_size = 0; - size_t offset = 0; - if (!ptr) { - /* use inline entry */ - ptr = cb->inline_insn.entry.score->data->data; - elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); - offset = cb->inline_insn.entry.offset; - } + char *ptr = cb->inline_insn.entry.score->data->data; + size_t elem_size = g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset = cb->inline_insn.entry.offset; uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) {