qemu-patch-raspberry4/hw/core
Laurent Vivier 3bfe57165b numa: equally distribute memory on nodes
When there are more nodes than available memory to put the minimum
allowed memory by node, all the memory is put on the last node.

This is because we put (ram_size / nb_numa_nodes) &
~((1 << mc->numa_mem_align_shift) - 1); on each node, and in this
case the value is 0. This is particularly true with pseries,
as the memory must be aligned to 256MB.

To avoid this problem, this patch uses an error diffusion algorithm [1]
to distribute equally the memory on nodes.

We introduce numa_auto_assign_ram() function in MachineClass
to keep compatibility between machine type versions.
The legacy function is used with pseries-2.9, pc-q35-2.9 and
pc-i440fx-2.9 (and previous), the new one with all others.

Example:

qemu-system-ppc64 -S -nographic  -nodefaults -monitor stdio -m 1G -smp 8 \
                  -numa node -numa node -numa node \
                  -numa node -numa node -numa node

Before:

(qemu) info numa
6 nodes
node 0 cpus: 0 6
node 0 size: 0 MB
node 1 cpus: 1 7
node 1 size: 0 MB
node 2 cpus: 2
node 2 size: 0 MB
node 3 cpus: 3
node 3 size: 0 MB
node 4 cpus: 4
node 4 size: 0 MB
node 5 cpus: 5
node 5 size: 1024 MB

After:
(qemu) info numa
6 nodes
node 0 cpus: 0 6
node 0 size: 0 MB
node 1 cpus: 1 7
node 1 size: 256 MB
node 2 cpus: 2
node 2 size: 0 MB
node 3 cpus: 3
node 3 size: 256 MB
node 4 cpus: 4
node 4 size: 256 MB
node 5 cpus: 5
node 5 size: 256 MB

[1] https://en.wikipedia.org/wiki/Error_diffusion

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20170502162955.1610-2-lvivier@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
[ehabkost: s/ram_size/size/ at numa_default_auto_assign_ram()]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2017-05-11 16:08:47 -03:00
..
bus.c bus: do not unref hotplug handler 2017-03-01 11:51:28 +04:00
empty_slot.c hw/core: Clean up includes 2016-01-29 15:07:25 +00:00
fw-path-provider.c hw/core: Clean up includes 2016-01-29 15:07:25 +00:00
generic-loader.c hw: Fix typos found by codespell 2017-01-24 23:26:52 +03:00
hotplug.c qdev: hotplug: drop HotplugHandler.post_plug callback 2016-11-15 17:20:37 +02:00
irq.c tcg: drop global lock during TCG code execution 2017-02-24 10:32:45 +00:00
loader-fit.c loader: Support Flattened Image Trees (FIT images) 2017-02-21 23:47:40 +00:00
loader.c elf-loader: Allow late loading of elf 2017-02-28 12:04:48 +01:00
machine.c numa: equally distribute memory on nodes 2017-05-11 16:08:47 -03:00
Makefile.objs loader: Support Flattened Image Trees (FIT images) 2017-02-21 23:47:40 +00:00
nmi.c nmi: remove x86 specific nmi handling 2016-05-23 16:53:46 +02:00
null-machine.c hw/core/null-machine: Print error message when using the -kernel parameter 2017-04-20 15:22:41 -03:00
or-irq.c hw/core/or-irq: Mark the device with cannot_instantiate_with_device_add_yet 2017-02-28 09:03:38 +03:00
platform-bus.c sysbus: Remove ignored return value of FindSysbusDeviceFunc 2016-09-27 17:03:34 -03:00
ptimer.c qemu-timer: do not include sysemu/cpus.h from util/qemu-timer.h 2017-03-14 13:28:18 +01:00
qdev-properties-system.c qdev: Constify local variable returned by blk_bs 2017-04-20 15:22:41 -03:00
qdev-properties.c qdev: Constify value passed to qdev_prop_set_macaddr 2017-04-20 15:22:41 -03:00
qdev.c migration/next for 20170421 2017-04-21 15:59:27 +01:00
register.c register: fix incorrect read mask 2017-02-28 09:03:38 +03:00
reset.c hw: move reset handlers from vl.c to hw/core 2017-01-16 17:52:35 +01:00
stream.c hw/core: Clean up includes 2016-01-29 15:07:25 +00:00
sysbus.c hw: remove pio_addr_t 2016-05-19 16:42:30 +02:00
uboot_image.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00