From patchwork Thu Jan 11 14:23:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 761848 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2422541wrz; Thu, 11 Jan 2024 06:25:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDwuWXBRWyU8zYOx2BI6XZU8e37IpO7Sg8LiWoArx+s/nrfzMKKJLNNH+fTP8pU9s+pxiM X-Received: by 2002:a0c:e349:0:b0:67f:8d72:8cb2 with SMTP id a9-20020a0ce349000000b0067f8d728cb2mr887375qvm.16.1704983111675; Thu, 11 Jan 2024 06:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704983111; cv=none; d=google.com; s=arc-20160816; b=rsFJN8zQ6XihtCL+6B44Hm2uLOrwm0xdr1pkWgNfbsfvjESt0DdcquKcMk/zR9IVKI SZJXOHXqYzeL7tLamv6Og2CTx594cFmAOEIccOYe/0t7nJDmkJe1o7ScOMhjNrRhXB2+ qJLiTQDaVaTzN2sfUS6iYnWmchtYWfXkJf5iF1G0LrFpvtvLG0hsDB2dD20x0Ko9CRaI SR35P4s7K5QTIAXT3CCBPwqd5ITnxNJV/JmlWCKx3WnoUqRZcTtGdBKdMAjZkDFCtARV ovvlC/EDHzd9eybSNKoXqM45Uv3a48EuOM+yD1xbd7EK9z769GAS9Tpznxp9UmfLyR4f vIjQ== 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=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; fh=4xQMyYYtmbynAmJxwWPpZ6ivTwZNkSfAt6fhFI9aNBQ=; b=VAsxcaqGZuqZMBYsqzNQI/gdTTdi7ZFGcE3QiToWzFdyns8ZFjhzlfexuPyDbQqLAX LGqzxZnpW8TQ8tatQc7C6b60037pTOMhrQTER/5hL6aVSsnULy9h6WURemVeT0yBw0DU 4DaPIvonTQz0jQUcJtp8Z9MJk0SGj3nH39nHRb60fMW9+Wfjl/HuIhTdSuH8y1HTjsOR OKq4MucsAeZ/5cEpMUaFl8kxPPHwIXZhAbaYjzKXepFSrSSmw9Z58r7m1D59T/ZcVrDi WKsuThbB3ztJPN6FnO5ca7qQAmQIGCoDRY4pOE0WCo+DqhQmhlZv8lY6zSD70+DoNPmu 4iMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IY+4PP3R; 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 w20-20020a05622a135400b00429af934db6si995191qtk.213.2024.01.11.06.25.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jan 2024 06:25:11 -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=IY+4PP3R; 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 1rNvyt-0004U3-8M; Thu, 11 Jan 2024 09:24:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNvyl-0004Pu-QQ for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -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 1rNvyh-0002kr-8g for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:17 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3376f71fcbbso3419644f8f.1 for ; Thu, 11 Jan 2024 06:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983047; x=1705587847; 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=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; b=IY+4PP3RRnYODzQ4PCuWOUaoD/2tBQUyeKp4EfDY8W10tK9bXGmkV3FPsmfEWWoZwe mEXUyZCLTqZjXkzQKJLPj0WNwtrhTRQIquwhjVjCJaOoz9zdXWABAjjMZHgCltOsPlUj kuqsdLm7kp+62uZVoq6q//MJRguQadrBGXhV1gEsOwADcMuH1jwata35rMn0hfQfcQPq iWRyGbbbs8n0wDaGYDNW613mexlmtc0jRQQR4EfdVUSRsPBnqYg2Zwia34rHvWojDu0E RfpcilZTTrshAC4JZNxXGoVZ0pBywropKD/tuT6soDECq2RSY7ZBnmvNsgj5Q5rN8aT8 pxFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983047; x=1705587847; 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=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; b=aBXpwVBkH2L9miWWTjFM6m/Af0rpStdtqjtELKrVqaAXLY7ZIHvI1L/tpKRXX117Z9 7bFlTGbznLkUDvyRfDP/svMBwwoDTn9cE3bj2WBCEiU8mk9PHYhNfGi4D2tIvvdlISbK kgm81fifTvfw4dAbvkEfIQPMtmPL7+Otma2en3j50PvwR/+GZSftxeyg/QF3M/eG0WIn fURWpdfmN2jcL8cYzx/Td/Fhqt0VHqeEUHDzDGKKRCylyoQYmM6h1VKScV8TNg2anPRS Sy61GN7T+R3lw5Mju8vM+g4Lrz5lmmlNsfOxw4BrtzqlCPDriGOXqSm3j4J3vmOwXznV digg== X-Gm-Message-State: AOJu0YyXIJTtm6wfprhg2qrZCnfVexMtCkHLfOqb8ITOmLx1ZhxnQz4E KCIiRq194JQj/2xl+uWH5O4RQzdsGfDUYMd5OAwRseq6hZr42g== X-Received: by 2002:a05:6000:1090:b0:337:68aa:c63d with SMTP id y16-20020a056000109000b0033768aac63dmr495790wrw.37.1704983047533; Thu, 11 Jan 2024 06:24:07 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:07 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:22 +0400 Message-ID: <20240111142326.1743444-10-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> References: <20240111142326.1743444-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: -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 Reviewed-by: Richard Henderson --- contrib/plugins/hotblocks.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 4de1b134944..1d95ac53143 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -17,6 +17,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; +#define MAX_CPUS 8 + static bool do_inline; /* Plugins need to take care of their own locking */ @@ -34,16 +36,25 @@ static guint64 limit = 20; */ typedef struct { uint64_t start_addr; - uint64_t exec_count; + uint64_t exec_count[MAX_CPUS]; int trans_count; unsigned long insns; } ExecCount; +static uint64_t exec_count(ExecCount *e) +{ + uint64_t res = 0; + for (int i = 0; i < MAX_CPUS; ++i) { + res += e->exec_count[i]; + } + return res; +} + 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; + return exec_count(ea) > exec_count(eb) ? -1 : 1; } static void plugin_exit(qemu_plugin_id_t id, void *p) @@ -65,7 +76,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) 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); + rec->insns, exec_count(rec)); } g_list_free(it); @@ -89,7 +100,7 @@ static void vcpu_tb_exec(unsigned int cpu_index, void *udata) cnt = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) hash); /* should always succeed */ g_assert(cnt); - cnt->exec_count++; + cnt->exec_count[cpu_index]++; g_mutex_unlock(&lock); } @@ -120,8 +131,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) 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, + cnt->exec_count, sizeof(uint64_t), 1); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -149,6 +161,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, plugin_init(); + g_assert(info->system.smp_vcpus <= MAX_CPUS); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0;