From nobody Sat Nov 15 11:53:43 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1594670977; cv=none; d=zohomail.com; s=zohoarc; b=QC4rTJ21vpafzb51e2jaNPAKmtB931UzGcXF3QlfZWb1KeT8CIMDLlwXmI4cPnhRL2bkX1fi4w85XRSoagweudvaAKc7bIbx9GY7KGM77M5IBMzhmMkfORxpUufOj3ZSPmEGpyVTQPK9Wls5VunqmnI6GMFP3V0fxJm6SRa+XNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594670977; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RFloOI9RdqsuY1jzWY/LdnGW0qTS1vaDIDIUNvMdMkw=; b=MWwSNsgj84rPouCX/MunovqhpG5uCqef9PDlatF1tqfLNuj7EBix0pRQSKcG3ivYY0dsiIHqDbfLWgt7l8FLe9Vg5k1yuK9pZEqhzisd53dGjYZwHxBl6hl+9SLKyUvP901K4FNmInoYtCHF/FuLkLmgqpR7kWl8Fi0VK9W2lH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594670977621958.6924662769711; Mon, 13 Jul 2020 13:09:37 -0700 (PDT) Received: from localhost ([::1]:33078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jv4lc-0000mA-Bi for importer@patchew.org; Mon, 13 Jul 2020 16:09:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jv4gj-0008Gz-De for qemu-devel@nongnu.org; Mon, 13 Jul 2020 16:04:33 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:44885) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jv4gh-0006JN-GR for qemu-devel@nongnu.org; Mon, 13 Jul 2020 16:04:33 -0400 Received: by mail-wr1-x442.google.com with SMTP id b6so18142756wrs.11 for ; Mon, 13 Jul 2020 13:04:31 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 190sm939618wmb.15.2020.07.13.13.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 13:04:23 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 43CCF1FF93; Mon, 13 Jul 2020 21:04:16 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RFloOI9RdqsuY1jzWY/LdnGW0qTS1vaDIDIUNvMdMkw=; b=zOKKinMl8Lc4tl+khcrq25otS5ClYMFza+X8Eb8n8PJ7hQDMp7qLKWT7XBzuLwUnTi VjmNAJQVQ8lV8KViFJt6Ozwz01fq/4O5j/ugnJOlgWRuWS2rLAvFgb/A1HQBF55RbRcZ GQvBF03MeCYdYuHLlSkW1GWLRGzaW/2xHlEzOxRnbI10ygzyNKxJW+TeXWZ60yztPJnx PwSYc/3A956kxyXldFVqJWJqmrfib28ef2fVWm+uiDaIOkbqTL/AdGRXizdlqrJpddv4 8IBew9zVF+kF5eibGXk6wzK6t67zqOdaQAphN8pyy3GT1vKQ8SeZRAq3HKPkeAvi7x7Q 3fsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RFloOI9RdqsuY1jzWY/LdnGW0qTS1vaDIDIUNvMdMkw=; b=HG6Ikq8ZHO+Vs/UYJ+j5HrrgIrKtr5bcVaHYHL5opYNB0HC+Vl3/y687JOH4QL8qlJ aV8kCd713EdH8aey2O1ugM5ZUZcBXiGkTwdZEP+tL6fcpT5+ZRg1FBkmbrujJ0p9Gv2c ay/dgyfdFldNDke89p23gXvB5Q+bbOGPSRqHy8ChzMiUuEg3y2LGSpTNYyxAd61ilBL9 ji/X7rTz4W2m8QeviiRJDr7zx5czlIS4tPnmrH1FWgRLSaZduxcx0i5IvVIE0qbsXLyn S4IICrwi/W/uPCDnFYr2lvEbkLOIMIKUtznB1LRrCh9kHpnQc/7xLOCCLBSDElPFNsdx e0pg== X-Gm-Message-State: AOAM530B8xazTi8iIvKMPlNruyh3RmR5jbCY1gx3KpP794VWJj5b3gOc SR4wTHNED6L0wMV77Rkm+CAuwg== X-Google-Smtp-Source: ABdhPJz0U1RwaSiDkrjwHwQDpu95CLWAZdSD8f+3Y7G8PVkw0FQyxceowkoWTeeyIBCnsVHLzEK73A== X-Received: by 2002:a5d:6107:: with SMTP id v7mr1188315wrt.174.1594670670106; Mon, 13 Jul 2020 13:04:30 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 07/11] plugins: expand the bb plugin to be thread safe and track per-cpu Date: Mon, 13 Jul 2020 21:04:11 +0100 Message-Id: <20200713200415.26214-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200713200415.26214-1-alex.bennee@linaro.org> References: <20200713200415.26214-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, robert.foley@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, Dave Bort , kuhn.chenqun@huawei.com, peter.puhov@linaro.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) While there isn't any easy way to make the inline counts thread safe we can ensure the callback based ones are. While we are at it we can reduce introduce a new option ("idle") to dump a report of the current bb and insn count each time a vCPU enters the idle state. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Robert Foley Cc: Dave Bort --- v2 - fixup for non-inline linux-user case - minor cleanup and re-factor v3 - checkpatch --- tests/plugin/bb.c | 97 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 13 deletions(-) diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index df19fd359d..e4cc7fdd6e 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -16,24 +16,67 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -static uint64_t bb_count; -static uint64_t insn_count; +typedef struct { + GMutex lock; + int index; + uint64_t bb_count; + uint64_t insn_count; +} CPUCount; + +/* Used by the inline & linux-user counts */ 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) +{ + if (count->bb_count) { + g_string_append_printf(report, "CPU%d: " + "bb's: %" PRIu64", insns: %" PRIu64 "\n", + count->index, + count->bb_count, count->insn_count); + } +} =20 static void plugin_exit(qemu_plugin_id_t id, void *p) { - g_autofree gchar *out =3D g_strdup_printf( - "bb's: %" PRIu64", insns: %" PRIu64 "\n", - bb_count, insn_count); - qemu_plugin_outs(out); + g_autoptr(GString) report =3D 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); + } + qemu_plugin_outs(report->str); +} + +static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) +{ + CPUCount *count =3D g_ptr_array_index(counts, cpu_index); + g_autoptr(GString) report =3D g_string_new(""); + gen_one_cpu_report(count, report); + + if (report->len > 0) { + g_string_prepend(report, "Idling "); + qemu_plugin_outs(report->str); + } } =20 static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - unsigned long n_insns =3D (unsigned long)udata; + CPUCount *count =3D max_cpus ? + g_ptr_array_index(counts, cpu_index) : &inline_count; =20 - insn_count +=3D n_insns; - bb_count++; + unsigned long n_insns =3D (unsigned long)udata; + g_mutex_lock(&count->lock); + count->insn_count +=3D n_insns; + count->bb_count++; + g_mutex_unlock(&count->lock); } =20 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -42,9 +85,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qe= mu_plugin_tb *tb) =20 if (do_inline) { qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &bb_count, 1); + &inline_count.bb_count, 1= ); qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &insn_count, n_insns); + &inline_count.insn_count, + n_insns); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -56,8 +100,35 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, const qemu_info_t *info, int argc, char **argv) { - if (argc && strcmp(argv[0], "inline") =3D=3D 0) { - do_inline =3D true; + int i; + + for (i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + if (g_strcmp0(opt, "inline") =3D=3D 0) { + do_inline =3D true; + } else if (g_strcmp0(opt, "idle") =3D=3D 0) { + idle_report =3D true; + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (info->system_emulation && !do_inline) { + max_cpus =3D info->system.max_vcpus; + counts =3D g_ptr_array_new(); + for (i =3D 0; i < max_cpus; i++) { + CPUCount *count =3D g_new0(CPUCount, 1); + g_mutex_init(&count->lock); + count->index =3D i; + g_ptr_array_add(counts, count); + } + } else if (!do_inline) { + g_mutex_init(&inline_count.lock); + } + + if (idle_report) { + qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle); } =20 qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); --=20 2.20.1