From patchwork Tue Dec 17 22:43: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: 851466 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp616712wrq; Tue, 17 Dec 2024 14:44:43 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUo2V0GNo07J3QEuOIeqh+C2Nva0em2lw8PPHBS6B8cn2yLdsLqt8drRDHYqd3uo6ev3xjZxw==@linaro.org X-Google-Smtp-Source: AGHT+IGjysBsdI2OWbGp3+1dP9qiAHBIiBsNFzrBGBMofNAKUZrh5A9yOslBPtOBxllRMwhFoKLl X-Received: by 2002:a05:620a:40c2:b0:7b6:d4a2:f123 with SMTP id af79cd13be357-7b8636f6de1mr71811185a.2.1734475482845; Tue, 17 Dec 2024 14:44:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734475482; cv=none; d=google.com; s=arc-20240605; b=RUwMiKdLSDPsx10CVDxPjsvEU0e1QLwlOP2nrm1yJ39xa2TWsS7Z80Wh9S5U5hWiZ9 LMQoPiEd/65XEep/ve6UQB1AjEBIg5tiv5PUi+vnVWYY2/Sd8veFkxZq5C5NGyWa8Fg9 H8FQwxWGHlZqZQSeo9SnfMbJy7NbDWP1mwiz1mQFMSfZd2CuwOUJBcEe42+2QOH5vb77 CnsfsNdLeZOdxi4xam8hTVyxNWflR149XfeRnnihe2d88oLSzKraxxk+JQ23/9b0JOY+ Ma8bgOxkehk1/mKpn9OLnNKk5SXKIO65orWD1+IWDGooxLbrJo+BmmBnEGLiKLpEnaCD 6WPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=gSO3SqC3k3PD4UDj10nreaVmTIRbnjLL+fnwPXL6Pds=; fh=e32mLanPjfs41dQwy8Wt4zFa68BQ2A3naWRPcWqt/Vw=; b=AxY1yNTug588Te+JCRpaRk9rpWwaaTCb2UZ/t4xLE4oTOBJz+cO84wVvTOHlqwIOyk DJbkOQLsWA11NxyHwuoZn7wEgo/HVdMn9COsDwYf2rCAW9WVSLGuUcuAF9mj5dkwrlXz 5fGtqszRsE3rH/gFWmopkUiwGmPdN5unGRugCH38L9hQCA34ddMohzndIDs4wbPqY3Qn Blz9bE21DYmOygcJe92mkeQod5Xk8daIg0bcJNlgEdtvbTw12lEBN1mLkD26eIfInblE 2HB7zCaaIgMpqmZmk1D2msoTK86zKuYSDW6ZfZmaYGkwIu8VoxfWJ/voZXGBdGo7GvPq Z4Cg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gB5X4eeJ; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b7048ce5f2si1047645685a.454.2024.12.17.14.44.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Dec 2024 14:44:42 -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=gB5X4eeJ; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNgHj-0004Lb-6a; Tue, 17 Dec 2024 17:43:23 -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 1tNgHg-0004Jn-Ad for qemu-devel@nongnu.org; Tue, 17 Dec 2024 17:43:20 -0500 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tNgHe-0001AK-J4 for qemu-devel@nongnu.org; Tue, 17 Dec 2024 17:43:20 -0500 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-725f4623df7so5204430b3a.2 for ; Tue, 17 Dec 2024 14:43:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734475397; x=1735080197; 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=gSO3SqC3k3PD4UDj10nreaVmTIRbnjLL+fnwPXL6Pds=; b=gB5X4eeJskPzkm8pmNWS2gNYrLWy4EYVV3NRbKRJsGIjPho2dLFYHWKrScTwjHNo6+ RL6XFQ13t7uTS/XUS0ZizHh1fPNJvFmdHqoh4RSa+ZifX4B+JJJxKwBeX2nU6m/4PTKs 2Xl5tA2wgwAYPHexNRMZ+fjG1bS0x65bSwVN+eHShuf1EYgbxyQDgA6mGyc5fRqetP/q 1IjF5RlDmnDTn7ASxPf+6TiyWTKqaECZGBgcb1Wnt0URetoKTZpnsq7wnhNwUKoV9zSN xhqgERzeAKnG1TM1s9ilVUDyJaGPaj5OPeMIp3xa94StNvRM9q96Oh5X4ko1uD+e0h4n VKIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734475397; x=1735080197; 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=gSO3SqC3k3PD4UDj10nreaVmTIRbnjLL+fnwPXL6Pds=; b=wOZ8m+IHJdJFzLwM5+bX+NwpqtTVQvstGOEhVDPFlaZpEG7lVdc6gT7FSK0SGJstpG /45Af/ZgVjyLwFqzQp0AwiVKYppUEdeCHCioFWDSJAPCxQovZ/aylLEirv1wIbWxgJGO COKAyWP3YxpYckPLWnohvDQwOYOk4Szc8XY17bCQXgu6rCDAx+WOAiaSODVsTlbSfukU 8ASWYyavqsnAirwSln0pQMOGYT4RW8s5moJpJO2AJiGoTuGC3hHMbB8ZyyE9YN4R08Gf mKxfi9D+FY+K5oO2PWTvQHMmNrruVQgH4RQ3KnO47gHCicjfJwBk9o5J3dskVTNyiCh7 Injw== X-Gm-Message-State: AOJu0Yy/c442VNdenUR2TgOJq9gxzb2JicVp7+ngiS/mqagVvKkzcRwa HiK7KnXQro8VEwsyxo8jvXQUIa+xc40o9cnNE38U/5L7jHUcr5nJSTCwETIb75ghoaxkY4eAVkt T8hw= X-Gm-Gg: ASbGncvYWXVuVIOAMuHrDFFEKTK/9jhAFv2+uM83NRt85sqXD5xu9tIopWekow6vw5l es1L9HfpokSsuNN6FY/VOijp+MY+557ziLvFFa/GDnSuF0IIFtlJAN0/I5AEhlOZPnfX++QEx7M NMirvfIQZPagMNLkfrw4PFHwyaNx9qhzwbYcIi2QnKYk6HDcEGM3NAv7KcM6SqJxnuc4b0Y3n2h 10LPtp8SkPKdFo/CiOE//PKPYYWx71Qs2pWoxP+X3t67txY/b8xD1k2 X-Received: by 2002:a05:6a00:6c98:b0:729:643:744f with SMTP id d2e1a72fcca58-72a8d2ee4f9mr906549b3a.25.1734475397117; Tue, 17 Dec 2024 14:43:17 -0800 (PST) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72918ac53f3sm7463214b3a.27.2024.12.17.14.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 14:43:16 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , richard.henderson@linaro.org, philmd@linaro.org, Alexandre Iooss , Mahmoud Mandour , Thomas Huth , Paolo Bonzini Subject: [PATCH v3 07/11] contrib/plugins/hotblocks: fix 32-bit build Date: Tue, 17 Dec 2024 14:43:02 -0800 Message-Id: <20241217224306.2900490-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241217224306.2900490-1-pierrick.bouvier@linaro.org> References: <20241217224306.2900490-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x431.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 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 | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 02bc5078bdd..f12bfb7a267 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -29,7 +29,7 @@ static guint64 limit = 20; * * The internals of the TCG are not exposed to plugins so we can only * get the starting PC for each block. We cheat this slightly by - * xor'ing the number of instructions to the hash to help + * checking the number of instructions as well to help * differentiate. */ typedef struct { @@ -50,6 +50,20 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b) return count_a > count_b ? -1 : 1; } +static guint exec_count_hash(gconstpointer v) +{ + const ExecCount *e = v; + return e->start_addr ^ e->insns; +} + +static gboolean exec_count_equal(gconstpointer v1, gconstpointer v2) +{ + const ExecCount *ea = v1; + const ExecCount *eb = v2; + return (ea->start_addr == eb->start_addr) && + (ea->insns == eb->insns); +} + static void exec_count_free(gpointer key, gpointer value, gpointer user_data) { ExecCount *cnt = value; @@ -91,7 +105,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) static void plugin_init(void) { - hotblocks = g_hash_table_new(NULL, g_direct_equal); + hotblocks = g_hash_table_new(exec_count_hash, exec_count_equal); } static void vcpu_tb_exec(unsigned int cpu_index, void *udata) @@ -111,10 +125,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) ExecCount *cnt; uint64_t pc = qemu_plugin_tb_vaddr(tb); size_t insns = qemu_plugin_tb_n_insns(tb); - uint64_t hash = pc ^ insns; g_mutex_lock(&lock); - cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); + { + ExecCount e; + e.start_addr = pc; + e.insns = insns; + cnt = (ExecCount *) g_hash_table_lookup(hotblocks, &e); + } + if (cnt) { cnt->trans_count++; } else { @@ -123,7 +142,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) 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_hash_table_insert(hotblocks, cnt, cnt); } g_mutex_unlock(&lock);