From patchwork Tue Feb 13 09:40: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: 13554848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52ECEC4829A for ; Tue, 13 Feb 2024 09:43:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZpIH-0001pv-TW; Tue, 13 Feb 2024 04:41:37 -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 1rZpIG-0001gP-9W for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:41:36 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZpI2-0000IY-Ul for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:41:35 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33b728b6981so1527777f8f.2 for ; Tue, 13 Feb 2024 01:41:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707817280; x=1708422080; 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=pYsOMq9r5LK5zEufaOE1Vs+5rr6DVHoYySvsquC0cD/D4e3AePjNkSqE/a/dtqtGde lAikcXzHzY0VB1qjsJOGSHHf8lViXQJ21Kqk+0zzf3fcMw4asLqoQplAb/xtVLV0x+Nc sNSQurxxzMEYODwkZm9ilpYzu6HgwoTa/YnezbYxx6nRJN11llfcvM4olAZhyX5/2vNB q2Q/O82jrPcxTcNz1QZPWn4yn3ZltZFMvgNFVyz+umwM4AACaZKYta9/998iI6lS8MSG SO5YNoyqXt41JCMXEXI+FiqGlppNX8Vj7ceP7AE+9SmPkRaFdOy3mvnIessca3Cimy9W PIxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707817280; x=1708422080; 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=eZslycFAFj7lHX7cHKwTV5IyiBMhymHL1H9yco4xrOCNGaJaJ7O6aKJXRJSeQropyM 5HejIi4WtwRkCdH3bwAlbcNgKj6WZDui2+GjMj6ZOSgtDPMXpKXW8/chgplw4DeYJImx HhPQnqdSFCsf+AmFP4q9ClU6+lWPFbdzv3evOisS5vojFXsztkUGX52jS1xwMH1pxW/1 uc1aJJPWOCbupx5lVRNwLyUkp2SKllSSpHnYsnPQBzPl5/RCrgdjyu0OEdZE4jgPzxMI TFeOXYGZIFOO1fBabBCXBaGlnWJZ/kxh68d9wfviuUyvlaAz6uYjoaoReVmGgRl+53/l yfhQ== X-Gm-Message-State: AOJu0Yx2ykm7Lbat1jFY0JV+f1KY21QS1OtJpWo0ApYaABS73EiBTGOi Mw6Aa3AB9G8jxkk2Dv7JjVxaGMH2WqPe97Qw95JXa8yKOyGZjnvqe3RNJqi98oPWHbAEs77tWo3 l X-Google-Smtp-Source: AGHT+IHrOl+A+LLLhsm6sf7v5uEUgYRZoS6cqjj4vGRRZNXvpse1abx8OHBaJRH4CtR/NXlLqUZZXg== X-Received: by 2002:a5d:65cd:0:b0:33b:64c9:da80 with SMTP id e13-20020a5d65cd000000b0033b64c9da80mr7067643wrw.19.1707817280275; Tue, 13 Feb 2024 01:41:20 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXzI+3Fr8yP2Nl0cGZMr+a1gwMipsAS4X6+I2yJz6hGzRiY/Kn4OB44gsT7WfpILvOGessXLfI9iPZXS7iqD/nbybaQfA8grEGPMYaXANZ48SbYZcVawZ4xOVj5DYMCMw8LabSforvUY41KgwrMP8PjvJEMweeFkm6eg71cmtkXmT0ORUuA1+LcjSJfQfeW8stA+jryNhrrKwhOLXUS+AxRBIOgykXXsiOwnd4gedqAX/hjGv9wJI+qVHUgRQnJIOCJmuuZ6Fei7BeaA/HBBXWPakbyZ6KVq0NdUXdZ7oJ6+1DDQE90oK7/hGYFaReAIwsJmNb5UjhHJNuDxDNKu5Xxb5hcwg== Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id cc19-20020a5d5c13000000b0033b728190c1sm8550261wrb.79.2024.02.13.01.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:41:20 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Marcel Apfelbaum , Paolo Bonzini , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Richard Henderson Subject: [PATCH v4 14/18] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Tue, 13 Feb 2024 13:40:04 +0400 Message-ID: <20240213094009.150349-15-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213094009.150349-1-pierrick.bouvier@linaro.org> References: <20240213094009.150349-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.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); } }