From: Shannon Zhao <zhaoshenglong@huawei.com>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org,
pbonzini@redhat.com, ganapatrao.kulkarni@caviumnetworks.com,
christoffer.dall@linaro.org, claudio.fontana@huawei.com
Cc: wanghaibin.wang@huawei.com, hangaohuai@huawei.com,
peter.huangpeng@huawei.com, zhaoshenglong@huawei.com
Subject: [Qemu-devel] [RFC PATCH v3 3/3] hw/arm/boot: Generate memory dtb according to NUMA topology
Date: Tue, 6 Jan 2015 13:57:19 +0800 [thread overview]
Message-ID: <1420523839-11672-4-git-send-email-zhaoshenglong@huawei.com> (raw)
In-Reply-To: <1420523839-11672-1-git-send-email-zhaoshenglong@huawei.com>
Add a new function arm_generate_memory_dtb which is used to
generate memory dtb according to NUMA topology and set the
NUMA topology property of every cpu.
Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com>
---
hw/arm/boot.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 52ebd8b..a39b2b4 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -312,6 +312,82 @@ static void set_kernel_args_old(const struct arm_boot_info *info)
}
}
+/*
+ * arm_generate_memory_dtb() - generate memory dtb according to NUMA topology
+ * @fdt: the pointer to device tree
+ * @binfo: struct describing the boot environment
+ * @acells: address-cells of device tree
+ * @scells: size-cells of device tree
+ *
+ * Returns:0 success,
+ * -1 on errors.
+ *
+ */
+static int arm_generate_memory_dtb(void *fdt, const struct arm_boot_info *binfo,
+ uint32_t acells, uint32_t scells)
+{
+ CPUState *cpu;
+ int i = 0;
+
+ if (!nb_numa_nodes) {
+ qemu_fdt_add_subnode(fdt, "/memory");
+ qemu_fdt_setprop_string(fdt, "/memory", "device_type", "memory");
+ return qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg",
+ acells, binfo->loader_start,
+ scells, binfo->ram_size);
+ }
+
+ struct {
+ uint64_t mem_map[6];
+ uint64_t cpu_map[6];
+ } numa_map;
+
+ hwaddr mem_base = binfo->loader_start;
+
+ for (i = 0; i < nb_numa_nodes; i++) {
+ /* Generate mem_map */
+ char *nodename;
+ nodename = g_strdup_printf("/memory@%" PRIx64, mem_base);
+ qemu_fdt_add_subnode(fdt, nodename);
+ qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
+ qemu_fdt_setprop_sized_cells(fdt, nodename, "reg",
+ acells, mem_base,
+ scells, numa_info[i].node_mem - 1);
+ numa_map.mem_map[0] = 0x1;
+ numa_map.mem_map[1] = i;
+ numa_map.mem_map[2] = 0x1;
+ numa_map.mem_map[3] = 0x0;
+ numa_map.mem_map[4] = 0x1;
+ numa_map.mem_map[5] = 0xffff;
+
+ qemu_fdt_setprop_sized_cells_from_array(fdt, nodename,
+ "arm,associativity", 3, numa_map.mem_map);
+
+ mem_base += numa_info[i].node_mem;
+ g_free(nodename);
+
+ /* Generate cpu_map */
+ CPU_FOREACH(cpu) {
+ if (test_bit(cpu->cpu_index, numa_info[i].node_cpu)) {
+ numa_map.cpu_map[0] = 0x1;
+ numa_map.cpu_map[1] = i;
+ numa_map.cpu_map[2] = 0x1;
+ numa_map.cpu_map[3] = 0x0;
+ numa_map.cpu_map[4] = 0x1;
+ numa_map.cpu_map[5] = cpu->cpu_index;
+ nodename = g_strdup_printf("/cpus/cpu@%d", cpu->cpu_index);
+ qemu_fdt_setprop_sized_cells_from_array(fdt, nodename,
+ "arm,associativity", 3, numa_map.cpu_map);
+ g_free(nodename);
+ }
+ }
+ }
+ qemu_fdt_setprop_sized_cells(fdt, "/",
+ "arm,associativity-reference-points", 1, 0, 1, 1);
+
+ return 0;
+}
+
/**
* load_dtb() - load a device tree binary image into memory
* @addr: the address to load the image at
@@ -387,9 +463,7 @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
goto fail;
}
- rc = qemu_fdt_setprop_sized_cells(fdt, "/memory", "reg",
- acells, binfo->loader_start,
- scells, binfo->ram_size);
+ rc = arm_generate_memory_dtb(fdt, binfo, acells, scells);
if (rc < 0) {
fprintf(stderr, "couldn't set /memory/reg\n");
goto fail;
--
1.7.1
next prev parent reply other threads:[~2015-01-06 6:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-06 5:57 [Qemu-devel] [RFC PATCH v3 0/3] Add support for NUMA on ARM64 Shannon Zhao
2015-01-06 5:57 ` [Qemu-devel] [RFC PATCH v3 1/3] hw/arm/virt: Use memory_region_allocate_system_memory to allocate memory Shannon Zhao
2015-01-06 5:57 ` [Qemu-devel] [RFC PATCH v3 2/3] hw/arm/virt: Don't add memory node in creat_fdt Shannon Zhao
2015-01-06 9:55 ` Peter Maydell
2015-01-06 10:05 ` Shannon Zhao
2015-01-06 5:57 ` Shannon Zhao [this message]
2015-01-06 9:58 ` [Qemu-devel] [RFC PATCH v3 3/3] hw/arm/boot: Generate memory dtb according to NUMA topology Peter Maydell
2015-01-06 10:09 ` Shannon Zhao
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=1420523839-11672-4-git-send-email-zhaoshenglong@huawei.com \
--to=zhaoshenglong@huawei.com \
--cc=christoffer.dall@linaro.org \
--cc=claudio.fontana@huawei.com \
--cc=ganapatrao.kulkarni@caviumnetworks.com \
--cc=hangaohuai@huawei.com \
--cc=pbonzini@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=wanghaibin.wang@huawei.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).