qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Apfelbaum <marcel@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>, qemu-devel@nongnu.org
Cc: Igor Mammedov <imammedo@redhat.com>,
	Marcel Apfelbaum <marcel.a@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 07/14] acpi: Remove guest_info parameters from functions
Date: Tue, 15 Dec 2015 14:36:10 +0200	[thread overview]
Message-ID: <5670093A.1010600@redhat.com> (raw)
In-Reply-To: <1449859353-1574-8-git-send-email-ehabkost@redhat.com>

On 12/11/2015 08:42 PM, Eduardo Habkost wrote:
> We can use PC_MACHINE(qdev_get_machine())->acpi_guest_info to get
> guest_info.

Hi Eduardo,

I like the idea of using qdev_get_machine() to get the machine instead of
keeping the reference around, however only in places we cannot get a reference
to it otherwise.

I'll follow inline.

>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>   hw/i386/acpi-build.c | 35 +++++++++++++++++++++--------------
>   hw/i386/acpi-build.h |  2 +-
>   hw/i386/pc.c         |  2 +-
>   3 files changed, 23 insertions(+), 16 deletions(-)
>
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index bca3f06..92d25c9 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -295,7 +295,7 @@ static void acpi_align_size(GArray *blob, unsigned align)
>
>   /* FACS */
>   static void
> -build_facs(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
> +build_facs(GArray *table_data, GArray *linker)

this function does not need guest_info, no problem here.

>   {
>       AcpiFacsDescriptorRev1 *facs = acpi_data_push(table_data, sizeof *facs);
>       memcpy(&facs->signature, "FACS", 4);
> @@ -365,9 +365,10 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
>   }
>
>   static void
> -build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
> -           PcGuestInfo *guest_info)
> +build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
>   {
> +    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
> +    PcGuestInfo *guest_info = &pcms->acpi_guest_info;

This function can get a reference of the machine from the caller, acpi_build, which
already queries for it. I am not talking about "speed" here, simply about keeping
the code clean, which is exactly what this series does.

>       int madt_start = table_data->len;
>
>       AcpiMultipleApicTable *madt;
> @@ -928,9 +929,11 @@ static Aml *build_crs(PCIHostState *host,
>   static void
>   build_ssdt(GArray *table_data, GArray *linker,
>              AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
> -           PcPciInfo *pci, PcGuestInfo *guest_info)
> +           PcPciInfo *pci)
>   {
>       MachineState *machine = MACHINE(qdev_get_machine());
> +    PCMachineState *pcms = PC_MACHINE(machine);
> +    PcGuestInfo *guest_info = &pcms->acpi_guest_info;

Same here. If you pass the machine you don't need another query here.
I see it was here before, but we can get rid of it.

>       uint32_t nr_mem = machine->ram_slots;
>       unsigned acpi_cpus = guest_info->apic_id_limit;
>       Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
> @@ -1453,7 +1456,7 @@ acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
>   }
>
>   static void
> -build_srat(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
> +build_srat(GArray *table_data, GArray *linker)
>   {
>       AcpiSystemResourceAffinityTable *srat;
>       AcpiSratProcessorAffinity *core;
> @@ -1464,6 +1467,7 @@ build_srat(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
>       int srat_start, numa_start, slots;
>       uint64_t mem_len, mem_base, next_base;
>       PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
> +    PcGuestInfo *guest_info = &pcms->acpi_guest_info;

Same here

>       ram_addr_t hotplugabble_address_space_size =
>           object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE,
>                                   NULL);
> @@ -1683,8 +1687,10 @@ static bool acpi_has_iommu(void)
>   }
>
>   static
> -void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
> +void acpi_build(AcpiBuildTables *tables)
>   {
> +    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
> +    PcGuestInfo *guest_info = &pcms->acpi_guest_info;

Here it makes sense to query for the machine because it is called from
acpi_build_update which is a callback with no machine reference.

However the other acpi methods can use this reference. Of course
you still get rid of PcGuestInfo.


>       GArray *table_offsets;
>       unsigned facs, ssdt, dsdt, rsdt;
>       AcpiCpuInfo cpu;
> @@ -1716,7 +1722,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
>        * requirements.
>        */
>       facs = tables_blob->len;
> -    build_facs(tables_blob, tables->linker, guest_info);
> +    build_facs(tables_blob, tables->linker);
>
>       /* DSDT is pointed to by FADT */
>       dsdt = tables_blob->len;
> @@ -1733,12 +1739,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
>
>       ssdt = tables_blob->len;
>       acpi_add_table(table_offsets, tables_blob);
> -    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
> -               guest_info);
> +    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci);
>       aml_len += tables_blob->len - ssdt;
>
>       acpi_add_table(table_offsets, tables_blob);
> -    build_madt(tables_blob, tables->linker, &cpu, guest_info);
> +    build_madt(tables_blob, tables->linker, &cpu);
>
>       if (misc.has_hpet) {
>           acpi_add_table(table_offsets, tables_blob);
> @@ -1755,7 +1760,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
>       }
>       if (guest_info->numa_nodes) {
>           acpi_add_table(table_offsets, tables_blob);
> -        build_srat(tables_blob, tables->linker, guest_info);
> +        build_srat(tables_blob, tables->linker);
>       }
>       if (acpi_get_mcfg(&mcfg)) {
>           acpi_add_table(table_offsets, tables_blob);
> @@ -1855,7 +1860,7 @@ static void acpi_build_update(void *build_opaque, uint32_t offset)
>
>       acpi_build_tables_init(&tables);
>
> -    acpi_build(build_state->guest_info, &tables);
> +    acpi_build(&tables);
>
>       acpi_ram_update(build_state->table_mr, tables.table_data);
>
> @@ -1893,8 +1898,10 @@ static const VMStateDescription vmstate_acpi_build = {
>       },
>   };
>
> -void acpi_setup(PcGuestInfo *guest_info)
> +void acpi_setup(void)
>   {
> +    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
> +    PcGuestInfo *guest_info = &pcms->acpi_guest_info;

acpi_setup is called from pc_guest_info_machine_done that after one
of you previous patches (4/14) has a reference to machine.

>       AcpiBuildTables tables;
>       AcpiBuildState *build_state;
>
> @@ -1920,7 +1927,7 @@ void acpi_setup(PcGuestInfo *guest_info)
>       acpi_set_pci_info();
>
>       acpi_build_tables_init(&tables);
> -    acpi_build(build_state->guest_info, &tables);
> +    acpi_build(&tables);
>
>       /* Now expose it all to Guest */
>       build_state->table_mr = acpi_add_rom_blob(build_state, tables.table_data,
> diff --git a/hw/i386/acpi-build.h b/hw/i386/acpi-build.h
> index e57b1aa..148c0f9 100644
> --- a/hw/i386/acpi-build.h
> +++ b/hw/i386/acpi-build.h
> @@ -4,6 +4,6 @@
>
>   #include "qemu/typedefs.h"
>
> -void acpi_setup(PcGuestInfo *);
> +void acpi_setup(void);
>
>   #endif
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index aa12814..14c0116 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1179,7 +1179,7 @@ void pc_machine_done(Notifier *notifier, void *data)
>           }
>       }
>
> -    acpi_setup(&pcms->acpi_guest_info);
> +    acpi_setup();
>   }
>
>   PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
>


My point is, keeping a reference to machine when it can be queried is not preferred,
querying for a pc machine when the caller has already a reference to it is also not preferred.

All this of course IMHO.

Thanks,
Marcel

  reply	other threads:[~2015-12-15 12:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-11 18:42 [Qemu-devel] [PATCH v2 00/14] pc: Eliminate struct PcGuestInfo Eduardo Habkost
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 01/14] q35: Remove MCHPCIState.guest_info field Eduardo Habkost
2015-12-15 11:10   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 02/14] pc: Group and document related PCMachineState/PCMachineclass fields Eduardo Habkost
2015-12-15 11:14   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 03/14] pc: Move PcGuestInfo declaration to top of file Eduardo Habkost
2015-12-15 11:19   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 04/14] pc: Eliminate struct PcGuestInfoState Eduardo Habkost
2015-12-15 11:37   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 05/14] pc: Simplify pc_memory_init() signature Eduardo Habkost
2015-12-15 11:39   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 06/14] pc: Simplify xen_load_linux() signature Eduardo Habkost
2015-12-15 11:45   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 07/14] acpi: Remove guest_info parameters from functions Eduardo Habkost
2015-12-15 12:36   ` Marcel Apfelbaum [this message]
2015-12-18 18:08     ` Eduardo Habkost
2015-12-18 18:51       ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 08/14] acpi: Don't save PcGuestInfo on AcpiBuildState Eduardo Habkost
2015-12-15 13:06   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 09/14] pc: Remove compat fields from PcGuestInfo Eduardo Habkost
2015-12-15 14:03   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 10/14] pc: Remove RAM size " Eduardo Habkost
2015-12-15 14:15   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 11/14] pc: Remove PcGuestInfo.isapc_ram_fw field Eduardo Habkost
2015-12-15 14:27   ` Marcel Apfelbaum
2015-12-16 19:48     ` Eduardo Habkost
2015-12-17  9:40       ` Marcel Apfelbaum
2015-12-17 16:04         ` Eduardo Habkost
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 12/14] pc: Move PcGuestInfo.fw_cfg to PCMachineState Eduardo Habkost
2015-12-15 14:28   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 13/14] pc: Move APIC and NUMA data from PcGuestInfo " Eduardo Habkost
2015-12-15 14:33   ` Marcel Apfelbaum
2015-12-11 18:42 ` [Qemu-devel] [PATCH v2 14/14] pc: Eliminate PcGuestInfo struct Eduardo Habkost
2015-12-15 14:37   ` Marcel Apfelbaum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5670093A.1010600@redhat.com \
    --to=marcel@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=marcel.a@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).