diff mbox

[v4,1/5] ARM: Virt: Add /distance-map node for NUMA

Message ID 1453549006-16044-2-git-send-email-zhaoshenglong@huawei.com
State Superseded
Headers show

Commit Message

Shannon Zhao Jan. 23, 2016, 11:36 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>


This /distance-map node is used to describe the accessing distance
between NUMA nodes.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>

---
 hw/arm/virt.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

-- 
2.0.4
diff mbox

Patch

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 15658f4..c725e29 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -39,6 +39,7 @@ 
 #include "sysemu/device_tree.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
+#include "sysemu/numa.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "exec/address-spaces.h"
@@ -183,6 +184,9 @@  static VirtBoardInfo *find_machine_info(const char *cpu)
 
 static void create_fdt(VirtBoardInfo *vbi)
 {
+    unsigned int i, j, number, count;
+    uint64_t *matrix;
+
     void *fdt = create_device_tree(&vbi->fdt_size);
 
     if (!fdt) {
@@ -219,6 +223,32 @@  static void create_fdt(VirtBoardInfo *vbi)
                                 "clk24mhz");
     qemu_fdt_setprop_cell(fdt, "/apb-pclk", "phandle", vbi->clock_phandle);
 
+    if (nb_numa_nodes <= 0) {
+        return;
+    }
+
+    /* Add /distance-map node for NUMA */
+    qemu_fdt_add_subnode(fdt, "/distance-map");
+    qemu_fdt_setprop_string(fdt, "/distance-map", "compatible",
+                            "numa,distance-map-v1");
+
+    number = nb_numa_nodes * nb_numa_nodes * 6;
+    matrix = g_malloc0(number * sizeof(uint64_t));
+    for (i = 0; i < nb_numa_nodes; i++) {
+        for (j = 0; j < nb_numa_nodes; j++) {
+            count = (i * nb_numa_nodes + j) * 6;
+            matrix[count++] = 1;
+            matrix[count++] = i;
+            matrix[count++] = 1;
+            matrix[count++] = j;
+            matrix[count++] = 1;
+            matrix[count++] = (i == j) ? 10 : 20;
+        }
+    }
+    qemu_fdt_setprop_sized_cells_from_array(fdt, "/distance-map",
+                                            "distance-matrix", number / 2,
+                                            matrix);
+    g_free(matrix);
 }
 
 static void fdt_add_psci_node(const VirtBoardInfo *vbi)