Re: [Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-12 Thread Igor Mammedov
On Thu, 11 Feb 2016 13:59:33 -0200
Eduardo Habkost  wrote:

> On Fri, Feb 05, 2016 at 05:44:49PM +0100, Igor Mammedov wrote:
> > On Fri, 5 Feb 2016 17:19:50 +0100
> > Igor Mammedov  wrote:
> >   
> > > On Fri, 5 Feb 2016 13:39:07 -0200
> > > Eduardo Habkost  wrote:
> > >   
> > > > On Thu, Feb 04, 2016 at 12:47:33PM +0100, Igor Mammedov wrote:
> > > > > cpu->found_cpus bitmap is used for setting present
> > > > > flag in CPON AML package at start up. But it takes
> > > > > a bunch of code to fill bitmap and cloud be simplified
> > > > > by calling qemu_get_cpu_by_arch_id(apic_id) directly.
> > > > > 
> > > > > Hence do so and remove not used anymore bitmap
> > > > > with related utilities, which saves us ~32LOC
> > > > > and also would simplify consolidating APCI parts
> > > > > of CPU hotplug.
> > > > > 
> > > > > Signed-off-by: Igor Mammedov   
> > > > 
> > > > This makes the code loops through all smp_cpus CPUs max_cpus
> > > > times, instead of just looping through the smp_cpus CPUs once.
> > > Yep, that looks bad.
> > > I'll redo it using possible_cpu_arch_ids(), it is a little
> > > bit bigger refactoring.  
> > I think I'll make bitmap local to build_processor_devices() as it's
> > needed only for building CPON package, that way it will go along
> > with related legacy hotplug and won't get in the way of new hotplug.  
> 
> What about pc_possible_cpu_arch_ids() itself? It has exactly the
> same problem: it looks at CPU objects smp_cpus*max_cpus times, to
> fill the CPUArchId.cpu field. If that's a problem for
> build_processor_devices(), I assume that's a problem for all
> other possible_cpu_arch_ids() callers?
pls see v2
https://www.mail-archive.com/qemu-devel@nongnu.org/msg351298.html





Re: [Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-11 Thread Eduardo Habkost
On Fri, Feb 05, 2016 at 05:44:49PM +0100, Igor Mammedov wrote:
> On Fri, 5 Feb 2016 17:19:50 +0100
> Igor Mammedov  wrote:
> 
> > On Fri, 5 Feb 2016 13:39:07 -0200
> > Eduardo Habkost  wrote:
> > 
> > > On Thu, Feb 04, 2016 at 12:47:33PM +0100, Igor Mammedov wrote:  
> > > > cpu->found_cpus bitmap is used for setting present
> > > > flag in CPON AML package at start up. But it takes
> > > > a bunch of code to fill bitmap and cloud be simplified
> > > > by calling qemu_get_cpu_by_arch_id(apic_id) directly.
> > > > 
> > > > Hence do so and remove not used anymore bitmap
> > > > with related utilities, which saves us ~32LOC
> > > > and also would simplify consolidating APCI parts
> > > > of CPU hotplug.
> > > > 
> > > > Signed-off-by: Igor Mammedov 
> > > 
> > > This makes the code loops through all smp_cpus CPUs max_cpus
> > > times, instead of just looping through the smp_cpus CPUs once.  
> > Yep, that looks bad.
> > I'll redo it using possible_cpu_arch_ids(), it is a little
> > bit bigger refactoring.
> I think I'll make bitmap local to build_processor_devices() as it's
> needed only for building CPON package, that way it will go along
> with related legacy hotplug and won't get in the way of new hotplug.

What about pc_possible_cpu_arch_ids() itself? It has exactly the
same problem: it looks at CPU objects smp_cpus*max_cpus times, to
fill the CPUArchId.cpu field. If that's a problem for
build_processor_devices(), I assume that's a problem for all
other possible_cpu_arch_ids() callers?

-- 
Eduardo



Re: [Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-05 Thread Eduardo Habkost
On Thu, Feb 04, 2016 at 12:47:33PM +0100, Igor Mammedov wrote:
> cpu->found_cpus bitmap is used for setting present
> flag in CPON AML package at start up. But it takes
> a bunch of code to fill bitmap and cloud be simplified
> by calling qemu_get_cpu_by_arch_id(apic_id) directly.
> 
> Hence do so and remove not used anymore bitmap
> with related utilities, which saves us ~32LOC
> and also would simplify consolidating APCI parts
> of CPU hotplug.
> 
> Signed-off-by: Igor Mammedov 

This makes the code loops through all smp_cpus CPUs max_cpus
times, instead of just looping through the smp_cpus CPUs once.

I'm all for making the code simpler, and there's an upper bound:
looking at CPU objects 64k times (because MAX_CPUMASK_BITS is
255). But I want to make sure we agree this is an optimization we
want to drop.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-05 Thread Igor Mammedov
On Fri, 5 Feb 2016 13:39:07 -0200
Eduardo Habkost  wrote:

> On Thu, Feb 04, 2016 at 12:47:33PM +0100, Igor Mammedov wrote:
> > cpu->found_cpus bitmap is used for setting present
> > flag in CPON AML package at start up. But it takes
> > a bunch of code to fill bitmap and cloud be simplified
> > by calling qemu_get_cpu_by_arch_id(apic_id) directly.
> > 
> > Hence do so and remove not used anymore bitmap
> > with related utilities, which saves us ~32LOC
> > and also would simplify consolidating APCI parts
> > of CPU hotplug.
> > 
> > Signed-off-by: Igor Mammedov   
> 
> This makes the code loops through all smp_cpus CPUs max_cpus
> times, instead of just looping through the smp_cpus CPUs once.
Yep, that looks bad.
I'll redo it using possible_cpu_arch_ids(), it is a little
bit bigger refactoring.

> 
> I'm all for making the code simpler, and there's an upper bound:
> looking at CPU objects 64k times (because MAX_CPUMASK_BITS is
> 255). But I want to make sure we agree this is an optimization we
> want to drop.
> 




Re: [Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-05 Thread Igor Mammedov
On Fri, 5 Feb 2016 17:19:50 +0100
Igor Mammedov  wrote:

> On Fri, 5 Feb 2016 13:39:07 -0200
> Eduardo Habkost  wrote:
> 
> > On Thu, Feb 04, 2016 at 12:47:33PM +0100, Igor Mammedov wrote:  
> > > cpu->found_cpus bitmap is used for setting present
> > > flag in CPON AML package at start up. But it takes
> > > a bunch of code to fill bitmap and cloud be simplified
> > > by calling qemu_get_cpu_by_arch_id(apic_id) directly.
> > > 
> > > Hence do so and remove not used anymore bitmap
> > > with related utilities, which saves us ~32LOC
> > > and also would simplify consolidating APCI parts
> > > of CPU hotplug.
> > > 
> > > Signed-off-by: Igor Mammedov 
> > 
> > This makes the code loops through all smp_cpus CPUs max_cpus
> > times, instead of just looping through the smp_cpus CPUs once.  
> Yep, that looks bad.
> I'll redo it using possible_cpu_arch_ids(), it is a little
> bit bigger refactoring.
I think I'll make bitmap local to build_processor_devices() as it's
needed only for building CPON package, that way it will go along
with related legacy hotplug and won't get in the way of new hotplug.

> 
> > 
> > I'm all for making the code simpler, and there's an upper bound:
> > looking at CPU objects 64k times (because MAX_CPUMASK_BITS is
> > 255). But I want to make sure we agree this is an optimization we
> > want to drop.
> >   
> 
> 




[Qemu-devel] [PATCH 7/9] pc: acpi: drop not needed intermediate bitmap cpu->found_cpus

2016-02-04 Thread Igor Mammedov
cpu->found_cpus bitmap is used for setting present
flag in CPON AML package at start up. But it takes
a bunch of code to fill bitmap and cloud be simplified
by calling qemu_get_cpu_by_arch_id(apic_id) directly.

Hence do so and remove not used anymore bitmap
with related utilities, which saves us ~32LOC
and also would simplify consolidating APCI parts
of CPU hotplug.

Signed-off-by: Igor Mammedov 
---
 hw/i386/acpi-build.c | 42 +-
 1 file changed, 5 insertions(+), 37 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 9eeeffa..921830e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -76,10 +76,6 @@
 #define ACPI_BUILD_DPRINTF(fmt, ...)
 #endif
 
-typedef struct AcpiCpuInfo {
-DECLARE_BITMAP(found_cpus, ACPI_CPU_HOTPLUG_ID_LIMIT);
-} AcpiCpuInfo;
-
 typedef struct AcpiMcfgInfo {
 uint64_t mcfg_base;
 uint32_t mcfg_size;
@@ -121,31 +117,6 @@ typedef struct AcpiBuildPciBusHotplugState {
 bool pcihp_bridge_en;
 } AcpiBuildPciBusHotplugState;
 
-static
-int acpi_add_cpu_info(Object *o, void *opaque)
-{
-AcpiCpuInfo *cpu = opaque;
-uint64_t apic_id;
-
-if (object_dynamic_cast(o, TYPE_CPU)) {
-apic_id = object_property_get_int(o, "apic-id", NULL);
-assert(apic_id < ACPI_CPU_HOTPLUG_ID_LIMIT);
-
-set_bit(apic_id, cpu->found_cpus);
-}
-
-object_child_foreach(o, acpi_add_cpu_info, opaque);
-return 0;
-}
-
-static void acpi_get_cpu_info(AcpiCpuInfo *cpu)
-{
-Object *root = object_get_root();
-
-memset(cpu->found_cpus, 0, sizeof cpu->found_cpus);
-object_child_foreach(root, acpi_add_cpu_info, cpu);
-}
-
 static void acpi_get_pm_info(AcpiPmInfo *pm)
 {
 Object *piix = piix4_pm_find();
@@ -967,8 +938,7 @@ static Aml *build_crs(PCIHostState *host,
 }
 
 static void build_processor_devices(Aml *sb_scope, unsigned acpi_cpus,
-AcpiCpuInfo *cpu, AcpiPmInfo *pm,
-MachineState *machine)
+AcpiPmInfo *pm, MachineState *machine)
 {
 int i;
 Aml *dev;
@@ -1063,7 +1033,7 @@ static void build_processor_devices(Aml *sb_scope, 
unsigned acpi_cpus,
  aml_varpackage(acpi_cpus);
 
 for (i = 0; i < acpi_cpus; i++) {
-uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
+uint8_t b = qemu_get_cpu_by_arch_id(i) ? 0x01 : 0x00;
 aml_append(pkg, aml_int(b));
 }
 aml_append(sb_scope, aml_name_decl(CPU_ON_BITMAP, pkg));
@@ -1955,7 +1925,7 @@ static Aml *build_q35_osc_method(void)
 
 static void
 build_dsdt(GArray *table_data, GArray *linker,
-   AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
+   AcpiPmInfo *pm, AcpiMiscInfo *misc,
PcPciInfo *pci, PcGuestInfo *guest_info,
MachineState *machine)
 {
@@ -2263,7 +2233,7 @@ build_dsdt(GArray *table_data, GArray *linker,
 
 sb_scope = aml_scope("\\_SB");
 {
-build_processor_devices(sb_scope, guest_info->apic_id_limit, cpu, pm,
+build_processor_devices(sb_scope, guest_info->apic_id_limit, pm,
 machine);
 
 build_memory_devices(sb_scope, nr_mem, pm->mem_hp_io_base,
@@ -2618,7 +2588,6 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 {
 GArray *table_offsets;
 unsigned facs, dsdt, rsdt, fadt;
-AcpiCpuInfo cpu;
 AcpiPmInfo pm;
 AcpiMiscInfo misc;
 AcpiMcfgInfo mcfg;
@@ -2628,7 +2597,6 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 GArray *tables_blob = tables->table_data;
 MachineState *machine = MACHINE(qdev_get_machine());
 
-acpi_get_cpu_info();
 acpi_get_pm_info();
 acpi_get_misc_info();
 acpi_get_pci_info();
@@ -2651,7 +2619,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables 
*tables)
 
 /* DSDT is pointed to by FADT */
 dsdt = tables_blob->len;
-build_dsdt(tables_blob, tables->linker, , , , ,
+build_dsdt(tables_blob, tables->linker, , , ,
guest_info, machine);
 
 /* Count the size of the DSDT and SSDT, we will need it for legacy
-- 
1.8.3.1