From nobody Mon Feb 9 18:19:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1678655275; cv=none; d=zohomail.com; s=zohoarc; b=U6uPlgwUnDejXErdJeb5LbJPdJG26i7GJJXqtYtOJsLjABV7O9aAiIgDxcjTjRcZCIDBwoRRkVMDFRFYbRcufsEv9FCp3/eDBC8RJKGs5z0eh6jdVtpbi7s/Y2FXbQMa9Xm8iPXuI4bXHMhg2UedaQRmWzmzTu2qBDH9GIjSy5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678655275; h=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=hJuQ9Ot9Rr33pUg6sU0ac4LU04XE1Atyy4CooADGLEw=; b=JVNEn2N8WJ+GJ6R0RQIk3/GAsT9eWWgselYiaVaXp8zVY3fuYZtAmENlSOftC3B/xwMy1ZciYvxfhWGihbT21OA1nn49F+xTOAsIKmJjQ+gvro3fthXnPyVwsjGnYgNngYGOJRsOrwv2IlGSs69qs/FBDN5LUiTwrocQ5Kq1mbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678655275790176.26158541757252; Sun, 12 Mar 2023 14:07:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pbSuA-0000Wy-9z; Sun, 12 Mar 2023 17:06:58 -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 1pbSu8-0000Vq-5E for qemu-devel@nongnu.org; Sun, 12 Mar 2023 17:06:56 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pbSu6-0006l8-9n for qemu-devel@nongnu.org; Sun, 12 Mar 2023 17:06:55 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id nv15so7120713qvb.7 for ; Sun, 12 Mar 2023 14:06:53 -0700 (PDT) Received: from debian.hsd1.ma.comcast.net ([2601:182:cc00:77b0::675]) by smtp.gmail.com with ESMTPSA id s17-20020a05622a019100b003b86b088755sm4291290qtw.15.2023.03.12.14.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 14:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678655213; 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=hJuQ9Ot9Rr33pUg6sU0ac4LU04XE1Atyy4CooADGLEw=; b=idoIzH8SVOE4Qnb4y+GOkgnF75qAoHKOXU61fsFEWMLwmT3xH5ZFoQ9sd/uxMg+T15 NfoIMvEBVvLkywrhu/RNulayVI0rYPdVGMuPMVWatqhx5yWHIuZ6Wxd/AM9nV8iUdmo+ kNsFY4aT3NFSYFeYV9n9nFHzkEMGLRE95dDDgEwmiFcg0TvTnfVvjsxxcVmr8uN/bpUE L+YeLVX49EPAxcftDnCZg5yV3zxhtVBh4cEl7F9oN0Y1/DhQmcIHGCWvoI6oHSvvggt6 TUJNSUmJzBv9kjPC1ZaT0biwv5rdPq1NGSbfYW8oba48YaXiJj8++sJuYNRTyrYsyhhf gu/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678655213; 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=hJuQ9Ot9Rr33pUg6sU0ac4LU04XE1Atyy4CooADGLEw=; b=1BixTz3N8BaXh4WvA6JxeCHi3A7yLlqcGCoFlPI3VloAChD0TLK6YrOsiQ5X8/BX9r U6eBhj4A0XzdHcQMi/GOORL+pz1g1hIKCSfikVKHI81Ny8x99VFf68oakU93TiSGLaKD GO/NU1u4kSxVl4w1R0GoR9Ic+j12XZxg4hWOyALBYyuLAT1AzaVPwXtaqPkO7ApfVS8M ViVtYNOVVrQpzlRWW/HKwmk3ffURwZPOSNlaijGZGK4sf3MO/9IfEkLqxUYM4B3XDYu3 LLCzB5tHL9cCVWRlB8yoBvsNgNOtm9jVGjWD4zSU+LbzU3YGJNRFjThVq/JuqYAB/+zm fwAA== X-Gm-Message-State: AO0yUKULAO/N6n6nuY64wWkfKzEwvdq/cm/PJQzpUPnNNrQDhewMGRvw wTOFtg73Vs9v9WcaR1Eti9z46bjRUvakJg== X-Google-Smtp-Source: AK7set9gVYyvQe9trjZTfbt/JKxrZh8jd9QUu2V9mCc0gmt4wQxVkFxNl20D9+rOvrTqZt32bDSDqw== X-Received: by 2002:a05:6214:20a8:b0:56e:fdff:29f9 with SMTP id 8-20020a05621420a800b0056efdff29f9mr9475054qvd.18.1678655213071; Sun, 12 Mar 2023 14:06:53 -0700 (PDT) From: Dinah Baum To: qemu-devel@nongnu.org Cc: Dinah Baum , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Richard Henderson , Paolo Bonzini , Markus Armbruster Subject: [PATCH 2/2] cpu, qdict, vl: Enable printing options for CPU type Date: Sun, 12 Mar 2023 17:06:24 -0400 Message-Id: <20230312210624.2326264-3-dinahbaum123@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230312210624.2326264-1-dinahbaum123@gmail.com> References: <20230312210624.2326264-1-dinahbaum123@gmail.com> MIME-Version: 1.0 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=2607:f8b0:4864:20::f2f; envelope-from=dinahbaum123@gmail.com; helo=mail-qv1-xf2f.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1678655277645100003 Content-Type: text/plain; charset="utf-8" Change parsing of -cpu argument to allow -cpu cpu,help to print options for the CPU type similar to how the '-device' option works. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1480 Signed-off-by: Dinah Baum --- cpu.c | 41 +++++++++++++++++++++++++++++++++++++++ include/exec/cpu-common.h | 2 ++ include/qapi/qmp/qdict.h | 2 ++ qemu-options.hx | 7 ++++--- qobject/qdict.c | 5 +++++ softmmu/vl.c | 36 ++++++++++++++++++++++++++++++++-- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/cpu.c b/cpu.c index c09edc4556..fe33c51061 100644 --- a/cpu.c +++ b/cpu.c @@ -23,7 +23,9 @@ #include "exec/target_page.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" +#include "qemu/qemu-print.h" #include "migration/vmstate.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -42,6 +44,8 @@ #include "hw/core/accel-cpu.h" #include "trace/trace-root.h" #include "qemu/accel.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" =20 uintptr_t qemu_host_page_size; intptr_t qemu_host_page_mask; @@ -311,6 +315,43 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, return get_cpu_model_expansion_info(type, model, errp); } =20 +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, + Error **errp) +{ + CpuModelExpansionInfo *expansion_info; + QDict *qdict; + QDictEntry *qdict_entry; + const char *key; + QObject *obj; + QType q_type; + GPtrArray *array; + int i; + const char *type_name; + + expansion_info =3D get_cpu_model_expansion_info(type, model, errp); + if (expansion_info) { + qdict =3D qobject_to(QDict, expansion_info->model->props); + if (qdict) { + qemu_printf("%s features:\n", model->name); + array =3D g_ptr_array_new(); + for (qdict_entry =3D (QDictEntry *)qdict_first(qdict); qdict_e= ntry; + qdict_entry =3D (QDictEntry *)qdict_next(qdict, qdict_ent= ry)) { + g_ptr_array_add(array, qdict_entry); + } + g_ptr_array_sort(array, (GCompareFunc)dict_key_compare); + for (i =3D 0; i < array->len; i++) { + qdict_entry =3D array->pdata[i]; + key =3D qdict_entry_key(qdict_entry); + obj =3D qdict_get(qdict, key); + q_type =3D qobject_type(obj); + type_name =3D QType_str(q_type); + qemu_printf(" %s=3D<%s>\n", key, type_name); + } + } + } +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index ec6024dfde..8fc05307ad 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -174,5 +174,7 @@ typedef void (*cpu_model_expansion_func)(CpuModelExpans= ionType type, CpuModelExpansionInfo *get_cpu_model_expansion_info(CpuModelExpansionType = type, CpuModelInfo *model, Error **errp); +void list_cpu_model_expansion(CpuModelExpansionType type, + CpuModelInfo *model, Error **errp); =20 #endif /* CPU_COMMON_H */ diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 82e90fc072..1ff9523a13 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -68,4 +68,6 @@ const char *qdict_get_try_str(const QDict *qdict, const c= har *key); =20 QDict *qdict_clone_shallow(const QDict *src); =20 +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2); + #endif /* QDICT_H */ diff --git a/qemu-options.hx b/qemu-options.hx index d42f60fb91..d5284b9330 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -169,11 +169,12 @@ SRST ERST =20 DEF("cpu", HAS_ARG, QEMU_OPTION_cpu, - "-cpu cpu select CPU ('-cpu help' for list)\n", QEMU_ARCH_ALL) + "-cpu cpu select CPU ('-cpu help' for list)\n" + " use '-cpu cpu,help' to print possible properties\n", = QEMU_ARCH_ALL) SRST ``-cpu model`` - Select CPU model (``-cpu help`` for list and additional feature - selection) + Select CPU model (``-cpu help`` and ``-cpu cpu,help``) for list and ad= ditional feature + selection ERST =20 DEF("accel", HAS_ARG, QEMU_OPTION_accel, diff --git a/qobject/qdict.c b/qobject/qdict.c index 8faff230d3..31407e62f6 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -447,3 +447,8 @@ void qdict_unref(QDict *q) { qobject_unref(q); } + +int dict_key_compare(QDictEntry **entry1, QDictEntry **entry2) +{ + return g_strcmp0(qdict_entry_key(*entry1), qdict_entry_key(*entry2)); +} diff --git a/softmmu/vl.c b/softmmu/vl.c index 3340f63c37..a9d70e559e 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -500,6 +500,15 @@ static QemuOptsList qemu_action_opts =3D { }, }; =20 +static QemuOptsList qemu_cpu_opts =3D { + .name =3D "cpu", + .implied_opt_name =3D "cpu", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head), + .desc =3D { + { /* end of list */ } + }, +}; + const char *qemu_get_vm_name(void) { return qemu_name; @@ -1147,6 +1156,26 @@ static int device_init_func(void *opaque, QemuOpts *= opts, Error **errp) return 0; } =20 +static int cpu_help_func(void *opaque, QemuOpts *opts, Error **errp) +{ + CpuModelInfo *model; + + if (cpu_option && is_help_option(cpu_option)) { + list_cpus(cpu_option); + return 1; + } + + if (!cpu_option || !qemu_opt_has_help_opt(opts)) { + return 0; + } + + model =3D g_new0(CpuModelInfo, 1); + model->name =3D (char *)qemu_opt_get(opts, "cpu"); + /* TODO: handle other expansion cases */ + list_cpu_model_expansion(CPU_MODEL_EXPANSION_TYPE_FULL, model, errp); + return 1; +} + static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err =3D NULL; @@ -2431,8 +2460,9 @@ static void qemu_process_help_options(void) * type and the user did not specify one, so that the user doesn't need * to say '-cpu help -machine something'. */ - if (cpu_option && is_help_option(cpu_option)) { - list_cpus(cpu_option); + Error *errp =3D NULL; + if (qemu_opts_foreach(qemu_find_opts("cpu"), + cpu_help_func, NULL, &errp)) { exit(0); } =20 @@ -2672,6 +2702,7 @@ void qemu_init(int argc, char **argv) qemu_add_opts(&qemu_semihosting_config_opts); qemu_add_opts(&qemu_fw_cfg_opts); qemu_add_opts(&qemu_action_opts); + qemu_add_opts(&qemu_cpu_opts); module_call_init(MODULE_INIT_OPTS); =20 error_init(argv[0]); @@ -2723,6 +2754,7 @@ void qemu_init(int argc, char **argv) switch(popt->index) { case QEMU_OPTION_cpu: /* hw initialization will check this */ + qemu_opts_parse_noisily(qemu_find_opts("cpu"), optarg, tru= e); cpu_option =3D optarg; break; case QEMU_OPTION_hda: --=20 2.30.2