x86/numa: Adjust datatypes for node and pxm
PATCH 1/1 x86/numa: Adjust datatypes for node and pxm
Use u8-sized node IDs and unsigned PXMs consistently throughout code (and introduce nodeid_t type).
--- xen/arch/x86/irq.c | 4 +- xen/arch/x86/numa.c | 15 ++++---- xen/arch/x86/setup.c | 2 +- xen/arch/x86/smpboot.c | 5 ++- xen/arch/x86/srat.c | 63 +++++++++++++++++++++------------- xen/arch/x86/x86_64/mm.c | 5 ++- xen/common/page_alloc.c | 5 ++- xen/drivers/passthrough/vtd/iommu.c | 5 ++- xen/include/asm-arm/numa.h | 4 ++- xen/include/asm-x86/irq.h | 3 +- xen/include/asm-x86/numa.h | 24 +++++++------ 11 files changed, 80 insertions(+), 55 deletions(-)
This was originally part of device topology series but I think it's really a standalone patch so I am sending it separately.
The main difference from earlier version is introduction of nodeid_t datatype and changes throughout code that replaced u8/char/uchar/int/unsigned declaration of node IDs with this type.
xen/arch/x86/irq.c +2 -2
@@ -153,7 +153,7 @@ int __init bind_irq_vector(int irq, int vector, const cpumask_t *cpu_mask)/* * Dynamic irq allocate and deallocation for MSI */ -int create_irq (int node) +int create_irq (nodeid_t node) {int irq, ret;struct irq_desc *desc;
@@ -173,7 +173,7 @@ int create_irq(int node) {cpumask_t *mask =NULL ; -if (node !=NUMA_NO_NODE && node >=0 ) +if ( node !=NUMA_NO_NODE ) { mask = &node_to_cpumask (node);if (cpumask_empty (mask))
xen/arch/x86/numa.c +8 -7
@@ -35,13 +35,13 @@ static typeof(*memnodemap) _memnodemap[64];unsigned long memnodemapsize;u8 *memnodemap; -unsigned char cpu_to_node[NR_CPUS ]__read_mostly = { +nodeid_t cpu_to_node[NR_CPUS ]__read_mostly = { [0 ...NR_CPUS -1 ] =NUMA_NO_NODE };/* * Keep BIOS's CPU2node information, should not be used for memory allocaion */ -unsigned char apicid_to_node[MAX_LOCAL_APIC ]__cpuinitdata = { +nodeid_t apicid_to_node[MAX_LOCAL_APIC ]__cpuinitdata = { [0 ...MAX_LOCAL_APIC -1 ] =NUMA_NO_NODE };cpumask_t node_to_cpumask[MAX_NUMNODES ]__read_mostly ;
@@ -65,7 +65,7 @@ int srat_disabled(void)* -1 if node overlap or lost ram (shift too big) */ static int __init populate_memnodemap (const struct node *nodes, -int numnodes,int shift,int *nodeids) +int numnodes,int shift,nodeid_t *nodeids) {unsigned long spdx, epdx;int i, res =-1 ;
@@ -150,7 +150,7 @@ static int __init extract_lsb_from_nodes(const struct node *nodes, }int __init compute_hash_shift (struct node *nodes,int numnodes, -int *nodeids) +nodeid_t *nodeids) {int shift;
@@ -172,7 +172,7 @@ int __init compute_hash_shift(struct node *nodes, int numnodes,return shift; }/* initialize NODE_DATA given nodeid and start/end */ -void __init setup_node_bootmem (int nodeid,u64 start,u64 end) +void __init setup_node_bootmem (nodeid_t nodeid,u64 start,u64 end) {unsigned long start_pfn, end_pfn;
@@ -294,7 +294,7 @@ __cpuinit void numa_add_cpu(int cpu)cpumask_set_cpu (cpu, &node_to_cpumask[cpu_to_node (cpu)]); } -void __cpuinit numa_set_node (int cpu,int node) +void __cpuinit numa_set_node (int cpu,nodeid_t node) { cpu_to_node[cpu] = node; }
@@ -340,7 +340,8 @@ static __init int numa_setup(char *opt)*/ void __init init_cpu_to_node (void ) { -int i, node; +unsigned i; +nodeid_t node;for ( i =0 ; i < nr_cpu_ids; i++ ) {
xen/arch/x86/setup.c +1 -1
@@ -188,7 +188,7 @@ static void __init init_idle_domain(void)void __devinit srat_detect_node (int cpu) { -unsigned node; +nodeid_t node;u32 apicid = x86_cpu_to_apicid[cpu]; node = apicid_to_node[apicid];
xen/arch/x86/smpboot.c +3 -2
@@ -843,7 +843,8 @@ void __cpu_die(unsigned int cpu)int cpu_add (uint32_t apic_id,uint32_t acpi_id,uint32_t pxm) { -int node, cpu =-1 ; +nodeid_t node; +int cpu =-1 ;dprintk (XENLOG_DEBUG ,"cpu_add apic_id %x acpi_id %x pxm %x\n" , apic_id, acpi_id, pxm);
@@ -877,7 +878,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm)if ( !srat_disabled () ) { -if ( (node =setup_node (pxm)) <0 ) +if ( (node =setup_node (pxm)) ==NUMA_NO_NODE ) {dprintk (XENLOG_WARNING ,"Setup node failed for pxm %x\n" , pxm);
xen/arch/x86/srat.c +39 -24
144 lines not on this page · raw message
xen/arch/x86/x86_64/mm.c +3 -2
@@ -1343,7 +1343,8 @@ int mem_hotadd_check(unsigned long spfn, unsigned long epfn)int memory_add (unsigned long spfn,unsigned long epfn,unsigned int pxm) {struct mem_hotadd_info info; -int ret, node; +int ret; +nodeid_t node;unsigned long old_max = max_page, old_total = total_pages;unsigned long old_node_start, old_node_span, orig_online;unsigned long i;
@@ -1353,7 +1354,7 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)if ( !mem_hotadd_check (spfn, epfn) )return -EINVAL ; -if ( (node =setup_node (pxm)) ==-1 ) +if ( (node =setup_node (pxm)) ==NUMA_NO_NODE )return -EINVAL ;if ( !valid_numa_range (spfn <<PAGE_SHIFT , epfn <<PAGE_SHIFT , node) )
xen/common/page_alloc.c +3 -2
@@ -581,7 +581,7 @@ static struct page_info *alloc_heap_pages( struct domain *d) {unsigned int first_node, i, j, zone =0 , nodemask_retry =0 ; -unsigned int node = (uint8_t )((memflags >> _MEMF_node) -1 ); +nodeid_t node = (nodeid_t)((memflags >> _MEMF_node) -1 );unsigned long request =1UL << order;struct page_info *pg;nodemask_t nodemask = (d !=NULL ) ? d->node_affinity : node_online_map;
@@ -1278,7 +1278,8 @@ static void __init smp_scrub_heap_pages(void *data)unsigned long mfn, start, end;struct page_info *pg;struct scrub_region *r; -unsigned int temp_cpu, node, cpu_idx =0 ; +unsigned int temp_cpu, cpu_idx =0 ; +nodeid_t node;unsigned int cpu =smp_processor_id ();if ( data )
xen/drivers/passthrough/vtd/iommu.c +3 -2
@@ -190,14 +190,15 @@ u64 alloc_pgtable_maddr(struct acpi_drhd_unit *drhd, unsigned long npages)struct acpi_rhsa_unit *rhsa;struct page_info *pg, *cur_pg;u64 *vaddr; -int node =-1 , i; +nodeid_t node =NUMA_NO_NODE ; +unsigned i; rhsa =drhd_to_rhsa (drhd);if ( rhsa ) node =pxm_to_node (rhsa->proximity_domain); pg =alloc_domheap_pages (NULL ,get_order_from_pages (npages), - (node ==-1 ) ?0 :MEMF_node (node)); + (node ==NUMA_NO_NODE ) ?0 :MEMF_node (node));if ( !pg )return 0 ;
xen/include/asm-arm/numa.h +3 -1
@@ -1,11 +1,13 @@#ifndef __ARCH_ARM_NUMA_H#define __ARCH_ARM_NUMA_H +typedef u8 nodeid_t ; +/* Fake one node for now. See also node_online_map. */ #define cpu_to_node (cpu) 0#define node_to_cpumask (node) (cpu_online_map) -static inline __attribute__((pure))int phys_to_nid (paddr_t addr) +static inline __attribute__((pure))nodeid_t phys_to_nid (paddr_t addr) {return 0 ; }
xen/include/asm-x86/irq.h +2 -1
@@ -5,6 +5,7 @@#include <xen/config.h> #include <asm/atomic.h> +#include <asm/numa.h> #include <xen/cpumask.h> #include <xen/smp.h> #include <xen/hvm/irq.h>
@@ -155,7 +156,7 @@ int init_irq_data(void);void clear_irq_vector (int irq);int irq_to_vector (int irq); -int create_irq (int node); +int create_irq (nodeid_t node);void destroy_irq (unsigned int irq);int assign_irq_vector (int irq,const cpumask_t *);
xen/include/asm-x86/numa.h +13 -11
@@ -5,6 +5,8 @@#define NODES_SHIFT 6 +typedef u8 nodeid_t ; +extern int srat_rev;extern unsigned char cpu_to_node[];
@@ -20,8 +22,8 @@ struct node { };extern int compute_hash_shift (struct node *nodes,int numnodes, -int *nodeids); -extern int pxm_to_node (int nid); +nodeid_t *nodeids); +extern nodeid_t pxm_to_node (unsigned pxm);#define ZONE_ALIGN (1UL << (MAX_ORDER+PAGE_SHIFT))#define VIRTUAL_BUG_ON (x)
@@ -32,12 +34,12 @@ extern int numa_off;extern int srat_disabled (void ); -extern void numa_set_node (int cpu,int node); -extern int setup_node (int pxm); +extern void numa_set_node (int cpu,nodeid_t node); +extern nodeid_t setup_node (unsigned pxm);extern void srat_detect_node (int cpu); -extern void setup_node_bootmem (int nodeid,u64 start,u64 end); -extern unsigned char apicid_to_node[]; +extern void setup_node_bootmem (nodeid_t nodeid,u64 start,u64 end); +extern nodeid_t apicid_to_node[];#ifdef CONFIG_NUMA extern void init_cpu_to_node (void );
@@ -54,14 +56,14 @@ extern u8 *memnodemap;struct node_data {unsigned long node_start_pfn;unsigned long node_spanned_pages; -unsigned int node_id; +nodeid_t node_id; };extern struct node_data node_data[]; -static inline __attribute__((pure))int phys_to_nid (paddr_t addr) +static inline __attribute__((pure))nodeid_t phys_to_nid (paddr_t addr) { -unsigned nid; +nodeid_t nid;VIRTUAL_BUG_ON ((paddr_to_pdx (addr) >> memnode_shift) >= memnodemapsize); nid = memnodemap[paddr_to_pdx (addr) >> memnode_shift];VIRTUAL_BUG_ON (nid >=MAX_NUMNODES || !node_data[nid]);
@@ -75,7 +77,7 @@ static inline __attribute__((pure)) int phys_to_nid(paddr_t addr)#define node_end_pfn (nid) (NODE_DATA(nid)->node_start_pfn + \ NODE_DATA(nid)->node_spanned_pages) -extern int valid_numa_range (u64 start,u64 end,int node); +extern int valid_numa_range (u64 start,u64 end,nodeid_t node);#else #define init_cpu_to_node () do {} while (0)#define clear_node_cpumask (cpu) do {} while (0)
@@ -83,6 +85,6 @@ extern int valid_numa_range(u64 start, u64 end, int node);#endif void srat_parse_regions (u64 addr); -extern int __node_distance (int a,int b); +extern int __node_distance (nodeid_t a,nodeid_t b);#endif
Signature · 1 line
1.7.1
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.02.15 at 19:14, <[email protected]> wrote:
Use u8-sized node IDs and unsigned PXMs consistently throughout code (and introduce
nodeid_ttype).Signed-off-by Boris Ostrovsky <[email protected]>
I think the description should call out areas not covered, like the node encoding in the top bits of MEMF_*.
xen/arch/x86/srat.c line 24
Quoted 7 lines
xen/arch/x86/srat.c +1
-0@@ -21,44 +21,55 @@#include <asm/e820.h> #include <asm/page.h> +#define MAX_PXM 255
Perhaps better (MAX_NUMNODES - 1) than a literal number? Or even do away with it altogether, use MAX_NUMNODES - 1 in the array definition and ARRAY_SIZE() elsewhere?
xen/arch/x86/srat.c line 56
Quoted 9 lines
xen/arch/x86/srat.c +5
-3-__devinit int setup_node (int pxm) +__devinit nodeid_t setup_node (unsigned pxm) { -unsigned node = pxm2node[pxm]; -if (node ==0xff ) { +nodeid_t node; + +/* NUMA_NO_NODE is 255 */ +BUILD_BUG_ON (MAX_NUMNODES >254 );
BUILD_BUG_ON(MAX_NUMNODES >= NUMA_NO_NODE);
(yielding the comment redundant)
xen/common/page_alloc.c static struct page_info *alloc_heap_pages( · line 584
Quoted 8 lines
xen/common/page_alloc.c +1
-1@@ -581,7 +581,7 @@ static struct page_info *alloc_heap_pages( struct domain *d) {unsigned int first_node, i, j, zone =0 , nodemask_retry =0 ; -unsigned int node = (uint8_t )((memflags >> _MEMF_node) -1 ); +nodeid_t node = (nodeid_t)((memflags >> _MEMF_node) -1 );
No-one will notice this needing adjustment if nodeid_t ever gets widened. We'll need a _MEMF_node_width or _MEMF_node_mask to do proper masking here (the latter would allow the use of MASK_EXTR()), avoiding the need for a cast altogether.
Jan
Quoted 14 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 21.02.15 at 19:14, <[email protected]> wrote:
Use u8-sized node IDs and unsigned PXMs consistently throughout code (and introduce
nodeid_ttype).Signed-off-by Boris Ostrovsky <[email protected]>I think the description should call out areas not covered, like the node encoding in the top bits of MEMF_*.
Quoted 6 lines
xen/arch/x86/srat.c +0
-0@@ -21,44 +21,55 @@#include <asm/e820.h> #include <asm/page.h>
Quoted 4 lines
xen/arch/x86/srat.c line 24
Quoted 1 line
xen/arch/x86/srat.c +1
-0+#define MAX_PXM 255Perhaps better (
MAX_NUMNODES- 1) than a literal number? Or even do away with it altogether, useMAX_NUMNODES- 1 in the array definition andARRAY_SIZE()elsewhere?
I am not sure we can do this: PXMs are not guaranteed to be zero-based.
And, in fact, the way we map PXMs to nodes is not quite right because of this --- it just so happens that PXMs are usually under 255 (and zero-based) and we can use them as index to 255-sized array. IIRC the spec defines them as 32-bit values.
-boris
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 15:42, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/srat.c line 24
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 21.02.15 at 19:14, <[email protected]> wrote:
xen/arch/x86/srat.c +1
-0@@ -21,44 +21,55 @@#include <asm/e820.h> #include <asm/page.h> +#define MAX_PXM 255Perhaps better (
MAX_NUMNODES- 1) than a literal number? Or even do away with it altogether, useMAX_NUMNODES- 1 in the array definition andARRAY_SIZE()elsewhere?
Quoted 6 lines
I am not sure we can do this: PXMs are not guaranteed to be zero-based.
And, in fact, the way we map PXMs to nodes is not quite right because of this --- it just so happens that PXMs are usually under 255 (and zero-based) and we can use them as index to 255-sized array. IIRC the spec defines them as 32-bit values.
Ah, yes, you're right. We may need to allocate the array dynamically as soon as we run into a system with large PXMs.
Jan
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 15:42, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/srat.c line 24
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 21.02.15 at 19:14, <[email protected]> wrote:
xen/arch/x86/srat.c +1
-0@@ -21,44 +21,55 @@#include <asm/e820.h> #include <asm/page.h> +#define MAX_PXM 255Perhaps better (
MAX_NUMNODES- 1) than a literal number? Or even do away with it altogether, useMAX_NUMNODES- 1 in the array definition andARRAY_SIZE()elsewhere?
Quoted 9 lines
Quoted 6 lines
I am not sure we can do this: PXMs are not guaranteed to be zero-based.
And, in fact, the way we map PXMs to nodes is not quite right because of this --- it just so happens that PXMs are usually under 255 (and zero-based) and we can use them as index to 255-sized array. IIRC the spec defines them as 32-bit values.
Ah, yes, you're right. We may need to allocate the array dynamically as soon as we run into a system with large PXMs.
But then we may end up with a huge and very sparse array. Maybe a hash with each element as a linked list? We will hit the first element in pretty much all cases so it should be reasonably fast.
-boris
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 15:53, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 15:42, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
xen/arch/x86/srat.c line 24
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 21.02.15 at 19:14, <[email protected]> wrote:
xen/arch/x86/srat.c +1
-0@@ -21,44 +21,55 @@#include <asm/e820.h> #include <asm/page.h> +#define MAX_PXM 255Perhaps better (
MAX_NUMNODES- 1) than a literal number? Or even do away with it altogether, useMAX_NUMNODES- 1 in the array definition andARRAY_SIZE()elsewhere?I am not sure we can do this: PXMs are not guaranteed to be zero-based.
And, in fact, the way we map PXMs to nodes is not quite right because of this --- it just so happens that PXMs are usually under 255 (and zero-based) and we can use them as index to 255-sized array. IIRC the spec defines them as 32-bit values.
Quoted 6 lines
Quoted 2 lines
Ah, yes, you're right. We may need to allocate the array dynamically as soon as we run into a system with large PXMs.
But then we may end up with a huge and very sparse array. Maybe a hash with each element as a linked list? We will hit the first element in pretty much all cases so it should be reasonably fast.
Anything more complicated than a flat array would be nice, but may pose a chicken-and-egg problem with allocating the memory for it.
Jan