From patchwork Tue Dec 17 22:38:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 851449 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp614855wrq; Tue, 17 Dec 2024 14:39:25 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU5wq+NknseMoSpmOXdAehw5Jc87VFx3Nb5RSVp9QbpfQRyJ+tn9cBAmOxN5X0/2cHwi83fsg==@linaro.org X-Google-Smtp-Source: AGHT+IFBmSV+l9A9CvRBLepwnBZ3/rrT8QFWZZBTuzTx3nIBPnF+inQ70dwVfLNplQ+xJ8/QEjPq X-Received: by 2002:a05:6214:e49:b0:6d1:7433:3670 with SMTP id 6a1803df08f44-6dd091927f5mr14177506d6.4.1734475164727; Tue, 17 Dec 2024 14:39:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734475164; cv=none; d=google.com; s=arc-20240605; b=Hi2QFzQnrwXr6whuQNrJsKwfcZ8MetcCAxrvUbYVlzCLkjO/hT01cQltnb8p2nfTnh XYRE9O3wdN5IkMHLVSc5nGqbHyRhyvUtnj1zWTep37UFyBQia6L69y29bxOq31lhAyZQ jJBEVMXluN4M2LSnIBlOYv/5PoqWeXY8MxJKKf4zHHC9FwCo21QamoxiCCHkTViU9fI3 fEO2XWy8WrDLB6zD641/Wvx5329bpLk8jXnbZhe1e2xYfoAB1Sk5vs1yozNpSmgN8hjs gt7dAJdfm5Xh3YFzxIBL0TRk6WDcrd3ewLNbKcNhMpsQuQqPy07kKINqGeVQebkbgotZ vonw== 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=+NflhOdr9R5O8MPEqbGfWeoDmt6zsMvcpjNabm4DZ9U=; b=kBUvBxqPc2200+RC4AoEWgD+HxoFQ/1JQQO+KVMHcti4Q12V4mLAZw+9vfhyUcS+Df liKBvHdIPM8zumKSzFPx/Kcfxl/5OMF8vWYBrNEFd92WCjvpohnJ2xaV6BDUaoEvez8f 1mfZqDqV0PSfLDlEEhz4S73p+JjiyAIAFc5mgoKa8D1TFz+qzLMiOQveqWA2keqp0dBb TqrLtCpD0ZDqt/2i8c6Z3GsZ/fIlFzU5c00y46GFJpvMjERQyCnwebsFSD54vvS0FsD1 T2cSALUgLpLebXiRwPYGkbN4nPIVQtDb1Hfuuf1ST0RbWGOmXKb7NqwAuvltuiSTq/zN LeMQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iAQ1m3xR; 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 6a1803df08f44-6dccd3b80besi109538986d6.552.2024.12.17.14.39.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Dec 2024 14:39: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=iAQ1m3xR; 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 1tNgDD-0005O6-73; Tue, 17 Dec 2024 17:38: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 1tNgDA-0005MP-GD for qemu-devel@nongnu.org; Tue, 17 Dec 2024 17:38:40 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tNgD8-0008R6-2z for qemu-devel@nongnu.org; Tue, 17 Dec 2024 17:38:40 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-21670dce0a7so64801355ad.1 for ; Tue, 17 Dec 2024 14:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734475117; x=1735079917; 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=iAQ1m3xRzzMpmce7MRQ7weAI8b57xQxUdzDK95p4N9LsL/QgHdqn4KfsaBHx6RwzvJ J3C1d7n+dBkB1NQiTac+ZB2pge1cgsoLzPGbeDMpqlPMzh2mcGeX7UsnH/PwxRTF7+Vg r7W0O1mYGNwHvAnJ11doYZRsujy/QdRi/uDu14HVKfuOgu0cvMIXGDKTamv7zVfLC9i5 5dGWxOF04lx6wX0wa7jl65EASga47r124xzijPXH025p5H63cNmbecaE3l35kvsrfAtV 8xyxmXuwROnqdoduHN6QDtgRl4X8wL6z/FVtD8BvHKetihHw+clMMyLfRzXKGblT8iiU +j/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734475117; x=1735079917; 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=AU+Olr7LNm8RvXN8rRBAbLl7Cp/HCAnOQA244UKcHYxTKFsD/0i800Xi3HcsfJF1Ie Hj7+2NN1sHAyyn3G5DA5AZkxSnSjqn3Csi5nHwvz4zue2rIZcRXzTIAsQEpc+zDz7JpV e6F+6jcJCirnXuFY4nNyx9UgbaPSDgpeTtgFwKTOW1HV72Uj+dleLCvcP5OHqerjMKVf f4tV5IqqaeunvQfrwnl9Skp8HD6SCmQtNdV04h8uIADODF9rBi6aaIGZSoP/xm+JTLXt IxLwmkEaiKKe3dYQjvBrkHOgFyEGrs6FU4tTPlAZT1DH7OMzKlKqcB1Cy0GoQAa5jvS4 UxGg== X-Gm-Message-State: AOJu0Yyd16nVj00qXLA8m9VTes3uXIPMSPJFnp7IM/noZxH5vwLWaBkX fNbY40Wh2nQ3AYBEixa0WRjXclulckNfqiuDrIgMBP1uE44Cd/1VPkPNEPz+bQmSMsZm3S5lMYk S3b0= X-Gm-Gg: ASbGncsZtbSUu2Sj322O1mdfsUiQZjf4MCDSL0bsIjz1REJjcCFGOGVKPZOMYBIe5v1 Gv8EvcnexdvvRn4Z3JNM2sjqhBtAQghJO5bxzx2tgs7zcmX2+2pVA19mKgCoIC1l3N0O8aCJG3k 1oHBdPRXzjJlK6S0HDsoIS3Khwjy/CSru2c/G3J6Fu4W5Xk4vrpJA+E5qxRc6iFWXBJstRfMDQh Q5g+aN2XOpfGE+6RJ6uyCtwfobwCg866Vzh4Qd7l+8el9elS+2zRWgq X-Received: by 2002:a17:902:fc47:b0:215:853d:38 with SMTP id d9443c01a7336-218d70f6e34mr8595865ad.25.1734475116839; Tue, 17 Dec 2024 14:38:36 -0800 (PST) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1dccb03sm64869465ad.98.2024.12.17.14.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 14:38:36 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Paolo Bonzini , philmd@linaro.org, Mahmoud Mandour , richard.henderson@linaro.org, Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss Subject: [PATCH v2 07/11] contrib/plugins/hotblocks: fix 32-bit build Date: Tue, 17 Dec 2024 14:38:21 -0800 Message-Id: <20241217223825.2895749-8-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241217223825.2895749-1-pierrick.bouvier@linaro.org> References: <20241217223825.2895749-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.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);