From patchwork Thu Feb 29 05:24:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776886 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp652105wrn; Wed, 28 Feb 2024 21:27:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWmHshJejMnogQmw5ZVpe53NZ3WWud6XzZZ6jHLbD7k99aK1K5Y0bb5mo0Dk27d0+4C7Zg6ufObxUWDqcdOryw7 X-Google-Smtp-Source: AGHT+IH9oJXJ4SBdgezo6WtcstwjQ0hu0fj3vY1Golt/mXJfBtyuZ6mjOoPzZ6rcoa4E1DG2gA+g X-Received: by 2002:a05:622a:50c:b0:42e:bbf6:fcd with SMTP id l12-20020a05622a050c00b0042ebbf60fcdmr588161qtx.13.1709184443706; Wed, 28 Feb 2024 21:27:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184443; cv=none; d=google.com; s=arc-20160816; b=NIK6HHuy7jEFE0E72ZYWksMTcAB7MgmRe6XPj2VKLOrAH4djuB01XJdb/KzT2GtbBl 8+UVclDSO6fsV3JEbwBMgMaXyGFqLhk1Z9AbzYI3MeVaAsR1LTv+yjpQttXyFak1SBt4 i7G8DQng9T3i8Ql5S16gjZzHuFGfhMrIYwP5sOZA22iCjqU40fTPDStHkhIY4ZqZnUcK b/aEJdvQDHoq2EdFZoXtXqYzLjyYHpCjIhzIuWXb/gLJqBqUThiLT+a5gO7sTGyymUec 1XOTGpRzrHlCACzTnYbESG1gKunVC9WL2uCnkejHkpqZEoQGX49s9GOZmLqVu2cSkdbl Cobw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=Qdqe7R/sj3JbQcl2QK3F48PYOsDLMTzLAJTZk8ajQra8Gaw/HPdWM7V8RuOF+8YA+Q 23CvdgmXASNe08nPJLHa1JdurLq5AUXt1qrKvjf7euqF9KL91IXnNkp/EgqnomXW+21D ze5Jt6pu3x1n7DNOHOvspVZcq02gFQxzWVwc2Wo7MWwKP4bsBxIdijckAytnLBn9OlHB a1npBcRtgbuymPVYpWsdBvhhYtW07hX35o5gJwPog1BlfdUy82dDoU8MWY8ZRBffjGSO apHjMPBF13EMwBDtHgPqq0lwtA4L47jV4FpRtDg9FDiAQhTiE9OrJ9VqikNSGqWS4U7I BSrg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aM4AupKP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r15-20020a05622a034f00b0042ea427730asi739867qtw.380.2024.02.28.21.27.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aM4AupKP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYv8-0002eZ-N5; Thu, 29 Feb 2024 00:25:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYv6-0002cj-Gb for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:24 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYv4-0005rg-Ho for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:24 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33d38c9ca5bso303110f8f.2 for ; Wed, 28 Feb 2024 21:25:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184321; x=1709789121; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; b=aM4AupKPE3Lz3AHjVQc4CuZmji5LrVO133QVliC+/olyLz0URAwCvMLC45oVSUhRhG EZL68Oq80HOYMlgLNiYivaWl56kfR8rY+Det7jb6A6cOl41SXDpPztFXWS0Afe0XxxeB lAi2+1Jay/C2HrI1d/NKeolDGnwHvfYoV4Zxpxd3iLYCCdt74f69/2j8piHud3YhM8El rXnkW765ajHNA/mgICXGJMVh600UUKyef1qlXr/h+KmIjZLfkx0mBFUaxeTxMSRa5KsN 3uxvAQuy/1kZB757KL5d39GF3vNhirc97aoR7pCSjIc3uzEtIEVwEylBZmifPWmq+njm 70ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184321; x=1709789121; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bl+1+D29tgAyJtkgNdnXLI/M1rjS3guiVEA7lI2vc74=; b=utd3+TyQ6ywzl2vbjpeXzYocGEQtdgupMbDZrPHkkuoAezyP148jZmXWfYbXwlq9df QQ0VbTX9g3DwSKR68s5nFuPq+6mlH+L61F5YRH7LH5dZyRYXCRMtI1WLuTFEdLsybyYz 8M465FMGt3XZ/RwBp56nlME2QkFO/LRCyYinSPYcTdG9IyMYTW4VHfHwX5VWADyj5N20 OPSMFYp5ad6H73dqvnR07UTJ3jmNO53UPpaZsTugGaaBeGoLqE3+tpjNrggBZ6ZzxoG9 c4hPMRTYEpRqzz6uN++wYWhMWuR/mCxDF6QOEaOB4ra3dbEnxe8LBYlbD7fSBIljncjr Zejg== X-Gm-Message-State: AOJu0YwdTFrR5YlYOJV6oDxE7ts4TKVm8SjQCf/COEC1V5b9CYGy00dS U1ApsVCmHBpis/fyChup+afpPLkvZjPRiCiJXKPxX2QDG/QJxehO3hDE3HqW2ulPLxUkKQpYGOe +Pbw= X-Received: by 2002:a5d:4687:0:b0:33d:e6e:b5f6 with SMTP id u7-20020a5d4687000000b0033d0e6eb5f6mr571115wrq.27.1709184320876; Wed, 28 Feb 2024 21:25:20 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:20 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 01/12] plugins: scoreboard API Date: Thu, 29 Feb 2024 09:24:55 +0400 Message-ID: <20240229052506.933222-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org We introduce a cpu local storage, automatically managed (and extended) by QEMU itself. Plugin allocate a scoreboard, and don't have to deal with how many cpus are launched. This API will be used by new inline functions but callbacks can benefit from this as well. This way, they can operate without a global lock for simple operations. At any point during execution, any scoreboard will be dimensioned with at least qemu_plugin_num_vcpus entries. New functions: - qemu_plugin_scoreboard_find - qemu_plugin_scoreboard_free - qemu_plugin_scoreboard_new Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/plugin.h | 6 ++++ include/qemu/qemu-plugin.h | 31 ++++++++++++++++++++ plugins/plugin.h | 6 ++++ plugins/api.c | 19 ++++++++++++ plugins/core.c | 57 ++++++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 3 ++ 6 files changed, 122 insertions(+) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index b3c94a34aa4..bf96d2c2aa3 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -112,6 +112,12 @@ struct qemu_plugin_insn { bool mem_only; }; +/* A scoreboard is an array of values, indexed by vcpu_index */ +struct qemu_plugin_scoreboard { + GArray *data; + QLIST_ENTRY(qemu_plugin_scoreboard) entry; +}; + /* * qemu_plugin_insn allocate and cleanup functions. We don't expect to * cleanup many of these structures. They are reused for each fresh diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 45e2ebc8f8f..31c468ddb2c 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -222,6 +222,8 @@ void qemu_plugin_register_vcpu_resume_cb(qemu_plugin_id_t id, struct qemu_plugin_tb; /** struct qemu_plugin_insn - Opaque handle for a translated instruction */ struct qemu_plugin_insn; +/** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ +struct qemu_plugin_scoreboard; /** * enum qemu_plugin_cb_flags - type of callback @@ -752,5 +754,34 @@ QEMU_PLUGIN_API int qemu_plugin_read_register(struct qemu_plugin_register *handle, GByteArray *buf); +/** + * qemu_plugin_scoreboard_new() - alloc a new scoreboard + * + * @element_size: size (in bytes) for one entry + * + * Returns a pointer to a new scoreboard. It must be freed using + * qemu_plugin_scoreboard_free. + */ +QEMU_PLUGIN_API +struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_size); + +/** + * qemu_plugin_scoreboard_free() - free a scoreboard + * @score: scoreboard to free + */ +QEMU_PLUGIN_API +void qemu_plugin_scoreboard_free(struct qemu_plugin_scoreboard *score); + +/** + * qemu_plugin_scoreboard_find() - get pointer to an entry of a scoreboard + * @score: scoreboard to query + * @vcpu_index: entry index + * + * Returns address of entry of a scoreboard matching a given vcpu_index. This + * address can be modified later if scoreboard is resized. + */ +QEMU_PLUGIN_API +void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, + unsigned int vcpu_index); #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/plugin.h b/plugins/plugin.h index 00b3509f708..043c740067d 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -31,6 +31,8 @@ struct qemu_plugin_state { * but with the HT we avoid adding a field to CPUState. */ GHashTable *cpu_ht; + QLIST_HEAD(, qemu_plugin_scoreboard) scoreboards; + size_t scoreboard_alloc_size; DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX); /* * @lock protects the struct as well as ctx->uninstalling. @@ -101,4 +103,8 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb); int plugin_num_vcpus(void); +struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size); + +void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score); + #endif /* PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 81f43c9ce8a..f8b15510ff7 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -465,3 +465,22 @@ int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray *buf) return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg)); } + +struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_size) +{ + return plugin_scoreboard_new(element_size); +} + +void qemu_plugin_scoreboard_free(struct qemu_plugin_scoreboard *score) +{ + plugin_scoreboard_free(score); +} + +void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, + unsigned int vcpu_index) +{ + g_assert(vcpu_index < qemu_plugin_num_vcpus()); + /* we can't use g_array_index since entry size is not statically known */ + char *base_ptr = score->data->data; + return base_ptr + vcpu_index * g_array_get_element_size(score->data); +} diff --git a/plugins/core.c b/plugins/core.c index 2db4d31354b..63f4c6c6ce3 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -18,6 +18,7 @@ #include "qemu/lockable.h" #include "qemu/option.h" #include "qemu/plugin.h" +#include "qemu/queue.h" #include "qemu/rcu_queue.h" #include "qemu/xxhash.h" #include "qemu/rcu.h" @@ -215,6 +216,35 @@ CPUPluginState *qemu_plugin_create_vcpu_state(void) return g_new0(CPUPluginState, 1); } +static void plugin_grow_scoreboards__locked(CPUState *cpu) +{ + if (cpu->cpu_index < plugin.scoreboard_alloc_size) { + return; + } + + bool need_realloc = FALSE; + while (cpu->cpu_index >= plugin.scoreboard_alloc_size) { + plugin.scoreboard_alloc_size *= 2; + need_realloc = TRUE; + } + + + if (!need_realloc || QLIST_EMPTY(&plugin.scoreboards)) { + /* nothing to do, we just updated sizes for future scoreboards */ + return; + } + + /* cpus must be stopped, as tb might still use an existing scoreboard. */ + start_exclusive(); + struct qemu_plugin_scoreboard *score; + QLIST_FOREACH(score, &plugin.scoreboards, entry) { + g_array_set_size(score->data, plugin.scoreboard_alloc_size); + } + /* force all tb to be flushed, as scoreboard pointers were changed. */ + tb_flush(cpu); + end_exclusive(); +} + void qemu_plugin_vcpu_init_hook(CPUState *cpu) { bool success; @@ -225,6 +255,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu) success = g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index, &cpu->cpu_index); g_assert(success); + plugin_grow_scoreboards__locked(cpu); qemu_rec_mutex_unlock(&plugin.lock); plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_INIT); @@ -578,6 +609,8 @@ static void __attribute__((__constructor__)) plugin_init(void) qemu_rec_mutex_init(&plugin.lock); plugin.id_ht = g_hash_table_new(g_int64_hash, g_int64_equal); plugin.cpu_ht = g_hash_table_new(g_int_hash, g_int_equal); + QLIST_INIT(&plugin.scoreboards); + plugin.scoreboard_alloc_size = 16; /* avoid frequent reallocation */ QTAILQ_INIT(&plugin.ctxs); qht_init(&plugin.dyn_cb_arr_ht, plugin_dyn_cb_arr_cmp, 16, QHT_MODE_AUTO_RESIZE); @@ -588,3 +621,27 @@ int plugin_num_vcpus(void) { return plugin.num_vcpus; } + +struct qemu_plugin_scoreboard *plugin_scoreboard_new(size_t element_size) +{ + struct qemu_plugin_scoreboard *score = + g_malloc0(sizeof(struct qemu_plugin_scoreboard)); + score->data = g_array_new(FALSE, TRUE, element_size); + g_array_set_size(score->data, plugin.scoreboard_alloc_size); + + qemu_rec_mutex_lock(&plugin.lock); + QLIST_INSERT_HEAD(&plugin.scoreboards, score, entry); + qemu_rec_mutex_unlock(&plugin.lock); + + return score; +} + +void plugin_scoreboard_free(struct qemu_plugin_scoreboard *score) +{ + qemu_rec_mutex_lock(&plugin.lock); + QLIST_REMOVE(score, entry); + qemu_rec_mutex_unlock(&plugin.lock); + + g_array_free(score->data, TRUE); + g_free(score); +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 27fe97239be..3f93e7d6b13 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -37,6 +37,9 @@ qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; + qemu_plugin_scoreboard_free; + qemu_plugin_scoreboard_find; + qemu_plugin_scoreboard_new; qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; From patchwork Thu Feb 29 05:24:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776878 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651823wrn; Wed, 28 Feb 2024 21:26:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX9FAwOuYqS7v5pL6kk+Eb342u9P2/stZ4hLXU3mqXSSmLpcSojHCDxO6ejJdwcOtvKEhSTfWURXLU2fP4jygh2 X-Google-Smtp-Source: AGHT+IFmUwYRNwo+PhBisNPqEr+Fklh6LsL05EOQTCqOsi2kYRBURed0z/7CMFtCOpfJqIJsMZL7 X-Received: by 2002:a05:6358:5927:b0:179:24b4:41fb with SMTP id g39-20020a056358592700b0017924b441fbmr1356958rwf.3.1709184376193; Wed, 28 Feb 2024 21:26:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=google.com; s=arc-20160816; b=xzztbaPn4scdYVeH6EDVi+j4Z/aYGKItRwRSzgJ/rJU2ai/G5JNyC0/gBmXYK6dh3T QpqpYxaiWRM2TqkLMdPPh05Z2jbPKcL1WY6CSSi2YckFZj6hGv83WXb/FZ1mfFwaFnHE xuLu0ve5Xrx5yU4tuYxVridMBzOq6/Ncp680aj5CiJyYZ/ZKYxBrYcQKaA8BlxTKFyv6 StOgwkmg7SG8YID7jeasv2UYh88TygKsUoIvUOzeR0kqd+xhB2r78bVk9iXU/A4VH9qX xc83Xd6td627r0s8Z/bWx1NdQq7BPgYzT4+ZZb9GHKkISXAW+l8Io7IyBxJXvLD+KcMw Lotw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=b7FE0PxgRAyzQl1z2RlFoemA40/GlRLvMyRf5bEf7upAPdl/YjsnGsc/LWy+IPrz+H pPGUrqqx37+Ttr0U0fYmWUr+A8CO8U47h+jftvoHBzp2WTu+sMPJh2UDnB9m5Yans88k lpiwsWWYvg+t8w0jwNaDWA4Q9bmIjGcI1rRqs1EkbOKg9h08b3HxgHrquSJNd0FonNXo RnuT979EsF+3jA6GKfOdGFnPzOGlq27ecW8M1aiEFSmhankpfwFtjBEdlsOEjtsqUqwx Gj26qK4rVX/p6tgPcpVrWcioGWULIYF/vaq2g60EzCinQ/3BWFUNvS/SkUcPpjXHlFNY T3qg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZfelCL3y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s20-20020a05622a019400b0042dd0bc17f7si807051qtw.124.2024.02.28.21.26.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZfelCL3y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvB-0002g0-Gp; Thu, 29 Feb 2024 00:25:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYv9-0002fD-RG for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:27 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYv7-0005vH-U4 for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:27 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-412bf8262caso145325e9.3 for ; Wed, 28 Feb 2024 21:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184324; x=1709789124; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; b=ZfelCL3yv+SSTTSccXNPFmCXWDfyVOHsZd592gx8pVjvwmsWYEv5vqpknrOYQtdWiO JVvB7rdhNrmyFWFOSiNYXUoCOJnAk/CWeTYAUM5Ti3latnPu2ub4hFEAYTel6qVERo5f F7WPBlfyT0uUfhhtiyAaaeHTdF536B/shyY3r5vev2WOLpZZ5FfNsA6Slwu2tCwlWNJG yVa/bNyKexX+G5HPN1D3JS3/R10VuXVn0dA927T0VIRUkyVyIpUCEwxEydOdNBzJSCQS XYoEvnN5bT+diSCiKT4ufz8yvd8Stq16bY7/l0lMKj8z+9fWJldjbmXM8vzBadF0wZ5f xqlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184324; x=1709789124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lsTM3pV8KdzbVuK5oQ1BIScgwFBKY5WsDX0K1DDX2g4=; b=CfgXZVUJItRMl2qqN1M2Zm7rZ3xoZ8v6jD2sXn7hlCy9bop9R8yKjpcejCuurpeMy8 7cVx52qY3nUa9Bi3etqOS3Mlk1+EyFWVVz/4ELKfjUH9k7uR57L+9k3ccwBuoItR7XqA U6KtzWdHs5u970qKtDvR0abPkKsRYxUiZ3pjSq8ANmYSUFNPdd7QDL7fU4qi+hR3Xqkw 5CnF5E5XSJI/gqAkv4ik62XO5tro/J3tmT55zo59rwY73CweCPurYYb9bzikYm3yPbiQ u8eI1utoyXV8NzYZLOdXXrB+uy2b5NaO6XbjJrWg3NbvfQN5NPln+pM+z8uanjYxCWXu /hww== X-Gm-Message-State: AOJu0YwNwaWE0KeoxHd4NkhrlhUnUW0FdqmrGKodLqGtyHSgWUibUMmW kr8nxWsPIFSIsu2yr1cQKcDf11Lajfx8GOsOEliXtiPBA4GsW7gZyN305q9KHkrktWRw+p54yQC zmbI= X-Received: by 2002:a5d:54cd:0:b0:33d:3ee3:cc11 with SMTP id x13-20020a5d54cd000000b0033d3ee3cc11mr505384wrv.47.1709184324337; Wed, 28 Feb 2024 21:25:24 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:24 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 02/12] plugins: define qemu_plugin_u64 Date: Thu, 29 Feb 2024 09:24:56 +0400 Message-ID: <20240229052506.933222-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Additionally to the scoreboard, we define a qemu_plugin_u64, which is a simple struct holding a pointer to a scoreboard, and a given offset. This allows to have a scoreboard containing structs, without having to bring offset to operate on a specific field. Since most of the plugins are simply collecting a sum of per-cpu values, qemu_plugin_u64 directly support this operation as well. All inline operations defined later will use a qemu_plugin_u64 as input. New functions: - qemu_plugin_u64_add - qemu_plugin_u64_get - qemu_plugin_u64_set - qemu_plugin_u64_sum New macros: - qemu_plugin_scoreboard_u64 - qemu_plugin_scoreboard_u64_in_struct Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 52 ++++++++++++++++++++++++++++++++++++ plugins/api.c | 34 +++++++++++++++++++++++ plugins/qemu-plugins.symbols | 4 +++ 3 files changed, 90 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 31c468ddb2c..ebf9a645e15 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -225,6 +225,17 @@ struct qemu_plugin_insn; /** struct qemu_plugin_scoreboard - Opaque handle for a scoreboard */ struct qemu_plugin_scoreboard; +/** + * typedef qemu_plugin_u64 - uint64_t member of an entry in a scoreboard + * + * This field allows to access a specific uint64_t member in one given entry, + * located at a specified offset. Inline operations expect this as entry. + */ +typedef struct { + struct qemu_plugin_scoreboard *score; + size_t offset; +} qemu_plugin_u64; + /** * enum qemu_plugin_cb_flags - type of callback * @@ -784,4 +795,45 @@ QEMU_PLUGIN_API void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, unsigned int vcpu_index); +/* Macros to define a qemu_plugin_u64 */ +#define qemu_plugin_scoreboard_u64(score) \ + (qemu_plugin_u64) {score, 0} +#define qemu_plugin_scoreboard_u64_in_struct(score, type, member) \ + (qemu_plugin_u64) {score, offsetof(type, member)} + +/** + * qemu_plugin_u64_add() - add a value to a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + * @added: value to add + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added); + +/** + * qemu_plugin_u64_get() - get value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, unsigned int vcpu_index); + +/** + * qemu_plugin_u64_set() - set value of a qemu_plugin_u64 for a given vcpu + * @entry: entry to query + * @vcpu_index: entry index + * @val: new value + */ +QEMU_PLUGIN_API +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val); + +/** + * qemu_plugin_u64_sum() - return sum of all vcpu entries in a scoreboard + * @entry: entry to sum + */ +QEMU_PLUGIN_API +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry); + #endif /* QEMU_QEMU_PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index f8b15510ff7..f4518a68afe 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -484,3 +484,37 @@ void *qemu_plugin_scoreboard_find(struct qemu_plugin_scoreboard *score, char *base_ptr = score->data->data; return base_ptr + vcpu_index * g_array_get_element_size(score->data); } + +static uint64_t *plugin_u64_address(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + char *ptr = qemu_plugin_scoreboard_find(entry.score, vcpu_index); + return (uint64_t *)(ptr + entry.offset); +} + +void qemu_plugin_u64_add(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t added) +{ + *plugin_u64_address(entry, vcpu_index) += added; +} + +uint64_t qemu_plugin_u64_get(qemu_plugin_u64 entry, + unsigned int vcpu_index) +{ + return *plugin_u64_address(entry, vcpu_index); +} + +void qemu_plugin_u64_set(qemu_plugin_u64 entry, unsigned int vcpu_index, + uint64_t val) +{ + *plugin_u64_address(entry, vcpu_index) = val; +} + +uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) +{ + uint64_t total = 0; + for (int i = 0, n = qemu_plugin_num_vcpus(); i < n; ++i) { + total += qemu_plugin_u64_get(entry, i); + } + return total; +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 3f93e7d6b13..6204453d0fd 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -44,6 +44,10 @@ qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr; + qemu_plugin_u64_add; + qemu_plugin_u64_get; + qemu_plugin_u64_set; + qemu_plugin_u64_sum; qemu_plugin_uninstall; qemu_plugin_vcpu_for_each; }; From patchwork Thu Feb 29 05:24:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776877 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651821wrn; Wed, 28 Feb 2024 21:26:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW0jAxV5y8sFCVtpkYVj7yeR5RUfTtNbPXrJDMe2adMBiQozbtRmn8NGvL1XzWTKn9AeQzD2zXfAoJNCVAJYK3G X-Google-Smtp-Source: AGHT+IEYnIoJOjQZF4xz7S4JNoDMlbaRF3aXjgLHH8mYm+gKx+Mi7/7EUASz95wMjDG1jmJJRaYh X-Received: by 2002:a67:ad07:0:b0:472:682a:ae64 with SMTP id t7-20020a67ad07000000b00472682aae64mr1045902vsl.31.1709184376113; Wed, 28 Feb 2024 21:26:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=google.com; s=arc-20160816; b=S7dDeOi8aYOB15tHe1Ga3GziPT/gHysD/0TWc033ZsRDhv4LoSfNyKeA5ybwVUsqsi IE4vls99Z6YdO/zqrGcodCPqV0dmXqwWBjFXqGwI9M1/0OQroVYWGRY5eaq8Yy5VCfLO aDiQklmafaaDKXeRqVGciyy/Hx3+gBA+RR1AM3M9yzqjKdYy3vngSdIW9ZlvSjaYGFpV SZRFk0NXcx4MMfe3m2w9TiDXHQ8fTp+j0zSkL4mmMLMbPpnUEO1xmaY3vSj1cb3qqt7D W4S87zfFmRTRhDf2YEGhtHvPbuPjYAd77ROU85dSvSMJuOMCIuVhRSJYORRPiE/CBvBS AgMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=FGYE4HB76guOq4XhLhy1u9sE6mkvcrrJtIM78j7Acnl9ESw0yju3uHe/pLnqrVWz2K RpfmXSqyoAGNTS9S4uwOfo+Y04CUaEzCOzfa1v/n/MYXRukgJFbLO8WHRoe1y0xhmrE+ FcWmcVqqQR/M0sN5Kx5XI1ZYDJO9dhno+QseEhj3zITq47hVJPz8PTaB4dcrh3a/dpNt DxDTjUEaF9D8y/cU4S0DdT7OFwu7tgnKiSGs1l9Iw7168gUNR9Aw4kdV/QEGsssTmpGE 8Kjai23xgVE92zZRSG+RLSrWV+tOMSfAFrFuAXVLq3ZFA0H82izhqMq/04qzHNKsdXCc TkTw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SQbFbN2e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f4-20020ac84984000000b0042e3bf2af6bsi648849qtq.796.2024.02.28.21.26.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SQbFbN2e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvF-0002jP-8t; Thu, 29 Feb 2024 00:25:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvD-0002hk-Ou for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:31 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvB-0005vn-Sh for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:31 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33d90dfe73cso248573f8f.0 for ; Wed, 28 Feb 2024 21:25:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184328; x=1709789128; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; b=SQbFbN2ejFrGMISEiSlZYxYAICpFptHynabDTxu2Kz7nJ67fqsLT1y+42J7uGGxhCe dTZ4WjgbHNNqvgtY4zVKx/4LkVP4xr0LKNt+QulgSu9sof1QyUFea5xGK1FK0mWnYd8P xG/I1TAEJyQnofI6yQwPPQKd22QGSFc0I2YlApVOnytABV627OM/lUMJVsu0IGGJ1Bgm IJiqm4TpJq4Rf6u6+WaTPKpksaDS4fEGK6g5NhFYikdoVkArETwso/fFJ6ZsiNjnwAhi uz5mi80WTgOowMbnRLDA9AfU1nZZ9Z8+zqLoZMNRsMeCQd92IH0yfSbiTY8BDJtGE2J6 6hnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184328; x=1709789128; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6k7cKkQj3V4Iw0Rj2K/jRNDNW77ILD5Zq0a5zxJXJbY=; b=Dq10TCSIeAJrc5A5jVxksIA1J/CNo5x+stlofn94CI0//5XpweZzMWSvDMcivH+nSP WdQs5/oH/0oD+5TmFqu05a39JusmxfSaslAYn2Vqfm2hPxwSSFEQbT6Q5pOsYXQpy1O1 CxKnUgZUuCgA4JQZzq6HKBFlSG76USrBQaBpMMnfYrPtDKDDKokUjVb+HNfg9ddLgnns kAP7/qvY1l16o3lcEn/2cpi8ClIV+xozom3V0st8A4aY18ArNjLtbdLTp7JFntuY+ab+ 1cpU5EBSJtQrHWrjvXly7DDw0K3oU4LAlawsv4L5fkhAclyB7npLzo0O2PkA86jjfbMt FvWA== X-Gm-Message-State: AOJu0Yx/9yZyRydu0J/2EycpNYei2WJHGyCO/BwTy8mGhrMJ27D25J3L e1vHN+kzz3Sipmh3BKfCRY6/0pS3qmP/+P5gDbBhOYk0TdlCr3bdYNm46Z+LMhmr85AD8UUUOMx HIoo= X-Received: by 2002:adf:db51:0:b0:33d:eb13:9e27 with SMTP id f17-20020adfdb51000000b0033deb139e27mr698654wrj.23.1709184327756; Wed, 28 Feb 2024 21:25:27 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:27 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 03/12] plugins: implement inline operation relative to cpu_index Date: Thu, 29 Feb 2024 09:24:57 +0400 Message-ID: <20240229052506.933222-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Instead of working on a fixed memory location, allow to address it based on cpu_index, an element size and a given offset. Result address: ptr + offset + cpu_index * element_size. With this, we can target a member in a struct array from a base pointer. Current semantic is not modified, thus inline operation still targets always the same memory location. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- plugins/plugin.h | 2 +- accel/tcg/plugin-gen.c | 69 ++++++++++++++++++++++++++++++++++-------- plugins/api.c | 3 +- plugins/core.c | 12 +++++--- 4 files changed, 67 insertions(+), 19 deletions(-) diff --git a/plugins/plugin.h b/plugins/plugin.h index 043c740067d..3bf1aaf5c2d 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -99,7 +99,7 @@ void plugin_register_vcpu_mem_cb(GArray **arr, enum qemu_plugin_mem_rw rw, void *udata); -void exec_inline_op(struct qemu_plugin_dyn_cb *cb); +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index); int plugin_num_vcpus(void); diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index ac6b52b9ec9..0f8be53d394 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -133,16 +133,28 @@ static void gen_empty_udata_cb_no_rwg(void) */ static void gen_empty_inline_cb(void) { + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); + TCGv_ptr cpu_index_as_ptr = tcg_temp_ebb_new_ptr(); TCGv_i64 val = tcg_temp_ebb_new_i64(); TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); + tcg_gen_ld_i32(cpu_index, tcg_env, + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); + /* second operand will be replaced by immediate value */ + tcg_gen_mul_i32(cpu_index, cpu_index, cpu_index); + tcg_gen_ext_i32_ptr(cpu_index_as_ptr, cpu_index); + tcg_gen_movi_ptr(ptr, 0); + tcg_gen_add_ptr(ptr, ptr, cpu_index_as_ptr); tcg_gen_ld_i64(val, ptr, 0); - /* pass an immediate != 0 so that it doesn't get optimized away */ - tcg_gen_addi_i64(val, val, 0xdeadface); + /* second operand will be replaced by immediate value */ + tcg_gen_add_i64(val, val, val); + tcg_gen_st_i64(val, ptr, 0); tcg_temp_free_ptr(ptr); tcg_temp_free_i64(val); + tcg_temp_free_ptr(cpu_index_as_ptr); + tcg_temp_free_i32(cpu_index); } static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info) @@ -290,12 +302,37 @@ static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr) return op; } +static TCGOp *copy_ld_i32(TCGOp **begin_op, TCGOp *op) +{ + return copy_op(begin_op, op, INDEX_op_ld_i32); +} + +static TCGOp *copy_ext_i32_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + op = copy_op(begin_op, op, INDEX_op_mov_i32); + } else { + op = copy_op(begin_op, op, INDEX_op_ext_i32_i64); + } + return op; +} + +static TCGOp *copy_add_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX == UINT32_MAX) { + op = copy_op(begin_op, op, INDEX_op_add_i32); + } else { + op = copy_op(begin_op, op, INDEX_op_add_i64); + } + return op; +} + static TCGOp *copy_ld_i64(TCGOp **begin_op, TCGOp *op) { if (TCG_TARGET_REG_BITS == 32) { /* 2x ld_i32 */ - op = copy_op(begin_op, op, INDEX_op_ld_i32); - op = copy_op(begin_op, op, INDEX_op_ld_i32); + op = copy_ld_i32(begin_op, op); + op = copy_ld_i32(begin_op, op); } else { /* ld_i64 */ op = copy_op(begin_op, op, INDEX_op_ld_i64); @@ -331,6 +368,13 @@ static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op, uint64_t v) return op; } +static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) +{ + op = copy_op(begin_op, op, INDEX_op_mul_i32); + op->args[2] = tcgv_i32_arg(tcg_constant_i32(v)); + return op; +} + static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) { if (UINTPTR_MAX == UINT32_MAX) { @@ -396,18 +440,17 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - /* const_ptr */ - op = copy_const_ptr(&begin_op, op, cb->userp); - - /* ld_i64 */ + char *ptr = cb->userp; + size_t elem_size = 0; + size_t offset = 0; + op = copy_ld_i32(&begin_op, op); + op = copy_mul_i32(&begin_op, op, elem_size); + op = copy_ext_i32_ptr(&begin_op, op); + op = copy_const_ptr(&begin_op, op, ptr + offset); + op = copy_add_ptr(&begin_op, op); op = copy_ld_i64(&begin_op, op); - - /* add_i64 */ op = copy_add_i64(&begin_op, op, cb->inline_insn.imm); - - /* st_i64 */ op = copy_st_i64(&begin_op, op); - return op; } diff --git a/plugins/api.c b/plugins/api.c index f4518a68afe..d8b461bc69c 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -106,7 +106,8 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, void *ptr, uint64_t imm) { if (!tb->mem_only) { - plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], 0, op, ptr, imm); + plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], + 0, op, ptr, imm); } } diff --git a/plugins/core.c b/plugins/core.c index 63f4c6c6ce3..65d5611f797 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -318,7 +318,8 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) void plugin_register_inline_op(GArray **arr, enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, + enum qemu_plugin_op op, + void *ptr, uint64_t imm) { struct qemu_plugin_dyn_cb *dyn_cb; @@ -474,9 +475,12 @@ void qemu_plugin_flush_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); } -void exec_inline_op(struct qemu_plugin_dyn_cb *cb) +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - uint64_t *val = cb->userp; + char *ptr = cb->userp; + size_t elem_size = 0; + size_t offset = 0; + uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) { case QEMU_PLUGIN_INLINE_ADD_U64: @@ -509,7 +513,7 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, vaddr, cb->userp); break; case PLUGIN_CB_INLINE: - exec_inline_op(cb); + exec_inline_op(cb, cpu->cpu_index); break; default: g_assert_not_reached(); From patchwork Thu Feb 29 05:24:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776880 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651865wrn; Wed, 28 Feb 2024 21:26:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXs4pSzXb5zrxiCBk12MsdsoxKHkC1MSWz4iayQ2DLf9UNfc7BWKRC0HIvif7DFZ8MSHdoWBOeWEI5b/S1cyxMJ X-Google-Smtp-Source: AGHT+IEK4LNhQrrTkmPegcNjEZo6QiWCsbM34IXZa4K/44FC9B46T572r3CGdEFMO2m/gxqpzaFG X-Received: by 2002:a05:6214:5e8b:b0:68f:2d80:c418 with SMTP id mm11-20020a0562145e8b00b0068f2d80c418mr1219983qvb.51.1709184389716; Wed, 28 Feb 2024 21:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184389; cv=none; d=google.com; s=arc-20160816; b=Qu6KV25/Dsx3M56t/8uYkrz3NYd2HT/IB/BJ5pxdyvEnoLKNGnYaJh1fkEurUh47Vt /2uNIoai1OS7ScofZVOZoXIo9Pl7SSvxx/+xulFSwAC8HdH0/17XZ8/bwqsSL5+6FvEf ExOtNgWhnr5ahN73tKyOdRxEUpKE2m189l2Tt94+ZMCP0Qva/SyeazlE9bx3OlNAQ7jS chrifc/qdHh6XNc9y3o2lYwvmqjRFJlyjWq++g8bUufEZmY+412AFIH+B2SVU6uxb5z6 5j6j2aq8QZoVV5t/WKVJn7cOIpGFWkry7q20VlHN/kUHmA3T4vTSL61Qj66bwz7G8Y8v Q6qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=gMFvVRY2/fmggXkrIlh10WffaWc6zUM78xSPlCdB1MBuA1PTOGuo4JqatQoHjEngDx FG8JS3P3/xAZsrZeLlmge4LERn8MJvFgVXnXWKQE++9TlmYetougeaC59rliZeSoGW81 dFza9x86sxp6NcgcR86SRwRNep63cV2KhOWeQuwNfAvh4xczFiGmqXsuKm7A/7W3oUPW 4Zp0v4DM97UfZgi/P4rI+pwqMjpDBXP4JZ8Yg6amUJ/nxIo6Ykyxa2i1OwvILkGrWjBN bGWQCaydWwkfdh24g+SqgjRGLkqox2AcJ55AHJzEEogioELeTlCgfG6aeHTmcNEIeSPa ewow==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hy8anaZ6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jm14-20020ad45ece000000b0068cb0aa2ec6si654536qvb.518.2024.02.28.21.26.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hy8anaZ6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvM-0002lW-2l; Thu, 29 Feb 2024 00:25:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvH-0002kb-HA for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:36 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvF-0005wj-Fp for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:35 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-412b83cfac4so3286945e9.0 for ; Wed, 28 Feb 2024 21:25:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184331; x=1709789131; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; b=hy8anaZ6vz/Scrs3Ul+tLGpm8MJXLCqpjxxOdtXKqLDxjTbCgmtSYQAZgOaGQ8sWhD CCYwsKFwEeqmK1T6iN9HDJ81vIWYRKFGUbktrOG7eTY6HpbEKW/J67On26wDKlVNfnHA oJGyd//X4w7H6IJftJCtmLX5V42gr2C5obeAeIXVitpxt+PIGVhk3hbij9JZEdRAPZ7f du5q03enIACcld+WDxpaPB+rbf0JKSB3HzWWST9BB/KtR3yfZ3Mi1+vhxB4CqbNxGxDs gcincsf27PwTK+addnqsuy7HMJ5gEv+rCI0hqdhCXRswY//C0AbfdzPVM5uWU3HtaRH1 FZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184331; x=1709789131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Phzx/q8Ox3vewF5mzB2k4EolMRZom0CGTbiI7NSeuAQ=; b=kHkgh5gWTEzGpRSe7EWK1Z4znGoVbp7rBYLs79rLmKhdSGgJLUqmswukB8mMrHNe6R UltJmfw4200hUzCFNWLGdnqLlkp1ZOnnFYARvzHtm/Uf5/50oaqbu96bqOavc258t/JI 4SGZyJD5isvmcVRtdbFZzQIL6bQa39VfEL/RHieHQEKC9+nzk8ZozuMo98UnwcI/Q05l ZFJBbVjSR5Z8gyyXvHRM0yM8MDZ9Su1nRHuW9E3hQpvQwcqGa3HhW5Cr+bUVtPqjU/fI ZMKNMO9f3nsqOIp9FG4TzisoJ9OTClMISZbLtGv8zeeMO429k7findKYGXLLR13A5gZ8 /u5A== X-Gm-Message-State: AOJu0YyqsYGtoNejhJBUoFigjWCLVqa0ShZIAohe5cQOIOKALsT7J7cP wp94hlh0wCIXDVNNLax6hUPBh4G9SqDhvp6yT2MD//hN3PVC8MtQWXok1383JTzs2bmNdCD6Th/ uEbA= X-Received: by 2002:a05:6000:18a9:b0:33d:2d2c:f404 with SMTP id b9-20020a05600018a900b0033d2d2cf404mr754759wri.15.1709184331273; Wed, 28 Feb 2024 21:25:31 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:31 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 04/12] plugins: add inline operation per vcpu Date: Thu, 29 Feb 2024 09:24:58 +0400 Message-ID: <20240229052506.933222-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Extends API with three new functions: qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline_per_vcpu(). Those functions takes a qemu_plugin_u64 as input. This allows to have a thread-safe and type-safe version of inline operations. Reviewed-by: Alex Bennée Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/plugin.h | 1 + include/qemu/qemu-plugin.h | 51 +++++++++++++++++++++++++++++++++++- plugins/plugin.h | 6 +++++ accel/tcg/plugin-gen.c | 7 +++++ plugins/api.c | 37 +++++++++++++++++++++++++- plugins/core.c | 23 ++++++++++++++++ plugins/qemu-plugins.symbols | 3 +++ 7 files changed, 126 insertions(+), 2 deletions(-) diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index bf96d2c2aa3..12a96cea2a4 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -92,6 +92,7 @@ struct qemu_plugin_dyn_cb { /* fields specific to each dyn_cb type go here */ union { struct { + qemu_plugin_u64 entry; enum qemu_plugin_op op; uint64_t imm; } inline_insn; diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index ebf9a645e15..6bbad068c01 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -328,6 +328,22 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, enum qemu_plugin_op op, void *ptr, uint64_t imm); +/** + * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline op + * @tb: the opaque qemu_plugin_tb handle for the translation + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @entry: entry to run op + * @imm: the op data (e.g. 1) + * + * Insert an inline op on a given scoreboard entry. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + /** * qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -358,6 +374,22 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); +/** + * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inline op + * @insn: the opaque qemu_plugin_insn handle for an instruction + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @entry: entry to run op + * @imm: the op data (e.g. 1) + * + * Insert an inline op to every time an instruction executes. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + /** * qemu_plugin_tb_n_insns() - query helper for number of insns in TB * @tb: opaque handle to TB passed to callback @@ -583,7 +615,24 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); - +/** + * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem access + * @insn: handle for instruction to instrument + * @rw: apply to reads, writes or both + * @op: the op, of type qemu_plugin_op + * @entry: entry to run op + * @imm: immediate data for @op + * + * This registers a inline op every memory access generated by the + * instruction. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, diff --git a/plugins/plugin.h b/plugins/plugin.h index 3bf1aaf5c2d..f6fa10a0f56 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -73,6 +73,12 @@ void plugin_register_inline_op(GArray **arr, enum qemu_plugin_op op, void *ptr, uint64_t imm); +void plugin_register_inline_op_on_entry(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm); + void plugin_reset_uninstall(qemu_plugin_id_t id, qemu_plugin_simple_cb_t cb, bool reset); diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 0f8be53d394..47e05ec6347 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -443,6 +443,13 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, char *ptr = cb->userp; size_t elem_size = 0; size_t offset = 0; + if (!ptr) { + /* use inline entry */ + ptr = cb->inline_insn.entry.score->data->data; + elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); + offset = cb->inline_insn.entry.offset; + } + op = copy_ld_i32(&begin_op, op); op = copy_mul_i32(&begin_op, op, elem_size); op = copy_ext_i32_ptr(&begin_op, op); diff --git a/plugins/api.c b/plugins/api.c index d8b461bc69c..ac3982c6636 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -111,6 +111,18 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, } } +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + if (!tb->mem_only) { + plugin_register_inline_op_on_entry( + &tb->cbs[PLUGIN_CB_INLINE], 0, op, entry, imm); + } +} + void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, qemu_plugin_vcpu_udata_cb_t cb, enum qemu_plugin_cb_flags flags, @@ -136,6 +148,18 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, } } +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + if (!insn->mem_only) { + plugin_register_inline_op_on_entry( + &insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], 0, op, entry, imm); + } +} + /* * We always plant memory instrumentation because they don't finalise until @@ -148,7 +172,7 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, void *udata) { plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULAR], - cb, flags, rw, udata); + cb, flags, rw, udata); } void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, @@ -160,6 +184,17 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, rw, op, ptr, imm); } +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + plugin_register_inline_op_on_entry( + &insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], rw, op, entry, imm); +} + void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_tb_trans_cb_t cb) { diff --git a/plugins/core.c b/plugins/core.c index 65d5611f797..7852590da88 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -332,6 +332,23 @@ void plugin_register_inline_op(GArray **arr, dyn_cb->inline_insn.imm = imm; } +void plugin_register_inline_op_on_entry(GArray **arr, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + qemu_plugin_u64 entry, + uint64_t imm) +{ + struct qemu_plugin_dyn_cb *dyn_cb; + + dyn_cb = plugin_get_dyn_cb(arr); + dyn_cb->userp = NULL; + dyn_cb->type = PLUGIN_CB_INLINE; + dyn_cb->rw = rw; + dyn_cb->inline_insn.entry = entry; + dyn_cb->inline_insn.op = op; + dyn_cb->inline_insn.imm = imm; +} + void plugin_register_dyn_cb__udata(GArray **arr, qemu_plugin_vcpu_udata_cb_t cb, enum qemu_plugin_cb_flags flags, @@ -480,6 +497,12 @@ void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) char *ptr = cb->userp; size_t elem_size = 0; size_t offset = 0; + if (!ptr) { + /* use inline entry */ + ptr = cb->inline_insn.entry.score->data->data; + elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); + offset = cb->inline_insn.entry.offset; + } uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) { diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 6204453d0fd..0d8141b85f1 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -28,13 +28,16 @@ qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_insn_exec_cb; qemu_plugin_register_vcpu_insn_exec_inline; + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu; qemu_plugin_register_vcpu_mem_cb; qemu_plugin_register_vcpu_mem_inline; + qemu_plugin_register_vcpu_mem_inline_per_vcpu; qemu_plugin_register_vcpu_resume_cb; qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; qemu_plugin_scoreboard_free; From patchwork Thu Feb 29 05:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776883 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651964wrn; Wed, 28 Feb 2024 21:26:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVx5FWS6PpzuFRh81RppJDftkM9KQZGEv5tFirxypklGyXjIMc1SBqnm9CzQGx4+r3vLQxsAmXF6zWf1I6huTpr X-Google-Smtp-Source: AGHT+IHIdkVhXKbNrqYAwi8ouvG1eML4Q4uEIajHh5LTRWbOdk0UFh5LPV6tqk28uV0trfxjGOQv X-Received: by 2002:ae9:c30d:0:b0:787:f545:a733 with SMTP id n13-20020ae9c30d000000b00787f545a733mr1410756qkg.38.1709184415762; Wed, 28 Feb 2024 21:26:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184415; cv=none; d=google.com; s=arc-20160816; b=BnnnL56xUnf+ztrHWTVnUr42adu2088zyVFX8Rtnnjn1f/+CRl2JrjNWIhBLC56r0C tnUUrQC1EWTO+yW/wkf9nQHeh0vpQ9SCMXAtIKulwNjtEj2BmP7boWloPRIHVcNp5e25 2oJjyH599BGt1sH4cQJAYkyyq67hOKYuYVix+eNs1Wu62mIIiIA7cOTNNrEfd4uBuSm9 gc/zt+gWTWf1DJ/qCOTxTmfdDrKuAb/1fIbtywsou8AIlX6lZu1a4G1gTQbOFHuSCabJ 1oUrYQvnPZsosVrP+3t5kLHBgVqmXv60n8oHzLN3rychbqLo7msbyD8DvCIlvF1+twbt vVGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=Ql+dzb3AhlcIgfD7DliLbgKyRxL6/ldCddiMf+4akB7rK0G0iqx8UeSiTwfwJqJtTW oEV6cGHlA1X03i7LUV+cf3FkuV//vvyu+mLLirtseeapJhXJvoW1Zdft0pEVBTMMniNL Ge6npRxXjnHOmPPKpa80GyEZ//1yopKltfKF4nvwXg6Kpf5lTLWn9cC72CE87on3NR5t 7QFa0ZUO3V8nJNImw+7lPap4gvUbk3JbSpPICZtDM6ophxM5rrc0LAwTUefXPFheBlkk 09sePaNWSZ/Ylgl7qA+pOCr243MTv3J4Dr6ezIhPBHjdiaAdxSc8wsK/xR2ME/CqJe6L GMfA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=umHAKc3W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id wj14-20020a05620a574e00b00787e02715bdsi720694qkn.253.2024.02.28.21.26.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:55 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=umHAKc3W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvP-0002m1-Sd; Thu, 29 Feb 2024 00:25:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvL-0002lc-CM for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:39 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvI-0005xC-Bq for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:38 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-412b5a9916eso3760455e9.1 for ; Wed, 28 Feb 2024 21:25:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184334; x=1709789134; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=umHAKc3WwxgAR5vU9QbbzcnBYCtjNPTwCZowm9k6Ay/RRlvTh1a15y68SWLnoJoRJB KpoFBq5o5ojU0G7JZOpDs7vc0DNbwhJpdiBOnOM0B/Y7hhlgDCYSbYRam2e4oJlWAJts qywVfotcUchKthABGpEVEPoJj7/mJsTQ7by8++AdnBavIwhqMnc2bNuB2JhgpxMkYXrH YhzrA47zB0FfzF0Qde9lShqVMy59y3GXFa/+PgqvF9KdRUvSpGKw6R8pCmQQL07bQdbU 4qXG6sGOB7+BEhAIg6AcXDxeOGJ9bsYFdgWHBMxdKCLykB9wVvtZKG4MxAdk86VfIqcf bQHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184335; x=1709789135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4WWaJPsclEFPyc9s7y8yPMs7GjvBirSud+8vEqilY/w=; b=BqJXIQFFkknpwG8oa6VZYBXd21gAWxzcXg3EyiGpd4wFxpwmjrdvW7evqekQjnIcgh GbXG9+4x6Ce9LqB4t+ihtttJjxIYhPrBqrC6jDMvZLzDhHUeybkySICjI8bYBe/pwcLd jmB2swVoNPq8J1YFT0t8RVsA7nAFxK+G3g32J/2LcUOtse3Ojz+bbEqnSxKNsC/y30KM GBFNA5skZdxSG/v/XyaKDt1h2IuhAANR1azCEJgclRms64PuoZhwT/Ghyrrvrehfgx7V LyIu6GtphxMyH0+uC34eUr6voEM2/DHqwFgVCOP8FDo40ergEYvIujOGBvv7T0jQb/3i 3cFg== X-Gm-Message-State: AOJu0YxLlQGJTamh5M0Vzs6Yn1mu77H0c1UVUY5XGr3rE3unJ0CNzgTb F0aNV7pI6DkmACG5DpBAhRkuRskBcWDjFkg02x4AZo6x9shgT2T2DtWItlOVChJaY8xWckSBzpO A7Js= X-Received: by 2002:a05:600c:4ed2:b0:412:b81f:758b with SMTP id g18-20020a05600c4ed200b00412b81f758bmr922858wmq.16.1709184334742; Wed, 28 Feb 2024 21:25:34 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:34 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 05/12] tests/plugin: add test plugin for inline operations Date: Thu, 29 Feb 2024 09:24:59 +0400 Message-ID: <20240229052506.933222-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org For now, it simply performs instruction, bb and mem count, and ensure that inline vs callback versions have the same result. Later, we'll extend it when new inline operations are added. Use existing plugins to test everything works is a bit cumbersome, as different events are treated in different plugins. Thus, this new one. Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- tests/plugin/inline.c | 186 +++++++++++++++++++++++++++++++++++++++ tests/plugin/meson.build | 2 +- 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/inline.c diff --git a/tests/plugin/inline.c b/tests/plugin/inline.c new file mode 100644 index 00000000000..0163e9b51c5 --- /dev/null +++ b/tests/plugin/inline.c @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2023, Pierrick Bouvier + * + * Demonstrates and tests usage of inline ops. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include + +#include + +typedef struct { + uint64_t count_tb; + uint64_t count_tb_inline; + uint64_t count_insn; + uint64_t count_insn_inline; + uint64_t count_mem; + uint64_t count_mem_inline; +} CPUCount; + +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 count_tb; +static qemu_plugin_u64 count_tb_inline; +static qemu_plugin_u64 count_insn; +static qemu_plugin_u64 count_insn_inline; +static qemu_plugin_u64 count_mem; +static qemu_plugin_u64 count_mem_inline; + +static uint64_t global_count_tb; +static uint64_t global_count_insn; +static uint64_t global_count_mem; +static unsigned int max_cpu_index; +static GMutex tb_lock; +static GMutex insn_lock; +static GMutex mem_lock; + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +static void stats_insn(void) +{ + const uint64_t expected = global_count_insn; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_insn); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_insn_inline); + printf("insn: %" PRIu64 "\n", expected); + printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void stats_tb(void) +{ + const uint64_t expected = global_count_tb; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_tb); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_tb_inline); + printf("tb: %" PRIu64 "\n", expected); + printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void stats_mem(void) +{ + const uint64_t expected = global_count_mem; + const uint64_t per_vcpu = qemu_plugin_u64_sum(count_mem); + const uint64_t inl_per_vcpu = + qemu_plugin_u64_sum(count_mem_inline); + printf("mem: %" PRIu64 "\n", expected); + printf("mem: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + g_assert(expected > 0); + g_assert(per_vcpu == expected); + g_assert(inl_per_vcpu == expected); +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + const unsigned int num_cpus = qemu_plugin_num_vcpus(); + g_assert(num_cpus == max_cpu_index + 1); + + for (int i = 0; i < num_cpus ; ++i) { + const uint64_t tb = qemu_plugin_u64_get(count_tb, i); + const uint64_t tb_inline = qemu_plugin_u64_get(count_tb_inline, i); + const uint64_t insn = qemu_plugin_u64_get(count_insn, i); + const uint64_t insn_inline = qemu_plugin_u64_get(count_insn_inline, i); + const uint64_t mem = qemu_plugin_u64_get(count_mem, i); + const uint64_t mem_inline = qemu_plugin_u64_get(count_mem_inline, i); + printf("cpu %d: tb (%" PRIu64 ", %" PRIu64 ") | " + "insn (%" PRIu64 ", %" PRIu64 ") | " + "mem (%" PRIu64 ", %" PRIu64 ")" + "\n", + i, tb, tb_inline, insn, insn_inline, mem, mem_inline); + g_assert(tb == tb_inline); + g_assert(insn == insn_inline); + g_assert(mem == mem_inline); + } + + stats_tb(); + stats_insn(); + stats_mem(); + + qemu_plugin_scoreboard_free(counts); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + qemu_plugin_u64_add(count_tb, cpu_index, 1); + g_mutex_lock(&tb_lock); + max_cpu_index = MAX(max_cpu_index, cpu_index); + global_count_tb++; + g_mutex_unlock(&tb_lock); +} + +static void vcpu_insn_exec(unsigned int cpu_index, void *udata) +{ + qemu_plugin_u64_add(count_insn, cpu_index, 1); + g_mutex_lock(&insn_lock); + global_count_insn++; + g_mutex_unlock(&insn_lock); +} + +static void vcpu_mem_access(unsigned int cpu_index, + qemu_plugin_meminfo_t info, + uint64_t vaddr, + void *userdata) +{ + qemu_plugin_u64_add(count_mem, cpu_index, 1); + g_mutex_lock(&mem_lock); + global_count_mem++; + g_mutex_unlock(&mem_lock); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + qemu_plugin_register_vcpu_tb_exec_cb( + tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, count_tb_inline, 1); + + for (int idx = 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, idx); + qemu_plugin_register_vcpu_insn_exec_cb( + insn, vcpu_insn_exec, QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, count_insn_inline, 1); + qemu_plugin_register_vcpu_mem_cb(insn, &vcpu_mem_access, + QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_MEM_RW, 0); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, QEMU_PLUGIN_MEM_RW, + QEMU_PLUGIN_INLINE_ADD_U64, + count_mem_inline, 1); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + count_tb = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb); + count_insn = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn); + count_mem = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_mem); + count_tb_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_tb_inline); + count_insn_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_insn_inline); + count_mem_inline = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, count_mem_inline); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/tests/plugin/meson.build b/tests/plugin/meson.build index e18183aaeda..9eece5bab51 100644 --- a/tests/plugin/meson.build +++ b/tests/plugin/meson.build @@ -1,6 +1,6 @@ t = [] if get_option('plugins') - foreach i : ['bb', 'empty', 'insn', 'mem', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall'] if host_os == 'windows' t += shared_module(i, files(i + '.c') + '../../contrib/plugins/win32_linker.c', include_directories: '../../include/qemu', From patchwork Thu Feb 29 05:25:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776882 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651896wrn; Wed, 28 Feb 2024 21:26:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXzuJTvW22IrZdpQ1n807USEeKApJN5gzdJzxUEhzG+t7/KHA6ITxC8tXFKCm3Bo7Q1M1SA68eqIiWNVU7CEg7W X-Google-Smtp-Source: AGHT+IEu3A6xkLCOf8A7VINVjXRfsraqsCPJvW1pwvuMvvIN1jWwoonpFMco1aZ13B6vwqHTwwpL X-Received: by 2002:ac8:5c91:0:b0:42e:616e:e2a0 with SMTP id r17-20020ac85c91000000b0042e616ee2a0mr1137585qta.3.1709184398436; Wed, 28 Feb 2024 21:26:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184398; cv=none; d=google.com; s=arc-20160816; b=a5gvcYcsl38KTbkx62Xlp22nuwIvASfE43R0X91vkb3Fz3DDM7txROg/nUDDna4ghA 591mhjO8ubRWJoEjsfKngIqg/B5d0vLWp+ov9QOhIPfgbgsk5gnxCnkBTakCLfKJvpIH at4jfK1Mg1/JeWCU2CrljYpqe1HvM146faMayoOGNnJVXRHJXQxgLNxtO//vc4CD20p3 m/ZsMCauquZuMS2uv+Tt97A5Jnn8lF7FwL36wJd5/FCys1xKBzA2Q1SHTtZuiY6x+S1h awFz/U3Ac+6hgtugEypchfFrz6I7/38Da4WugQ0EarmrukzLZbVdZ/iOa+WWOS8gyN4s 0Nog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; fh=L0hh/ue2K8HHkGVTIweE28wZeVS7aL+T29VaciJhggs=; b=Ey2nuZYKf2a8jqwVwQDCLZeq/ifeTT9UvDXYlHPVTGaNpMragsTns5qcwTovg8VBzr J5EoYJWDNWg3VVX6WTC7/Fsm0/pZRoozy3CUIMdSPr6a5BCwi6XAv0EXqCDcRjBL0uZz ayA0oItjD3JhQ9FS0T/lBOfn/4wlrHSwh8uIWF2I8ZxM25ZssjDaHVRsuSsq8B9wSqm5 5evIm4cPYAZt5KZJMOWVYG8Rkuh7PWJ19xseS/HD0Sf34FcH4/Dz2SBEHPF5nBOOD4gg nEhtXO+kjzb75/Iu5ZMmuA4EJpfUNQZ38wygKqiKmk9mgSFav8Jj92kPcf5m9LAtXyOL f+fg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iybd0eA+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c16-20020ac87dd0000000b0042e5fee19a3si748538qte.739.2024.02.28.21.26.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iybd0eA+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvS-0002ml-PO; Thu, 29 Feb 2024 00:25:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvP-0002m0-7u for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:43 -0500 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvN-0005xw-ET for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:42 -0500 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2d22b8801b9so6336111fa.0 for ; Wed, 28 Feb 2024 21:25:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184338; x=1709789138; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; b=iybd0eA+flXnrAqHVZFm09FnNG5wi1CscblhpoORfODoWTM0xvY6V588EulcNkSL4Z yXSc06k7LkLCGsir8YFBQi43Zvm7Bb3Jzj9G2JQiPH8vTHXBQ3+KSAi1/p7QdzlF6H0w yLrP7SU7hTXRWKVQ93dPTdZLZPECLTy2KXq8vLB94POJLhW7ggLuyuVuQIkQqWpd1sV2 hiMcLpaHVv2wwNRDSlcdhBylgnb3A3u6bwwevGBfZRSXUGGMXwLWe6shhRUWTTjwk1iw wNPCIbvU09FSilTBq0+OaXzIEEG66qGljprWywP60/p0Vmqmbpp7hoTiyLBmhraftKmf 9iXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184338; x=1709789138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=356+Cre4aJDUmUdLtOAGHoP1lMAEwsxajGw7J4xrJ/Q=; b=B/m31V5hByMPOhCQ4Z9K9q4fPLh1iRkneOWa7pLZjB0BANYTNEMZTb0pr2qjQbIZ6k Xkc+ZfWsjb9Pde4sHpiWRj2muDwq7rkw7di3sO7d21gZ2IU4BYeodt+q/dXwt5asNS7N FRvHJ6Yk1c2DDV6iujYquF8Uws90JC/0cQB67xl20EMjuqa5dtkzZYpF3wbluN+rn2l5 4CGPzlqjIibzwsgrOP+7XPIJ9xsmRjH18wUEnef81Cg2kTrZOBfrglJ7C3N/d07tgc00 160pA5SiJxniERyJ+RWHlXqCoQM25QlYfRoFGwkpYRPkwxMAJPWJUVlAxReL7L71F/Pr 7gQA== X-Gm-Message-State: AOJu0Yzole2S4L1dHqfTLHF3/sLz+HJfl3zEyDJDRSC/2HKWBj7AN/HS xi2lJ9O9CE4RwkmW2ITU5ApKnLTcakmcRHplnyKgWSKNnl5rAv/DDPS1UXbiuyBOEXeh6Z9OiBc XGU0= X-Received: by 2002:ac2:5b9a:0:b0:512:9dee:44fe with SMTP id o26-20020ac25b9a000000b005129dee44femr653009lfn.26.1709184338435; Wed, 28 Feb 2024 21:25:38 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:38 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 06/12] tests/plugin/mem: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:00 +0400 Message-ID: <20240229052506.933222-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- tests/plugin/mem.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..b650dddcce1 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,9 +16,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t inline_mem_count; -static uint64_t cb_mem_count; -static uint64_t io_count; +typedef struct { + uint64_t mem_count; + uint64_t io_count; +} CPUCount; + +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 mem_count; +static qemu_plugin_u64 io_count; static bool do_inline, do_callback; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; @@ -27,16 +32,16 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) out = g_string_new(""); - if (do_inline) { - g_string_printf(out, "inline mem accesses: %" PRIu64 "\n", inline_mem_count); - } - if (do_callback) { - g_string_append_printf(out, "callback mem accesses: %" PRIu64 "\n", cb_mem_count); + if (do_inline || do_callback) { + g_string_printf(out, "mem accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(mem_count)); } if (do_haddr) { - g_string_append_printf(out, "io accesses: %" PRIu64 "\n", io_count); + g_string_append_printf(out, "io accesses: %" PRIu64 "\n", + qemu_plugin_u64_sum(io_count)); } qemu_plugin_outs(out->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, @@ -46,12 +51,12 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, struct qemu_plugin_hwaddr *hwaddr; hwaddr = qemu_plugin_get_hwaddr(meminfo, vaddr); if (qemu_plugin_hwaddr_is_io(hwaddr)) { - io_count++; + qemu_plugin_u64_add(io_count, cpu_index, 1); } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } else { - cb_mem_count++; + qemu_plugin_u64_add(mem_count, cpu_index, 1); } } @@ -64,9 +69,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); if (do_inline) { - qemu_plugin_register_vcpu_mem_inline(insn, rw, - QEMU_PLUGIN_INLINE_ADD_U64, - &inline_mem_count, 1); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, rw, + QEMU_PLUGIN_INLINE_ADD_U64, + mem_count, 1); } if (do_callback) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, @@ -117,6 +123,16 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } + if (do_inline && do_callback) { + fprintf(stderr, + "can't enable inline and callback counting at the same time\n"); + return -1; + } + + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + mem_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, mem_count); + io_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, io_count); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0; From patchwork Thu Feb 29 05:25:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776887 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp652108wrn; Wed, 28 Feb 2024 21:27:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWWj7at0cZFYnuy8yMOAKUtAKDSEY0WQs6EwSOEOJX8Ru/roEkOTYHcBBlVp5FBYuu0mYV20ABdpXnVI/Bob7zI X-Google-Smtp-Source: AGHT+IE5I/fKyOkb1LjmSrzj6TV6kXvJwFYRtCt0xHsU8KFlXWkFXmQeM5vCxvDO5SCjlZ3zfvOW X-Received: by 2002:a05:622a:1015:b0:42e:b4d7:d0d with SMTP id d21-20020a05622a101500b0042eb4d70d0dmr1229682qte.49.1709184444195; Wed, 28 Feb 2024 21:27:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184444; cv=none; d=google.com; s=arc-20160816; b=XVYzTitjsq70xW1QT8rGh7HMwF1YwNNWenLYvbUm1ig7H2JYQSaRsQUngC/an4qgdl VV1jGrHdrlshAPPxwpLCK6RsP815NScWcIFZ9IGSPPEQC0LInSGmbSQ/DeoRIUY6Yq+D LoSsP2eMvdebkrLmWt5DKW6oiFLlah4OvLzq9UtuyaaX86d4uNQPff95MkVg5mnj4eIs A35vqrcm5MzEh1VtUJV913XwAs1APy0yB7js0bNpuNp31TIvXTsM34FpqidCUA4NhSnp 6AubHzTeKzKihWNJ3auv0agslXlu4FDBDMR+nmN8TovVOsimlPAib9XE13sVA4lttkwf oiIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; fh=L0hh/ue2K8HHkGVTIweE28wZeVS7aL+T29VaciJhggs=; b=i8ufb5VTyzvojltONJOG4OaHi1T8S6sG70MJ4XFaJgSx6svZiGhgO3KmN4suBfc0NG osTlUVW5oE/a59I+wFXpFAf2y/UXkXDsA0iaW0zCSinNYNMrNchyHwLwMrzWFZyF+EFm lvZT0t6LAMobCGMTQErYE9XIjemP3GBDh4zkuORoAk8uOJ2y6qLi6MHp2mWQWgThTaHU mmqpQDK/i6TO+z2TkCjHh7l6SRk4U/fgiyCEbNdnU+6rl1UDfZlkpGlfWtv5SMapL0Mw ggtSg5lvxDXYuxJG5ZOefG5W3xR8M/77cjhxK4xkZtQZOfiJJPs3ZgzzkRvSqUZ8loLk MF/g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YAiOnZjq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 18-20020ac85912000000b0042e61d9aaa1si755716qty.10.2024.02.28.21.27.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:24 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YAiOnZjq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvV-0002n7-K4; Thu, 29 Feb 2024 00:25:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvR-0002mY-JR for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:45 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvP-0005yR-Nk for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:45 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33d6f1f17e5so321037f8f.3 for ; Wed, 28 Feb 2024 21:25:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184342; x=1709789142; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; b=YAiOnZjq6Suxdka9ppBUMAG7hE12ow9iaWWdTPpc+pVPJx1vmyt+R+xVSnR12kbMOq TXk6L1yjxsG/v/Riifawytxgb8tHFnScnw7qdcvL2YygRdEjhNFcVBVHB+fZGI/h/lxW Fje9ya8m8nAymjcKBqfqdPppQ8JYT1wHR091EXB2mNZ0FLUYC9PoU5iIc8wi8hXiVtjC G5UxXx6bw4zePFzEbu5H8QFAt7ccuV0q5tc28XywzGAzopHl3FGyRxw5g2SsbAtibH3D N8c6oL1Q8qHU9+d9UDeBp8q6rQtMrfPzHP8OeV95RzkPKfTp9m42BCgwkFRYUPQ7JLf/ hwBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184342; x=1709789142; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+mdlljGjjXpWyYuEwsIaeI9gGRtfmPnU4W1OBz5Lh8Y=; b=ErpkHohBK0D22UbXoHysiDkZHp/8PvjvN6Y83u6LTgozDvL6lsfKqQ4LvVzOz67Zvg d9K9lq1Vij/pQdjsFr0sG80VCi3XCI9KB2cKFwuYrHQTU7CdWYF3MDBau7EbLPC/KhUg wihMcJkIWwfw1uN76PlONTowrHwodsfzg/GCkx/KdHI31YUz24BjD2XfhAaQbniWoDv/ vBnWDeEK3F7Z4dTZMIl2w7ECD5hP9RWFkX0FCFl0YoUCDQHVwKfqdiBUDo6jW24duflN PjVNiryOGRUlokX+V9h+BmYz8+Y3cloSQwOgn9m2Xnil3UdkUmmtCAlZoIZAhRUy41D0 E5Xg== X-Gm-Message-State: AOJu0YxMaxJ7eDZxEcrAue6etjXcJZiR877pA4MVdIgxA8mopoqv/stv W09smdnUWlKQ7+rKBplfwhLtDBEMydtO0ETl8zYObFKGcauoNBYU7JJNNqYBFXRJ/q2dmEDj3gJ nvMw= X-Received: by 2002:a5d:53d2:0:b0:33d:26b1:c460 with SMTP id a18-20020a5d53d2000000b0033d26b1c460mr506434wrw.39.1709184342122; Wed, 28 Feb 2024 21:25:42 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:41 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:01 +0400 Message-ID: <20240229052506.933222-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- tests/plugin/insn.c | 106 +++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 54da06fcf26..5e0aa03223e 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -16,25 +16,21 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -#define MAX_CPUS 8 /* lets not go nuts */ - -typedef struct { - uint64_t insn_count; -} InstructionCount; - -static InstructionCount counts[MAX_CPUS]; -static uint64_t inline_insn_count; +static qemu_plugin_u64 insn_count; static bool do_inline; static bool do_size; static GArray *sizes; +typedef struct { + uint64_t hits; + uint64_t last_hit; + uint64_t total_delta; +} MatchCount; + typedef struct { char *match_string; - uint64_t hits[MAX_CPUS]; - uint64_t last_hit[MAX_CPUS]; - uint64_t total_delta[MAX_CPUS]; - GPtrArray *history[MAX_CPUS]; + struct qemu_plugin_scoreboard *counts; /* MatchCount */ } Match; static GArray *matches; @@ -67,41 +63,40 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; - InstructionCount *c = &counts[i]; - - c->insn_count++; + qemu_plugin_u64_add(insn_count, cpu_index, 1); } static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *udata) { - unsigned int i = cpu_index % MAX_CPUS; Instruction *insn = (Instruction *) udata; - Match *match = insn->match; + Match *insn_match = insn->match; + MatchCount *match = qemu_plugin_scoreboard_find(insn_match->counts, + cpu_index); + g_autoptr(GString) ts = g_string_new(""); insn->hits++; g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits", insn->vaddr, insn->disas, insn->hits); - uint64_t icount = counts[i].insn_count; - uint64_t delta = icount - match->last_hit[i]; + uint64_t icount = qemu_plugin_u64_get(insn_count, cpu_index); + uint64_t delta = icount - match->last_hit; - match->hits[i]++; - match->total_delta[i] += delta; + match->hits++; + match->total_delta += delta; g_string_append_printf(ts, - ", %"PRId64" match hits, " - "Δ+%"PRId64 " since last match," + " , cpu %u," + " %"PRId64" match hits," + " Δ+%"PRId64 " since last match," " %"PRId64 " avg insns/match\n", - match->hits[i], delta, - match->total_delta[i] / match->hits[i]); + cpu_index, + match->hits, delta, + match->total_delta / match->hits); - match->last_hit[i] = icount; + match->last_hit = icount; qemu_plugin_outs(ts->str); - - g_ptr_array_add(match->history[i], insn); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -113,8 +108,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1); } else { uint64_t vaddr = qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -136,10 +131,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) * information about the instruction which we also need to * save if there is a hit. */ - if (matches) { + if (matches->len) { char *insn_disas = qemu_plugin_insn_disas(insn); - int j; - for (j = 0; j < matches->len; j++) { + for (int j = 0; j < matches->len; j++) { Match *m = &g_array_index(matches, Match, j); if (g_str_has_prefix(insn_disas, m->match_string)) { Instruction *rec = g_new0(Instruction, 1); @@ -169,36 +163,33 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "len %d bytes: %ld insns\n", i, *cnt); } } - } else if (do_inline) { - g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_count); } else { - uint64_t total_insns = 0; - for (i = 0; i < MAX_CPUS; i++) { - InstructionCount *c = &counts[i]; - if (c->insn_count) { - g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", - i, c->insn_count); - total_insns += c->insn_count; - } + for (i = 0; i < qemu_plugin_num_vcpus(); i++) { + g_string_append_printf(out, "cpu %d insns: %" PRIu64 "\n", + i, qemu_plugin_u64_get(insn_count, i)); } g_string_append_printf(out, "total insns: %" PRIu64 "\n", - total_insns); + qemu_plugin_u64_sum(insn_count)); } qemu_plugin_outs(out->str); + + qemu_plugin_scoreboard_free(insn_count.score); + for (i = 0; i < matches->len; ++i) { + Match *m = &g_array_index(matches, Match, i); + g_free(m->match_string); + qemu_plugin_scoreboard_free(m->counts); + } + g_array_free(matches, TRUE); + g_array_free(sizes, TRUE); } /* Add a match to the array of matches */ static void parse_match(char *match) { - Match new_match = { .match_string = match }; - int i; - for (i = 0; i < MAX_CPUS; i++) { - new_match.history[i] = g_ptr_array_new(); - } - if (!matches) { - matches = g_array_new(false, true, sizeof(Match)); - } + Match new_match = { + .match_string = g_strdup(match), + .counts = qemu_plugin_scoreboard_new(sizeof(MatchCount)) }; g_array_append_val(matches, new_match); } @@ -206,6 +197,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { + matches = g_array_new(false, true, sizeof(Match)); + /* null terminated so 0 is not a special case */ + sizes = g_array_new(true, true, sizeof(unsigned long)); + for (int i = 0; i < argc; i++) { char *opt = argv[i]; g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); @@ -227,9 +222,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (do_size) { - sizes = g_array_new(true, true, sizeof(unsigned long)); - } + insn_count = qemu_plugin_scoreboard_u64( + qemu_plugin_scoreboard_new(sizeof(uint64_t))); /* Register init, translation block and exit callbacks */ qemu_plugin_register_vcpu_init_cb(id, vcpu_init); From patchwork Thu Feb 29 05:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776885 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp652003wrn; Wed, 28 Feb 2024 21:27:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXrSJo0ZVhRAtKSDqMd1maTZZzQnLXuWen0seLPSQZOB1wDje9Exry/5Tays47QvsnkS6NiLfg0GuDs1ffP94Qi X-Google-Smtp-Source: AGHT+IGEN8HuyiV1VTFF7H4tNY4Axu/h9vUu4Ivp9VaXiupa2p0JHbM7n2AkZCHRZBrtnA6+5V8v X-Received: by 2002:a05:6214:2b48:b0:68f:ff45:8793 with SMTP id jy8-20020a0562142b4800b0068fff458793mr1385361qvb.25.1709184426400; Wed, 28 Feb 2024 21:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184426; cv=none; d=google.com; s=arc-20160816; b=ZTp0w/UHGCPinT7SDVtFW+rRzk6YimQydlK6sopYq8e2R5dHp4W/44nP+8bNNgJFqP LniaOSGpNXXO3VfwakTh5pmvowuQ5EQ01chZdkQIGl2/6Tg7eDz2t4gv8u7iQLOuvSiw ogMgG6kl0KzY0zE/udNpbT8wh+wjzvLLuGktBtut2d6r3IKY+7G0QqlmRTKWdAAiKJ3t GONanGLtWPucQrMTW0sSWRxODTrteIRaW6JKn9svdRbsey/AVDj687QNIZJ4zcTABybl DEs8XuFxQ6/MKm57n11PW6nRrKUUVRRwgdTQlpmsrHxkCDZ7UtyUqpNF/RdBaKwSR8dI qudA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; fh=L0hh/ue2K8HHkGVTIweE28wZeVS7aL+T29VaciJhggs=; b=NpAfWd1my2rce7UPEJhSvco5gqW1pg/1r3zQ3tJwILNcTwP0vAZ6EyzplJ6GEIDihh pEdEs7IE2HnlyW55Czb56sWoRAAXOLidcaKssaBQIjnwHjwgyDJLaGSMaBkg9P9/L47j aXWWrFj5RPcaQAFz6oprAfBPWULs567DuGFDBAtjCptjzq5t+BuiO1Ye7W1glEBSVrfv nvk19/87dtWxKks8JrYs/Tyst+AaJ8WwFLRNApjXbU1Cwl0luuzEFvPEMsNY5VIIlREV 17l0qqdlq5DAyj1AgmjPu6nFUKbH8ynRnW9vlzMy/qVsG1xwDLT/+sV6MmHXymewY7Ez 3/Dw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AGcRFjWX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 4-20020a0562140d0400b0068f610acb50si647916qvh.613.2024.02.28.21.27.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:06 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AGcRFjWX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvb-0002op-Tt; Thu, 29 Feb 2024 00:25:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvZ-0002o9-VM for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvV-0005zR-0V for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33de6da5565so284511f8f.2 for ; Wed, 28 Feb 2024 21:25:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184345; x=1709789145; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=AGcRFjWX6e5NrHfn7l8x6uLb7O4Fq3GdX5FehSsPlaMWF6SzBGGtK15L0mb5mwa9vf kaJmVqz2+nJq6rWQR2yI+b7ebbBE5gCC6SRjm0CqkAi7yZ7YZtUr+DPZHL4mgdB9oXrh NkbkHlYNJE9SAs5Sh/FAtH9ZoFU0yIa8SSpl602jvd/5lXDpFspymJX4tQe4z30jzGC2 qma7gwCgWvl8JzABz6a59sZ5osn1zKdxL4/HDdv+jrEZ9xUMyfhsQUpozKp/TQW6NTCy 9Uw1AKvQxq00CYdgkNOjOOvOPoRzCD7Of1gyl3EkRzIdbGrBOZm5dIEQqnw4YDiqITie 5zHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184345; x=1709789145; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=jxSDHfQ2TTKqJmvC74WddScq6ifQGhx4uD/vr2iVUZX+QV8kq0Hc0hKddZz2dRU+/P CU8n1T8EuKr3T8hi8z79M8qKDr4706OBVpezzFuUQ7dKtk0e3TecEEMyOXOz8iQ8WC4q XAUvwj1ZmzjSYSKgacJt/wXPQkBV9aY1teTyUxwNU8VI4WYsi3PnBJw3XNGn/cpd8FaA tS7ZMuyCUm4SmyaDsxsMqnCE5jFl1/3uxuzcQRde+emApbZr4zW3VCUv0mZGycT4F6aO tA62zQaGf8EkkLH/U5jlUnYAH80HHWmGI2zlOG3HmViYXW2tqiaycr+93DO2Y7HX+H8K FYTg== X-Gm-Message-State: AOJu0Yzf2rb7HY7kIUKwU6IYq03HV4Z8wPRkoEzgDo9tnHFlkJ6z37Z0 5GUtfPhJ7Dy4KCzDZcJCReUXBCCzhCVb/ZJtTUhcRnSMlukAeCskQpfenmzk2wve6FJRr64B9XI KrSc= X-Received: by 2002:a5d:4b8a:0:b0:33d:96c7:ae3d with SMTP id b10-20020a5d4b8a000000b0033d96c7ae3dmr503207wrt.16.1709184345745; Wed, 28 Feb 2024 21:25:45 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:45 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:02 +0400 Message-ID: <20240229052506.933222-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Luc Michel Signed-off-by: Pierrick Bouvier --- tests/plugin/bb.c | 63 +++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index df50d1fd3bc..36776dee1e1 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -17,27 +17,25 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; typedef struct { - GMutex lock; - int index; uint64_t bb_count; uint64_t insn_count; } CPUCount; -/* Used by the inline & linux-user counts */ +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 bb_count; +static qemu_plugin_u64 insn_count; + static bool do_inline; -static CPUCount inline_count; - /* Dump running CPU total on idle? */ static bool idle_report; -static GPtrArray *counts; -static int max_cpus; -static void gen_one_cpu_report(CPUCount *count, GString *report) +static void gen_one_cpu_report(CPUCount *count, GString *report, + unsigned int cpu_index) { if (count->bb_count) { g_string_append_printf(report, "CPU%d: " "bb's: %" PRIu64", insns: %" PRIu64 "\n", - count->index, + cpu_index, count->bb_count, count->insn_count); } } @@ -46,20 +44,23 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new(""); - if (do_inline || !max_cpus) { - g_string_printf(report, "bb's: %" PRIu64", insns: %" PRIu64 "\n", - inline_count.bb_count, inline_count.insn_count); - } else { - g_ptr_array_foreach(counts, (GFunc) gen_one_cpu_report, report); + for (int i = 0; i < qemu_plugin_num_vcpus(); ++i) { + CPUCount *count = qemu_plugin_scoreboard_find(counts, i); + gen_one_cpu_report(count, report, i); } + g_string_append_printf(report, "Total: " + "bb's: %" PRIu64", insns: %" PRIu64 "\n", + qemu_plugin_u64_sum(bb_count), + qemu_plugin_u64_sum(insn_count)); qemu_plugin_outs(report->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count = g_ptr_array_index(counts, cpu_index); + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); g_autoptr(GString) report = g_string_new(""); - gen_one_cpu_report(count, report); + gen_one_cpu_report(count, report, cpu_index); if (report->len > 0) { g_string_prepend(report, "Idling "); @@ -69,14 +70,11 @@ static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - CPUCount *count = max_cpus ? - g_ptr_array_index(counts, cpu_index) : &inline_count; + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); uintptr_t n_insns = (uintptr_t)udata; - g_mutex_lock(&count->lock); count->insn_count += n_insns; count->bb_count++; - g_mutex_unlock(&count->lock); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -84,11 +82,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t n_insns = qemu_plugin_tb_n_insns(tb); if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.bb_count, 1); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.insn_count, - n_insns); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, bb_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, n_insns); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -121,18 +118,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (info->system_emulation && !do_inline) { - max_cpus = info->system.max_vcpus; - counts = g_ptr_array_new(); - for (i = 0; i < max_cpus; i++) { - CPUCount *count = g_new0(CPUCount, 1); - g_mutex_init(&count->lock); - count->index = i; - g_ptr_array_add(counts, count); - } - } else if (!do_inline) { - g_mutex_init(&inline_count.lock); - } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + bb_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, bb_count); + insn_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, insn_count); if (idle_report) { qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle); From patchwork Thu Feb 29 05:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776889 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp652166wrn; Wed, 28 Feb 2024 21:27:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWr9y77CzEWRS6QGl/zna8bP9KjLpZgwHozxOYlSRsEew55W/iygWtv3kMRjvonRJFHpU9TrNa1hv757tuwhuGJ X-Google-Smtp-Source: AGHT+IH/1Da6eCjIjZ/uAyi+enDvMlCc5xhKug67ReT2cu1EfrBWUAfEmNSJmVMgWLHkOHedl+/e X-Received: by 2002:a0c:fa11:0:b0:68f:5546:c7e8 with SMTP id q17-20020a0cfa11000000b0068f5546c7e8mr1219044qvn.48.1709184461968; Wed, 28 Feb 2024 21:27:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184461; cv=none; d=google.com; s=arc-20160816; b=WOXRTjdFW1Pn7YLxSqLUdl8Pc4l23V7kbHY0nK5Eqe6U8S2tlNYhYMgktCFenC7zLF l8tBOl/H2hiJUe1ttuBZHFDkaYYpiSNDA3GEuFOGOKeIgyZ+SMD0IdW/veETXLH5AFUA MX7NxPn6Ed2LNrmFReHwkCgMg4vmpC48imK8ojztdtkmTd0pfwInTP7UIErPaNuq1cQF neha5OxnDtBjqqdC93QYpBbCpTVFQVtl0r6iMnsxMNEpIXHfi9g48jcaXKyzvoIkG+BO 01ggAwBIBu/OqcZCsqLFnEjjiW75t9C9XphV7ikx4LkFDQv4EtYHn6i1YI0/o6tHh+3p U4lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=0SJ9aRRnP+eMPu02o/hdBRgAkbCbhMvYygo5toVjBUc2p76RUNhWKjyWTW2ioVqY/j E17ng7+gYbwacrz50rW6SRl9h4lRmR2PPgcfgTKckofjE/n7ddi7X8IO/K1vje5JcD0p T7erMd0cR0W1gd/2BcTlhlVw5Vut1eiKMTfxDFruU8JdgBlOh/DFy/Tfvl2T3WV7fvxY wu0UBjcdiO0OhTdxyXA1UGsMuZxIQKusrbvFoNYI6xn1kAkqJDHNL5T1Mv4HyVifv9px ZCzchBgfnwDYczqDSSAOu6CWDs5oPWXsIon7z9Can5L+klRYworniBMY3ws8erzkU1FD TmQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vQX8UFDb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jz1-20020a0562140e6100b0068fe8554c3csi689754qvb.86.2024.02.28.21.27.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:41 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vQX8UFDb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYva-0002oP-93; Thu, 29 Feb 2024 00:25:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvY-0002ne-WB for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvX-0005zu-Cy for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:52 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-412b98c9b2fso4018205e9.0 for ; Wed, 28 Feb 2024 21:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184349; x=1709789149; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=vQX8UFDbQrfNOeUFlshmwZNp4x6SawUjMH0NAOlrfJqXL7+73bE8nWgfPI7Cky807T hX2d4wrEBscqiFNvSbk5ruTDGL6HxxmpndC1rVtwUux3Vu2KqtMH8tE4RBRD4J6IK3/3 aBoteYWoFfpO74qRZOHSMrxAH+9jTOb4gDyPiyMCKy58eEYBPInbdg6IPS3QtfHU9W4S tme4bLjKg3U7oI1EohxObDilR2WVo1koFiS9XGUWUNpHS4s9LogJJuUUdtKWCESJG1aF SSe8B55pSjj5PEQougbcbQpP4zarbUX2/Oe1PelkDaWJSLon/aHafzDJENzDHecRgA/c H4Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184349; x=1709789149; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RwJ8e6wUH7fqyic9sqG77ZVCFxcpo7vgFJo8+jFAkz0=; b=EzulzV2hUhcmqCAXOHHdjt1lbXT3NFcgdI+O0M5XO8NcJCXYXyWUOB2iQz96TRPI5Q SPaIPhtr1E7Mh1bLiwTPOZ8Z6GLddjvoiXOqNx+bvgbuhwtUpzByBnfwQ3wab00U8oW3 RWzmGzcKltpLQ84WzPI7f/RKh8nV1iqbJH0VraVSoY+tUG5RD0Ys3FsVevVskTN4Advy +IU1j/FdEg1fSB/Rw5HCDF04xI2vWx3r9ZUyVrsat28EMURh2Hp1G/J+Axjgbw73JkqI HO37TdtGCEHkhNhI5kiK4WroJt1PGT3ndsFD1Z1Me7KS7C8Q4DhAak9gDuRCNC8lqUfL pmOA== X-Gm-Message-State: AOJu0Yw4rO8lc+qLOaOczFOEVmqTb2pbK3InhdHpiKpEcRKx3Mn6BFLw dkC49ZxLrwucdW2uNUH+cSKonMqDAjI9WXf0It/i58gdLpWK5oN0+BWZlqODmJRxRSFXsB4swmY aVgU= X-Received: by 2002:adf:fe51:0:b0:33d:a452:2fff with SMTP id m17-20020adffe51000000b0033da4522fffmr636091wrs.11.1709184349147; Wed, 28 Feb 2024 21:25:49 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:48 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:03 +0400 Message-ID: <20240229052506.933222-10-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Pierrick Bouvier --- contrib/plugins/hotblocks.c | 50 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 4de1b134944..02bc5078bdd 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -34,8 +34,8 @@ static guint64 limit = 20; */ typedef struct { uint64_t start_addr; - uint64_t exec_count; - int trans_count; + struct qemu_plugin_scoreboard *exec_count; + int trans_count; unsigned long insns; } ExecCount; @@ -43,7 +43,17 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { ExecCount *ea = (ExecCount *) a; ExecCount *eb = (ExecCount *) b; - return ea->exec_count > eb->exec_count ? -1 : 1; + uint64_t count_a = + qemu_plugin_u64_sum(qemu_plugin_scoreboard_u64(ea->exec_count)); + uint64_t count_b = + qemu_plugin_u64_sum(qemu_plugin_scoreboard_u64(eb->exec_count)); + return count_a > count_b ? -1 : 1; +} + +static void exec_count_free(gpointer key, gpointer value, gpointer user_data) +{ + ExecCount *cnt = value; + qemu_plugin_scoreboard_free(cnt->exec_count); } static void plugin_exit(qemu_plugin_id_t id, void *p) @@ -52,7 +62,6 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) GList *counts, *it; int i; - g_mutex_lock(&lock); g_string_append_printf(report, "%d entries in the hash table\n", g_hash_table_size(hotblocks)); counts = g_hash_table_get_values(hotblocks); @@ -63,16 +72,21 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) for (i = 0; i < limit && it->next; i++, it = it->next) { ExecCount *rec = (ExecCount *) it->data; - g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", - rec->start_addr, rec->trans_count, - rec->insns, rec->exec_count); + g_string_append_printf( + report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n", + rec->start_addr, rec->trans_count, + rec->insns, + qemu_plugin_u64_sum( + qemu_plugin_scoreboard_u64(rec->exec_count))); } g_list_free(it); } - g_mutex_unlock(&lock); qemu_plugin_outs(report->str); + + g_hash_table_foreach(hotblocks, exec_count_free, NULL); + g_hash_table_destroy(hotblocks); } static void plugin_init(void) @@ -82,15 +96,9 @@ static void plugin_init(void) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - ExecCount *cnt; - uint64_t hash = (uint64_t) udata; - - g_mutex_lock(&lock); - cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); - /* should always succeed */ - g_assert(cnt); - cnt->exec_count++; - g_mutex_unlock(&lock); + ExecCount *cnt = (ExecCount *)udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(cnt->exec_count), + cpu_index, 1); } /* @@ -114,18 +122,20 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) cnt->start_addr = pc; cnt->trans_count = 1; cnt->insns = insns; + cnt->exec_count = qemu_plugin_scoreboard_new(sizeof(uint64_t)); g_hash_table_insert(hotblocks, (gpointer) hash, (gpointer) cnt); } g_mutex_unlock(&lock); if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &cnt->exec_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + qemu_plugin_scoreboard_u64(cnt->exec_count), 1); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, - (void *)hash); + (void *)cnt); } } From patchwork Thu Feb 29 05:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776884 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651999wrn; Wed, 28 Feb 2024 21:27:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWfqZf0JY4k+irV6Pt/c/G4MJZ7HAYlX6/P8Tuy2kkmfh1FYahXOZ4fxBZA7ISqH9BFKMpvwLykKsxRWGZcbY74 X-Google-Smtp-Source: AGHT+IG/VvyI6a0PtVA1cJaIyo5XiJ3+W2jvrpmNcXko3WSL+Q2GLl/+Gmu+8Ij/7HymiSwKD4sp X-Received: by 2002:a05:622a:90:b0:42e:bcde:94a9 with SMTP id o16-20020a05622a009000b0042ebcde94a9mr455921qtw.10.1709184424804; Wed, 28 Feb 2024 21:27:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184424; cv=none; d=google.com; s=arc-20160816; b=rZrg8a/yQTMYkthRY9ko+cgybtYRk5ZRogx70UgORK7Db0KPzHjMoP7DOOrxsj2PMa QPNNHnEmuqN2ulVyH1v4xLhtDh5lqTn1RvdQtnruuLaXKBJ8DIsoXSSi8lpIbyLg7HGj zzupequMYf9dNjb0FMCvd06xusk7YTdr8AEU47yWG2waVFnzUc4Tg5wXrhg66otSrIuS ae5aCxVC+g9h2DQNuLuttbWVZlnbfEFex/XM2zIPf26HxoSQyVoACIrRAQjJf5xPrZ0s 3i9AouQ5nN8i6CFON0JZi8afd+N4NftGuC7Mo+QHLv/Rx6XjFLK1bkcF4iFLHDIwkgj9 nYxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=VS+ohFSlV0ydSmm+5sUfi7kSD3OHsunUBteDUCNheCffOqh2w8fRFHfeCEewXWGlML 49nHGSqpPmpygBm5wR+SqpUgNEs6Rbwnkqee0ZnMdsUdIhusrn9JAZveAp7k55AVQjIt BSvRC3Vqc94+AWKSB3OJMdMpoC+6av9kL1QcJXX6L9VPf1e83so04q26FZ3LoONxW0Vn AFtrssGczSM1m+FEnmNL7goDYYnPHBTUTB7IriuuTp9OtCF89DTrY5Jlhn3qBUgTF60P G74ZTyCa/OIWUt/UnF43sE7jsPy8EtHTlLDn6+MRa8Kl3EULXYJXt0kNEAUiSgX4+7N+ SIOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bGq9ziO2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m13-20020ac866cd000000b0042ea738979dsi699615qtp.299.2024.02.28.21.27.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bGq9ziO2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvf-0002x1-Th; Thu, 29 Feb 2024 00:25:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvd-0002qV-7F for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:57 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvb-00060U-G6 for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:56 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3392b045e0aso280569f8f.2 for ; Wed, 28 Feb 2024 21:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184352; x=1709789152; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=bGq9ziO2WrChGw5N6UMaeMxrmcJ5UXk7lOBX43oP/o0H0B4d/g8FkKkOjB9z+iLs2H zyk0GxRmYF4P8QSK43/IC4N2X+fDy5ndhYWpJ2Hgawp12cBO20WLfzPLj/ck01gi5Z9N ltUMmGVe3jQxSSDbmMyJkJ9GN8G1DOGTUN9bQswH4hAUfOPb2bE8xCBzCGFWeZEzE6N4 j5Xp2KdEpoZ3HgUfx8238//9mywsu15AD0zjy1BEDPtQai+emx/WWCqD1nlEq5nCGahX rYCZoaQEueA8tyAYjR90Pk9eJ0sBaJRjf1U8KGk48zLRL+pJLgxFVWBpkWiaL3lhNUSP aTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184352; x=1709789152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KLrDeSzxAfz0BkmoOA2bd0HrCpMytbURUXRn/P+Vjdc=; b=r/RFMsDz3SWvh3pxQE9zDZyJUcUppRE8gBwJDgxSnMuSnDYxTWZSpz8tYOqdy5ETuD Vw+5kvz3oePv69fjYbRtca3s/E4uXJBZ8Yn4ri/yYrrXSBSUldqu9Xw0TjGu41E6E6Ic YDFYc4z+FB7R9FbHbprv6TL5WXvAgiauT5kunf8Z9GHoJJ/QygCjNO6RoNIA6b8snVi2 9J2y7JfxDZrH/32+fHUZ5N7rKmy46ew26GKUco8m+8nqbf10bw2DF+MMy31d0tIKd+9r oYDsOcVb/PNaZUg1RCqznHNlK7LMam1+BUJnyF10+YGtaTl/HFpBcsB9AvHaDaqckthx 2gWw== X-Gm-Message-State: AOJu0YzT8Dau9aP8/WczD2FG+p0pNSLDpwPL4bTHNOvU0x4C6VX5J8ID hIKX0AQWkY9zqNteDS29N5B7zlIm1hb21fU1miSTVkEyykR1DQ/SltmXPpE8xwrnGSmFY523dW3 ZYMg= X-Received: by 2002:a05:6000:12:b0:33d:e7a2:fb05 with SMTP id h18-20020a056000001200b0033de7a2fb05mr572526wrx.48.1709184352637; Wed, 28 Feb 2024 21:25:52 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:52 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:04 +0400 Message-ID: <20240229052506.933222-11-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Pierrick Bouvier --- contrib/plugins/howvec.c | 53 ++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..2d10c87e0fb 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -43,13 +43,13 @@ typedef struct { uint32_t mask; uint32_t pattern; CountType what; - uint64_t count; + qemu_plugin_u64 count; } InsnClassExecCount; typedef struct { char *insn; uint32_t opcode; - uint64_t count; + qemu_plugin_u64 count; InsnClassExecCount *class; } InsnExecCount; @@ -159,7 +159,9 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) { InsnExecCount *ea = (InsnExecCount *) a; InsnExecCount *eb = (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + uint64_t count_a = qemu_plugin_u64_sum(ea->count); + uint64_t count_b = qemu_plugin_u64_sum(eb->count); + return count_a > count_b ? -1 : 1; } static void free_record(gpointer data) @@ -167,12 +169,14 @@ static void free_record(gpointer data) InsnExecCount *rec = (InsnExecCount *) data; g_free(rec->insn); g_free(rec); + qemu_plugin_scoreboard_free(rec->count.score); } static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new("Instruction Classes:\n"); int i; + uint64_t total_count; GList *counts; InsnClassExecCount *class = NULL; @@ -180,11 +184,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) class = &class_table[i]; switch (class->what) { case COUNT_CLASS: - if (class->count || verbose) { + total_count = qemu_plugin_u64_sum(class->count); + if (total_count || verbose) { g_string_append_printf(report, "Class: %-24s\t(%" PRId64 " hits)\n", class->class, - class->count); + total_count); } break; case COUNT_INDIVIDUAL: @@ -212,7 +217,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "Instr: %-24s\t(%" PRId64 " hits)" "\t(op=0x%08x/%s)\n", rec->insn, - rec->count, + qemu_plugin_u64_sum(rec->count), rec->opcode, rec->class ? rec->class->class : "un-categorised"); @@ -221,6 +226,12 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) } g_hash_table_destroy(insns); + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + qemu_plugin_scoreboard_free(class_tables[i].table[j].count.score); + } + } + qemu_plugin_outs(report->str); } @@ -232,11 +243,12 @@ static void plugin_init(void) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { - uint64_t *count = (uint64_t *) udata; - (*count)++; + struct qemu_plugin_scoreboard *score = udata; + qemu_plugin_u64_add(qemu_plugin_scoreboard_u64(score), cpu_index, 1); } -static uint64_t *find_counter(struct qemu_plugin_insn *insn) +static struct qemu_plugin_scoreboard *find_counter( + struct qemu_plugin_insn *insn) { int i; uint64_t *cnt = NULL; @@ -265,7 +277,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) case COUNT_NONE: return NULL; case COUNT_CLASS: - return &class->count; + return class->count.score; case COUNT_INDIVIDUAL: { InsnExecCount *icount; @@ -279,13 +291,16 @@ static uint64_t *find_counter(struct qemu_plugin_insn *insn) icount->opcode = opcode; icount->insn = qemu_plugin_insn_disas(insn); icount->class = class; + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + icount->count = qemu_plugin_scoreboard_u64(score); g_hash_table_insert(insns, GUINT_TO_POINTER(opcode), (gpointer) icount); } g_mutex_unlock(&lock); - return &icount->count; + return icount->count.score; } default: g_assert_not_reached(); @@ -300,14 +315,14 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t i; for (i = 0; i < n; i++) { - uint64_t *cnt; struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i); - cnt = find_counter(insn); + struct qemu_plugin_scoreboard *cnt = find_counter(insn); if (cnt) { if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + qemu_plugin_scoreboard_u64(cnt), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, cnt); @@ -322,6 +337,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, { int i; + for (i = 0; i < ARRAY_SIZE(class_tables); i++) { + for (int j = 0; j < class_tables[i].table_sz; ++j) { + struct qemu_plugin_scoreboard *score = + qemu_plugin_scoreboard_new(sizeof(uint64_t)); + class_tables[i].table[j].count = qemu_plugin_scoreboard_u64(score); + } + } + /* Select a class table appropriate to the guest architecture */ for (i = 0; i < ARRAY_SIZE(class_tables); i++) { ClassSelector *entry = &class_tables[i]; From patchwork Thu Feb 29 05:25:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776881 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651874wrn; Wed, 28 Feb 2024 21:26:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVTYr5z6Y0hAW8Y6PsIS6Wr6Cw/vNb5fi9uYlYy240aeR3waerMVVB0mTvCkVm3zOyFdzJwAn4i3l1x9UQuUTzU X-Google-Smtp-Source: AGHT+IFaAQcApWbgUFsbmcLBnQSeEswETDASM1K+nThhFuzqv5En8jDcyNDjlvF4kGN8vAr4DoYs X-Received: by 2002:a05:620a:136c:b0:787:93a2:5b88 with SMTP id d12-20020a05620a136c00b0078793a25b88mr1183421qkl.44.1709184393641; Wed, 28 Feb 2024 21:26:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184393; cv=none; d=google.com; s=arc-20160816; b=xxU2bQZk7oYIObkJ/EJ+urIbpeI+FnHNafD3yWtAewSyYpaGfnAIUT84OFO1BdQwQ/ f5vmEPDs85lME5wz67sgKjiSPnwReKYyP25zV+u3u6CCz41ZXSC55KWhMHe71kOFR8Ch fM+sGuFK9Hz1Jw3HT12adGFK2ptSLFwvNMGg/UR8Ln7t4Rg7BjWBEqhxxaxVdpRnx/ZD zsA9L15mW2iOKzoG8VhH6Gv3DhcvmJiVHlBn0ZBIBHWDeJ4DU0Ymnt3Mvz+Ri5nB16gW pPpwXsHRlNvPm+5zUcva/2H4+aNa8skgCCKAd8LO3vn0IBfSbm7hrs7FGPRdPQi6E72t h+zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=G6BdNWmefYkJd9kHZ2tBl04/iUSBuhTWVLmVnWG8Jwwt/8tYEbpsHv8jtFMNH8agUC fvei4zYa2K98mMNECXnS1dRbgPpKpxkmGcXUHrXmDt6Jc1YPA1AHMo/VQ2ZlFPdewCxf FX7F+ANRTTYhj8/ML4/UcEDT01q+8OJe6NppiHBrMt97IR/91pPNprlzP1u3KFI85QUv xNaY2R1FoMC7nQOdjCrUHhdK/zmpNJm2XEmCjQVnDZ05DePaCaR/gcwLTgqyTpNfFzJH gd7o2a8Z9CnCRolb/1sXWEsKB+3Cc2YtBG9qOekoCHiTFM+qTOusJtF+U/92fnil2a0I O+Lg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="l4k9P/8Q"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h22-20020a05620a13f600b00787843d906bsi692636qkl.590.2024.02.28.21.26.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="l4k9P/8Q"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvh-0002yE-61; Thu, 29 Feb 2024 00:26:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvg-0002xI-3a for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:00 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYve-00061L-Ad for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:59 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33de620be53so224630f8f.2 for ; Wed, 28 Feb 2024 21:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184356; x=1709789156; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; b=l4k9P/8Qfmj8jCvPz9I9b4RAAuQY521o+nHT+Qp+81yIEaemXge/lpyANJULoR4mVs HCYlOuV3rXONvYjOGZKbWNoKiBMFFejah6UDnBLiqtiXnH7Ie2wXzfMEgQ22BdC1TqvS 2Uws+o+YhZfBTrb6Yrr6EZscB4baJuGkPLsIs/w6jRg7CU3a2G3KBAKb5+8sViSBVhFw b49NrIFCGdEmhEygOsxuzKy2T1Mnjv6rGkJeSLkE6Pg3vbVJlM8VwOZQhHrUHiQJm7tl rYvSZI7K7m1KrBLQALoM8s+kjWqtpA9EVu3bOzzWWEwgS2+vc8eguJBuDR8/pVtumgsn AaOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184356; x=1709789156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tachJBXUDnFOS5ckKG1N1M9AuSTSiQfvZYEsFfsbLg8=; b=l1vRf9jgpu180/Xb39yMIayC8ZW1yHqPuxN+ydYoe6SqEEQLO1XNeKobuVVOMpG4Vt TqqEP7Qji+KxBAs5Dogn/J3eGnBYStJvGTaUSoTheYWVPOce1njPAgQGiBXiS326pRC9 0coyatnVh9v4nGcm1DzfNH7G5DAmVs9RvFUW/cckO4WFCA577uAad7dVqHEVMRzsdzSo npHOLTv8dJoVSfxPJrwFXW+47aZZQbiboQI1QVK6iqYlf2boxEepnbrLRoy0fh0/DlKg dqGuzuCJOd9YYn1JU1Wkm7mA3hGU8/16+KTv7w7719AcUVFWP3+OM4owaWKsmPE103FN 8uKQ== X-Gm-Message-State: AOJu0YyJ0Kf97lplv89mDhahggKJT2h6IUZfE82W01pdpMzBLWt92yOG cm8v9tcDYrAdrF1rFUbeaHd9LOPcQDa6Yfatev1vJMF3jRAoJZiuP6LkTTxi4WU6FCtfC5WIT97 EWkM= X-Received: by 2002:adf:a3d8:0:b0:33d:c5c5:9bc6 with SMTP id m24-20020adfa3d8000000b0033dc5c59bc6mr803696wrb.54.1709184356175; Wed, 28 Feb 2024 21:25:56 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:55 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 11/12] plugins: remove non per_vcpu inline operation from API Date: Thu, 29 Feb 2024 09:25:05 +0400 Message-ID: <20240229052506.933222-12-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Now we have a thread-safe equivalent of inline operation, and that all plugins were changed to use it, there is no point to keep the old API. In more, it will help when we implement more functionality (conditional callbacks), as we can assume that we operate on a scoreboard. API version bump was already done as part of this series. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 58 ++++-------------------------------- plugins/api.c | 29 ------------------ plugins/qemu-plugins.symbols | 3 -- 3 files changed, 5 insertions(+), 85 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 6bbad068c01..4fc6c3739b2 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -52,7 +52,11 @@ typedef uint64_t qemu_plugin_id_t; * The plugins export the API they were built against by exposing the * symbol qemu_plugin_version which can be checked. * - * version 2: removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * version 2: + * - removed qemu_plugin_n_vcpus and qemu_plugin_n_max_vcpus + * - Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline. + * Those functions are replaced by *_per_vcpu variants, which guarantee + * thread-safety for operations. */ extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; @@ -309,25 +313,6 @@ enum qemu_plugin_op { QEMU_PLUGIN_INLINE_ADD_U64, }; -/** - * qemu_plugin_register_vcpu_tb_exec_inline() - execution inline op - * @tb: the opaque qemu_plugin_tb handle for the translation - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time a translated unit executes. - * Useful if you just want to increment a single counter somewhere in - * memory. - * - * Note: ops are not atomic so in multi-threaded/multi-smp situations - * you will get inexact results. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline op * @tb: the opaque qemu_plugin_tb handle for the translation @@ -359,21 +344,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, enum qemu_plugin_cb_flags flags, void *userdata); -/** - * qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op - * @insn: the opaque qemu_plugin_insn handle for an instruction - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time an instruction executes. Useful - * if you just want to increment a single counter somewhere in memory. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inline op * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -597,24 +567,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, void *userdata); -/** - * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any memory access - * @insn: handle for instruction to instrument - * @rw: apply to reads, writes or both - * @op: the op, of type qemu_plugin_op - * @ptr: pointer memory for the op - * @imm: immediate data for @op - * - * This registers a inline op every memory access generated by the - * instruction. This provides for a lightweight but not thread-safe - * way of counting the number of operations done. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm); - /** * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem access * @insn: handle for instruction to instrument diff --git a/plugins/api.c b/plugins/api.c index ac3982c6636..58e851effdb 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -101,16 +101,6 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_plugin_tb *tb, } } -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - if (!tb->mem_only) { - plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], - 0, op, ptr, imm); - } -} - void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( struct qemu_plugin_tb *tb, enum qemu_plugin_op op, @@ -138,16 +128,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qemu_plugin_insn *insn, } } -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - if (!insn->mem_only) { - plugin_register_inline_op(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INLINE], - 0, op, ptr, imm); - } -} - void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_op op, @@ -175,15 +155,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, cb, flags, rw, udata); } -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm) -{ - plugin_register_inline_op(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], - rw, op, ptr, imm); -} - void qemu_plugin_register_vcpu_mem_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 0d8141b85f1..a9fac056c7f 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -27,16 +27,13 @@ qemu_plugin_register_vcpu_idle_cb; qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_insn_exec_cb; - qemu_plugin_register_vcpu_insn_exec_inline; qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu; qemu_plugin_register_vcpu_mem_cb; - qemu_plugin_register_vcpu_mem_inline; qemu_plugin_register_vcpu_mem_inline_per_vcpu; qemu_plugin_register_vcpu_resume_cb; qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_vcpu_tb_exec_cb; - qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; From patchwork Thu Feb 29 05:25:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776879 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp651825wrn; Wed, 28 Feb 2024 21:26:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUVehotG7L0lDg8uTOy6B3OZUrTUnKptz3DTZxj/Uvdukg6fJF2UGULn3QofSFV7VsxUuLyjhKf3EyLaid369t9 X-Google-Smtp-Source: AGHT+IGzydRdo6s5fcC2cUmTUMzpWBp4DYQKL9yNcreDsqzJiTjdFwA0TgHJvph9GjJXOSB9dGpy X-Received: by 2002:a05:6214:b29:b0:690:4aaf:95ba with SMTP id w9-20020a0562140b2900b006904aaf95bamr40578qvj.18.1709184376547; Wed, 28 Feb 2024 21:26:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184376; cv=none; d=google.com; s=arc-20160816; b=M1g9DAcfYxCnCU3fQcUy84nw6mTWNzXok1/ZB4OWfTsnXFB47S8ffbb4CLhJYVwMBw Tz5fQe2rn6fOpUXokMJ/+nUL/LRzSueucF0DRas7U4MMpc9D4YaqeABuBIXTJwqLla3J kX1VsyG0xQ9ob8YGicIShvV+mbcn5KxMyqyrBsmuz2CAKdwndp5IVvqiGeFG8HzrcE3t Wz3WhItiTGhL1s8N39oSoo+4pMgaXnmEceK1Q6A09jpHdFUGtwUmUw4sIt7F8Ik/Z7fX J9EG0AmsGyxL23+n0SshvzsAi+IS/o4jj6HRlxgY9wbkaoB0YLLZplpU6+d8Myx9AjUT c7pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; fh=nGClJJsVFmntY4VqdXC/iKBtyneNNRVjg3eop4mLm3Q=; b=pMNnIG8dtraNnZu6dIoVMaRmZTWYZ+xl8SQCZRZNS3cwKVKTOlF/8ZEuQqfNCsZuSE xeq+q2JYrOczNvUO5cOSwZP+/nm2W7e2ZkHnKW8nxjXznh84Mu3jhm2Ig01xawQMRq93 Ab5iAOpD4tYFxraneNR7jYlf6I8Cmlcrt7O8IEEBd55TLQG4dHyL7eqzc2jvHnaWhS7J u7eAz1d1JWS6ThW8xn8Am6RdDTV1YpVk0IdWmvGPsK7/2SpXWPkKtqyODqv76qbeTx5c mJdb3qVvjkbGhBWl+pZYYK2JgV9HnhtaLsOCm4ilynBoNQoibVeksAcO3ZlKjbsSLSBF nevA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lbJLKAG4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id im6-20020a056214246600b0069037a85652si692597qvb.18.2024.02.28.21.26.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:26:16 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lbJLKAG4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfYvk-0002z9-LV; Thu, 29 Feb 2024 00:26:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfYvj-0002yo-IL for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:03 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvh-00061l-Sg for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:26:03 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33dc3fe739aso938403f8f.0 for ; Wed, 28 Feb 2024 21:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184360; x=1709789160; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; b=lbJLKAG4fKyrq5lOFdbIC0KqmaSYbuc4TkqDb/jJYljrBUbyNFKG50+WjD0SnoHePr QFK/CuloX4kSYpY+hvfCqmttyozLpViiTDMieU+DVU/dD6IXOg14az9qKMTjugys0S0o LRNgD+ZYyQuatQFESo+tjG1OCKkHu8ziBgUKmJ14X7KaCtzAKUDXy1y1T8WBsDO4AvTV LSfYete6JSrWE6ORoRMEB/02ZbIfT7+HVrfjKX2FJy2GqI84K7rNgRaDQwU95D/g4ds5 ZusCuwO8sW1n4ICNvBEBxTbrY28pQ8VGjUk6IpwOZ3mJkDpZ1O9YhkR54Tz7naKKyKit M7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184360; x=1709789160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wPVNOJfP9AetgNRAiGgypd7Btd6VXu2RDR6kPX3cnbY=; b=MprtoumSJRdShCyDvrnoxm6oNVOqW0EJhjaTTkxZnF1aJXusZh6Jv4Z+d/ADcb222B Ra3Wrd3nm1zeAXJyEQV2a4a2RogX27LK2r8aBHhRXDigByH++1AWrl/Or822STZHwxMV cbr4iYVSvCtdScf5JKgEIRBlv5klArBUQcRCmwbxH0XcscTYAnYH1XlsSe6zXxm/T6ib r0D56Dkf1p4WfuBS22knQgm2NHTStfyFbtX0cL+EM8WJ68fkZYeSjeE2ZFfIloKnWbR8 WbS9z75qkAlpQjLPLq+YHqDrKasr5Uy+m0ysfXEOX+xdMOpmpc5aZqS/4kX2viHyZI8I 1+0Q== X-Gm-Message-State: AOJu0Ywyte+gembh2vQKl7YvN3AxgUxrF/YsMuqkyeZdjh6jnpdSb3jS LIp3wM+Mk0f5PBYSDo527QZW9u9GWPh00WbsEI0vzB9x2/thLBIwMhf4yJBEz9zNHdmh1fQIvY6 QXeo= X-Received: by 2002:adf:8b5a:0:b0:33d:119e:2ca1 with SMTP id v26-20020adf8b5a000000b0033d119e2ca1mr630694wra.5.1709184359774; Wed, 28 Feb 2024 21:25:59 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:59 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss Subject: [PATCH v6 12/12] plugins: cleanup codepath for previous inline operation Date: Thu, 29 Feb 2024 09:25:06 +0400 Message-ID: <20240229052506.933222-13-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- plugins/plugin.h | 5 ----- accel/tcg/plugin-gen.c | 13 ++++--------- plugins/core.c | 29 ++++------------------------- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/plugins/plugin.h b/plugins/plugin.h index f6fa10a0f56..7c34f23cfcb 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -68,11 +68,6 @@ struct qemu_plugin_ctx { struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plugin_id_t id); -void plugin_register_inline_op(GArray **arr, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, - uint64_t imm); - void plugin_register_inline_op_on_entry(GArray **arr, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 47e05ec6347..8028786c7bb 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -440,15 +440,10 @@ static TCGOp *append_inline_cb(const struct qemu_plugin_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - char *ptr = cb->userp; - size_t elem_size = 0; - size_t offset = 0; - if (!ptr) { - /* use inline entry */ - ptr = cb->inline_insn.entry.score->data->data; - elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); - offset = cb->inline_insn.entry.offset; - } + char *ptr = cb->inline_insn.entry.score->data->data; + size_t elem_size = g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset = cb->inline_insn.entry.offset; op = copy_ld_i32(&begin_op, op); op = copy_mul_i32(&begin_op, op, elem_size); diff --git a/plugins/core.c b/plugins/core.c index 7852590da88..11ca20e6267 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -316,22 +316,6 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(GArray **arr) return &g_array_index(cbs, struct qemu_plugin_dyn_cb, cbs->len - 1); } -void plugin_register_inline_op(GArray **arr, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, - void *ptr, - uint64_t imm) -{ - struct qemu_plugin_dyn_cb *dyn_cb; - - dyn_cb = plugin_get_dyn_cb(arr); - dyn_cb->userp = ptr; - dyn_cb->type = PLUGIN_CB_INLINE; - dyn_cb->rw = rw; - dyn_cb->inline_insn.op = op; - dyn_cb->inline_insn.imm = imm; -} - void plugin_register_inline_op_on_entry(GArray **arr, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, @@ -494,15 +478,10 @@ void qemu_plugin_flush_cb(void) void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - char *ptr = cb->userp; - size_t elem_size = 0; - size_t offset = 0; - if (!ptr) { - /* use inline entry */ - ptr = cb->inline_insn.entry.score->data->data; - elem_size = g_array_get_element_size(cb->inline_insn.entry.score->data); - offset = cb->inline_insn.entry.offset; - } + char *ptr = cb->inline_insn.entry.score->data->data; + size_t elem_size = g_array_get_element_size( + cb->inline_insn.entry.score->data); + size_t offset = cb->inline_insn.entry.offset; uint64_t *val = (uint64_t *)(ptr + offset + cpu_index * elem_size); switch (cb->inline_insn.op) {