From patchwork Fri Jan 28 19:10:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 80885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5BD77B70E9 for ; Sat, 29 Jan 2011 06:39:03 +1100 (EST) Received: from localhost ([127.0.0.1]:52765 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Piu9s-0007ew-C2 for incoming@patchwork.ozlabs.org; Fri, 28 Jan 2011 14:39:00 -0500 Received: from [140.186.70.92] (port=58685 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Piu9J-0007er-Ik for qemu-devel@nongnu.org; Fri, 28 Jan 2011 14:38:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Piu9I-0004bO-8R for qemu-devel@nongnu.org; Fri, 28 Jan 2011 14:38:25 -0500 Received: from mail15c26.carrierzone.com ([64.29.152.165]:48579) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Piu9I-0004bB-33 for qemu-devel@nongnu.org; Fri, 28 Jan 2011 14:38:24 -0500 X-Authenticated-User: third_harmonic.myfairpoint.net Received: from anvil.naka.net (pool-72-73-80-12.ptldme.east.myfairpoint.net [72.73.80.12]) (authenticated bits=0) by mail15c26.carrierzone.com (8.13.6/8.13.1) with ESMTP id p0SJcJNR006220; Fri, 28 Jan 2011 19:38:21 GMT Message-ID: <4D431493.9060701@third-harmonic.com> Date: Fri, 28 Jan 2011 14:10:11 -0500 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: qemu-devel@nongnu.org X-Enigmail-Version: 0.96.0 X-CSC: 0 X-CHA: v=1.1 cv=7GX4LaeITwjd1wJ23IAmGCpJXTUsgG3jne2n0yU8Qn0= c=1 sm=1 a=Py_5SJvh4H0A:10 a=8nJEP1OIZ-IA:10 a=z0zpaTH0yP2UMNBzZfFMNw==:17 a=20KFwNOVAAAA:8 a=Y6JJKmIpAAAA:8 a=XkOfON2R1a5ABzQKY_0A:9 a=kXeFUTLc8TI9_Lr8xnBTmB4b9HwA:4 a=wPNLvfGTeEIA:10 a=jEp0ucaQiEUA:10 a=V_msMhXgnbQA:10 a=z0zpaTH0yP2UMNBzZfFMNw==:117 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 64.29.152.165 Cc: john cooper , Anthony Liguori Subject: [Qemu-devel] [PATCH] Allow "-cpu [check|enforce]" to be used implicitly with default CPU model. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Launching qemu with "-cpu [check|enforce]" without explicitly prefixing a valid model name doesn't do as intuitively expected. Rather qemu exits with a CLI parse error. Unfortunately due to qemu's CLI argument parsing structure and the fact cpu models are initialized depending on build configuration, supporting the above implicitly for the default model is far more clunky than it ought to be. So as a minor concession to a far more simple solution, a pseudo model name of "default" is added which expands internally to qemu's build configuration default and is then interpreted conventionally. The result is then the following example usage: # x86_64-softmmu/qemu-system-x86_64 -cpu default,check Using CPU model "qemu64,check" warning: host cpuid 0000_0001 lacks requested flag 'popcnt' [0x00800000] warning: host cpuid 8000_0001 lacks requested flag 'abm' [0x00000020] warning: host cpuid 8000_0001 lacks requested flag 'sse4a' [0x00000040] # x86_64-softmmu/qemu-system-x86_64 -cpu default,enforce,+sse4.2,+popcnt Using CPU model "qemu64,enforce,+sse4.2,+popcnt" warning: host cpuid 0000_0001 lacks requested flag 'sse4.2|sse4_2' [0x00100000] warning: host cpuid 0000_0001 lacks requested flag 'popcnt' [0x00800000] warning: host cpuid 8000_0001 lacks requested flag 'abm' [0x00000020] warning: host cpuid 8000_0001 lacks requested flag 'sse4a' [0x00000040] Unable to find x86 CPU definition etc.. allowing both the ability here to "check|enforce" the default model, as well as accepting arbitrary feature flags due to fan into the existing flag parsing. The resulting patch, which also indicates the CPU model in use, is fairly simple. Please review and apply. Signed-off-by: john cooper diff --git a/hw/pc.c b/hw/pc.c index 119c110..27c87b5 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -861,18 +861,49 @@ static CPUState *pc_new_cpu(const char *cpu_model) return env; } +/* CLI cpu model name which expands to the actual configuration default + */ +#define CMDEF_KEYWORD "default" +#define CMDEF_KEYWORD_LN (sizeof (CMDEF_KEYWORD) - 1) + +/* set configuration default cpu model if current model string is + * uninitialized, or if user explicitly requests use of the config'ed + * default by specifying a cpu model name of "default". + * Use of "default" as a cpu model pseudo-name exists primarily to + * ease treatment of qualifier flags requested by the user without + * requiring knowledge of all cpu model names in advance of full "-cpu" + * option parsing. + */ +static const char *setdef_cpu_model(const char *model_str, + const char *default_str) +{ + int default_str_ln = strlen(default_str); + + if (!model_str || !*model_str) { + return default_str; + } else if (strncmp(model_str, CMDEF_KEYWORD, CMDEF_KEYWORD_LN)) { + return model_str; + } else { + char *new = qemu_malloc(strlen(model_str) - CMDEF_KEYWORD_LN + + default_str_ln + 1); + + strcpy(new, default_str); + strcpy(new + default_str_ln, model_str + CMDEF_KEYWORD_LN); + return new; + } +} + void pc_cpus_init(const char *cpu_model) { int i; /* init CPUs */ - if (cpu_model == NULL) { + cpu_model = setdef_cpu_model(cpu_model, #ifdef TARGET_X86_64 - cpu_model = "qemu64"; + "qemu64"); #else - cpu_model = "qemu32"; + "qemu32"); #endif - } for(i = 0; i < smp_cpus; i++) { pc_new_cpu(cpu_model); diff --git a/target-i386/helper.c b/target-i386/helper.c index 26ea1e5..1b0b586 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -1129,6 +1129,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model) env = qemu_mallocz(sizeof(CPUX86State)); cpu_exec_init(env); env->cpu_model_str = cpu_model; + fprintf(stderr, "Using CPU model \"%s\"\n", cpu_model); /* init various static tables */ if (!inited) {