kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wen Congyang <wency@cn.fujitsu.com>
To: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, seabios@seabios.org,
	avi@redhat.com, anthony@codemonkey.ws, kevin@koconnor.net,
	kraxel@redhat.com, eblake@redhat.com, blauwirbel@gmail.com,
	gleb@redhat.com, imammedo@redhat.com
Subject: Re: [RFC PATCH v3 19/19][SeaBIOS] Calculate pcimem_start and pcimem64_start from SRAT entries
Date: Mon, 24 Sep 2012 14:51:00 +0800	[thread overview]
Message-ID: <506002D4.4050604@cn.fujitsu.com> (raw)
In-Reply-To: <1348226255-4226-20-git-send-email-vasilis.liaskovitis@profitbricks.com>

At 09/21/2012 07:17 PM, Vasilis Liaskovitis Wrote:
> pcimem_start and pcimem64_start are adjusted from srat entries. For this reason,
> paravirt info (NUMA SRAT entries and number of cpus) need to be read before pci_setup.
> Imho, this is an ugly code change since SRAT bios tables and number of
> cpus have to be read earlier. But the advantage is that no new paravirt interface
> is introduced. Suggestions to make the code change cleaner are welcome.
> 
> The alternative patch (will be sent as a reply to this patch) implements a
> paravirt interface to read the starting values of pcimem_start and
> pcimem64_start from QEMU.
> 
> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> ---
>  src/acpi.c    |   82 ++++++++++++++++++++++++++++++++++++++++----------------
>  src/acpi.h    |    3 ++
>  src/pciinit.c |    6 +++-
>  src/post.c    |    3 ++
>  src/smp.c     |    4 +++
>  5 files changed, 72 insertions(+), 26 deletions(-)
> 
> diff --git a/src/acpi.c b/src/acpi.c
> index 1223b52..9e99aa7 100644
> --- a/src/acpi.c
> +++ b/src/acpi.c
> @@ -428,7 +428,10 @@ encodeLen(u8 *ssdt_ptr, int length, int bytes)
>  #define MEM_OFFSET_END   63
>  #define MEM_OFFSET_SIZE  79
>  
> -u64 nb_hp_memslots = 0;
> +u64 nb_hp_memslots = 0, nb_numanodes;
> +u64 *numa_data, *hp_memdata;
> +u64 below_4g_hp_mem_size = 0;
> +u64 above_4g_hp_mem_size = 0;
>  struct srat_memory_affinity *mem;
>  
>  #define SSDT_SIGNATURE 0x54445353 // SSDT
> @@ -763,17 +766,7 @@ acpi_build_srat_memory(struct srat_memory_affinity *numamem,
>  static void *
>  build_srat(void)
>  {
> -    int nb_numa_nodes = qemu_cfg_get_numa_nodes();
> -
> -    u64 *numadata = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numa_nodes));
> -    if (!numadata) {
> -        warn_noalloc();
> -        return NULL;
> -    }
> -
> -    qemu_cfg_get_numa_data(numadata, MaxCountCPUs + nb_numa_nodes);
> -
> -    qemu_cfg_get_numa_data(&nb_hp_memslots, 1);
> +    int nb_numa_nodes = nb_numanodes;
>      struct system_resource_affinity_table *srat;
>      int srat_size = sizeof(*srat) +
>          sizeof(struct srat_processor_affinity) * MaxCountCPUs +
> @@ -782,7 +775,7 @@ build_srat(void)
>      srat = malloc_high(srat_size);
>      if (!srat) {
>          warn_noalloc();
> -        free(numadata);
> +        free(numa_data);
>          return NULL;
>      }
>  
> @@ -791,6 +784,7 @@ build_srat(void)
>      struct srat_processor_affinity *core = (void*)(srat + 1);
>      int i;
>      u64 curnode;
> +    u64 *numadata = numa_data;
>  
>      for (i = 0; i < MaxCountCPUs; ++i) {
>          core->type = SRAT_PROCESSOR;
> @@ -847,15 +841,7 @@ build_srat(void)
>      mem = (void*)numamem;
>  
>      if (nb_hp_memslots) {
> -        u64 *hpmemdata = malloc_tmphigh(sizeof(u64) * (3 * nb_hp_memslots));
> -        if (!hpmemdata) {
> -            warn_noalloc();
> -            free(hpmemdata);
> -            free(numadata);
> -            return NULL;
> -        }
> -
> -        qemu_cfg_get_numa_data(hpmemdata, 3 * nb_hp_memslots);
> +        u64 *hpmemdata = hp_memdata;
>  
>          for (i = 1; i < nb_hp_memslots + 1; ++i) {
>              mem_base = *hpmemdata++;
> @@ -865,7 +851,7 @@ build_srat(void)
>              numamem++;
>              slots++;
>          }
> -        free(hpmemdata);
> +        free(hp_memdata);
>      }
>  
>      for (; slots < nb_numa_nodes + nb_hp_memslots + 2; slots++) {
> @@ -875,10 +861,58 @@ build_srat(void)
>  
>      build_header((void*)srat, SRAT_SIGNATURE, srat_size, 1);
>  
> -    free(numadata);
> +    free(numa_data);
>      return srat;
>  }
>  
> +/* QEMU paravirt SRAT entries need to be read in before pci initilization */
> +void read_srat_early(void)
> +{
> +    int i;
> +
> +    nb_numanodes = qemu_cfg_get_numa_nodes();
> +    u64 *hpmemdata;
> +    u64 mem_len, mem_base;
> +
> +    numa_data = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numanodes));
> +    if (!numa_data) {
> +        warn_noalloc();
> +    }
> +
> +    qemu_cfg_get_numa_data(numa_data, MaxCountCPUs + nb_numanodes);
> +    qemu_cfg_get_numa_data(&nb_hp_memslots, 1);
> +
> +    if (nb_hp_memslots) {
> +        hp_memdata = malloc_tmphigh(sizeof(u64) * (3 * nb_hp_memslots));
> +        if (!hp_memdata) {
> +            warn_noalloc();
> +            free(hp_memdata);
> +            free(numa_data);
> +        }
> +
> +        qemu_cfg_get_numa_data(hp_memdata, 3 * nb_hp_memslots);
> +        hpmemdata = hp_memdata;
> +
> +        for (i = 1; i < nb_hp_memslots + 1; ++i) {
> +            mem_base = *hpmemdata++;
> +            mem_len = *hpmemdata++;
> +            hpmemdata++;
> +            if (mem_base >= 0x100000000LL) {
> +                above_4g_hp_mem_size += mem_len;
> +            }
> +            /* if dimm fits before pci hole, append it normally */
> +            else if (mem_base + mem_len <= BUILD_PCIMEM_START) {
> +                below_4g_hp_mem_size += mem_len;
> +            }
> +            /* otherwise place it above 4GB */
> +            else {
> +                above_4g_hp_mem_size += mem_len;
> +            }
> +        }
> +
> +    }
> +}
> +
>  static const struct pci_device_id acpi_find_tbl[] = {
>      /* PIIX4 Power Management device. */
>      PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL),
> diff --git a/src/acpi.h b/src/acpi.h
> index cb21561..d29837f 100644
> --- a/src/acpi.h
> +++ b/src/acpi.h
> @@ -5,6 +5,9 @@
>  
>  void acpi_bios_init(void);
>  u32 find_resume_vector(void);
> +void read_srat_early(void);
> +extern u64 below_4g_hp_mem_size;
> +extern u64 above_4g_hp_mem_size;
>  
>  #define RSDP_SIGNATURE 0x2052545020445352LL // "RSD PTR "
>  
> diff --git a/src/pciinit.c b/src/pciinit.c
> index 31115ee..c5a4b24 100644
> --- a/src/pciinit.c
> +++ b/src/pciinit.c
> @@ -12,6 +12,7 @@
>  #include "ioport.h" // PORT_ATA1_CMD_BASE
>  #include "config.h" // CONFIG_*
>  #include "xen.h" // usingXen
> +#include "acpi.h"
>  
>  #define PCI_DEVICE_MEM_MIN     0x1000
>  #define PCI_BRIDGE_IO_MIN      0x1000
> @@ -597,7 +598,7 @@ static void pci_region_map_entries(struct pci_bus *busses, struct pci_region *r)
>  
>  static void pci_bios_map_devices(struct pci_bus *busses)
>  {
> -    pcimem_start = RamSize;
> +    pcimem_start = RamSize + below_4g_hp_mem_size;
>  
>      if (pci_bios_init_root_regions(busses)) {
>          struct pci_region r64_mem, r64_pref;
> @@ -616,7 +617,8 @@ static void pci_bios_map_devices(struct pci_bus *busses)
>          u64 align_mem = pci_region_align(&r64_mem);
>          u64 align_pref = pci_region_align(&r64_pref);
>  
> -        r64_mem.base = ALIGN(0x100000000LL + RamSizeOver4G, align_mem);
> +        r64_mem.base = ALIGN(0x100000000LL + RamSizeOver4G +
> +                above_4g_hp_mem_size, align_mem);
>          r64_pref.base = ALIGN(r64_mem.base + sum_mem, align_pref);
>          pcimem64_start = r64_mem.base;
>          pcimem64_end = r64_pref.base + sum_pref;
> diff --git a/src/post.c b/src/post.c
> index 924b311..c37730b 100644
> --- a/src/post.c
> +++ b/src/post.c
> @@ -234,6 +234,9 @@ maininit(void)
>      // Initialize mtrr
>      mtrr_setup();
>  
> +    smp_get_ncpus();
> +    read_srat_early();
> +
>      // Initialize pci
>      pci_setup();
>      smm_init();
> diff --git a/src/smp.c b/src/smp.c
> index 4975412..3922776 100644
> --- a/src/smp.c
> +++ b/src/smp.c
> @@ -138,7 +138,11 @@ smp_probe(void)
>  
>      // Restore memory.
>      *(u64*)BUILD_AP_BOOT_ADDR = old;
> +}
>  
> +void
> +smp_get_ncpus(void)

You don't declare this function, and use it in another file. It will break
building:
src/post.c: In function ‘maininit’:
src/post.c:237: warning: implicit declaration of function ‘smp_get_ncpus’
src/smp.c:144: note: previous definition of ‘smp_get_ncpus’ was here
src/post.c:237: error: incompatible implicit declaration of function ‘smp_get_ncpus’
src/smp.c:144: note: previous definition of ‘smp_get_ncpus’ was here

Thanks
Wen Congyang

> +{
>      MaxCountCPUs = qemu_cfg_get_max_cpus();
>      if (!MaxCountCPUs || MaxCountCPUs < CountCPUs)
>          MaxCountCPUs = CountCPUs;


  parent reply	other threads:[~2012-09-24  6:45 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 11:17 [RFC PATCH v3 00/19] ACPI memory hotplug Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 01/19][SeaBIOS] Add ACPI_EXTRACT_DEVICE* macros Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 02/19][SeaBIOS] Add SSDT memory device support Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 03/19][SeaBIOS] acpi-dsdt: Implement functions for memory hotplug Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 04/19][SeaBIOS] acpi: generate hotplug memory devices Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 05/19] Implement dimm device abstraction Vasilis Liaskovitis
2012-09-24  6:02   ` Wen Congyang
2012-10-23 12:25   ` [Qemu-devel] " Stefan Hajnoczi
2012-10-24  8:06     ` liu ping fan
2012-10-24 10:15       ` Stefan Hajnoczi
2012-10-24 17:16         ` Vasilis Liaskovitis
2012-10-25  8:00           ` liu ping fan
2012-10-31 11:15       ` Avi Kivity
2012-10-31 12:18         ` [Qemu-devel] " Stefan Hajnoczi
2012-10-31 12:34           ` Avi Kivity
2012-10-31 12:34             ` [Qemu-devel] " Stefan Hajnoczi
2012-09-21 11:17 ` [RFC PATCH v3 06/19] Implement "-dimm" command line option Vasilis Liaskovitis
2012-09-22 13:46   ` Blue Swirl
2012-09-24 10:42     ` Vasilis Liaskovitis
2012-09-29 11:13       ` Blue Swirl
2012-10-09 17:04         ` Vasilis Liaskovitis
2012-10-13  8:57           ` Blue Swirl
2012-10-17  9:19             ` Vasilis Liaskovitis
2012-10-17 10:03               ` Avi Kivity
2012-10-18  9:27                 ` Vasilis Liaskovitis
2012-10-18 12:33                   ` Avi Kivity
2012-10-19 17:48                     ` Blue Swirl
2012-10-22 10:55                       ` Avi Kivity
2012-10-22  8:39                     ` Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 07/19] acpi_piix4: Implement memory device hotplug registers Vasilis Liaskovitis
2012-09-22 13:49   ` Blue Swirl
2012-09-21 11:17 ` [RFC PATCH v3 08/19] pc: calculate dimm physical addresses and adjust memory map Vasilis Liaskovitis
2012-09-22 14:15   ` Blue Swirl
2012-09-24 15:27     ` Vasilis Liaskovitis
2012-09-29 11:27       ` Blue Swirl
2012-09-21 11:17 ` [RFC PATCH v3 09/19] pc: Add dimm paravirt SRAT info Vasilis Liaskovitis
2012-09-27  3:55   ` Wen Congyang
2012-09-21 11:17 ` [RFC PATCH v3 10/19] fix live-migration when "populated=on" is missing Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 11/19] Implement qmp and hmp commands for notification lists Vasilis Liaskovitis
2012-09-21 22:03   ` Eric Blake
2012-09-24 14:45     ` Vasilis Liaskovitis
2012-10-23 12:15   ` Stefan Hajnoczi
2012-09-21 11:17 ` [RFC PATCH v3 12/19] Implement "info memory-total" and "query-memory-total" Vasilis Liaskovitis
2012-09-21 22:36   ` Eric Blake
2012-09-21 11:17 ` [RFC PATCH v3 13/19] balloon: update with hotplugged memory Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 14/19][SeaBIOS] Add _OST dimm method Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 15/19] Add _OST dimm support Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 16/19] Update dimm state on reset Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 17/19][SeaBIOS] Implement _PS3 method for memory device Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 18/19] Implement _PS3 for dimm Vasilis Liaskovitis
2012-09-21 11:17 ` [RFC PATCH v3 19/19][SeaBIOS] Calculate pcimem_start and pcimem64_start from SRAT entries Vasilis Liaskovitis
2012-09-21 11:19   ` [RFC PATCH v3 19/19] alternative: Introduce paravirt interface QEMU_CFG_PCI_WINDOW Vasilis Liaskovitis
2012-09-21 11:20   ` [RFC PATCH v3 20/19][SeaBIOS] alternative: Use paravirt interface for pci windows Vasilis Liaskovitis
2012-09-24  6:35     ` Wen Congyang
2012-09-24 10:46       ` Vasilis Liaskovitis
2012-09-24  6:51   ` Wen Congyang [this message]
2012-09-22 14:17 ` [RFC PATCH v3 00/19] ACPI memory hotplug Blue Swirl
2012-10-31 10:58 ` Stefan Hajnoczi
2012-10-31 11:16   ` Avi Kivity
2012-11-01  9:01     ` Vasilis Liaskovitis

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=506002D4.4050604@cn.fujitsu.com \
    --to=wency@cn.fujitsu.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=eblake@redhat.com \
    --cc=gleb@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.org \
    --cc=vasilis.liaskovitis@profitbricks.com \
    /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).