]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/ppc/spapr_numa.c
2 * QEMU PowerPC pSeries Logical Partition NUMA associativity handling
4 * Copyright IBM Corp. 2020
7 * Daniel Henrique Barboza <danielhb413@gmail.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qemu-common.h"
15 #include "hw/ppc/spapr_numa.h"
16 #include "hw/ppc/fdt.h"
19 void spapr_numa_associativity_init(SpaprMachineState
*spapr
,
20 MachineState
*machine
)
22 int nb_numa_nodes
= machine
->numa_state
->num_nodes
;
26 * For all associativity arrays: first position is the size,
27 * position MAX_DISTANCE_REF_POINTS is always the numa_id,
28 * represented by the index 'i'.
30 * This will break on sparse NUMA setups, when/if QEMU starts
31 * to support it, because there will be no more guarantee that
32 * 'i' will be a valid node_id set by the user.
34 for (i
= 0; i
< nb_numa_nodes
; i
++) {
35 spapr
->numa_assoc_array
[i
][0] = cpu_to_be32(MAX_DISTANCE_REF_POINTS
);
36 spapr
->numa_assoc_array
[i
][MAX_DISTANCE_REF_POINTS
] = cpu_to_be32(i
);
40 void spapr_numa_write_associativity_dt(SpaprMachineState
*spapr
, void *fdt
,
41 int offset
, int nodeid
)
43 _FDT((fdt_setprop(fdt
, offset
, "ibm,associativity",
44 spapr
->numa_assoc_array
[nodeid
],
45 sizeof(spapr
->numa_assoc_array
[nodeid
]))));
48 int spapr_numa_fixup_cpu_dt(SpaprMachineState
*spapr
, void *fdt
,
49 int offset
, PowerPCCPU
*cpu
)
51 int vcpu_assoc_size
= NUMA_ASSOC_SIZE
+ 1;
52 uint32_t vcpu_assoc
[vcpu_assoc_size
];
53 int index
= spapr_get_vcpu_id(cpu
);
57 * VCPUs have an extra 'cpu_id' value in ibm,associativity
58 * compared to other resources. Increment the size at index
59 * 0, copy all associativity domains already set, then put
62 vcpu_assoc
[0] = cpu_to_be32(MAX_DISTANCE_REF_POINTS
+ 1);
64 for (i
= 1; i
<= MAX_DISTANCE_REF_POINTS
; i
++) {
65 vcpu_assoc
[i
] = spapr
->numa_assoc_array
[cpu
->node_id
][i
];
68 vcpu_assoc
[vcpu_assoc_size
- 1] = cpu_to_be32(index
);
70 /* Advertise NUMA via ibm,associativity */
71 return fdt_setprop(fdt
, offset
, "ibm,associativity",
72 vcpu_assoc
, sizeof(vcpu_assoc
));
76 int spapr_numa_write_assoc_lookup_arrays(SpaprMachineState
*spapr
, void *fdt
,
79 MachineState
*machine
= MACHINE(spapr
);
80 int nb_numa_nodes
= machine
->numa_state
->num_nodes
;
81 int nr_nodes
= nb_numa_nodes
? nb_numa_nodes
: 1;
82 uint32_t *int_buf
, *cur_index
, buf_len
;
85 /* ibm,associativity-lookup-arrays */
86 buf_len
= (nr_nodes
* MAX_DISTANCE_REF_POINTS
+ 2) * sizeof(uint32_t);
87 cur_index
= int_buf
= g_malloc0(buf_len
);
88 int_buf
[0] = cpu_to_be32(nr_nodes
);
89 /* Number of entries per associativity list */
90 int_buf
[1] = cpu_to_be32(MAX_DISTANCE_REF_POINTS
);
92 for (i
= 0; i
< nr_nodes
; i
++) {
94 * For the lookup-array we use the ibm,associativity array,
95 * from numa_assoc_array. without the first element (size).
97 uint32_t *associativity
= spapr
->numa_assoc_array
[i
];
98 memcpy(cur_index
, ++associativity
,
99 sizeof(uint32_t) * MAX_DISTANCE_REF_POINTS
);
100 cur_index
+= MAX_DISTANCE_REF_POINTS
;
102 ret
= fdt_setprop(fdt
, offset
, "ibm,associativity-lookup-arrays", int_buf
,
103 (cur_index
- int_buf
) * sizeof(uint32_t));
110 * Helper that writes ibm,associativity-reference-points and
111 * max-associativity-domains in the RTAS pointed by @rtas
114 void spapr_numa_write_rtas_dt(SpaprMachineState
*spapr
, void *fdt
, int rtas
)
116 SpaprMachineClass
*smc
= SPAPR_MACHINE_GET_CLASS(spapr
);
117 uint32_t refpoints
[] = {
122 uint32_t nr_refpoints
= ARRAY_SIZE(refpoints
);
123 uint32_t maxdomain
= cpu_to_be32(spapr
->gpu_numa_id
> 1 ? 1 : 0);
124 uint32_t maxdomains
[] = {
129 cpu_to_be32(spapr
->gpu_numa_id
),
132 if (smc
->pre_5_1_assoc_refpoints
) {
136 _FDT(fdt_setprop(fdt
, rtas
, "ibm,associativity-reference-points",
137 refpoints
, nr_refpoints
* sizeof(refpoints
[0])));
139 _FDT(fdt_setprop(fdt
, rtas
, "ibm,max-associativity-domains",
140 maxdomains
, sizeof(maxdomains
)));