From patchwork Tue Oct 3 18:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728812 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285825wrt; Tue, 3 Oct 2023 11:33:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6Zj0aE+CdTE9XZGxCNHkUt1eCzG1D1Feruk8BNAvmc4eutgXnwe7MqNZ8/z/BePFcMEnV X-Received: by 2002:ac8:7d4f:0:b0:412:21f4:6f9c with SMTP id h15-20020ac87d4f000000b0041221f46f9cmr315022qtb.60.1696357997945; Tue, 03 Oct 2023 11:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357997; cv=none; d=google.com; s=arc-20160816; b=Js9rQHWv+CgAviAZLlCa4fUYUGzbbQBs8fbHyAxJm98mgtutKxci1NBrowIdbiIPnQ 0og6EJPlkOdTMJ9iEKh4hW9LSMdEF7Cj7tNT0s2GiDQaHR7RIW0TIaJt4BkHldwCzY0k ULkXQPH2RVJy96Q3pDapWBnGzQQjcPhryOS3NlcVo3vgggBpZfTqIYpfg3JOnjLoxL2d ru8rmwMnul0AUxJ2U/hXXsDqPJMxSqF6hhflHMvUVeI1wOxAihzghVmp0Qit/2FHPb6I gp3ywfmTiQXVJzRVqPh+5iUaflyR0HH4s6BSnDdoMoj5uQ9J5jmoxA4mYcdUTSeAdbN4 q66g== 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; fh=5Ef+GGgUKhMqUJ634tl8oclCuvdgCDBmJobFnWqHX6s=; b=0bv+oxsCsJSLp7iwZf+rTJLF5vqL/EWJRUOq+G6LuOCZYr6bLSPRxCjnCdk2zUdAVA 9jIWYQFaZgFYLko2kbiJLsZOIE8oQ3J9/GhhsblnIZnnucMXjYuIBzuFmhviWo18cxFq EYQoGzbXUcRZDsF1733JMx2+oA5U0oMGe5CR/EBO1snDWdSvO9kg4Bz7Gz5sMjb65Py3 D3bRHMgOSaNnalYeO1aZerDXKSo5CmbOu48YmFhRqtG7x9QU4FsGt2RyRH+1KFCzFNaU qXqchF/l72uisKD3uKYVhZRuhWJDsg+RvQ/NKpLLDJ/91n2Qe4UlaYAfQuvX43IvEDd8 bbXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQJOWpj4; 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 v41-20020a05622a18a900b00411f7e63bd3si774005qtc.522.2023.10.03.11.33.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:17 -0700 (PDT) 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=IQJOWpj4; 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 1qnkAr-000849-CR; Tue, 03 Oct 2023 14:31:13 -0400 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 1qnkAo-00081k-S1 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:10 -0400 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 1qnkAm-0001fO-O1 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:10 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c61bde0b4bso10798895ad.3 for ; Tue, 03 Oct 2023 11:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357867; x=1696962667; 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; b=IQJOWpj4ZMH2cFnFwIq5NcIk9e0MxkSlc6pz/kQQbELbkNdyWhGT2tXfvpn536VZJK pebn8V2gGKSc+3F3CsuHhtnCkSqi9Hl8ATp5XWaW/PAy10fK40YEQwYgR8rHCbUm8OqU ttL47BPHrGvWeUMF8ulN9NDdUkSllJEMJbo5aQeUpimu7m+Sy6QH3GG9uPY724Q3wlPG xLsvKSm1y/yyvlFG3sb6DOh3xpFu1IOKG/KI4N4cxHkkMGjAAW2xNkDtLwAUAJ/QOysL K7vdBEGDoc3ibRxLHEc/re7ooGKeQjdXLuaS8RRa9ldA/E3lm7fkRzmIfDB2KcLqYpzl HAPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357867; x=1696962667; 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; b=GgMQK1d4rcDRBkIi6MnmYFOVMwkkhoG7BNifcigAF24HHVldXeUe/aXLHfz9ZaaM7a 5Gk8fu/9Q0isSkeXzotbbKIYFsQBY+cBiHpTntM4cNfxyD4hJMeVmQv9LDYA3omE4VH6 bhc/X5L8+PiAQ/MwmZvkVGu/wfvvTpZPDqHPdV6SJOWRg5iGG1yaZ11noAgPu3ZGtmiC byTxaHXaj2N2uT48tjcZWT62JfJw60AZwDJeFLSA9uPZUXW9b0u+9b64kMPquE2lBNnL YOC0WNAlWIVYCxF4SyzkFWFQR5B1kT8ZEkE2RVb10Gl58OAdO736ERuwFtMHLMMTTmTa ZbkA== X-Gm-Message-State: AOJu0YzxH3ZkreQNMcfrlsaTP+0UFkzmnihSbhm319IP23X21RyUA+mt 2j3IDBC84HqD/4AOWfS4IzlBZJztpuuYIqeRDmo= X-Received: by 2002:a17:903:32cb:b0:1c3:2ee6:3811 with SMTP id i11-20020a17090332cb00b001c32ee63811mr425165plr.8.1696357867317; Tue, 03 Oct 2023 11:31:07 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , "Dr . David Alan Gilbert" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 08/16] accel/tcg: Add tb_stats hmp command Date: Tue, 3 Oct 2023 11:30:50 -0700 Message-Id: <20231003183058.1639121-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@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 From: "Vanderson M. do Rosario" Add tb_stats [start|stop|status] command to hmp. This allows controlling the collection of statistics. The goal of this command is to allow the dynamic exploration of the TCG behavior and quality. Therefore, for now, a corresponding QMP command is not considered worthwhile. Acked-by: Dr. David Alan Gilbert Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Significantly reorganized.] Signed-off-by: Richard Henderson --- accel/tcg/monitor.c | 70 ++++++++++++++++++++++++++++++++++++++++++++- hmp-commands.hx | 15 ++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index 093efe9714..370fea883c 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -12,11 +12,15 @@ #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" +#include "qapi/qmp/qdict.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" +#include "tcg/tb-stats.h" +#include "exec/tb-flush.h" #include "internal-common.h" #include "tb-context.h" @@ -235,10 +239,74 @@ HumanReadableText *qmp_x_query_opcount(Error **errp) return human_readable_text_from_str(buf); } +static void tb_stats_init_safe(CPUState *cpu, run_on_cpu_data icmd) +{ + uint32_t flags = icmd.host_int; + + tb_stats_init(flags); + tb_flush(cpu); +} + +static void hmp_tbstats(Monitor *mon, const QDict *qdict) +{ + uint32_t flags = TB_STATS_NONE; + const char *cmd; + + if (!tcg_enabled()) { + monitor_printf(mon, "Only available with accel=tcg\n"); + return; + } + + cmd = qdict_get_try_str(qdict, "command"); + + if (strcmp(cmd, "start") == 0) { + const char *sflag = qdict_get_try_str(qdict, "flag"); + + flags = TB_STATS_ALL; + if (sflag) { + if (strcmp(sflag, "all") == 0) { + flags = TB_STATS_ALL; + } else if (strcmp(sflag, "jit") == 0) { + flags = TB_STATS_JIT; + } else if (strcmp(sflag, "exec") == 0) { + flags = TB_STATS_EXEC; + } else { + monitor_printf(mon, "Invalid argument to tb_stats start\n"); + return; + } + } + + if (tb_stats_enabled) { + monitor_printf(mon, "TB statistics already being recorded\n"); + return; + } + } else if (strcmp(cmd, "stop") == 0) { + if (!tb_stats_enabled) { + monitor_printf(mon, "TB statistics not being recorded\n"); + return; + } + } else if (strcmp(cmd, "status") == 0) { + if (tb_stats_enabled) { + monitor_printf(mon, "TB statistics are enabled:%s%s\n", + tb_stats_enabled & TB_STATS_EXEC ? " EXEC" : "", + tb_stats_enabled & TB_STATS_JIT ? " JIT" : ""); + } else { + monitor_printf(mon, "TB statistics are disabled\n"); + } + return; + } else { + monitor_printf(mon, "Invalid command\n"); + return; + } + + async_safe_run_on_cpu(first_cpu, tb_stats_init_safe, + RUN_ON_CPU_HOST_INT(flags)); +} + static void hmp_tcg_register(void) { monitor_register_hmp_info_hrt("jit", qmp_x_query_jit); monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount); + monitor_register_hmp("tb_stats", false, hmp_tbstats); } - type_init(hmp_tcg_register); diff --git a/hmp-commands.hx b/hmp-commands.hx index 63eac22734..e1d78ab69d 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1673,6 +1673,21 @@ SRST Executes a qemu-io command on the given block device. ERST +#if defined(CONFIG_TCG) + { + .name = "tb_stats", + .args_type = "command:s,flag:s?", + .params = "command [flag]", + .help = "Control tb statistics collection:" + "tb_stats (start|stop|status) [all|jit|exec]", + }, +#endif + +SRST +``tb_stats`` *command* *flag* + Control recording tb statistics +ERST + { .name = "qom-list", .args_type = "path:s?",