From nobody Tue Nov 26 08:35:01 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=1708938949; cv=none; d=zohomail.com; s=zohoarc; b=F/jRJZNQD9ILITfvfz3EC1yEDB54L6CSTFu80Qj2DpDq79N0bn6V6GMrdFwHy5EEk26peknuPHNjBaz5fnneXhyw/BUvBSk+FQWtp40sGduVqqpg8Hs7SUc0BXGRHrnecFiJcJvIl/ByofRUzW7ioRildBwZ+oH8pbfXHcfGhVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938949; 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=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; b=EXlaaLflxcfLvVWQ9Q5es8u5SrY9putZmhpQ8s1elneIDs7lFF6Bl9GThPtp9UEEH/ZRxq936TYja62XUZGxP6xBdTf/nbl1+6GWJm+kTXC9UYPU5p8npwUO8u2T7G8GbezD0sW7K5zSJx3CbawxNZBUISJ9CWKdchkHFSrnPW4= 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 1708938949100285.065359367699; Mon, 26 Feb 2024 01:15:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX4j-0003M5-Re; Mon, 26 Feb 2024 04:15:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX4i-0003Ld-Dt for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:04 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4g-0004xk-6c for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:04 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-412a3ebad2aso6233975e9.1 for ; Mon, 26 Feb 2024 01:15:01 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938900; x=1709543700; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; b=PUn6mks+iuxlxJqPVpN+afSdrfQ24p3qhZycCqpt1huoqU75LZsqxFFrnXvxfLc62b F4ICArEThL+pdj9jIMLbRKFLCmrKepSUtyjE1zPx/9aXKR6ZVcXqNi+664MxbFQQmwPn T1E2TP4lYWhpvFV4lhlwhyQdzY77rNgQv2dLdF2MHRNttWuOCktIDHz2j9LT88VCi8Wb d/8ZRoZ03Sy3C97kh6stH0gvu0GtmIpZdbceZOdUvxvcxIiP+EyHqO2OkySTztO7uCd6 bcQ5tXrfJ0DkGJbNuft7+3aqrX6oUOkVNV35vJ1mHx8Dsdkxc2gi4/PBVvqEcDBnbElp eTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938900; x=1709543700; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WjnaxfBlqHMfZubpzTX1mFMWly6pKvNc0NOCUlfiHoU=; b=eSzAHGG4KzKtGut1fxMX7DtdpYONRUBpmB3pnAfPG7aUDAev+W8NmL96sgUtAgwg7c 5a3ima775cAGUVA0TrtWySFCJiNqVYx3x88HwowqqARaFDLTxocK7HJfP4PF8r1rqo7V wGI73t8PgK1SjTtN8gycoxqcmLNTp6KEHXDgj/ivunvc7r2am7EpOsOoxJvXxYdCohvA SiTbeZcjaohmPNg2DUpqWWPja9YGv1nxj2INyND8VoEnXDfYN94mvrCEncwVSBTY0hQd gSeyoMmSxTNNLqbjNxcFSSlKvIbfYcZuZbyvq/hQGfeAYohAyrnmv8l5wxW6mXQloTyP abag== X-Gm-Message-State: AOJu0Yw7woYordqLiLHjD3vxcSHUnSMKkLTQLbPDqXOcrkrZconr17eG WsS9cJYd+CefuKP0a4UmqjuwzFS19AKhVkXbnO2FlyYBeK2lwhUECHQY5QClbyUZ887yXGJ9s7I QNy5PTA== X-Google-Smtp-Source: AGHT+IEry6jzPXW1WbaR6KoXdgHwbXvdc7xCmCUClMz8mUYIHMtLUf4zCLUJdFyW+ad0BbBQriRnJw== X-Received: by 2002:a05:600c:5114:b0:412:9687:493b with SMTP id o20-20020a05600c511400b004129687493bmr4899413wms.8.1708938900038; Mon, 26 Feb 2024 01:15:00 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 01/12] plugins: scoreboard API Date: Mon, 26 Feb 2024 13:14:33 +0400 Message-ID: <20240226091446.479436-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::32a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938950199100001 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 64fb425fb0b..53d80341a8c 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 3b6b18058d2..f0c26827e04 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -222,6 +222,8 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id= _t id, struct qemu_plugin_tb; /** struct qemu_plugin_insn - Opaque handle for a translated instruction */ struct qemu_plugin_insn; +/** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ +struct qemu_plugin_scoreboard; =20 /** * enum qemu_plugin_cb_flags - type of callback @@ -750,5 +752,34 @@ GArray *qemu_plugin_get_registers(void); int qemu_plugin_read_register(struct qemu_plugin_register *handle, GByteArray *buf); =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 f6c3ba2366f..2dfc3ce4eaf 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -498,3 +498,22 @@ int qemu_plugin_read_register(struct qemu_plugin_regis= ter *reg, GByteArray *buf) =20 return gdb_read_register(current_cpu, buf, reg->gdb_reg_num); } + +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 83745663f32..12ec6911d5e 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -18,6 +18,7 @@ #include "qemu/lockable.h" #include "qemu/option.h" #include "qemu/plugin.h" +#include "qemu/queue.h" #include "qemu/rcu_queue.h" #include "qemu/xxhash.h" #include "qemu/rcu.h" @@ -214,6 +215,35 @@ CPUPluginState * qemu_plugin_create_vcpu_state(void) return g_new0(CPUPluginState, 1); } =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; @@ -224,6 +254,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); @@ -577,6 +608,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); @@ -587,3 +620,27 @@ int plugin_num_vcpus(void) { return plugin.num_vcpus; } + +struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size) +{ + struct qemu_plugin_scoreboard *score =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 08:35:01 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=1708938959; cv=none; d=zohomail.com; s=zohoarc; b=aCldJ9Ha996SAPXEepa9f0DCuQACsRLYSlyxE5aJNsT0zPmfg13bqV4xnQwmGMbXj0DhSHesWud+uwDZu0aDAXtKqq541a1bF57rsBtlF2asEWaH3BD/3R4QdrWEluqraj/4ZN/XgIe52LO6yPAZ9ngw9rEYCTKlDfaYCT63K4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938959; 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=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; b=gXMw7Uxt28YNY+2QMipMH9uRiYRm9SZ/N64zPqr0N090ZLAKbPH3JH1bOv9tpY2wKBo5T/4HxWj8Qeef2zE99fid3i2lFTUmvdD867ZBtoctJ9m2JhpS6Ymj82yz+M65dU31CsxCTv1/mNvwSi4bHMPr2NXnq1pXiXOF/AsLzvo= 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 1708938959955403.0164350145892; Mon, 26 Feb 2024 01:15:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX4n-0003NC-0f; Mon, 26 Feb 2024 04:15:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX4l-0003MV-F9 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:07 -0500 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4j-00058r-Ja for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:07 -0500 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2d24a727f78so40475351fa.0 for ; Mon, 26 Feb 2024 01:15:05 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938903; x=1709543703; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; b=mEoSVDduxsZJrg7cphVxDu3n9gZ6uIcLevJmTR2Op15uxuRPm/RBCqaBOAtdzvsejl woCcNvZRXs2GFjfUMETLelcpTFTs1cTjvF4eyI22R6hA82ivLWaGq5dXD1aU4DlbiTDN ceCzuK3agoZuYjLH4w6jft4aHM4rlYEjplT4K6iGvqRRfFVCmczccGmTKWkoqcOhrB78 lAQHS4q7mRrfbVkA7abftHXwmNvT32sWJqtqGZEQFzQBU0/XjLOwEz9193F2tNESz9Nt Qq5W4Py9HHQp3PqmZxG2d928XVBV4k4KcOd9PhjyAq0chc7URNyMm9jRdhXNFKUEV8/T BpZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938903; x=1709543703; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J8AWKRaOtLsPflMexUu/NAAwKkc6F+cV+H803nuHaV0=; b=S2Uw+7lwpcFOYnPzEYj1dfdkQ2+ske5eTZeRTT03M3zC+21e/q6F+jCuBIkboXlzfq NSZ7pfYk8hOKhWMMJJn2eqllXXAGSVA+1CxKC88zht95hYCG0B3w+sey31BtxmNUtNgl z2lvcM9CMbUT1NWPTVY+B8yMiGJjmMpnhUCGTKupI7Xpljo6tIcIw8jJtyhNDyDjFM27 5AUjfMIFh4uHiYkJQzQUYvFB3oSARUQCouWLmBTklEE5Bf900RwT9lit4Ea002kbufON J16F1c8VkL7JTuTDIpGhqXMjPBLtpqs9Vaagx3Ntstb4E/ZyV8tdXCtJbtwddZlqq4Ii qMYA== X-Gm-Message-State: AOJu0YyHsemu2VqP8x4JhZD66DNnga1If7tbL9kZyRR5z1KrKVnBM43w kUgshsH+hV5AG2NFW5aaOo8mPmIevxn1h7Zy81CullLje17Ke9NH8XSUI63cXj/4ZLQCX++GrOU R634G5Q== X-Google-Smtp-Source: AGHT+IFKOrNXMB9ppJvF1SPjl3pzZWv4mHtsJmUKtAD2Y1iGeCvf68LwXLwKRJEhh3A5xETs5gMKsA== X-Received: by 2002:a2e:9902:0:b0:2d2:3a2b:7ad3 with SMTP id v2-20020a2e9902000000b002d23a2b7ad3mr3581633lji.26.1708938903522; Mon, 26 Feb 2024 01:15:03 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 02/12] plugins: define qemu_plugin_u64 Date: Mon, 26 Feb 2024 13:14:34 +0400 Message-ID: <20240226091446.479436-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::229; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x229.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938960292100001 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 f0c26827e04..6442ab041be 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -225,6 +225,17 @@ struct qemu_plugin_insn; /** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ struct qemu_plugin_scoreboard; =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 * @@ -782,4 +793,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 2dfc3ce4eaf..579fe4a6e54 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -517,3 +517,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 08:35:01 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=1708938959; cv=none; d=zohomail.com; s=zohoarc; b=T2ESDtLDPwIxauI/Hn+QRvuYEWZUgno7ai0WI2wr5+ZDDgFMGdBIzXwg4n+Im5MnOl0l6s5jA7IkPO1DhsTaXquin2CyPFZ7eCMIooa0rdmrfsIJtJoTZTkjuwn3omcYasmcbsbrES+ZvrgtDD/hAcdcCmMi80LqsnlJVIFZ3mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938959; 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=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; b=NZ/X/gh6CNMVKniW6+NhYd3P+nJPEqgwBaC2aWMgk+DKjw4z25cK0QJcSwpBNg8g7gDB4b/oYJ8cwiX/IgJB6e/HrIEWy2UKPTnljeDfR1HW5y1kmHBLMtb3dRZcbPA17zfCdtEwmYGF0tftvqztr5IfDQ8p04H2SiiP4A30ga4= 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 1708938959900275.94533160157346; Mon, 26 Feb 2024 01:15:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX4x-0003kF-6J; Mon, 26 Feb 2024 04:15:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX4q-0003XM-Ov for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:16 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4m-00059d-Ty for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:11 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33d6f26ff33so1989745f8f.0 for ; Mon, 26 Feb 2024 01:15:08 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938907; x=1709543707; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; b=DUmYNaImplbViz27f5RiVrIP8J5luh1e7NNeyXW1iHy7jSz1E6nDnP/OQs88qSyhlx 1+oIXYftTTKqEIRIeGuWao74CnhqzEV9txmGnyQUbpPI5VXse344VVmQjypeFT5IzZda u4mfiQj8MVWPh2eOs61Y9l4XOu51c0m1EGYWPgb7i25uO2u1j70L/Ih+rnduGJX/i0Kf Qt8TIB90KeCVxFXmgsViUF801UNCJL5904x4/2GU6GvjXfXV4XzK3RuHr3QinFk/zKpn SgRy9B7LdOB1vkCD+CEI6gnEBSgkv1lBXj7DmytN3g15Yiypm025sTDKXLn28+emABn6 S9Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938907; x=1709543707; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dNkK1YdASGhq7cpzL4oM731QmQ8XAlPsGKyetFEOQRg=; b=J6OJEiNULQ6yVeq5ONml1jKSCkRmN9ujbVzMu1Ytu2GqeKOn38jR8OZDOdrLiAGRII yuTGTiWZc3/uYKtk8c4ZY5/iZtP9pGCut226pL3mI9nClQAAIntlO4PQvcVAhPgEJsxD 5lrYVi3Pyth1MKvTNupysvY+30sk5e73tFcdg2bPtx3++TmUIlIHiJeVTBimhp7K8VR1 zIWAouNiLac5GUcZyj8xdqNGmVuhRoNw4V4c8mcmnOhZf3TeK+66OMVmNdRrJLQ7EzMk BJZEbIzc1xNw4qwwgtaHcn6RxEMc8b8SYXC477pMBEjKBGR+FzUDCbzj1dGkpDHpE/uG wvAg== X-Gm-Message-State: AOJu0Yz4AT/nzQhG+IQlURmcX8g88kfjoGXxEoedx8qRJ0hXl87wXoBs scJcsbDR2fC9YL05MwtOfANBvRtiiHTKNg4gUkUljwQVumhvQhyhvxGoAYQRfSnorQjwcKBWn41 4jq180g== X-Google-Smtp-Source: AGHT+IEginwH1wxXJIoSFeChYF+ktiIyck3RzVxhgONpkKWHaFxvLvf+ATwxqEYnd7I8lWvK4VjpUw== X-Received: by 2002:a05:6000:9:b0:33d:5484:e451 with SMTP id h9-20020a056000000900b0033d5484e451mr4186713wrx.34.1708938907158; Mon, 26 Feb 2024 01:15:07 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 03/12] plugins: implement inline operation relative to cpu_index Date: Mon, 26 Feb 2024 13:14:35 +0400 Message-ID: <20240226091446.479436-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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: 1708938960292100002 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 579fe4a6e54..af4b98a1127 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 12ec6911d5e..e3ec68ec286 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -317,7 +317,8 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(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; @@ -473,9 +474,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: @@ -508,7 +512,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 08:35:01 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=1708938960; cv=none; d=zohomail.com; s=zohoarc; b=glf9SH926kO84VqdGuPoS/pH7ABVeMyPdLcXveS7iIWgDTP/ZofwD03Q6YY/dDitdey7XSqWA9zB7LQbBlrckENCkQ8S86mUF5p3YwP5Fltd7rIum0RpKrngyuIZMZtZUVLNWJQIDHldYRF0RwN/MWaIhShGf88vYgejCR6WHXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938960; 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=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; b=H+Ek/PZAMneXDA+xhpHRqUc+aSuUtcsTpcbx9F1af50LpuGHTBrYNKg/CM0dwt2VbEQ+il+XhMzwkANn6UOoQ1aKdi+dOqsG6Ayha+ZxeH9I+0cVI3+eDskaN8Q6DyaEX+pZ4eSnqtlNvyJr7qc6LAYH5+5ZD8PDHssOcdODrm8= 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 1708938960047858.9646942500005; Mon, 26 Feb 2024 01:16:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX4z-0003vo-G6; Mon, 26 Feb 2024 04:15:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX4w-0003k7-Qq for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:19 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4t-0005A4-MG for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:18 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33de4d3483eso53632f8f.3 for ; Mon, 26 Feb 2024 01:15:12 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938911; x=1709543711; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; b=ys/WGGmuWY6d0VjfauyQUy4IO6KlCYC65pvY6cUuH4nPRCxw+j7753Zw5knz0Zd5S0 mpsVcnT0UWeZmumcZ1qssxGDOdDPd8r2B79ID4gx1yPTKqiZAaF3IdR6oDOz6fnhjsJO HIDPmXZU+sKOaucLMVLqWD1UFxwe5BE2FKOdqEPfN/LAsLgqYilDSzR9VoUOaoDXwV89 SFKkRJaZRLQZeShJPRlneI1YZf5/zrwBXUYOWaAKVqvzIOcmvTCEV2TNDPzimTY+jZHG HLkMsVFjzhQoUdeGbdQRL1VSB4zAFVQ20cip5IMP+xoGo+xxA7pcG9kCczTG47wQKs1Q +LNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938911; x=1709543711; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G2Gpr9sQP+b3FncF4RGwosbanyLpRVRSAM1YTzMy4U0=; b=ZIyJOtvXpXO8dJSLBkYjTd9Q4unkLikfn3ee+Xdx+13pYzVEsjpBnt3F5Xld2jNqzI MIowxATqxen7HmAouxdw3XJk1NJ4lP++tLi0Lh3xnJ/tvrTrUn2fHk9OHIWkOTZkKi5f NWTEXG61+QhLgsv8GL9nKVig4Aht6gwXwdhEaabLYP0GwsSh/bW/yNzg5DuryntZU2FV VDJx6U+jUi/redQ38jSE8WByjWCTDTqgEuV0JWzwxLLqjfV7xn5hkYPCJi5ZHwnhfTbQ v0ZoCx9SSZw2Lltca8nLr8v4eB4BPWrBRf2G3Ubl4v3mVdaYqH5nPUl3xRFBv6JhD3Jl 0ZGQ== X-Gm-Message-State: AOJu0YyWX663nK1lt7llu0AddhIbjbWXdCHyVfV1ygP3E0/GUuBpzYGh 8IWTTh0cpUnrkgwfSurYsqqIItKDGADl++Im9HDULcFJLFTCckqQt4dMCaqzS6vQgq+XWLXZL1+ aGzSHsw== X-Google-Smtp-Source: AGHT+IEchv2zwxn06WkmR9VBHonB2rP3WSKO08hYv9+7qXJcz/QRF0Ke7tutC3NLqIersDGhOlHNAw== X-Received: by 2002:adf:e546:0:b0:33d:6edc:99af with SMTP id z6-20020adfe546000000b0033d6edc99afmr4745593wrm.34.1708938911524; Mon, 26 Feb 2024 01:15:11 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 04/12] plugins: add inline operation per vcpu Date: Mon, 26 Feb 2024 13:14:36 +0400 Message-ID: <20240226091446.479436-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::42d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938962192100013 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 53d80341a8c..378fea77b5f 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -92,6 +92,7 @@ struct qemu_plugin_dyn_cb { /* fields specific to each dyn_cb type go here */ union { struct { + qemu_plugin_u64 entry; enum qemu_plugin_op op; uint64_t imm; } inline_insn; diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 6442ab041be..7c33e2a5887 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -328,6 +328,22 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct 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 af4b98a1127..5fed50d9b09 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 e3ec68ec286..4b428dc25b1 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -331,6 +331,23 @@ void plugin_register_inline_op(GArray **arr, dyn_cb->inline_insn.imm =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, @@ -479,6 +496,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 08:35:01 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=1708939010; cv=none; d=zohomail.com; s=zohoarc; b=W/nYPPdaOGLxguKCJ98x0vqbW1Yg3lyFxOGd4uUS7S1PDPKlhpQ8ifChaTDbQshBh3isfCjcBXPcVbgupMBypk/XW8fLhpKxP3g/gjAv29xXLCt9Df9yi2ZRs6sU8HqlPNs9a9/CvHjo++UW/sf7QmARQ80DqtGfMBPC39pc7wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708939010; 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=GURftJDdETQSEbIWO/vhA6nDIuY8m3HMan0KneZSaFZqmwj1eU42tAgOvu0PjSkZyleAlgapBq13kpi9czmBIQUx1/tr76oKWYoN4PSGP4WxzoXcp7802tzaE3Aswm65YXfwIT57KG1O+Grhcm/BONK6n/pLxVW8xsV61rBheOc= 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 1708939010779631.3815433028503; Mon, 26 Feb 2024 01:16:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX52-0004Bg-Q6; Mon, 26 Feb 2024 04:15:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX4z-0003wG-Fm for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:21 -0500 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4x-0005Bb-97 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:21 -0500 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2d220e39907so47810931fa.1 for ; Mon, 26 Feb 2024 01:15:17 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938915; x=1709543715; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=uEBVZLctK/CzRN7ZBB6J9ouzBGg1UzwYcXq+BCi+doGchBvz74GLcTq2PEbGs4c2RQ b+/n/t36j92FIMbEf7Q4h6JbZ1Be5ROJHZ6F4uWa70MWkMGCLwFU3d9zk6pfpNpRxeY1 CsfcmfTA8U/wthjFjSeIshnf2B4ew/BmIxpSoUHJjUN8BTOPuTnZPyGM62yQFYn9kaIq H8Pg93gqcThg+dI5zSTt56xFjTwM3KeZ4nFCYXfrfksNwYhOTDQQ0nojpmyM2e4UqxAu jumpfvnSSjLokX1cxizUred5CFKf3umORNzgUlRlEkg1yw+DoWhQMq1VZkczl2akWqCq XXnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938915; x=1709543715; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=NPtGBj/vqDtd/TibiX9VBHA3D6H7gs4AsR8oT2ALQO5MRD3SELFCRZd+izarsyHXNM SlhGQ83eZMlQwrr2BOE9LjTISc6f5muGEb2MQfMwDcwIU7EFRYjUTrTxsq2p0TV3o48E OFEwg18iOoWzVnMzXRakvM2N62i6fZsWJwidwc6kkqtQ1Z+VM7I8AB/ZsOxajPLth7fb 5G8gMUmfgrqVTHiFep2gjuV7gsFc2O1ahdRM2ToNJkutKXZlMc1VmsI8EcJ4HaXjU0wF XP/YwKnx3Vawiwn3ZvqtWgr1jf8vQmQkK3JUKoakxKjEpvTSRYpzKs08tiAeXT5tBuiq hxZg== X-Gm-Message-State: AOJu0YywFU1ViBO/Bd+mEa0bINaobiJURjs8vx83yFpmT44/nt/KJOC4 Vu7zGgpvsI/wG5JBHyN6oKUlU91j5dpyriEPIrZMFlfMS/CpOEnDb35rM/LMhepyOGAKLTI7B5F sUf7bOg== X-Google-Smtp-Source: AGHT+IGV8XV5JBzfOKGMphctSf+9URshj4F5FaPo2Y88PiaX8KIMUoTmVRwTc6X9JWok/dyp51fA5w== X-Received: by 2002:a05:651c:2112:b0:2d2:892a:62 with SMTP id a18-20020a05651c211200b002d2892a0062mr2485405ljq.46.1708938914998; Mon, 26 Feb 2024 01:15:14 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 05/12] tests/plugin: add test plugin for inline operations Date: Mon, 26 Feb 2024 13:14:37 +0400 Message-ID: <20240226091446.479436-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::22a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708939012382100005 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 08:35:01 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=1708939043; cv=none; d=zohomail.com; s=zohoarc; b=V0eAPPouppMd3mVu17l9yUAUdSbukrv3dco7TJgPhwBvPuXrTspDh1x6wYoGw00/pO8HaR2kcCPsYowD/TocMx6E6YJC33R6iRmjDd0K1OlBsGbDbtTYI621Q95Wt140HY/Msqm0jmDq7KgrM2S9dh0Pkkbu+jPcECi9Ghsxlqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708939043; 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=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; b=XpzTppJ4n+rEFVEHtXuD3OHtMU3IxLWQseS1mGcFaGg0hHJpfmpp8T6q7SVyf5dwkwhm0fc7wzActPBA2YlIffbnGBMZKJ6wpvMi7+XYfVQQ1Pv1Pru7vlPBbxfZobfNJERbsu2tK8TFl5zQ9gcKgZ+Rp26uBfYKbS3qQqKNSK8= 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 1708939043089343.74285757011626; Mon, 26 Feb 2024 01:17:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX55-0004IH-6R; Mon, 26 Feb 2024 04:15:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX50-00040J-Bg for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:22 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX4y-0005Bs-KS for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:22 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33d6f26ff33so1989923f8f.0 for ; Mon, 26 Feb 2024 01:15:20 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938918; x=1709543718; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; b=UG4prCl3ubyr7SIGfLItQxpg+qmenGLWDqjU5fDxkKUpunNvFm08isf4FlYo16mZWN BKvYZQzoqdugS6aKAkkTML4pRjYv4FqRUuaGula25Z1XLy1/b9UPP561+OjJNRnQxEYm I8+LUc4xdge/4m3o14kUD4SKgUvjeOWkLNeamlWiy0tjKvjR9nC4D42/vYiFkVm9KNKI Y/I3au7yEoxX9dFUf0yBzwlHWYmQMUgSd0M7u1YVbTby0CTOUG8Pzo3Rr7eB/qUM/+Kj 9hDDmOxhjHIZp9/tiqkaow4m+LXw7MqVa2WX3xmT0Z5wk6AR45FdOaP1yr7uNF1vuhcw p4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938918; x=1709543718; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HgTl20rCSJYbUu3H7bqnk8bx/uKJfuAIG49cFMEfy7s=; b=EeI3ENsoGL3DDFog4hFpi/gxZjpsCgzsfsmmxCFma1DBG4w9cTDcTD0s2sOC+UK/1V o1SKFVMzeMjC8x3OchsfxrlZbJy7bZcTz7qcznlXIH2JaSxInlPXeqo+/O25zXnUeM04 J5K7RanNwF5vUSoDLwFi7g6IWhWW2a5b6AspOeyxNcDUFyBilGTAMYG7LScCNYdz/Nir QLyrD8B89JRqV3mzVRMT083RihPJBQVVohZ6o54hGjOwInHTMoUdX7FIsojIrBPP6sUq yN0agDXVY19qbor1pVWCyS4KF9dvcYhOblHzq3kl5nyXJWVDtsJusURrxe8d+t6hLzeX Mk3A== X-Gm-Message-State: AOJu0YzXSs47Oj5KlcKuf3Dv4pbVgPxOk1JKdSV4U9oBTZdCSbiQyBkZ Yleazfium5fYURGs1ysXIixgV0nXAt4InTK6hRypJsmQj6VQ4lr5iYEWQocy8TyrP/nK5J5oKkE I95OXxg== X-Google-Smtp-Source: AGHT+IGgaaYMvNMgVeBX23Mxbf8y0ULfBFRRTLiX9K6xU/QZLtws4ylBWPsE9MdlG1gFK5PFlLre9w== X-Received: by 2002:a5d:4a88:0:b0:33d:4fca:a47f with SMTP id o8-20020a5d4a88000000b0033d4fcaa47fmr5084130wrq.18.1708938918435; Mon, 26 Feb 2024 01:15:18 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 06/12] tests/plugin/mem: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:38 +0400 Message-ID: <20240226091446.479436-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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: 1708939044410100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Luc Michel --- tests/plugin/mem.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..d4729f5e015 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,9 +16,14 @@ =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,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, } } =20 + 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 08:35:01 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=1708939032; cv=none; d=zohomail.com; s=zohoarc; b=L6ZJCCsl5EbtKHKu7dWRkFoaGbHOGqgTGte8/+UJmLG5MQJzjm8tkbTr1TtsBGbtusf8YZ47pU+J0oQ1cAYT4MMNTNdL86W0xoGEhOCPmqgUhQtJ5R7U6ST0d37fckBlPnrmniFQ5wpQ2UBioFW70mUusfmrfvsih677MpYtvOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708939032; 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=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; b=l5t16q8//4wc4u22Fb9S1wK0L+FgKb5RJalon8jV9ssWgDIsNpW9RX4LcTsnZc2Qsb+Hm94PvcpoNpZNSQS+fQEsLevbWC+0IfalYkY18mH6IGBbhV0SPB+ZbjbNEzAyEDqik+CLaoVfVlbe7NXSLd0vHwJQaqzn9g231h+DBVM= 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 1708939032202347.2531428506792; Mon, 26 Feb 2024 01:17:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX55-0004I8-3i; Mon, 26 Feb 2024 04:15:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX53-0004EZ-LO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:25 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX51-0005CT-NO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:25 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33d8739ddd4so2256325f8f.2 for ; Mon, 26 Feb 2024 01:15:23 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938922; x=1709543722; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; b=Nx27Wjxpe9DyaWO++l0nRjR8hbNxD5P+EB7iVFL/3/xngfScU5nA62Pt6PqL2X3eVP ZFY6Y2ICYs8Qetj9FsjQOifMxS9e1MVJpNxMQtXvLszHE92kyXGOl9n+grFSCSLhKW+i hQp98qjSIL+bAf5ow8TA47X2jvQutGNPruOUwbWXtG5L82G79quVcWKRT+NIuVuVUVUb TIGiXjN+S3IUYoBM78TGC3WWWwAQMeR69NNlRlfNuO/i7boD/idIEZaCoMPAwg4ivvZu iXRiM6v1E2hRBHwgDi8Lnf7spEN392R9zbriKOrcYhaqXVLfXcP6okx/uZ2fkKt+2Kw1 QgAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938922; x=1709543722; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f4lxEBeDIaVgT+LUCDhPIFhreMkjyovHnZVpuPiLlXE=; b=fF5b/CdLcA4BZj9VJXd6c0zmAER7Ysmnk4MzRLscPYEVxClc089uuyPtCVs+4ScRLi wX1zS4P72WNCgyDN9Q6zvPd0FlPMrM2dBbA7uvSdy8igYfSC7lR5fw8Xdwn2xNpNKf2I nSGjstD7IPyG3nkaFzAjJxjJfftXLkHa1KhELovyXV9ni7+WGoCzS0Kc9Tnk1i8I9QgL 7KP/8LDqLIcXN2eNzRnRmQNEbPg396lXT3KBwNxixp2AiL0Bnn5lX+yklNWK/5y1fK95 ii39m57RKD37bt3yIELt3hKGZQQae3FLn5+CXvo/5YtzA/Q3qbnj7kRKuelKJ8AeTyT5 RtcQ== X-Gm-Message-State: AOJu0YyxyBBSoRGP9+4PATO71ND55GyBtwTxFWUCmkcb0JXvHAsKXFM/ 3ODTtpW+SqctSE9WLaAauUmNB1VkNeRKPXWzgU2GdnX1dc8gyP+AoW4mnvmR4UMgYVDWAuMac50 n4FBd7Q== X-Google-Smtp-Source: AGHT+IF9WXgWZXz8op5o743RPcjkvPc4dSeth4G8JYZbLpzJMLcVr3asT52Kg+/JQGiwzwhUKZ8Lnw== X-Received: by 2002:a5d:6346:0:b0:33b:302:c08 with SMTP id b6-20020a5d6346000000b0033b03020c08mr4182825wrw.43.1708938921887; Mon, 26 Feb 2024 01:15:21 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:39 +0400 Message-ID: <20240226091446.479436-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708939032439100001 Signed-off-by: Pierrick Bouvier Reviewed-by: Luc Michel --- tests/plugin/insn.c | 106 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 54da06fcf26..5e0aa03223e 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,25 +16,21 @@ =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 08:35:01 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=1708939032; cv=none; d=zohomail.com; s=zohoarc; b=hDmTSMGPv6W7kfNuKGx8RYDFsH3i/EzoeK+epRqmRfGVym8tXIpTFb7UHHHxFtaZASi9M/BZH237GmghfHaex8SW3k+yr3jszC4SESrSZHYU5kWXvOh/MrocyWqYJtwRXb/vkHRqYynKzrgOUut7L2LLf2XC9z77Rg3gZiLGRbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708939032; 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=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; b=FwA7g7BQWDjVziZs9xSvszCdgi+RHU8kdq8GkmeMDl42FOA4dDqWEbRFl0kZoI8QBXiwHIVpB0SnFC/NVwa8c8nJNPkE1vM0RS/0do0w1GI2VDHLy6XDpvsrDhL8/rjzQZMucagYetOrjwGQTc6sV8wy7l1zB0bdJBT4Bg82+/g= 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 17089390324430.9901697623039354; Mon, 26 Feb 2024 01:17:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX5A-0004LA-9Z; Mon, 26 Feb 2024 04:15:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX57-0004KH-Au for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:29 -0500 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX55-0005DC-Ld for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:29 -0500 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2d21a68dd3bso37996661fa.1 for ; Mon, 26 Feb 2024 01:15:27 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938925; x=1709543725; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; b=C6bPY0mkiSMBrJ/QRKxCECQiF36DK6zJg2ufLh4BH7tFAEo6n2Xure9AnQfEaUk3Bw sg6gaphAZOFu7nowS88kX2PubG/sgqq+id7oO61PNjRWlSraX40hvtS2yGchGfVYgWPQ S+48WcROCPefo4C7NzhVGD7vvZFMkvXFuGzSQRJFb2TkHZpa65h+WzmAXInItWPBzaBl 9ZTry/T+C8WqNxqe7FRXOiaKrv4pR5Cq85AOEVKzfaBmFoSF7oOij+45mm8+hM0r7rlo zwsxdsziHwN7VdjufvtVJWh/lnLAhWmGO++WtiZpnwQVcqKWEgsmKBpYY9NvAvDstiKA pu6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938925; x=1709543725; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vpn7ZrX++QOMXIPnhSOuAzbdhuGwGNkpxbx03u36x+U=; b=SVoLrDR1sbgprSQWlh42hsLazTYQJUCbzKq7iUAteYxBpSCv6PDhrjgQREr3jMeSge oWuS2piOXIQKW4ChPzDhrI6fjgLRELLhCMl7+AGQ7vWW03rJu6QE6zBh9e8DxjZP/nm7 I8JByH1IxrQW/yjEwcQFZrHjSActc9yxUUcrmVouyLxdij+SdqQTKNkyG1Z/cSngq5cl thwOwtvGNH9KMLniXrnQ3ZYd3sqnkgk30nMAxFGA8G32MT4p0U9/bjKfvKF/TzzNJkgt fjc/IP9MnZUdUirtX/47IldJcL+eb0/YhOEr5Nr7sstVZbjsP/mWYgL707oOIpc8YEXJ RZcg== X-Gm-Message-State: AOJu0YzYnkQXYaZkDHeF/9OMpUmeGJ+JfphUgO+Yg5dsonm0x3INny4T tIAeeeqSjwr1Js8M9s/XVl8hVlq5594vdjVUeqaLeid3Bcdl2H1s8/bnGEkGJwtyfFnMD3Pd+FI 0dYZ5jw== X-Google-Smtp-Source: AGHT+IH2KVmGh8LzsWZvBu0ANxDIln0x4CRcbsQsiSrRfPXRweoD8WRzUPuAQk9+rtVUtquOV+5WPw== X-Received: by 2002:a2e:b170:0:b0:2d2:4cb2:59e4 with SMTP id a16-20020a2eb170000000b002d24cb259e4mr3894689ljm.31.1708938925534; Mon, 26 Feb 2024 01:15:25 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:40 +0400 Message-ID: <20240226091446.479436-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::236; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708939034387100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Luc Michel --- 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 08:35:01 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=1708938991; cv=none; d=zohomail.com; s=zohoarc; b=P8hpuspHYD+tj4aJERIGiI+YZPPoQoK4UbkynjUw9u3Gy4ReZ3eAwdEIO4VR0mudzkCqq1JoreqcuJE2nD1URn3L143CBmC0iZpuLXP7kvAYBpPXVBLmiQOK7+9tS/6oJ4K4UrdguKX8bK0Ac+Xki655HQvBLfMyZ/99FwP4FYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938991; 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=Wf5MLVzQCTF1zAGAME443lexMstLzQG710rUMXR632qPvbpQSLwddsRkk1KiTTfye4pqWXyrQccmS2Zes0LSW9mM8VMY/S3o7sTlbPz7czKo1Clz9f2hTWasSQZs+Q5vpmkJFLVCRxuSSC+PB7p80Nbngd8uzRaxNNa4dhjXHk0= 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 1708938990995970.4111296677384; Mon, 26 Feb 2024 01:16:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX5L-0004W5-63; Mon, 26 Feb 2024 04:15:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX5I-0004UY-2h for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:40 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5B-0005DP-Sz for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:38 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33dcd8dec88so654874f8f.1 for ; Mon, 26 Feb 2024 01:15:33 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938929; x=1709543729; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=cCw1Pwfud3hGF7uAydYs7LOsTS3aDpX0i52AGLlShFBhbT03nSFErBRjvD5r5v/QZC cajN/S0lzidbexwWA3yJ77haRhJhaDvmM1BY5nVZctUwMAX8LXM1h5kinKak9LQoEguj fLbTaDdHyxl6OqTZi7m4LPGmL8mmxSYSawGEKZqUjRqS/l8x/AaVWdUXGiDOvBvJBS0h tjL36otWM5W3LFmCoQv1/i/O4Zi0YhePY5VEl1+XHUyAddOleYm7Bq8E6bpitbkO2Z30 oWaKjMXaBJ9nfJ62kMrB8UnwASTiZEpUsD9osumbJfCgZByptg4z2dD5VHLuITlQ+ACF cxyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938929; x=1709543729; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=KkqtCF2GqhD8yesP+T0/SQbOiTTkUnkYMAGLcs+HYoY5BH7NmQJ7YRMjtIzL5fNuLF 61T2fLaWfgf+aAso7blxKekOaJjpxHoxmcD0jAFWwG5Zx3sfFwTgAEseq7KH2D5Rq715 x2yL8u2IyFizmvnYXpUbV/lbAmrvriwFK+AImUznQODwhRjzeS7f1tL9oOeI/D3bv6Fw /Kn+9K9IC2/WhXeUBn613fFiRFr/TWUj1KwUoSrAyyE4WANKZBotfByydcVDy8rUIrjb eQw/c4377sG8BseFM8aWlez8RyM/OwZHC1Nilb0AYwEwF+F4ML4d5Ow9Vzu0ljHdqCT/ QXNQ== X-Gm-Message-State: AOJu0Yzagtja7hOuxiRvsuhFYcDSgNuTC4B1RRuBD/NT6L0/SQwCz1FH JnvilhzT3Z8QKR8lbRAzCoWnLjE/wCEf3PjM+94RrnOxP9XtAuTCqsigJ+cSDp2gdomhlr3epXg PEHcFpA== X-Google-Smtp-Source: AGHT+IGUQbnBj7V3S0Yv3MR/K1iQBtAOlV+k7jLXslKRYYJ950rWiutTjVHX9tQgB/ol7NKpPr82PA== X-Received: by 2002:a05:6000:1243:b0:33d:b32a:8acb with SMTP id j3-20020a056000124300b0033db32a8acbmr4350659wrx.23.1708938929000; Mon, 26 Feb 2024 01:15:29 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:41 +0400 Message-ID: <20240226091446.479436-10-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::429; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938992278100005 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 08:35:01 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=1708938960; cv=none; d=zohomail.com; s=zohoarc; b=hjgHhNWhiKz5FGlwnwpiq1zDgRgjGEVZzXHkJ/lXCH1RG/6TeA5oASnjWF2NwELYAL7giN5ZrNmlXhq8Jkx2+hOC6nBfPNIMylBrixnTLs2IBqUbrWb5sS7SxqUW21JBh+XdXA7MwtZ4BwQwdLubmzI5RN7g0CO/NvCRuHuy3BA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938960; 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=TMNGktOH0Aj5+or8pK4SrIfr2VKOkuQh2/WHHsqxmcZsNJGHfL5VIaYOfADZdl4QPhDcwgYl8eMgFDzu9FW8/fHM3DUkcQnQ96hhX6NiMr8nonVbzqQhbpqz4AketOypFmIfkNjQvor31Hiy0xPUnMJIqPiIcDJyCqqrOYyY9Gc= 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 1708938959999406.7880950478849; Mon, 26 Feb 2024 01:15:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX5O-0004Xv-V0; Mon, 26 Feb 2024 04:15:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX5M-0004X7-NU for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5E-0005DR-HK for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:44 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-412a3eba4dcso6888865e9.2 for ; Mon, 26 Feb 2024 01:15:34 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938932; x=1709543732; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=jCTjBQJ6Wg9S1DSraCK8f0/d2+vml46XQpWGRHOQL24uBK3JiOD66mZDV7/RcOPNB3 NjX68+9k9ri6X3eqzc//Cd09ZQ+7K5Yy3wJp3RuAYl36GNmtopfr4WpeIMC5U43NztF3 UijLtzvL7wKFSYcBI4+BpVgK+ZidofOynfyJaRFg0Cp0bwwroJd0nyCQas0Q1zRmuETC HD2RnJY0KYbwsjQzfyn0q8OG7Ox8Rb/GkJSrt9CDWo6za3/5PyU7W9WvK5HnraanIoLw Xh1LdFdTVxRckItbkWD5lrRuRcTepaduo/OBb2BZHEAAERxxR2FyUd7/Rz17ZRN77r1w vm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938932; x=1709543732; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=ahmlYvaSXVrZfy+/gFuYEPPZanOy2iJ7j4GIaYS1SjZWLgZdFVpe5Y++zhJOK5GY4N 8yyOZ2YQE/5NaMUAyUXphloa/TADHdIBXJlSoOB6GVDWlmclDJGB5ZBXH+YLbx1YLZns bKNbeSN6/MriOnX/5Y9ZMB07cxq9E/0PvGSg/rF4qLVyK90HoPbNkbq4eDCzyW50rDe6 a4iLkrUvOhoJbKCSItNzk8rIHEi4QxOuM6/ImQdW04BSkhVmICrm/mTVaSJ/7sv+U+g6 ZSBdV4uoWERned1edm+/Zl4ZfrSHIUZVtN02f1Jrez+h3Hlr2ZmWRWnvgD309MrBL7R3 Fuzw== X-Gm-Message-State: AOJu0Yx8ob/H/bdHmjiK8OiHnAB6aF2A7iH7CUZGyKqko7UohXs0BEaD WYoAC0fQEuH7FMWzU9F+ynJjTIR7veHYW4PWq2520yXYH8vwKfDAQbXJADAcxiXD1c043GsXd7W ymkqQLA== X-Google-Smtp-Source: AGHT+IHvYFWH7iH0EIRkhKDnMoIiST5hsDr49mt5wVwmPCfzen667ic6YuGjAOFWEmKfmhYnhnDnlg== X-Received: by 2002:a05:600c:41c2:b0:412:9018:74ca with SMTP id t2-20020a05600c41c200b00412901874camr5016399wmh.35.1708938932471; Mon, 26 Feb 2024 01:15:32 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Mon, 26 Feb 2024 13:14:42 +0400 Message-ID: <20240226091446.479436-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::335; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938962204100014 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e --- 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 08:35:01 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=1708939009; cv=none; d=zohomail.com; s=zohoarc; b=mzKKoum2Az67ZyjsyQSNqna5EzlwckS9ZPvxNOFkk5do/0MFyHyDe6KWtHlMoMd5LUx3h6XlWlY7kAO3Y3k6piXrC0hcdP9WXR/LGc2ZPRY4qJNrrP8usf66oiu5Y3iatouzveScmnVQX808GHb4IfV73G01gQp8VdbA2FhGg2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708939009; 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=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; b=DFB5lRw0au/Mel+x+0oByR+LSmJZ81Vmkn5rhEo8qn5wiXgsUfNw0P+RZXoON8wvtwZKCd+ckZka6YI1kbdV5kXh6V9WDevkwElaJ+wS9KDwDAgzpXDqb+P4TdGWzzMeiTE5BcNHXV8cTBZ44EYH0o/bgTszaPnjb1qyApAUtLw= 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 1708939009944706.9401932442282; Mon, 26 Feb 2024 01:16:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX5N-0004XB-17; Mon, 26 Feb 2024 04:15:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX5K-0004WU-OI for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:42 -0500 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5I-0005DX-EI for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:42 -0500 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d204e102a9so33230521fa.0 for ; Mon, 26 Feb 2024 01:15:37 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938936; x=1709543736; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; b=g9Utxd1lUFyfiIhCpMtPezXa2u7fmMyiNaKtd/Xwern8V8WJepDid8wFT1uya8/bVJ VTd+qzGQttML9Ahfcb3hBhi43ZL4RbTW885ZEDSEwRLHQkCj6oahwhPiIVXX/NiZOKBe 28ukjmkVmai5Mx9Zv+NmBxJUuThHum45kvkktlxfd3O4XU4CStisDzeRFJIadrFPK8x2 JhwWEzHU61rhRr/JCtBIQ6IoalfVC4U7QSGU6pIRBQVTGtCX4TQT6/irgZKU0PzNtqQQ RteIdpWUUxp6ChyadrzXk1Iq2YebPAymss/182qi1639I7dUmi3E8lYwmSflqXhlFQwi 00JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938936; x=1709543736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sSRYlMn2hSsf+I7l6Q4HwB+KtyzCuf3ojUzmxEiGWTA=; b=CQlj68ASqgGqfcTVtWiK2OYIn0e0Wwo63fbMLrRcvvuAtKrbxI2e86FRX95jJ70Br8 5CjbPhBGaaKP4CEIyQgRm1BSN7LMqBSKgLFpSRCXGrl0X9p4yP0GPpETLeJZt+W2oFgb Z7PfG/BE+1kPH0+NqLsyG4/evRtvkvZbHWMJ5m/d8hq3UmeQ1dgEz928FvOFFfkqEf0x x9ibQqjiN9/DxZRVcsEO78fgVyH0V2c8whWJaPPTEMldDFj41bBXVyCARTbE2ykVQN92 238U57n0nCMsTXq9S33uk9XaLHiRMvgZR1UO3j5V31GO7oBe31lCnL+avovSlQYg6aW/ 6ilA== X-Gm-Message-State: AOJu0YzwA2xLngxF6ljFLUaLApVYJkk5xkAh/Z55wenRoxs/CnAQ0kwt 1orefDtEEbnbHYUl4PvrVyzhYq/1EDsZw3PoRcw2kb3PPRuffUOk8TryzKjBW1i4aCEMzstIpOb YOkGMUw== X-Google-Smtp-Source: AGHT+IFf/X1FmtFq6WRKWkmp6Fci4+m/pUViUz5ip3QOyZS1xv/v1PeJz4M7SubD+Mbe1Qc3xwS8sg== X-Received: by 2002:a05:651c:11cf:b0:2d2:2bd2:78e8 with SMTP id z15-20020a05651c11cf00b002d22bd278e8mr3125899ljo.47.1708938935937; Mon, 26 Feb 2024 01:15:35 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 11/12] plugins: remove non per_vcpu inline operation from API Date: Mon, 26 Feb 2024 13:14:43 +0400 Message-ID: <20240226091446.479436-12-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::22b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708939010358100001 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 Reviewed-by: Alex Benn=C3=A9e --- include/qemu/qemu-plugin.h | 58 ++++-------------------------------- plugins/api.c | 29 ------------------ plugins/qemu-plugins.symbols | 3 -- 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 7c33e2a5887..1044fa7b14f 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -52,7 +52,11 @@ typedef uint64_t qemu_plugin_id_t; * The plugins export the API they were built against by exposing the * symbol qemu_plugin_version which can be checked. * - * version 2: removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * version 2: + * - removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * - Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline. + * Those functions are replaced by *_per_vcpu variants, which guarantee + * thread-safety for operations. */ =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 5fed50d9b09..e0af3c4a9e3 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -101,16 +101,6 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_= plugin_tb *tb, } } =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 08:35:01 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=1708938989; cv=none; d=zohomail.com; s=zohoarc; b=d4Ol04jEaGVgEvSkAobgbtRpLn4zgUaO1jBpRG4/8Sahl+I1yttNvf0tmYUpfqsp2nAlxjqxO9XQWBjW1vH7U+uhGvaIf+5YXkeTyFaJov69wy1h/MEezJPDrXkkjzYQX0rD/KJp1JGbjbkDkDiYiqAmjXTY1lhYTESSo44EODs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708938989; 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=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; b=T75d0agVqAtev5ARkCHaBpjbFlso+JZOKcHAUJFTlA5k4gdr4lQPd11ut8zYmdNNjRYliSuEGPMW0V2XNbXdTdBM9C+i9yYVOZ3uV5VvleRaay2PAyYcmQXyxSpK3uZAj4hpukOX9oPNLcdGt7dQrDlku4EWNd6vOOm/f2X4CzQ= 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 170893898964539.01812036751869; Mon, 26 Feb 2024 01:16:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reX5S-0004c1-Pa; Mon, 26 Feb 2024 04:15:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reX5R-0004bV-KC for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:49 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reX5J-0005Dj-D3 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 04:15:49 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33dcd8dec88so654933f8f.1 for ; Mon, 26 Feb 2024 01:15:40 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id g7-20020adfe407000000b0033d2ae84fafsm7578814wrm.52.2024.02.26.01.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708938939; x=1709543739; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; b=AVADNh4GfA+Ax15dyNFHnDuxHBCYZcNjUgUfWZUvcFKytXa9VjOluygN2L+uN1vXVa 7/ZUec01JI0ErVCIxeeRD/PGwewZUHpDeVml8co1zD1UiV3uFj5KewSZwa5hQgZEdmCB AEQoSspNqumPUPBj6gNByNdDF59IiTcVk5EOh6OuSaE3e1NGd2X8kwRTFQgXB3DQrXYt 3eCYyU1lap8KtktBjKLKH8Cdb6oAc6XJNlVwRrgsTN9KVXrAquTud7LfMmYuCWc7AjwY +xfUy4QNGICJqmbpeKEfqUFhqsTPSMjW8rkx+ZYZS+qIutHnUDdIv1XKem2CwIZgtMyv /dwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708938939; x=1709543739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X2JL0lvPjHTbqYBDEnpbpZDHGDP1jZ/xznh+r/K8/d0=; b=cUS/x1HaLlxXUQNuloVEmowgXoOkMJ9ZXP4wDr03JLIzeYA6LI2xzrQFRDRyG3Hyp4 iMnLts1YWckKhblt/8xpW76kbenO8js41EFkzXnYGIfN1pXzZAZ/gCsD7o/VV7BE55at u4FOfAR25pYb5HXmHemxLJwqMLJAQTJsxWJOywHl3OkqUGTqjFTABCeW9TabiEJ1t4FA pPQ6a8Yq3gM8bU5gLj+kHp1hBPBnc1TCb0zNSpgUKAiqaT0pqwAKHG7AAl/WRS5ninXj fTvAHf8e0wflCfHu00sHHT0G+q7QcM5Uqlh3LL3xkk0N80RY2i7G8mCbSyUf/FRX7FI3 k74w== X-Gm-Message-State: AOJu0Yzm64ZubbQVvBruHLcr5hIkmN6LDp6ozkaxHU+ZgSJRn3gQ814+ xKpPqCQS2BxltAzridv4dPEh8niNUATISzoelZTEEmHlOYKN3UEBA2a/+09cQTRmBugl80LIWYy yk93sfg== X-Google-Smtp-Source: AGHT+IHb65bP/rHVwoupwbaI8n9GSPTwk+1yMBz5ukoWHayDWmsBYybwUsGOhWcLkogrFv8IibZeAg== X-Received: by 2002:adf:e78f:0:b0:33d:38cf:aa76 with SMTP id n15-20020adfe78f000000b0033d38cfaa76mr4572454wrm.46.1708938939398; Mon, 26 Feb 2024 01:15:39 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , Yanan Wang , Paolo Bonzini , Mahmoud Mandour , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eduardo Habkost Subject: [PATCH v5 12/12] plugins: cleanup codepath for previous inline operation Date: Mon, 26 Feb 2024 13:14:44 +0400 Message-ID: <20240226091446.479436-13-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226091446.479436-1-pierrick.bouvier@linaro.org> References: <20240226091446.479436-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 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::42b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708938990296100001 Content-Type: text/plain; charset="utf-8" Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Reviewed-by: Alex Benn=C3=A9e --- 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 4b428dc25b1..c0f06d6bcf9 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -315,22 +315,6 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(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, @@ -493,15 +477,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