From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sypsp-00021M-9a for qemu-devel@nongnu.org; Tue, 07 Aug 2012 15:56:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sypsn-0008O1-Ei for qemu-devel@nongnu.org; Tue, 07 Aug 2012 15:56:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39896) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sypsn-0008NR-6d for qemu-devel@nongnu.org; Tue, 07 Aug 2012 15:56:01 -0400 From: Eduardo Habkost Date: Tue, 7 Aug 2012 16:56:38 -0300 Message-Id: <1344369413-9053-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [RFC 00/15] attempt to fix CPU topology info on CPU APIC IDs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gleb Natapov , Paolo Bonzini First, the bug description: The CPU APIC IDs generated by QEMU are broken if the number of cores-per-socket or threads-per-core are not powers of 2, as the bits on the APIC ID do not correspond to what's expected to reflect the CPU sockets/cores/threads topology[1]. [1] http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/ This is an attempt to fix it, but there were some obstacles on the way: 1) The NUMA fw_cfg interface requires the full topology information to be available even for hotplug CPUs that don't exist yet, so we need to be able to calculate the APIC ID solely from the CPU index. 2) CPU objects are not qdev objects (yet). 3) We don't have a "list CPUs" object (yet), so we don't have an object where a compatibility global property could be set, and that would be responsible for calculating the APIC IDs. That said, the patches are organized as follows: - Patches 1 to 3 are just code movements or smaller fixes to prepare for the actual fix. They should be safe to be applied right now. - Patches 4 to 6 addresses issue #1 above. - Patches 7 to 12 change the global property handling code to make it at least possible to use a global property without requiring QOM or qdev (due to issues #2 and #3 above). I expect it to be controversial and I would like to get some feedback. - Patches 13 and 14 are the actual fix, that changes the APIC ID calculation to match the requested CPU topology, and use a "SMP.contiguous_apic_ids" global property to keep compatibility on pc-1.1 and older machine-types. The fix depends on commit 008c1fc5bd4f1c545c38e07242ad676830ea7785 of SeaBIOS, that allows CPU APIC IDs to be non-contiguous. However, older SeaBIOS verions should still work, as long as cores/threads are powers of 2 or you use the "pc-1.1" machine-type (or older). I am aware of the coding style warnings from checkpatch.pl (mainly "line over 80 characters" warnings), and I plan to fix them in the final version of the fix. Eduardo Habkost (15): cpus.h: include cpu-common.h hw/apic.c: rename bit functions to not conflict with bitops.h (v2) kvm: set vcpu_id to APIC ID instead of CPU index i386: create apic_id_for_cpu() function (v2) remove FW_CFG_MAX_CPUS from fw_cfg_init() pc: set FW_CFG data based on APIC ID calculation qdev: allow qdev_prop_parse() to report errors move global properties code to global-properties.c isolate qdev-independent parts of qdev_prop_set_globals() create object_prop_set_globals() rename qdev_prop_register_global_list to qemu_globals_register_list create qemu_global_get() function tests: support target-specific unit tests i386: topology & APIC ID utility functions (v2) generate APIC IDs according to CPU topology (v2) Makefile.objs | 1 + cpus.h | 2 + global-properties.c | 88 ++++++++++++++++++++++++++++++ hw/apic.c | 35 ++++++------ hw/fw_cfg.c | 1 - hw/pc.c | 23 +++++--- hw/pc_piix.c | 4 ++ hw/ppc_newworld.c | 1 + hw/ppc_oldworld.c | 1 + hw/qdev-monitor.c | 6 ++- hw/qdev-properties.c | 67 ++--------------------- hw/qdev.h | 18 +++++-- hw/sun4m.c | 3 ++ hw/sun4u.c | 1 + kvm-all.c | 2 +- target-i386/cpu.c | 40 +++++++++++++- target-i386/cpu.h | 17 ++++++ target-i386/topology.h | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/.gitignore | 1 + tests/Makefile | 19 +++++-- tests/test-x86-cpuid.c | 108 +++++++++++++++++++++++++++++++++++++ vl.c | 6 +-- 22 files changed, 488 insertions(+), 100 deletions(-) create mode 100644 global-properties.c create mode 100644 target-i386/topology.h create mode 100644 tests/test-x86-cpuid.c -- 1.7.11.2