From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184443; cv=none; d=zohomail.com; s=zohoarc; b=V6T7zN7+dYcDs2Z0HXgGqKPLlgRsQFHGH8bkcZcG6wvESpIdBIqsWA7FWGldMBP9066t6EHi9IG3Talf86265JMgpHeAjZJTtgbSkGbP0wW6vJV1Y9PEX1cOnPMqdjofk7hd9fEslw/55276N5GDIRYyPT4n1r5btnXHYzjbWA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184443; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; b=J021hpU++20ziO52z3AXhKy1UZeXaTyv7kCt/8GHHekE0v/hEd7ZwXJpxMrkx1yyug8W1SXrY+4ar5Meidk/Gr/yJSmNnsY5J0kGJycJIA+JdGMOq2wZZmD7znNXlTXHtxvZAVwYaoHXkhy4Satd3euVtrONrIDbqXN1sxq3oMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184443867911.9840748030579; Wed, 28 Feb 2024 21:27:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYv8-0002eZ-N5; Thu, 29 Feb 2024 00:25:26 -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 1rfYv6-0002cj-Gb for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:24 -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 1rfYv4-0005rg-Ho for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:24 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33d38c9ca5bso303110f8f.2 for ; Wed, 28 Feb 2024 21:25:22 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184321; x=1709789121; 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=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; b=aM4AupKPE3Lz3AHjVQc4CuZmji5LrVO133QVliC+/olyLz0URAwCvMLC45oVSUhRhG EZL68Oq80HOYMlgLNiYivaWl56kfR8rY+Det7jb6A6cOl41SXDpPztFXWS0Afe0XxxeB lAi2+1Jay/C2HrI1d/NKeolDGnwHvfYoV4Zxpxd3iLYCCdt74f69/2j8piHud3YhM8El rXnkW765ajHNA/mgICXGJMVh600UUKyef1qlXr/h+KmIjZLfkx0mBFUaxeTxMSRa5KsN 3uxvAQuy/1kZB757KL5d39GF3vNhirc97aoR7pCSjIc3uzEtIEVwEylBZmifPWmq+njm 70ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184321; x=1709789121; 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=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; b=utd3+TyQ6ywzl2vbjpeXzYocGEQtdgupMbDZrPHkkuoAezyP148jZmXWfYbXwlq9df QQ0VbTX9g3DwSKR68s5nFuPq+6mlH+L61F5YRH7LH5dZyRYXCRMtI1WLuTFEdLsybyYz 8M465FMGt3XZ/RwBp56nlME2QkFO/LRCyYinSPYcTdG9IyMYTW4VHfHwX5VWADyj5N20 OPSMFYp5ad6H73dqvnR07UTJ3jmNO53UPpaZsTugGaaBeGoLqE3+tpjNrggBZ6ZzxoG9 c4hPMRTYEpRqzz6uN++wYWhMWuR/mCxDF6QOEaOB4ra3dbEnxe8LBYlbD7fSBIljncjr Zejg== X-Gm-Message-State: AOJu0YwdTFrR5YlYOJV6oDxE7ts4TKVm8SjQCf/COEC1V5b9CYGy00dS U1ApsVCmHBpis/fyChup+afpPLkvZjPRiCiJXKPxX2QDG/QJxehO3hDE3HqW2ulPLxUkKQpYGOe +Pbw= X-Google-Smtp-Source: AGHT+IGiLOPsoUihocH0Hs++6nosIzklLnkRmxIJaYF4EEOHWRS9wDObe7NoLU7HTd8TKraaQkSWbA== X-Received: by 2002:a5d:4687:0:b0:33d:e6e:b5f6 with SMTP id u7-20020a5d4687000000b0033d0e6eb5f6mr571115wrq.27.1709184320876; Wed, 28 Feb 2024 21:25:20 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 01/12] plugins: scoreboard API Date: Thu, 29 Feb 2024 09:24:55 +0400 Message-ID: <20240229052506.933222-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184444543100005 Content-Type: text/plain; charset="utf-8" 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 b3c94a34aa4..bf96d2c2aa3 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -112,6 +112,12 @@ struct qemu_plugin_insn { bool mem_only; }; =20 +/* 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 45e2ebc8f8f..31c468ddb2c 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; =20 /** * enum qemu_plugin_cb_flags - type of callback @@ -752,5 +754,34 @@ QEMU_PLUGIN_API int qemu_plugin_read_register(struct qemu_plugin_register *handle, GByteArray *buf); =20 +/** + * 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_s= ize); + +/** + * 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. T= his + * 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); =20 #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); =20 int plugin_num_vcpus(void); =20 +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 81f43c9ce8a..f8b15510ff7 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -465,3 +465,22 @@ int qemu_plugin_read_register(struct qemu_plugin_regis= ter *reg, GByteArray *buf) =20 return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg)); } + +struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s= ize) +{ + 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 =3D 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 2db4d31354b..63f4c6c6ce3 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" @@ -215,6 +216,35 @@ CPUPluginState *qemu_plugin_create_vcpu_state(void) return g_new0(CPUPluginState, 1); } =20 +static void plugin_grow_scoreboards__locked(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.scoreboard_alloc_size) { + return; + } + + bool need_realloc =3D FALSE; + while (cpu->cpu_index >=3D plugin.scoreboard_alloc_size) { + plugin.scoreboard_alloc_size *=3D 2; + need_realloc =3D 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; @@ -225,6 +255,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu) success =3D 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); =20 plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT); @@ -578,6 +609,8 @@ static void __attribute__((__constructor__)) plugin_ini= t(void) qemu_rec_mutex_init(&plugin.lock); plugin.id_ht =3D g_hash_table_new(g_int64_hash, g_int64_equal); plugin.cpu_ht =3D g_hash_table_new(g_int_hash, g_int_equal); + QLIST_INIT(&plugin.scoreboards); + plugin.scoreboard_alloc_size =3D 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); @@ -588,3 +621,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 =3D + g_malloc0(sizeof(struct qemu_plugin_scoreboard)); + score->data =3D 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; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=zohomail.com; s=zohoarc; b=aZIjdewnySMFXNN4rSbuW2YLiTyFmqB+XEc4N61bDUftnVIs802EuwzncQrrT1tT0d1oOCRx9df8ITDdfNdY8O08iiuVLjRjqBUDjxzjHpg12ROjuUztd4DLx24wABR1i//f2OIE+QcG+IfpZRaCZDoFw2a7B47YJvjQBcg4iqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184376; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; b=ZP6oIHOhBUSxwHx8ZMFK8JDbK2EUuLHeh6kwkkERcb5qZSbSxPIVKF2102Ilcn/HSd5YM2HXld94AQVZWPYztJJr7HE6HCb7kL/On5nj0ZinNv0ZAdxWXi8iqnufNTfsgKKgfWDfMN6uuybBwrl3ysU1s+EsWu7eJED8lQlZWU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184376551234.9073948301692; Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvB-0002g0-Gp; Thu, 29 Feb 2024 00:25:29 -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 1rfYv9-0002fD-RG for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:27 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYv7-0005vH-U4 for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:27 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-412bf8262caso145325e9.3 for ; Wed, 28 Feb 2024 21:25:25 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184324; x=1709789124; 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=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; b=ZfelCL3yv+SSTTSccXNPFmCXWDfyVOHsZd592gx8pVjvwmsWYEv5vqpknrOYQtdWiO JVvB7rdhNrmyFWFOSiNYXUoCOJnAk/CWeTYAUM5Ti3latnPu2ub4hFEAYTel6qVERo5f F7WPBlfyT0uUfhhtiyAaaeHTdF536B/shyY3r5vev2WOLpZZ5FfNsA6Slwu2tCwlWNJG yVa/bNyKexX+G5HPN1D3JS3/R10VuXVn0dA927T0VIRUkyVyIpUCEwxEydOdNBzJSCQS XYoEvnN5bT+diSCiKT4ufz8yvd8Stq16bY7/l0lMKj8z+9fWJldjbmXM8vzBadF0wZ5f xqlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184324; x=1709789124; 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=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; b=CfgXZVUJItRMl2qqN1M2Zm7rZ3xoZ8v6jD2sXn7hlCy9bop9R8yKjpcejCuurpeMy8 7cVx52qY3nUa9Bi3etqOS3Mlk1+EyFWVVz/4ELKfjUH9k7uR57L+9k3ccwBuoItR7XqA U6KtzWdHs5u970qKtDvR0abPkKsRYxUiZ3pjSq8ANmYSUFNPdd7QDL7fU4qi+hR3Xqkw 5CnF5E5XSJI/gqAkv4ik62XO5tro/J3tmT55zo59rwY73CweCPurYYb9bzikYm3yPbiQ u8eI1utoyXV8NzYZLOdXXrB+uy2b5NaO6XbjJrWg3NbvfQN5NPln+pM+z8uanjYxCWXu /hww== X-Gm-Message-State: AOJu0YwNwaWE0KeoxHd4NkhrlhUnUW0FdqmrGKodLqGtyHSgWUibUMmW kr8nxWsPIFSIsu2yr1cQKcDf11Lajfx8GOsOEliXtiPBA4GsW7gZyN305q9KHkrktWRw+p54yQC zmbI= X-Google-Smtp-Source: AGHT+IEey+M+9XtaLT/n1eznCiBUc59+gTypwWZ2pGgz80fgtReQuVdsyDppgoJrynVqL/LbQTSifA== X-Received: by 2002:a5d:54cd:0:b0:33d:3ee3:cc11 with SMTP id x13-20020a5d54cd000000b0033d3ee3cc11mr505384wrv.47.1709184324337; Wed, 28 Feb 2024 21:25:24 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 02/12] plugins: define qemu_plugin_u64 Date: Thu, 29 Feb 2024 09:24:56 +0400 Message-ID: <20240229052506.933222-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184378665100009 Content-Type: text/plain; charset="utf-8" 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 31c468ddb2c..ebf9a645e15 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -225,6 +225,17 @@ struct qemu_plugin_insn; /** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ struct qemu_plugin_scoreboard; =20 +/** + * typedef qemu_plugin_u64 - uint64_t member of an entry in a scoreboard + * + * This field allows to access a specific uint64_t member in one given ent= ry, + * located at a specified offset. Inline operations expect this as entry. + */ +typedef struct { + struct qemu_plugin_scoreboard *score; + size_t offset; +} qemu_plugin_u64; + /** * enum qemu_plugin_cb_flags - type of callback * @@ -784,4 +795,45 @@ QEMU_PLUGIN_API void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, unsigned int vcpu_index); =20 +/* Macros to define a qemu_plugin_u64 */ +#define qemu_plugin_scoreboard_u64(score) \ + (qemu_plugin_u64) {score, 0} +#define qemu_plugin_scoreboard_u64_in_struct(score, type, member) \ + (qemu_plugin_u64) {score, offsetof(type, member)} + +/** + * qemu_plugin_u64_add() - add a value to a qemu_plugin_u64 for a given vc= pu + * @entry: entry to query + * @vcpu_index: entry index + * @added: value to add + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added); + +/** + * qemu_plugin_u64_get() - get value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, unsigned int vcpu_inde= x); + +/** + * qemu_plugin_u64_set() - set value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + * @val: new value + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val); + +/** + * qemu_plugin_u64_sum() - return sum of all vcpu entries in a scoreboard + * @entry: entry to sum + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index f8b15510ff7..f4518a68afe 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -484,3 +484,37 @@ void *qemu_plugin_scoreboard_find(struct qemu_plugin_s= coreboard *score, char *base_ptr =3D score->data->data; return base_ptr + vcpu_index * g_array_get_element_size(score->data); } + +static uint64_t *plugin_u64_address(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + char *ptr =3D qemu_plugin_scoreboard_find(entry.score, vcpu_index); + return (uint64_t *)(ptr + entry.offset); +} + +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added) +{ + *plugin_u64_address(entry, vcpu_index) +=3D added; +} + +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + return *plugin_u64_address(entry, vcpu_index); +} + +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val) +{ + *plugin_u64_address(entry, vcpu_index) =3D val; +} + +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) +{ + uint64_t total =3D 0; + for (int i =3D 0, n =3D qemu_plugin_num_vcpus(); i < n; ++i) { + total +=3D qemu_plugin_u64_get(entry, i); + } + return total; +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 3f93e7d6b13..6204453d0fd 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -44,6 +44,10 @@ qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr; + qemu_plugin_u64_add; + qemu_plugin_u64_get; + qemu_plugin_u64_set; + qemu_plugin_u64_sum; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; }; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=zohomail.com; s=zohoarc; b=Jv4MDLWU970exKoWk+rc8JZv3QK1h1SrHIzi2AK/aUX7GdJ2GhvTs9A9Jz1vWOAQTAl7avXRsY6mzUbo3QwIX4TT2PfsCuAq/Xf3cE3ptOpiFHvrn0+PeTVIpWyjjir9cqLfmS61dDf2kgzWXdUDVGirrpGZdCG9j6fWk7mp9yg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184376; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; b=OXUM1AUQLfkeKQR4WbMnZGGV4JchrwSW0FX1SzuutepAjsGb+CYXGIB+0WQaGWXvx78qCRF5DIc7i6XS/e7ZH88eN51ESSnazvdjapUectHg8iCBwSZ/49C+y34t5ApQOQE8Vda53ARbL/zQdlCI7apbHo5wm43IIgw0lXnC1eQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17091843762191013.7566571895616; Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvF-0002jP-8t; Thu, 29 Feb 2024 00:25:33 -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 1rfYvD-0002hk-Ou for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:31 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvB-0005vn-Sh for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:31 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33d90dfe73cso248573f8f.0 for ; Wed, 28 Feb 2024 21:25:29 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184328; x=1709789128; 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=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; b=SQbFbN2ejFrGMISEiSlZYxYAICpFptHynabDTxu2Kz7nJ67fqsLT1y+42J7uGGxhCe dTZ4WjgbHNNqvgtY4zVKx/4LkVP4xr0LKNt+QulgSu9sof1QyUFea5xGK1FK0mWnYd8P xG/I1TAEJyQnofI6yQwPPQKd22QGSFc0I2YlApVOnytABV627OM/lUMJVsu0IGGJ1Bgm IJiqm4TpJq4Rf6u6+WaTPKpksaDS4fEGK6g5NhFYikdoVkArETwso/fFJ6ZsiNjnwAhi uz5mi80WTgOowMbnRLDA9AfU1nZZ9Z8+zqLoZMNRsMeCQd92IH0yfSbiTY8BDJtGE2J6 6hnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184328; x=1709789128; 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=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; b=Dq10TCSIeAJrc5A5jVxksIA1J/CNo5x+stlofn94CI0//5XpweZzMWSvDMcivH+nSP WdQs5/oH/0oD+5TmFqu05a39JusmxfSaslAYn2Vqfm2hPxwSSFEQbT6Q5pOsYXQpy1O1 CxKnUgZUuCgA4JQZzq6HKBFlSG76USrBQaBpMMnfYrPtDKDDKokUjVb+HNfg9ddLgnns kAP7/qvY1l16o3lcEn/2cpi8ClIV+xozom3V0st8A4aY18ArNjLtbdLTp7JFntuY+ab+ 1cpU5EBSJtQrHWrjvXly7DDw0K3oU4LAlawsv4L5fkhAclyB7npLzo0O2PkA86jjfbMt FvWA== X-Gm-Message-State: AOJu0Yx/9yZyRydu0J/2EycpNYei2WJHGyCO/BwTy8mGhrMJ27D25J3L e1vHN+kzz3Sipmh3BKfCRY6/0pS3qmP/+P5gDbBhOYk0TdlCr3bdYNm46Z+LMhmr85AD8UUUOMx HIoo= X-Google-Smtp-Source: AGHT+IEeEa3tins4ySzqRR1XNYkXzCjtLgX0mwfx0rFm8gEznyaXTRU907eik4bOGdmyg3MuHKalgQ== X-Received: by 2002:adf:db51:0:b0:33d:eb13:9e27 with SMTP id f17-20020adfdb51000000b0033deb139e27mr698654wrj.23.1709184327756; Wed, 28 Feb 2024 21:25:27 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 03/12] plugins: implement inline operation relative to cpu_index Date: Thu, 29 Feb 2024 09:24:57 +0400 Message-ID: <20240229052506.933222-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184378666100010 Content-Type: text/plain; charset="utf-8" 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); =20 -void exec_inline_op(struct qemu_plugin_dyn_cb *cb); +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index); =20 int plugin_num_vcpus(void); =20 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 =3D tcg_temp_ebb_new_i32(); + TCGv_ptr cpu_index_as_ptr =3D tcg_temp_ebb_new_ptr(); TCGv_i64 val =3D tcg_temp_ebb_new_i64(); TCGv_ptr ptr =3D tcg_temp_ebb_new_ptr(); =20 + 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 !=3D 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); } =20 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; } =20 +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 =3D=3D UINT32_MAX) { + op =3D copy_op(begin_op, op, INDEX_op_mov_i32); + } else { + op =3D 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 =3D=3D UINT32_MAX) { + op =3D copy_op(begin_op, op, INDEX_op_add_i32); + } else { + op =3D 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 =3D=3D 32) { /* 2x ld_i32 */ - op =3D copy_op(begin_op, op, INDEX_op_ld_i32); - op =3D copy_op(begin_op, op, INDEX_op_ld_i32); + op =3D copy_ld_i32(begin_op, op); + op =3D copy_ld_i32(begin_op, op); } else { /* ld_i64 */ op =3D 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; } =20 +static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) +{ + op =3D copy_op(begin_op, op, INDEX_op_mul_i32); + op->args[2] =3D tcgv_i32_arg(tcg_constant_i32(v)); + return op; +} + static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) { if (UINTPTR_MAX =3D=3D UINT32_MAX) { @@ -396,18 +440,17 @@ static TCGOp *append_inline_cb(const struct qemu_plug= in_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - /* const_ptr */ - op =3D copy_const_ptr(&begin_op, op, cb->userp); - - /* ld_i64 */ + char *ptr =3D cb->userp; + size_t elem_size =3D 0; + size_t offset =3D 0; + op =3D copy_ld_i32(&begin_op, op); + op =3D copy_mul_i32(&begin_op, op, elem_size); + op =3D copy_ext_i32_ptr(&begin_op, op); + op =3D copy_const_ptr(&begin_op, op, ptr + offset); + op =3D copy_add_ptr(&begin_op, op); op =3D copy_ld_i64(&begin_op, op); - - /* add_i64 */ op =3D copy_add_i64(&begin_op, op, cb->inline_insn.imm); - - /* st_i64 */ op =3D copy_st_i64(&begin_op, op); - return op; } =20 diff --git a/plugins/api.c b/plugins/api.c index f4518a68afe..d8b461bc69c 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -106,7 +106,8 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qe= mu_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); } } =20 diff --git a/plugins/core.c b/plugins/core.c index 63f4c6c6ce3..65d5611f797 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -318,7 +318,8 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GAr= ray **arr) =20 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; @@ -474,9 +475,12 @@ void qemu_plugin_flush_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); } =20 -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 =3D cb->userp; + char *ptr =3D cb->userp; + size_t elem_size =3D 0; + size_t offset =3D 0; + uint64_t *val =3D (uint64_t *)(ptr + offset + cpu_index * elem_size); =20 switch (cb->inline_insn.op) { case QEMU_PLUGIN_INLINE_ADD_U64: @@ -509,7 +513,7 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t va= ddr, 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(); --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184389; cv=none; d=zohomail.com; s=zohoarc; b=f4cpshi9LXDU+t9VE8AIMjLYt/70kFJxT0Pxo314VwMr4HLBQ134WeMm527a/2N2tQqiYDiuC7doSGg7V8G4lWBKFxR5FumlD+uyWRwzr0m1MRGV+R4zzFPd4v5XXyZYB0jPRtxZ4OTnRvcnrUdF9bWArVxsGGd/SrrldBaxcdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184389; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; b=A8n+mRRcFzZw9SYuJZnoN358BE0PCFVSFrOM51CeNpPXXHivM+0+SbFzkIKOVavWpwK2tM5cNeLN10zRygj7T1bjgmo0qGlNbrTCundM2E5Y88WjEl1Wo56MWJXyZn+3XGqTNz6f0zxkibPt+13dZHcdVc4nmrQIJjM1Kw3SqYw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184389879853.6932451928519; Wed, 28 Feb 2024 21:26:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvM-0002lW-2l; Thu, 29 Feb 2024 00:25:40 -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 1rfYvH-0002kb-HA for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:36 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvF-0005wj-Fp for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:35 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-412b83cfac4so3286945e9.0 for ; Wed, 28 Feb 2024 21:25:33 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184331; x=1709789131; 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=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; b=hy8anaZ6vz/Scrs3Ul+tLGpm8MJXLCqpjxxOdtXKqLDxjTbCgmtSYQAZgOaGQ8sWhD CCYwsKFwEeqmK1T6iN9HDJ81vIWYRKFGUbktrOG7eTY6HpbEKW/J67On26wDKlVNfnHA oJGyd//X4w7H6IJftJCtmLX5V42gr2C5obeAeIXVitpxt+PIGVhk3hbij9JZEdRAPZ7f du5q03enIACcld+WDxpaPB+rbf0JKSB3HzWWST9BB/KtR3yfZ3Mi1+vhxB4CqbNxGxDs gcincsf27PwTK+addnqsuy7HMJ5gEv+rCI0hqdhCXRswY//C0AbfdzPVM5uWU3HtaRH1 FZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184331; x=1709789131; 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=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; b=kHkgh5gWTEzGpRSe7EWK1Z4znGoVbp7rBYLs79rLmKhdSGgJLUqmswukB8mMrHNe6R UltJmfw4200hUzCFNWLGdnqLlkp1ZOnnFYARvzHtm/Uf5/50oaqbu96bqOavc258t/JI 4SGZyJD5isvmcVRtdbFZzQIL6bQa39VfEL/RHieHQEKC9+nzk8ZozuMo98UnwcI/Q05l ZFJBbVjSR5Z8gyyXvHRM0yM8MDZ9Su1nRHuW9E3hQpvQwcqGa3HhW5Cr+bUVtPqjU/fI ZMKNMO9f3nsqOIp9FG4TzisoJ9OTClMISZbLtGv8zeeMO429k7findKYGXLLR13A5gZ8 /u5A== X-Gm-Message-State: AOJu0YyqsYGtoNejhJBUoFigjWCLVqa0ShZIAohe5cQOIOKALsT7J7cP wp94hlh0wCIXDVNNLax6hUPBh4G9SqDhvp6yT2MD//hN3PVC8MtQWXok1383JTzs2bmNdCD6Th/ uEbA= X-Google-Smtp-Source: AGHT+IEZiMtkRht2Yb81ezIBP/Wl/RKCYp8RNxx6L2Kjnhz+nbdDwme9HFANINwLbtL8Ece0A9JAjw== X-Received: by 2002:a05:6000:18a9:b0:33d:2d2c:f404 with SMTP id b9-20020a05600018a900b0033d2d2cf404mr754759wri.15.1709184331273; Wed, 28 Feb 2024 21:25:31 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 04/12] plugins: add inline operation per vcpu Date: Thu, 29 Feb 2024 09:24:58 +0400 Message-ID: <20240229052506.933222-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184390386100003 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=C3=A9e 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 bf96d2c2aa3..12a96cea2a4 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 ebf9a645e15..6bbad068c01 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 q= emu_plugin_tb *tb, enum qemu_plugin_op op, void *ptr, uint64_t imm); =20 +/** + * 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); =20 +/** + * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inlin= e 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 *pt= r, uint64_t imm); =20 - +/** + * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem acc= ess + * @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); =20 typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_in= dex, 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); =20 +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_plugi= n_dyn_cb *cb, char *ptr =3D cb->userp; size_t elem_size =3D 0; size_t offset =3D 0; + if (!ptr) { + /* use inline entry */ + ptr =3D cb->inline_insn.entry.score->data->data; + elem_size =3D g_array_get_element_size(cb->inline_insn.entry.score= ->data); + offset =3D cb->inline_insn.entry.offset; + } + op =3D copy_ld_i32(&begin_op, op); op =3D copy_mul_i32(&begin_op, op, elem_size); op =3D copy_ext_i32_ptr(&begin_op, op); diff --git a/plugins/api.c b/plugins/api.c index d8b461bc69c..ac3982c6636 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -111,6 +111,18 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct q= emu_plugin_tb *tb, } } =20 +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 flag= s, @@ -136,6 +148,18 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct= qemu_plugin_insn *insn, } } =20 +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, im= m); + } +} + =20 /* * We always plant memory instrumentation because they don't finalise until @@ -148,7 +172,7 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugi= n_insn *insn, void *udata) { plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULA= R], - cb, flags, rw, udata); + cb, flags, rw, udata); } =20 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); } =20 +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 65d5611f797..7852590da88 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -332,6 +332,23 @@ void plugin_register_inline_op(GArray **arr, dyn_cb->inline_insn.imm =3D imm; } =20 +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 =3D plugin_get_dyn_cb(arr); + dyn_cb->userp =3D NULL; + dyn_cb->type =3D PLUGIN_CB_INLINE; + dyn_cb->rw =3D rw; + dyn_cb->inline_insn.entry =3D entry; + dyn_cb->inline_insn.op =3D op; + dyn_cb->inline_insn.imm =3D imm; +} + void plugin_register_dyn_cb__udata(GArray **arr, qemu_plugin_vcpu_udata_cb_t cb, enum qemu_plugin_cb_flags flags, @@ -480,6 +497,12 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int= cpu_index) char *ptr =3D cb->userp; size_t elem_size =3D 0; size_t offset =3D 0; + if (!ptr) { + /* use inline entry */ + ptr =3D cb->inline_insn.entry.score->data->data; + elem_size =3D g_array_get_element_size(cb->inline_insn.entry.score= ->data); + offset =3D cb->inline_insn.entry.offset; + } uint64_t *val =3D (uint64_t *)(ptr + offset + cpu_index * elem_size); =20 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; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184416; cv=none; d=zohomail.com; s=zohoarc; b=Ezy/oBoeGNI03LN1sBP2Ll1iZBWamGrWITSFKd/rM1LdIM/VGwPMDVc+QFd20wJhdv9oskPFuqiIEPxCw2sAoCufXVtqcnQk5bElUutRvyX6+HpsMTbN6riPP+SF9mad821PkbZ4DT6ZiOHOkM+wVJA617xRN7rHw6d5s/tBIJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184416; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=Hv56FrUSYNYIddAuxqUfXz0bijY98WHIcHlDJMXerxIec2bQUR0MOusPdOoRQtf+sbT5sv8Br8IGQWD1YeJVs5JZ4jbdb4JfsfxUMIeOLiEl2QiCGGMlJnI8TMWbpgWtSRXjSLXgjReBi5FEp8d2hNat9y8ohuECRt5ZMYuX310= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184416096441.38225545957835; Wed, 28 Feb 2024 21:26:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvP-0002m1-Sd; Thu, 29 Feb 2024 00:25: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 1rfYvL-0002lc-CM for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:39 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvI-0005xC-Bq for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:38 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-412b5a9916eso3760455e9.1 for ; Wed, 28 Feb 2024 21:25:35 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184334; x=1709789134; 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=umHAKc3WwxgAR5vU9QbbzcnBYCtjNPTwCZowm9k6Ay/RRlvTh1a15y68SWLnoJoRJB KpoFBq5o5ojU0G7JZOpDs7vc0DNbwhJpdiBOnOM0B/Y7hhlgDCYSbYRam2e4oJlWAJts qywVfotcUchKthABGpEVEPoJj7/mJsTQ7by8++AdnBavIwhqMnc2bNuB2JhgpxMkYXrH YhzrA47zB0FfzF0Qde9lShqVMy59y3GXFa/+PgqvF9KdRUvSpGKw6R8pCmQQL07bQdbU 4qXG6sGOB7+BEhAIg6AcXDxeOGJ9bsYFdgWHBMxdKCLykB9wVvtZKG4MxAdk86VfIqcf bQHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184335; x=1709789135; 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=BqJXIQFFkknpwG8oa6VZYBXd21gAWxzcXg3EyiGpd4wFxpwmjrdvW7evqekQjnIcgh GbXG9+4x6Ce9LqB4t+ihtttJjxIYhPrBqrC6jDMvZLzDhHUeybkySICjI8bYBe/pwcLd jmB2swVoNPq8J1YFT0t8RVsA7nAFxK+G3g32J/2LcUOtse3Ojz+bbEqnSxKNsC/y30KM GBFNA5skZdxSG/v/XyaKDt1h2IuhAANR1azCEJgclRms64PuoZhwT/Ghyrrvrehfgx7V LyIu6GtphxMyH0+uC34eUr6voEM2/DHqwFgVCOP8FDo40ergEYvIujOGBvv7T0jQb/3i 3cFg== X-Gm-Message-State: AOJu0YxLlQGJTamh5M0Vzs6Yn1mu77H0c1UVUY5XGr3rE3unJ0CNzgTb F0aNV7pI6DkmACG5DpBAhRkuRskBcWDjFkg02x4AZo6x9shgT2T2DtWItlOVChJaY8xWckSBzpO A7Js= X-Google-Smtp-Source: AGHT+IEENWwZJeuc2bWKqppSdQ4SmpipMPfuIrIcunXZWgrICcHNLWNd2PwHVW4fd6evVZUZvsrqDQ== X-Received: by 2002:a05:600c:4ed2:b0:412:b81f:758b with SMTP id g18-20020a05600c4ed200b00412b81f758bmr922858wmq.16.1709184334742; Wed, 28 Feb 2024 21:25:34 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 05/12] tests/plugin: add test plugin for inline operations Date: Thu, 29 Feb 2024 09:24:59 +0400 Message-ID: <20240229052506.933222-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184416527100003 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=C3=A9e 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 =3D QEMU_PLUGIN_VERSION; + +static void stats_insn(void) +{ + const uint64_t expected =3D global_count_insn; + const uint64_t per_vcpu =3D qemu_plugin_u64_sum(count_insn); + const uint64_t inl_per_vcpu =3D + 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 =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); +} + +static void stats_tb(void) +{ + const uint64_t expected =3D global_count_tb; + const uint64_t per_vcpu =3D qemu_plugin_u64_sum(count_tb); + const uint64_t inl_per_vcpu =3D + 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 =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); +} + +static void stats_mem(void) +{ + const uint64_t expected =3D global_count_mem; + const uint64_t per_vcpu =3D qemu_plugin_u64_sum(count_mem); + const uint64_t inl_per_vcpu =3D + 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 =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + const unsigned int num_cpus =3D qemu_plugin_num_vcpus(); + g_assert(num_cpus =3D=3D max_cpu_index + 1); + + for (int i =3D 0; i < num_cpus ; ++i) { + const uint64_t tb =3D qemu_plugin_u64_get(count_tb, i); + const uint64_t tb_inline =3D qemu_plugin_u64_get(count_tb_inline, = i); + const uint64_t insn =3D qemu_plugin_u64_get(count_insn, i); + const uint64_t insn_inline =3D qemu_plugin_u64_get(count_insn_inli= ne, i); + const uint64_t mem =3D qemu_plugin_u64_get(count_mem, i); + const uint64_t mem_inline =3D 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 =3D=3D tb_inline); + g_assert(insn =3D=3D insn_inline); + g_assert(mem =3D=3D 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 =3D 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 =3D 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn =3D 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 =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); + count_tb =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb); + count_insn =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn); + count_mem =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_mem); + count_tb_inline =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb_inline); + count_insn_inline =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn_inline); + count_mem_inline =3D 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 =3D [] if get_option('plugins') - foreach i : ['bb', 'empty', 'insn', 'mem', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall'] if host_os =3D=3D 'windows' t +=3D shared_module(i, files(i + '.c') + '../../contrib/plugins/win= 32_linker.c', include_directories: '../../include/qemu', --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184398; cv=none; d=zohomail.com; s=zohoarc; b=QK3X8dE1U4/yWLsnWoCQkTKtEYWjFU/D6bgp6R8RZukSbwhQKDaMPNc+azUfIWyqep6m3war1gWuIiryZAuJljCYhlWHTBr9YebO5eanHFcp3BFTptKCTNzWzsgXTbUVREZLb5MMOUCF4DSbJgvV22lS0zCSyDMoAeVV48vD5dU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184398; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; b=IwtcFrNdopHipqPNeafkWFQZenzZZRdZ8WHgDFnQ7u+5NfXc4z3FA1fXTpb3V04I4ml1ys0jLhO8OAXPFKZCWU2ulFQAdn+gIB+CDErv4wJVWZpHOD2bE69zj/sR02qBHqmtZ5p9fTP9h4SMDhSI22n27ypakAXNPb4YIITkZm8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184398753868.6488104629876; Wed, 28 Feb 2024 21:26:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvS-0002ml-PO; Thu, 29 Feb 2024 00:25:46 -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 1rfYvP-0002m0-7u for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:43 -0500 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvN-0005xw-ET for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:42 -0500 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2d22b8801b9so6336111fa.0 for ; Wed, 28 Feb 2024 21:25:40 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184338; x=1709789138; 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=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; b=iybd0eA+flXnrAqHVZFm09FnNG5wi1CscblhpoORfODoWTM0xvY6V588EulcNkSL4Z yXSc06k7LkLCGsir8YFBQi43Zvm7Bb3Jzj9G2JQiPH8vTHXBQ3+KSAi1/p7QdzlF6H0w yLrP7SU7hTXRWKVQ93dPTdZLZPECLTy2KXq8vLB94POJLhW7ggLuyuVuQIkQqWpd1sV2 hiMcLpaHVv2wwNRDSlcdhBylgnb3A3u6bwwevGBfZRSXUGGMXwLWe6shhRUWTTjwk1iw wNPCIbvU09FSilTBq0+OaXzIEEG66qGljprWywP60/p0Vmqmbpp7hoTiyLBmhraftKmf 9iXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184338; x=1709789138; 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=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; b=B/m31V5hByMPOhCQ4Z9K9q4fPLh1iRkneOWa7pLZjB0BANYTNEMZTb0pr2qjQbIZ6k Xkc+ZfWsjb9Pde4sHpiWRj2muDwq7rkw7di3sO7d21gZ2IU4BYeodt+q/dXwt5asNS7N FRvHJ6Yk1c2DDV6iujYquF8Uws90JC/0cQB67xl20EMjuqa5dtkzZYpF3wbluN+rn2l5 4CGPzlqjIibzwsgrOP+7XPIJ9xsmRjH18wUEnef81Cg2kTrZOBfrglJ7C3N/d07tgc00 160pA5SiJxniERyJ+RWHlXqCoQM25QlYfRoFGwkpYRPkwxMAJPWJUVlAxReL7L71F/Pr 7gQA== X-Gm-Message-State: AOJu0Yzole2S4L1dHqfTLHF3/sLz+HJfl3zEyDJDRSC/2HKWBj7AN/HS xi2lJ9O9CE4RwkmW2ITU5ApKnLTcakmcRHplnyKgWSKNnl5rAv/DDPS1UXbiuyBOEXeh6Z9OiBc XGU0= X-Google-Smtp-Source: AGHT+IE8WbxFfHGpwQFm33lD/qjD1x3/wMmNCW7S+BN8ohGbG4NMSXxKJKLcxVpBIOj+bpyvGQyGJg== X-Received: by 2002:ac2:5b9a:0:b0:512:9dee:44fe with SMTP id o26-20020ac25b9a000000b005129dee44femr653009lfn.26.1709184338435; Wed, 28 Feb 2024 21:25:38 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 06/12] tests/plugin/mem: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:00 +0400 Message-ID: <20240229052506.933222-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184400514100003 Content-Type: text/plain; charset="utf-8" Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- tests/plugin/mem.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..b650dddcce1 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,9 +16,14 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -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 =3D QEMU_PLUGIN_MEM_RW; @@ -27,16 +32,16 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out =3D g_string_new(""); =20 - 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); } =20 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_plugi= n_meminfo_t meminfo, struct qemu_plugin_hwaddr *hwaddr; hwaddr =3D 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); } } =20 @@ -64,9 +69,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qe= mu_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 if (do_inline) { - qemu_plugin_register_vcpu_mem_inline(insn, rw, - QEMU_PLUGIN_INLINE_ADD_U6= 4, - &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,16 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, } } =20 + if (do_inline && do_callback) { + fprintf(stderr, + "can't enable inline and callback counting at the same tim= e\n"); + return -1; + } + + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); + mem_count =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, mem_count); + io_count =3D 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; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184444; cv=none; d=zohomail.com; s=zohoarc; b=DFFIiLrXtChZ6G22FnFwxwVEydMwdjINVV2aB0q8x4JgGjktzoLSf3D95pammjDdk3YNIZZs0ySCKWjMNBmyhoW4U5gnu3jryqdxbVEl+OPHgYc6YtHSkLt+eVdWRU8Xc73i8245hFTFgO0kNuHOuQwLqRRDwPIVr1aZ3GrhOs4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184444; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; b=A2l4EBp9lMxA/PijXgU6kExw1E/5L0863rj5ONVSDoEyENibbbISL9OUUMVk92arjYhn+dT2efLmGZgT0zZjmVnUo0hw1DA1rCZbyuG7jdjnben5Rw5GYRhspV24dBhj0EjyYuJjKGsXdZy1abWSqw3hceVBQSm2lh64ru3mf1s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184444427102.41889748250071; Wed, 28 Feb 2024 21:27:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvV-0002n7-K4; Thu, 29 Feb 2024 00:25:49 -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 1rfYvR-0002mY-JR for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:45 -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 1rfYvP-0005yR-Nk for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:45 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33d6f1f17e5so321037f8f.3 for ; Wed, 28 Feb 2024 21:25:43 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184342; x=1709789142; 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=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; b=YAiOnZjq6Suxdka9ppBUMAG7hE12ow9iaWWdTPpc+pVPJx1vmyt+R+xVSnR12kbMOq TXk6L1yjxsG/v/Riifawytxgb8tHFnScnw7qdcvL2YygRdEjhNFcVBVHB+fZGI/h/lxW Fje9ya8m8nAymjcKBqfqdPppQ8JYT1wHR091EXB2mNZ0FLUYC9PoU5iIc8wi8hXiVtjC G5UxXx6bw4zePFzEbu5H8QFAt7ccuV0q5tc28XywzGAzopHl3FGyRxw5g2SsbAtibH3D N8c6oL1Q8qHU9+d9UDeBp8q6rQtMrfPzHP8OeV95RzkPKfTp9m42BCgwkFRYUPQ7JLf/ hwBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184342; x=1709789142; 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=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; b=ErpkHohBK0D22UbXoHysiDkZHp/8PvjvN6Y83u6LTgozDvL6lsfKqQ4LvVzOz67Zvg d9K9lq1Vij/pQdjsFr0sG80VCi3XCI9KB2cKFwuYrHQTU7CdWYF3MDBau7EbLPC/KhUg wihMcJkIWwfw1uN76PlONTowrHwodsfzg/GCkx/KdHI31YUz24BjD2XfhAaQbniWoDv/ vBnWDeEK3F7Z4dTZMIl2w7ECD5hP9RWFkX0FCFl0YoUCDQHVwKfqdiBUDo6jW24duflN PjVNiryOGRUlokX+V9h+BmYz8+Y3cloSQwOgn9m2Xnil3UdkUmmtCAlZoIZAhRUy41D0 E5Xg== X-Gm-Message-State: AOJu0YxMaxJ7eDZxEcrAue6etjXcJZiR877pA4MVdIgxA8mopoqv/stv W09smdnUWlKQ7+rKBplfwhLtDBEMydtO0ETl8zYObFKGcauoNBYU7JJNNqYBFXRJ/q2dmEDj3gJ nvMw= X-Google-Smtp-Source: AGHT+IF+zUHb7AT9Eqy2aqBPm7Obowug+fZ3WzH18bK7Yicbtw1LDQSmbJBsVZ7wcrqpaKrRTQ9AAw== X-Received: by 2002:a5d:53d2:0:b0:33d:26b1:c460 with SMTP id a18-20020a5d53d2000000b0033d26b1c460mr506434wrw.39.1709184342122; Wed, 28 Feb 2024 21:25:42 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:01 +0400 Message-ID: <20240229052506.933222-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184446636100001 Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- 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 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -#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; =20 static bool do_inline; static bool do_size; static GArray *sizes; =20 +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; =20 static GArray *matches; @@ -67,41 +63,40 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int= vcpu_index) =20 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i =3D cpu_index % MAX_CPUS; - InstructionCount *c =3D &counts[i]; - - c->insn_count++; + qemu_plugin_u64_add(insn_count, cpu_index, 1); } =20 static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *ud= ata) { - unsigned int i =3D cpu_index % MAX_CPUS; Instruction *insn =3D (Instruction *) udata; - Match *match =3D insn->match; + Match *insn_match =3D insn->match; + MatchCount *match =3D qemu_plugin_scoreboard_find(insn_match->counts, + cpu_index); + g_autoptr(GString) ts =3D g_string_new(""); =20 insn->hits++; g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits", insn->vaddr, insn->disas, insn->hits); =20 - uint64_t icount =3D counts[i].insn_count; - uint64_t delta =3D icount - match->last_hit[i]; + uint64_t icount =3D qemu_plugin_u64_get(insn_count, cpu_index); + uint64_t delta =3D icount - match->last_hit; =20 - match->hits[i]++; - match->total_delta[i] +=3D delta; + match->hits++; + match->total_delta +=3D delta; =20 g_string_append_printf(ts, - ", %"PRId64" match hits, " - "=CE=94+%"PRId64 " since last match," + " , cpu %u," + " %"PRId64" match hits," + " =CE=94+%"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); =20 - match->last_hit[i] =3D icount; + match->last_hit =3D icount; =20 qemu_plugin_outs(ts->str); - - g_ptr_array_add(match->history[i], insn); } =20 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 q= emu_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 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 =3D 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 =3D qemu_plugin_insn_disas(insn); - int j; - for (j =3D 0; j < matches->len; j++) { + for (int j =3D 0; j < matches->len; j++) { Match *m =3D &g_array_index(matches, Match, j); if (g_str_has_prefix(insn_disas, m->match_string)) { Instruction *rec =3D 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, *cn= t); } } - } else if (do_inline) { - g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_co= unt); } else { - uint64_t total_insns =3D 0; - for (i =3D 0; i < MAX_CPUS; i++) { - InstructionCount *c =3D &counts[i]; - if (c->insn_count) { - g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", - i, c->insn_count); - total_insns +=3D c->insn_count; - } + for (i =3D 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 =3D 0; i < matches->len; ++i) { + Match *m =3D &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); } =20 =20 /* Add a match to the array of matches */ static void parse_match(char *match) { - Match new_match =3D { .match_string =3D match }; - int i; - for (i =3D 0; i < MAX_CPUS; i++) { - new_match.history[i] =3D g_ptr_array_new(); - } - if (!matches) { - matches =3D g_array_new(false, true, sizeof(Match)); - } + Match new_match =3D { + .match_string =3D g_strdup(match), + .counts =3D qemu_plugin_scoreboard_new(sizeof(MatchCount)) }; g_array_append_val(matches, new_match); } =20 @@ -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 =3D g_array_new(false, true, sizeof(Match)); + /* null terminated so 0 is not a special case */ + sizes =3D g_array_new(true, true, sizeof(unsigned long)); + for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); @@ -227,9 +222,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, } } =20 - if (do_size) { - sizes =3D g_array_new(true, true, sizeof(unsigned long)); - } + insn_count =3D qemu_plugin_scoreboard_u64( + qemu_plugin_scoreboard_new(sizeof(uint64_t))); =20 /* Register init, translation block and exit callbacks */ qemu_plugin_register_vcpu_init_cb(id, vcpu_init); --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184426; cv=none; d=zohomail.com; s=zohoarc; b=R7306MMFJU83cvv+wgoTmvE7ETfGwsXBxBVSaS8ypNfE1Hf5btim2fpIhdtVYM8MDgfdOewIoMVNqw66JRSSN1j0m1i+OWvrsoWLeuOPKnxDhPgUmWbM8Rmt6J+BOQHLQY8OWq4bn1thQdGBhG4vzJC+lpeH3rsEiLQRQHSiVeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184426; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=b3CWIBEGC0BsXKNjmwrObvNdc1EF+mN59yxlciepUAtMUqalBUm9rV39YPjVRVLuGdKBoAUlsU+D5rX3qhMScFYUXezhoR4ErjUeBA2vbonzCDszABQLhz79O4dglnUylbBXlNofmkbTckiYspgG6pym8VL02EYGGPmiRz4j61o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184426702606.603563810284; Wed, 28 Feb 2024 21:27:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvb-0002op-Tt; Thu, 29 Feb 2024 00:25:55 -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 1rfYvZ-0002o9-VM for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -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 1rfYvV-0005zR-0V for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33de6da5565so284511f8f.2 for ; Wed, 28 Feb 2024 21:25:47 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184345; x=1709789145; 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=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=AGcRFjWX6e5NrHfn7l8x6uLb7O4Fq3GdX5FehSsPlaMWF6SzBGGtK15L0mb5mwa9vf kaJmVqz2+nJq6rWQR2yI+b7ebbBE5gCC6SRjm0CqkAi7yZ7YZtUr+DPZHL4mgdB9oXrh NkbkHlYNJE9SAs5Sh/FAtH9ZoFU0yIa8SSpl602jvd/5lXDpFspymJX4tQe4z30jzGC2 qma7gwCgWvl8JzABz6a59sZ5osn1zKdxL4/HDdv+jrEZ9xUMyfhsQUpozKp/TQW6NTCy 9Uw1AKvQxq00CYdgkNOjOOvOPoRzCD7Of1gyl3EkRzIdbGrBOZm5dIEQqnw4YDiqITie 5zHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184345; x=1709789145; 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=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=jxSDHfQ2TTKqJmvC74WddScq6ifQGhx4uD/vr2iVUZX+QV8kq0Hc0hKddZz2dRU+/P CU8n1T8EuKr3T8hi8z79M8qKDr4706OBVpezzFuUQ7dKtk0e3TecEEMyOXOz8iQ8WC4q XAUvwj1ZmzjSYSKgacJt/wXPQkBV9aY1teTyUxwNU8VI4WYsi3PnBJw3XNGn/cpd8FaA tS7ZMuyCUm4SmyaDsxsMqnCE5jFl1/3uxuzcQRde+emApbZr4zW3VCUv0mZGycT4F6aO tA62zQaGf8EkkLH/U5jlUnYAH80HHWmGI2zlOG3HmViYXW2tqiaycr+93DO2Y7HX+H8K FYTg== X-Gm-Message-State: AOJu0Yzf2rb7HY7kIUKwU6IYq03HV4Z8wPRkoEzgDo9tnHFlkJ6z37Z0 5GUtfPhJ7Dy4KCzDZcJCReUXBCCzhCVb/ZJtTUhcRnSMlukAeCskQpfenmzk2wve6FJRr64B9XI KrSc= X-Google-Smtp-Source: AGHT+IF/JTFGNOphkTjxuaXJmbyQTW1Y5pjbLcQfSt915ENO+pSRNlX126NWD06DcIEez6EVnQjITg== X-Received: by 2002:a5d:4b8a:0:b0:33d:96c7:ae3d with SMTP id b10-20020a5d4b8a000000b0033d96c7ae3dmr503207wrt.16.1709184345745; Wed, 28 Feb 2024 21:25:45 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:02 +0400 Message-ID: <20240229052506.933222-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x436.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184428494100007 Content-Type: text/plain; charset="utf-8" Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- 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 =3D QEMU_PLUGIN_VERSION; =20 typedef struct { - GMutex lock; - int index; uint64_t bb_count; uint64_t insn_count; } CPUCount; =20 -/* 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; =20 -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 =3D g_string_new(""); =20 - 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 =3D 0; i < qemu_plugin_num_vcpus(); ++i) { + CPUCount *count =3D 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); } =20 static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count =3D g_ptr_array_index(counts, cpu_index); + CPUCount *count =3D qemu_plugin_scoreboard_find(counts, cpu_index); g_autoptr(GString) report =3D g_string_new(""); - gen_one_cpu_report(count, report); + gen_one_cpu_report(count, report, cpu_index); =20 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) =20 static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - CPUCount *count =3D max_cpus ? - g_ptr_array_index(counts, cpu_index) : &inline_count; + CPUCount *count =3D qemu_plugin_scoreboard_find(counts, cpu_index); =20 uintptr_t n_insns =3D (uintptr_t)udata; - g_mutex_lock(&count->lock); count->insn_count +=3D n_insns; count->bb_count++; - g_mutex_unlock(&count->lock); } =20 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 q= emu_plugin_tb *tb) size_t n_insns =3D qemu_plugin_tb_n_insns(tb); =20 if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &inline_count.bb_count, 1= ); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_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_plugi= n_id_t id, } } =20 - if (info->system_emulation && !do_inline) { - max_cpus =3D info->system.max_vcpus; - counts =3D g_ptr_array_new(); - for (i =3D 0; i < max_cpus; i++) { - CPUCount *count =3D g_new0(CPUCount, 1); - g_mutex_init(&count->lock); - count->index =3D i; - g_ptr_array_add(counts, count); - } - } else if (!do_inline) { - g_mutex_init(&inline_count.lock); - } + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); + bb_count =3D qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, bb= _count); + insn_count =3D qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, insn_count); =20 if (idle_report) { qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle); --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184462; cv=none; d=zohomail.com; s=zohoarc; b=CjgElYCY4BAS8C3FgTPbpYnn89zeTskOhQ7XZ9RzwvX4fyIuqe1c4aTe0s0c8mNnNQOZflZd8ATJGwSHl3izI/hr0oeg1K1NrWcPtaLzZUm+slkIEhvS3Tv0zxykZF1ihI/mgFTiLUVMUS72kRZilvx1q0FVBzTZA0mX2doEsOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184462; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=KJLHyvrL+SxLFryxmYJVE9IgysxOCsdXQOy8EWApy+BlMCxnNyMFspPc0XvertEgrq6uzXi7eSgXrDDR97BQ3R871aViJHgaaKLZNMKikB7iVnpibUo41BEG8Jlq/HlBq/rrQQfEySasBMTGQXzEC25ObArcDbxsf0IBv1G2fL0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170918446238421.73592845688279; Wed, 28 Feb 2024 21:27:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYva-0002oP-93; Thu, 29 Feb 2024 00:25:54 -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 1rfYvY-0002ne-WB for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvX-0005zu-Cy for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:52 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-412b98c9b2fso4018205e9.0 for ; Wed, 28 Feb 2024 21:25:51 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184349; x=1709789149; 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=vQX8UFDbQrfNOeUFlshmwZNp4x6SawUjMH0NAOlrfJqXL7+73bE8nWgfPI7Cky807T hX2d4wrEBscqiFNvSbk5ruTDGL6HxxmpndC1rVtwUux3Vu2KqtMH8tE4RBRD4J6IK3/3 aBoteYWoFfpO74qRZOHSMrxAH+9jTOb4gDyPiyMCKy58eEYBPInbdg6IPS3QtfHU9W4S tme4bLjKg3U7oI1EohxObDilR2WVo1koFiS9XGUWUNpHS4s9LogJJuUUdtKWCESJG1aF SSe8B55pSjj5PEQougbcbQpP4zarbUX2/Oe1PelkDaWJSLon/aHafzDJENzDHecRgA/c H4Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184349; x=1709789149; 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=EzulzV2hUhcmqCAXOHHdjt1lbXT3NFcgdI+O0M5XO8NcJCXYXyWUOB2iQz96TRPI5Q SPaIPhtr1E7Mh1bLiwTPOZ8Z6GLddjvoiXOqNx+bvgbuhwtUpzByBnfwQ3wab00U8oW3 RWzmGzcKltpLQ84WzPI7f/RKh8nV1iqbJH0VraVSoY+tUG5RD0Ys3FsVevVskTN4Advy +IU1j/FdEg1fSB/Rw5HCDF04xI2vWx3r9ZUyVrsat28EMURh2Hp1G/J+Axjgbw73JkqI HO37TdtGCEHkhNhI5kiK4WroJt1PGT3ndsFD1Z1Me7KS7C8Q4DhAak9gDuRCNC8lqUfL pmOA== X-Gm-Message-State: AOJu0Yw4rO8lc+qLOaOczFOEVmqTb2pbK3InhdHpiKpEcRKx3Mn6BFLw dkC49ZxLrwucdW2uNUH+cSKonMqDAjI9WXf0It/i58gdLpWK5oN0+BWZlqODmJRxRSFXsB4swmY aVgU= X-Google-Smtp-Source: AGHT+IE5qRXU+ftwho6g2xm+NxpERA/VIVQadgUldcNI/RI28lEy2L8feoY11BXFhmgP9zQbVecepA== X-Received: by 2002:adf:fe51:0:b0:33d:a452:2fff with SMTP id m17-20020adffe51000000b0033da4522fffmr636091wrs.11.1709184349147; Wed, 28 Feb 2024 21:25:49 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:03 +0400 Message-ID: <20240229052506.933222-10-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184462620100003 Content-Type: text/plain; charset="utf-8" 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 =3D 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; =20 @@ -43,7 +43,17 @@ static gint cmp_exec_count(gconstpointer a, gconstpointe= r b) { ExecCount *ea =3D (ExecCount *) a; ExecCount *eb =3D (ExecCount *) b; - return ea->exec_count > eb->exec_count ? -1 : 1; + uint64_t count_a =3D + qemu_plugin_u64_sum(qemu_plugin_scoreboard_u64(ea->exec_count)); + uint64_t count_b =3D + 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_da= ta) +{ + ExecCount *cnt =3D value; + qemu_plugin_scoreboard_free(cnt->exec_count); } =20 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; =20 - g_mutex_lock(&lock); g_string_append_printf(report, "%d entries in the hash table\n", g_hash_table_size(hotblocks)); counts =3D g_hash_table_get_values(hotblocks); @@ -63,16 +72,21 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) =20 for (i =3D 0; i < limit && it->next; i++, it =3D it->next) { ExecCount *rec =3D (ExecCount *) it->data; - g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRI= d64"\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))); } =20 g_list_free(it); } - g_mutex_unlock(&lock); =20 qemu_plugin_outs(report->str); + + g_hash_table_foreach(hotblocks, exec_count_free, NULL); + g_hash_table_destroy(hotblocks); } =20 static void plugin_init(void) @@ -82,15 +96,9 @@ static void plugin_init(void) =20 static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - ExecCount *cnt; - uint64_t hash =3D (uint64_t) udata; - - g_mutex_lock(&lock); - cnt =3D (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) h= ash); - /* should always succeed */ - g_assert(cnt); - cnt->exec_count++; - g_mutex_unlock(&lock); + ExecCount *cnt =3D (ExecCount *)udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(cnt->exec_count), + cpu_index, 1); } =20 /* @@ -114,18 +122,20 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct= qemu_plugin_tb *tb) cnt->start_addr =3D pc; cnt->trans_count =3D 1; cnt->insns =3D insns; + cnt->exec_count =3D qemu_plugin_scoreboard_new(sizeof(uint64_t)); g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt); } =20 g_mutex_unlock(&lock); =20 if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_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); } } =20 --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184424; cv=none; d=zohomail.com; s=zohoarc; b=KZ00wHVudYmKdZB4n5voZqBmEfpv29XttI4KBafKBlhpa3ytrhfgzyzEirbyAFR3gZLuLO1d9ehyVbbDWLEHzvZ0OXfqsN+nz0Mq999cSId3ylk2C5T4TdGJyhdKT5PVE8vEr8stWbWjr48ApxtTJlefkdCKNzYUsDbkS1SOZn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184424; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=LrBC1M6E/sZjzdg57Eu/LJHum113Z0kwYGleFva7d5TXBtrgwkAepNYX6MbNrJy5if2ml8uR2C4Z90VYVk1+sPWn/sGT7uvlmeCslNoFrArttonAyiUYWkwirbUKrZpmKDTW72t0bncfkW0IaGcueKuZ5sLRtV02OCPzV9txdOA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184424960732.2266726082227; Wed, 28 Feb 2024 21:27:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvf-0002x1-Th; Thu, 29 Feb 2024 00:25:59 -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 1rfYvd-0002qV-7F for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:57 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvb-00060U-G6 for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:56 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3392b045e0aso280569f8f.2 for ; Wed, 28 Feb 2024 21:25:54 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184352; x=1709789152; 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=bGq9ziO2WrChGw5N6UMaeMxrmcJ5UXk7lOBX43oP/o0H0B4d/g8FkKkOjB9z+iLs2H zyk0GxRmYF4P8QSK43/IC4N2X+fDy5ndhYWpJ2Hgawp12cBO20WLfzPLj/ck01gi5Z9N ltUMmGVe3jQxSSDbmMyJkJ9GN8G1DOGTUN9bQswH4hAUfOPb2bE8xCBzCGFWeZEzE6N4 j5Xp2KdEpoZ3HgUfx8238//9mywsu15AD0zjy1BEDPtQai+emx/WWCqD1nlEq5nCGahX rYCZoaQEueA8tyAYjR90Pk9eJ0sBaJRjf1U8KGk48zLRL+pJLgxFVWBpkWiaL3lhNUSP aTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184352; x=1709789152; 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=r/RFMsDz3SWvh3pxQE9zDZyJUcUppRE8gBwJDgxSnMuSnDYxTWZSpz8tYOqdy5ETuD Vw+5kvz3oePv69fjYbRtca3s/E4uXJBZ8Yn4ri/yYrrXSBSUldqu9Xw0TjGu41E6E6Ic YDFYc4z+FB7R9FbHbprv6TL5WXvAgiauT5kunf8Z9GHoJJ/QygCjNO6RoNIA6b8snVi2 9J2y7JfxDZrH/32+fHUZ5N7rKmy46ew26GKUco8m+8nqbf10bw2DF+MMy31d0tIKd+9r oYDsOcVb/PNaZUg1RCqznHNlK7LMam1+BUJnyF10+YGtaTl/HFpBcsB9AvHaDaqckthx 2gWw== X-Gm-Message-State: AOJu0YzT8Dau9aP8/WczD2FG+p0pNSLDpwPL4bTHNOvU0x4C6VX5J8ID hIKX0AQWkY9zqNteDS29N5B7zlIm1hb21fU1miSTVkEyykR1DQ/SltmXPpE8xwrnGSmFY523dW3 ZYMg= X-Google-Smtp-Source: AGHT+IF5/BqcTRfHkxJNb9h/OiGjFdX1ge+UIVfxIIxbxiIQ76Oh4+UjBaKXQZGwxDgFV/8FZwcuuQ== X-Received: by 2002:a05:6000:12:b0:33d:e7a2:fb05 with SMTP id h18-20020a056000001200b0033de7a2fb05mr572526wrx.48.1709184352637; Wed, 28 Feb 2024 21:25:52 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:04 +0400 Message-ID: <20240229052506.933222-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184426489100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- 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; =20 typedef struct { char *insn; uint32_t opcode; - uint64_t count; + qemu_plugin_u64 count; InsnClassExecCount *class; } InsnExecCount; =20 @@ -159,7 +159,9 @@ static gint cmp_exec_count(gconstpointer a, gconstpoint= er b) { InsnExecCount *ea =3D (InsnExecCount *) a; InsnExecCount *eb =3D (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + uint64_t count_a =3D qemu_plugin_u64_sum(ea->count); + uint64_t count_b =3D qemu_plugin_u64_sum(eb->count); + return count_a > count_b ? -1 : 1; } =20 static void free_record(gpointer data) @@ -167,12 +169,14 @@ static void free_record(gpointer data) InsnExecCount *rec =3D (InsnExecCount *) data; g_free(rec->insn); g_free(rec); + qemu_plugin_scoreboard_free(rec->count.score); } =20 static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report =3D g_string_new("Instruction Classes:\n"); int i; + uint64_t total_count; GList *counts; InsnClassExecCount *class =3D NULL; =20 @@ -180,11 +184,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) class =3D &class_table[i]; switch (class->what) { case COUNT_CLASS: - if (class->count || verbose) { + total_count =3D 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=3D0x%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) } =20 g_hash_table_destroy(insns); + for (i =3D 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j =3D 0; j < class_tables[i].table_sz; ++j) { + qemu_plugin_scoreboard_free(class_tables[i].table[j].count.sco= re); + } + } + =20 qemu_plugin_outs(report->str); } @@ -232,11 +243,12 @@ static void plugin_init(void) =20 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - uint64_t *count =3D (uint64_t *) udata; - (*count)++; + struct qemu_plugin_scoreboard *score =3D udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(score), cpu_index, 1); } =20 -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 =3D 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 =3D opcode; icount->insn =3D qemu_plugin_insn_disas(insn); icount->class =3D class; + struct qemu_plugin_scoreboard *score =3D + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + icount->count =3D qemu_plugin_scoreboard_u64(score); =20 g_hash_table_insert(insns, GUINT_TO_POINTER(opcode), (gpointer) icount); } g_mutex_unlock(&lock); =20 - 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; =20 for (i =3D 0; i < n; i++) { - uint64_t *cnt; struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); - cnt =3D find_counter(insn); + struct qemu_plugin_scoreboard *cnt =3D find_counter(insn); =20 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, c= nt); @@ -322,6 +337,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, { int i; =20 + for (i =3D 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j =3D 0; j < class_tables[i].table_sz; ++j) { + struct qemu_plugin_scoreboard *score =3D + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + class_tables[i].table[j].count =3D qemu_plugin_scoreboard_u64(= score); + } + } + /* Select a class table appropriate to the guest architecture */ for (i =3D 0; i < ARRAY_SIZE(class_tables); i++) { ClassSelector *entry =3D &class_tables[i]; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184393; cv=none; d=zohomail.com; s=zohoarc; b=mFLnEMzMtx1qjQg+A8XfXcAVEj56jt+UP7p6UTXYCSUTNq9k0DHF+K45asDyG42jmYgaiSbDLpdsb3dkXOEZHyTxZ92aoy/VunVrhwMfzLjX1zBYU+5QpvEZXEFgLD498z6o5tW1GY8YBHDV2EgI8LOTIGfWRIVOazYn5FXs8O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184393; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; b=BDweB4zTRApoAiOmffp8ztqe7Gc76PXzAcBubVkrv3gNaNGAzscSqNoVbl5s/ER6iWYbNjFvFXF7wZFzpPQ5OzskuUa/Ni1GhZjtZqEwCLFOHM/E7zoTgOQjvWRkAXBUD5Peuuzp/JqORBBVAZCtcxCSOjUrPOTHl5oVbvSx7Cw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170918439395278.19765401914572; Wed, 28 Feb 2024 21:26:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvh-0002yE-61; Thu, 29 Feb 2024 00:26:01 -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 1rfYvg-0002xI-3a for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:00 -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 1rfYve-00061L-Ad for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:59 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33de620be53so224630f8f.2 for ; Wed, 28 Feb 2024 21:25:57 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184356; x=1709789156; 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=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; b=l4k9P/8Qfmj8jCvPz9I9b4RAAuQY521o+nHT+Qp+81yIEaemXge/lpyANJULoR4mVs HCYlOuV3rXONvYjOGZKbWNoKiBMFFejah6UDnBLiqtiXnH7Ie2wXzfMEgQ22BdC1TqvS 2Uws+o+YhZfBTrb6Yrr6EZscB4baJuGkPLsIs/w6jRg7CU3a2G3KBAKb5+8sViSBVhFw b49NrIFCGdEmhEygOsxuzKy2T1Mnjv6rGkJeSLkE6Pg3vbVJlM8VwOZQhHrUHiQJm7tl rYvSZI7K7m1KrBLQALoM8s+kjWqtpA9EVu3bOzzWWEwgS2+vc8eguJBuDR8/pVtumgsn AaOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184356; x=1709789156; 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=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; b=l1vRf9jgpu180/Xb39yMIayC8ZW1yHqPuxN+ydYoe6SqEEQLO1XNeKobuVVOMpG4Vt TqqEP7Qji+KxBAs5Dogn/J3eGnBYStJvGTaUSoTheYWVPOce1njPAgQGiBXiS326pRC9 0coyatnVh9v4nGcm1DzfNH7G5DAmVs9RvFUW/cckO4WFCA577uAad7dVqHEVMRzsdzSo npHOLTv8dJoVSfxPJrwFXW+47aZZQbiboQI1QVK6iqYlf2boxEepnbrLRoy0fh0/DlKg dqGuzuCJOd9YYn1JU1Wkm7mA3hGU8/16+KTv7w7719AcUVFWP3+OM4owaWKsmPE103FN 8uKQ== X-Gm-Message-State: AOJu0YyJ0Kf97lplv89mDhahggKJT2h6IUZfE82W01pdpMzBLWt92yOG cm8v9tcDYrAdrF1rFUbeaHd9LOPcQDa6Yfatev1vJMF3jRAoJZiuP6LkTTxi4WU6FCtfC5WIT97 EWkM= X-Google-Smtp-Source: AGHT+IG14ULe5eR8eeL4shh9YvgH1Sn/IX8xwBtg7mIt4QGjHATTIViucDRavEkXeimAia/utnlxLA== X-Received: by 2002:adf:a3d8:0:b0:33d:c5c5:9bc6 with SMTP id m24-20020adfa3d8000000b0033dc5c59bc6mr803696wrb.54.1709184356175; Wed, 28 Feb 2024 21:25:56 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 11/12] plugins: remove non per_vcpu inline operation from API Date: Thu, 29 Feb 2024 09:25:05 +0400 Message-ID: <20240229052506.933222-12-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184394443100003 Content-Type: text/plain; charset="utf-8" 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 --- 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 6bbad068c01..4fc6c3739b2 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. */ =20 extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; @@ -309,25 +313,6 @@ enum qemu_plugin_op { QEMU_PLUGIN_INLINE_ADD_U64, }; =20 -/** - * 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 qem= u_plugin_insn *insn, enum qemu_plugin_cb_flags flag= s, void *userdata); =20 -/** - * 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 *i= nsn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inlin= e op * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -597,24 +567,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plug= in_insn *insn, enum qemu_plugin_mem_rw rw, void *userdata); =20 -/** - * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any m= emory 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 *pt= r, - uint64_t imm); - /** * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem acc= ess * @insn: handle for instruction to instrument diff --git a/plugins/api.c b/plugins/api.c index ac3982c6636..58e851effdb 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, } } =20 -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 qem= u_plugin_insn *insn, } } =20 -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *i= nsn, - 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_INL= INE], - 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_plug= in_insn *insn, cb, flags, rw, udata); } =20 -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *pt= r, - 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; --=20 2.43.0 From nobody Tue Nov 26 06:59:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=zohomail.com; s=zohoarc; b=kHBUNw202rdNnEELn6Ik+d/Ph4Bz6aFDCztgDqaiJZVNO9x+oShgyb6gkmF/0Moo8KhzklNbDqIvgKUcbaYr8tGoknqrKrHsJLSQtxiaxKUiMYj6ZeQxVsgOyt/YTjp0EpSFhhBVVRar4hnx+uc/I0cKLjZkSTW0LQC2CPL/xb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709184376; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; b=ho6+jEIL9MF41qJgTKiS7+b4GH3HWqNqyaPrGIC+LJWHKF5s+tdt23JphVYqrtG/avcGV6uNNFTnM1iJWGvU9OCwG+2qOsYLigfUv5NTRMscqdlNf8mS9kYYCTEWN1ZbZoNN/0BdeGzfw3qkZR6w4UZG7SFrP2cZQNseEe5KdFY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709184376816689.1623974941805; Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvk-0002z9-LV; Thu, 29 Feb 2024 00:26:04 -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 1rfYvj-0002yo-IL for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:03 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvh-00061l-Sg for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:03 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33dc3fe739aso938403f8f.0 for ; Wed, 28 Feb 2024 21:26:01 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184360; x=1709789160; 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=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; b=lbJLKAG4fKyrq5lOFdbIC0KqmaSYbuc4TkqDb/jJYljrBUbyNFKG50+WjD0SnoHePr QFK/CuloX4kSYpY+hvfCqmttyozLpViiTDMieU+DVU/dD6IXOg14az9qKMTjugys0S0o LRNgD+ZYyQuatQFESo+tjG1OCKkHu8ziBgUKmJ14X7KaCtzAKUDXy1y1T8WBsDO4AvTV LSfYete6JSrWE6ORoRMEB/02ZbIfT7+HVrfjKX2FJy2GqI84K7rNgRaDQwU95D/g4ds5 ZusCuwO8sW1n4ICNvBEBxTbrY28pQ8VGjUk6IpwOZ3mJkDpZ1O9YhkR54Tz7naKKyKit M7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184360; x=1709789160; 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=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; b=MprtoumSJRdShCyDvrnoxm6oNVOqW0EJhjaTTkxZnF1aJXusZh6Jv4Z+d/ADcb222B Ra3Wrd3nm1zeAXJyEQV2a4a2RogX27LK2r8aBHhRXDigByH++1AWrl/Or822STZHwxMV cbr4iYVSvCtdScf5JKgEIRBlv5klArBUQcRCmwbxH0XcscTYAnYH1XlsSe6zXxm/T6ib r0D56Dkf1p4WfuBS22knQgm2NHTStfyFbtX0cL+EM8WJ68fkZYeSjeE2ZFfIloKnWbR8 WbS9z75qkAlpQjLPLq+YHqDrKasr5Uy+m0ysfXEOX+xdMOpmpc5aZqS/4kX2viHyZI8I 1+0Q== X-Gm-Message-State: AOJu0Ywyte+gembh2vQKl7YvN3AxgUxrF/YsMuqkyeZdjh6jnpdSb3jS LIp3wM+Mk0f5PBYSDo527QZW9u9GWPh00WbsEI0vzB9x2/thLBIwMhf4yJBEz9zNHdmh1fQIvY6 QXeo= X-Google-Smtp-Source: AGHT+IFDxjqa/QIONM8xZInv+rM8hwSqNVAvDCULvwymMGZWUcLAU/qvdQF3RSaSteACsJqTipGLrw== X-Received: by 2002:adf:8b5a:0:b0:33d:119e:2ca1 with SMTP id v26-20020adf8b5a000000b0033d119e2ca1mr630694wra.5.1709184359774; Wed, 28 Feb 2024 21:25:59 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 12/12] plugins: cleanup codepath for previous inline operation Date: Thu, 29 Feb 2024 09:25:06 +0400 Message-ID: <20240229052506.933222-13-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709184378628100007 Content-Type: text/plain; charset="utf-8" Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- 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 { =20 struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id); =20 -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_plug= in_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - char *ptr =3D cb->userp; - size_t elem_size =3D 0; - size_t offset =3D 0; - if (!ptr) { - /* use inline entry */ - ptr =3D cb->inline_insn.entry.score->data->data; - elem_size =3D g_array_get_element_size(cb->inline_insn.entry.score= ->data); - offset =3D cb->inline_insn.entry.offset; - } + char *ptr =3D cb->inline_insn.entry.score->data->data; + size_t elem_size =3D g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset =3D cb->inline_insn.entry.offset; =20 op =3D copy_ld_i32(&begin_op, op); op =3D copy_mul_i32(&begin_op, op, elem_size); diff --git a/plugins/core.c b/plugins/core.c index 7852590da88..11ca20e6267 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -316,22 +316,6 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GA= rray **arr) return &g_array_index(cbs, struct qemu_plugin_dyn_cb, cbs->len - 1); } =20 -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 =3D plugin_get_dyn_cb(arr); - dyn_cb->userp =3D ptr; - dyn_cb->type =3D PLUGIN_CB_INLINE; - dyn_cb->rw =3D rw; - dyn_cb->inline_insn.op =3D op; - dyn_cb->inline_insn.imm =3D imm; -} - void plugin_register_inline_op_on_entry(GArray **arr, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, @@ -494,15 +478,10 @@ void qemu_plugin_flush_cb(void) =20 void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - char *ptr =3D cb->userp; - size_t elem_size =3D 0; - size_t offset =3D 0; - if (!ptr) { - /* use inline entry */ - ptr =3D cb->inline_insn.entry.score->data->data; - elem_size =3D g_array_get_element_size(cb->inline_insn.entry.score= ->data); - offset =3D cb->inline_insn.entry.offset; - } + char *ptr =3D cb->inline_insn.entry.score->data->data; + size_t elem_size =3D g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset =3D cb->inline_insn.entry.offset; uint64_t *val =3D (uint64_t *)(ptr + offset + cpu_index * elem_size); =20 switch (cb->inline_insn.op) { --=20 2.43.0