From patchwork Wed Aug 17 05:25:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bharata B Rao X-Patchwork-Id: 110278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6C0FBB6F7D for ; Wed, 17 Aug 2011 15:26:06 +1000 (EST) Received: from localhost ([::1]:42877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtYdY-0004W3-5A for incoming@patchwork.ozlabs.org; Wed, 17 Aug 2011 01:25:56 -0400 Received: from eggs.gnu.org ([140.186.70.92]:36214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtYdS-0004Vy-0X for qemu-devel@nongnu.org; Wed, 17 Aug 2011 01:25:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QtYdQ-0002u5-H6 for qemu-devel@nongnu.org; Wed, 17 Aug 2011 01:25:49 -0400 Received: from mail-iy0-f171.google.com ([209.85.210.171]:49307) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QtYdQ-0002ty-1u for qemu-devel@nongnu.org; Wed, 17 Aug 2011 01:25:48 -0400 Received: by iyf13 with SMTP id 13so1259105iyf.30 for ; Tue, 16 Aug 2011 22:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Ln6jFoo9BB2LMXoR5Nn/ZnSdla1zIF9zOJPq+jeXRIk=; b=EkWSE170hFWBynCC/vm6ESINayD3sf5p0hP9aT2Bq8V9GVyG/dZ+fStRVnjko+llKI xrd/0kE9n2jdNWqoyc71uf/Vq0CR1DYLmxiPee+Hz3mzy7Xu7TFlkjuKiy9h91m5ypoE XksmYP6oyTLT56DfBXO5uwhOQoG9TTlmVzEvY= MIME-Version: 1.0 Received: by 10.42.151.2 with SMTP id c2mr499302icw.15.1313558747108; Tue, 16 Aug 2011 22:25:47 -0700 (PDT) Received: by 10.42.172.72 with HTTP; Tue, 16 Aug 2011 22:25:47 -0700 (PDT) In-Reply-To: References: Date: Wed, 17 Aug 2011 10:55:47 +0530 Message-ID: From: Bharata B Rao To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.171 Subject: [Qemu-devel] X86 CPU topology broken in qemu ? X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi, I see that x86 CPU topology inside VM is not showing up as specified. With some debugging, I found out that the root cause for this: qemu is not enumerating the apic ids correctly for vcpus. I made the below hackish change to get it working.  Has anybody else seen this problem ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest. *************************** Fix apic id enumeration apic id returned to guest kernel in ebx for cpuid(function=1) depends on CPUX86State->cpuid_apic_id which gets populated after the cpuid information is cached in the host kernel. Fix this by setting cpuid_apic_id before cpuid information is passed to the host kernel. Signed-off-by: Bharata B Rao ---  hw/pc.c           |    4 +---  target-i386/kvm.c |    3 +++  2 files changed, 4 insertions(+), 3 deletions(-) ************************** This is how various fields look like before and after this change with qemu command line option of "-smp ,sockets=1,cores=4,threads=2" Before ------ root@sqzy:~# grep "core id" /proc/cpuinfo core id         : 0 core id         : 0 core id         : 0 core id         : 0 core id         : 0 core id         : 0 core id         : 0 core id         : 0 After ----- root@sqzy:~# grep "core id" /proc/cpuinfo core id         : 0 core id         : 0 core id         : 1 core id         : 1 core id         : 2 core id         : 2 core id         : 3 core id         : 3 Before ------ root@sqzy:~# grep "cpu cores" /proc/cpuinfo cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 cpu cores       : 1 After ----- root@sqzy:~# grep "cpu cores" /proc/cpuinfo cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 cpu cores       : 4 Before ------ root@sqzy:~# grep apicid /proc/cpuinfo apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 apicid          : 0 initial apicid  : 0 After ----- root@sqzy:~# grep apicid /proc/cpuinfo apicid          : 0 initial apicid  : 0 apicid          : 1 initial apicid  : 1 apicid          : 2 initial apicid  : 2 apicid          : 3 initial apicid  : 3 apicid          : 4 initial apicid  : 4 apicid          : 5 initial apicid  : 5 apicid          : 6 initial apicid  : 6 apicid          : 7 initial apicid  : 7 Before ------ root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/core_siblings_list 0-7 0-7 0-7 0-7 0-7 0-7 0-7 0-7 root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/thread_siblings_list 0-7 0-7 0-7 0-7 0-7 0-7 0-7 0-7 After ----- root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/core_siblings_list 0-7 0-7 0-7 0-7 0-7 0-7 0-7 0-7 root@sqzy:/sys/devices/system/cpu# cat cpu*/topology/thread_siblings_list 0-1 0-1 2-3 2-3 4-5 4-5 6-7 6-7 Regards, Bharata. -- http://bharata.sulekha.com/blog/posts.htm, http://raobharata.wordpress.com/ Index: qemu-kvm-0.14.1/hw/pc.c =================================================================== --- qemu-kvm-0.14.1.orig/hw/pc.c +++ qemu-kvm-0.14.1/hw/pc.c @@ -930,10 +930,8 @@ CPUState *pc_new_cpu(const char *cpu_mod         fprintf(stderr, "Unable to find x86 CPU definition\n");         exit(1);     } -    if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) { -        env->cpuid_apic_id = env->cpu_index; +    if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1)         env->apic_state = apic_init(env, env->cpuid_apic_id); -    }     qemu_register_reset(pc_cpu_reset, env);     pc_cpu_reset(env);     return env; Index: qemu-kvm-0.14.1/target-i386/kvm.c =================================================================== --- qemu-kvm-0.14.1.orig/target-i386/kvm.c +++ qemu-kvm-0.14.1/target-i386/kvm.c @@ -340,6 +340,9 @@ int kvm_arch_init_vcpu(CPUState *env)     cpuid_i = 0; +    if (env->cpuid_features & CPUID_APIC) +        env->cpuid_apic_id = env->cpu_index; +  #ifdef CONFIG_KVM_PARA     /* Paravirtualization CPUIDs */     memcpy(signature, "KVMKVMKVM\0\0\0", 12);