- x86_64-get-mp_bus_to_node-as-early-v2.patch removed from -mm tree
[email protected]
tree noticeThe patch titled
x86_64: get mp_bus_to_node as early
has been removed from the -mm tree. Its filename was
x86_64-get-mp_bus_to_node-as-early-v2.patchThis patch was dropped because finish-i386-and-x86-64-sysdata-conversion.patch destroyed it
------------------------------------------------------
Subject: x86_64: get mp_bus_to_node as early
From: "Yinghai Lu" <[email protected]>
In struct device, we already have numa_node member. and we can use dev_to_node() /set_dev_node() to get and set numa_node in the device. set_dev_node is called in pci_device_add() with pcibus_to_node(bus). and pci_bus_to_node use bus->sysdata for nodeid. the problem is when pci_add_device is called, bus->sysdata is not assigned correct nodeid yet. the result will be numa_node always is 0. pcibios_scan_root and pci_scan_root could take sysdata. So we need to get mp_bus_to_node mapping before these two are called. and get_mp_bus_to_node could get correct node for sysdata in root bus. in scanning of root bus, all child bus will take parent bus sysdata. So all pci_device->dev.numa_node will be assigned correctly automatically. later we could use dev_to_node(&pci_dev->dev) to numa_node, and we could also could make other bus specific device get the correct numa_node too. and in different driver we could use kmalloc_node instead of kmalloc for skbuff/net or urb/usb etc. That could help improve performance with usb or net or sata for AMD K8 two sockets beyond system.
For example:
two way opteron system and only one HT chain on node 0. USB controller on SB will be on node0. some dma accessing is used with kmalloc/dma_map_single. and these address will be on node1 instead of node0. and even worse, when node1 ram is above 4G, we may need to iommu mapping for usb operation. two way system with one HT chain on different node, we will need to kmalloc/dma_map_single to use ram on corresonding node too. esp for nvidia mcp55/io55 system. the second io55 could have nic/sata/pcie devices.
this is one update version to pci_sysdata ... also reverse pci_acpi_scan_root to use pcibios_scan_root again.
without this patch: /sys/devices/pci0000:80/*/numa_node for HT chains other than on node0 always 0.
---
arch/i386/pci/Makefile | 1 arch/i386/pci/acpi.c | 40 ++++---------- arch/i386/pci/common.c | 7 ++ arch/i386/pci/irq.c | 18 ++++++ arch/i386/pci/legacy.c | 22 +++++++- arch/i386/pci/mp_bus_to_node.c | 23 ++++++++ arch/x86_64/pci/k8-bus.c | 83 +++++++++++++++++++++---------- include/asm-i386/topology.h | 10 +++ include/asm-x86_64/topology.h | 13 ++++ 9 files changed, 159 insertions(+), 58 deletions(-)
arch/i386/pci/Makefile renamed from arch/i386/pci/Makefile~x86_64-get-mp_bus_to_node-as-early-v2 +1 -0
@@ -10,5 +10,6 @@ pci-y += legacy.o irq.o pci-$(CONFIG_X86_VISWS) := visws.o fixup.o pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o +pci-$(CONFIG_NUMA) += mp_bus_to_node.o obj-y += $(pci-y) common.o early.o
arch/i386/pci/acpi.c renamed from arch/i386/pci/acpi.c~x86_64-get-mp_bus_to_node-as-early-v2 +11 -29
@@ -8,46 +8,28 @@struct pci_bus *__devinit pci_acpi_scan_root (struct acpi_device *device,int domain,int busnum) {struct pci_bus *bus; -struct pci_sysdata *sd; +#ifdef CONFIG_ACPI_NUMA int pxm; - -/* Allocate per-root-bus (not per bus) arch-specific data. -* TODO: leak; this memory is never freed. -* It's arguable whether it's worth the trouble to care. -*/ - sd =kzalloc (sizeof (*sd),GFP_KERNEL ); -if (!sd) { -printk (KERN_ERR "PCI: OOM, not probing PCI bus %02x\n" , busnum); -return NULL ; - } +int node; +#endif if (domain !=0 ) {printk (KERN_WARNING "PCI: Multiple domains not supported\n" ); -kfree (sd);return NULL ; } - sd->node =-1 ; - - pxm =acpi_get_pxm (device->handle);#ifdef CONFIG_ACPI_NUMA -if (pxm >=0 ) - sd->node =pxm_to_node (pxm); + pxm =acpi_get_pxm (device->handle); +if (pxm >=0 ) { + node =pxm_to_node (pxm); +printk (KERN_INFO "bus %02x -> pxm %d -> node %02x\n" , + busnum, pxm, node); +set_mp_bus_to_node (busnum, node); + }#endif - bus =pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); -if (!bus) -kfree (sd); + bus =pcibios_scan_root (busnum); -#ifdef CONFIG_ACPI_NUMA -if (bus !=NULL ) { -if (pxm >=0 ) { -printk ("bus %d -> pxm %d -> node %d\n" , - busnum, pxm, sd->node); - } - } -#endif -return bus; }
arch/i386/pci/common.c renamed from arch/i386/pci/common.c~x86_64-get-mp_bus_to_node-as-early-v2 +6 -1
@@ -314,9 +314,14 @@ struct pci_bus * __devinit pcibios_scan_return NULL ; } + sd->node =get_mp_bus_to_node (busnum); +printk (KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n" , busnum); + bus =pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); +if (!bus) +kfree (sd); -return pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); +return bus; }extern u8 pci_cache_line_size;
arch/i386/pci/irq.c renamed from arch/i386/pci/irq.c~x86_64-get-mp_bus_to_node-as-early-v2 +17 -1
@@ -136,10 +136,26 @@ static void __init pirq_peer_trick(void) busmap[e->bus] =1 ; }for (i =1 ; i <256 ; i++) { +struct pci_bus *bus =NULL ; +struct pci_sysdata *sd;if (!busmap[i] ||pci_find_bus (0 , i))continue ; -if (pci_scan_bus (i, &pci_root_ops,NULL )) +/* Allocate per-root-bus (not per bus) arch-specific data. +* TODO: leak; this memory is never freed. +* It's arguable whether it's worth the trouble to care. +*/ + sd =kzalloc (sizeof (*sd),GFP_KERNEL ); +if (!sd) { +printk (KERN_ERR "PCI: OOM, not probing PCI bus %02x\n" , + i); +continue ; + } + sd->node =get_mp_bus_to_node (i); + bus =pci_scan_bus (i, &pci_root_ops, sd); +if (bus)printk (KERN_INFO "PCI: Discovered primary peer bus %02x [IRQ]\n" , i); +else +kfree (sd); } pcibios_last_bus =-1 ; }
arch/i386/pci/legacy.c renamed from arch/i386/pci/legacy.c~x86_64-get-mp_bus_to_node-as-early-v2 +21 -1
@@ -12,6 +12,9 @@static void __devinit pcibios_fixup_peer_bridges (void ) {int n, devfn; +struct pci_bus *bus =NULL ; +struct pci_sysdata *sd; +long node;if (pcibios_last_bus <=0 || pcibios_last_bus >=0xff )return ;
@@ -21,12 +24,29 @@ static void __devinit pcibios_fixup_peeru32 l;if (pci_find_bus (0 , n))continue ; + node =get_mp_bus_to_node (n);for (devfn =0 ; devfn <256 ; devfn +=8 ) {if (!raw_pci_ops->read (0 , n, devfn,PCI_VENDOR_ID ,2 , &l) && l !=0x0000 && l !=0xffff ) {DBG ("Found device at %02x:%02x [%04x]\n" , n, devfn, l);printk (KERN_INFO "PCI: Discovered peer bus %02x\n" , n); -pci_scan_bus (n, &pci_root_ops,NULL ); +/* Allocate per-root-bus (not per bus) +* arch-specific data. +* TODO: leak; this memory is never freed. +* It's arguable whether it's worth the trouble +* to care. +*/ + sd =kzalloc (sizeof (*sd),GFP_KERNEL ); +if (!sd) { +printk (KERN_ERR +"PCI: OOM, not probing PCI bus %02x\n" , + n); +break ; + } + sd->node = node; + bus =pci_scan_bus (n, &pci_root_ops, sd); +if (!bus) +kfree (sd);break ; } }
arch/i386/pci/mp_bus_to_node.c new file +23 -0
@@ -0,0 +1,23 @@ +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/topology.h> + +#define BUS_NR 256 + +static unsigned char mp_bus_to_node[BUS_NR ]; + +void set_mp_bus_to_node (int busnum,int node) +{ +if (busnum >=0 && busnum <BUS_NR ) + mp_bus_to_node[busnum] = (unsigned char ) node; +} + +int get_mp_bus_to_node (int busnum) +{ +int node; + +if (busnum <0 || busnum > (BUS_NR -1 ) ) +return 0 ; + node = mp_bus_to_node[busnum]; +return node; +}
arch/x86_64/pci/k8-bus.c renamed from arch/x86_64/pci/k8-bus.c~x86_64-get-mp_bus_to_node-as-early-v2 +57 -26
128 lines not on this page · raw message
include/asm-i386/topology.h renamed from include/asm-i386/topology.h~x86_64-get-mp_bus_to_node-as-early-v2 +10 -0
@@ -101,7 +101,17 @@ extern unsigned long node_remap_size[];#define node_has_online_mem (nid) (node_start_pfn[nid] != node_end_pfn[nid]) +int get_mp_bus_to_node (int busnum); +void set_mp_bus_to_node (int busnum,int node); +#else /* !CONFIG_NUMA */ +static inline int get_mp_bus_to_node (int busnum) +{ +return 0 ; +} +static inline void set_mp_bus_to_node (int busnum,int node) +{ +}/* * Other i386 platforms should define their own version of the * above macros here.
include/asm-x86_64/topology.h renamed from include/asm-x86_64/topology.h~x86_64-get-mp_bus_to_node-as-early-v2 +13 -0
@@ -53,6 +53,19 @@ extern int __node_distance(int, int); .nr_balance_failed = 0, \ } +int get_mp_bus_to_node (int busnum); +void set_mp_bus_to_node (int busnum,int node); + +#else + +static inline int get_mp_bus_to_node (int busnum) +{ +return 0 ; +} +static inline void set_mp_bus_to_node (int busnum,int node) +{ +} +#endif #ifdef CONFIG_SMP
_
Patches currently in -mm which might be from [email protected] are
finish-i386-and-x86-64-sysdata-conversion.patch x86_64-get-mp_bus_to_node-as-early-v2.patch x86_64-use-bus-conf-in-nb-conf-fun1-to-get-bus-range-on-node.patch try-parent-numa_node-at-first-before-using-default-v2.patch net-use-numa_node-in-net_devcice-dev-instead-of-parent.patch dma-use-dev_to_node-to-get-node-for-device-in-dma_alloc_pages.patch x86_64-store-core-id-bits-in-cpuinfo_x8.patch x86_64-use-core-id-bits-for-apicid_to_node-initialization.patch x86_64-remove-never-used-apic_mapped.patch x86_64-get-boot_cpu_id-as-early-for-k8_scan_nodes.patch
PATCH 1/5 x86_64: get mp_bus_to_node as early v3
please check this one against pci_scan_bus_with_sysdata
[PATCH 1/5] x86_64: get mp_bus_to_node as early v3
current on amd k8 system with multi ht chain, the numa_node of pci devices under /sys/devices/pci0000:80/* always 0, even that chain is on node 1 or 2 or 3.
workaround: pcibus_to_node(bus) is used when we want to get node that pci_device is on.
In struct device, we already have numa_node member. and we could use dev_to_node() /set_dev_node() to get and set numa_node in the device.set_dev_node is called in pci_device_add() with pcibus_to_node(bus). and pcibus_to_node use bus->sysdata for nodeid.
the problem is when pci_add_device is called, bus->sysdata is not assigned correct nodeid yet. the result will be numa_node always is 0.
pcibios_scan_root and pci_scan_root could take sysdata. So we need to get mp_bus_to_node mapping before these two are called. and get_mp_bus_to_node could get correct node for sysdata in root bus.
in scanning of root bus, all child bus will take parent bus sysdata. So all pci_device->dev.numa_node will be assigned correctly automatically.
later we could use dev_to_node(&pci_dev->dev) to get numa_node, and we could also could make other bus specific device get the correct numa_node too.
this is one update version to pci_sysdata ...
also reverse pci_acpi_scan_root to use pcibios_scan_root again.
arch/i386/pci/Makefile | 1 arch/i386/pci/Makefile | 1 arch/i386/pci/acpi.c | 40 +++++-------------- arch/i386/pci/common.c | 17 ++++++-- arch/i386/pci/irq.c | 4 + arch/i386/pci/legacy.c | 6 ++ arch/i386/pci/mp_bus_to_node.c | 24 +++++++++++ arch/x86_64/pci/k8-bus.c | 83 ++++++++++++++++++++++++++++------------- include/asm-i386/pci.h | 1 include/asm-i386/topology.h | 10 ++++ include/asm-x86_64/pci.h | 1 include/asm-x86_64/topology.h | 13 ++++++ 11 files changed, 138 insertions(+), 62 deletions(-)
arch/i386/pci/Makefile +1 -0
@@ -10,5 +10,6 @@ pci-y += legacy.o irq.o pci-$(CONFIG_X86_VISWS) := visws.o fixup.o pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o +pci-$(CONFIG_NUMA) += mp_bus_to_node.o obj-y += $(pci-y) common.o early.o
arch/i386/pci/acpi.c +11 -29
@@ -8,46 +8,28 @@struct pci_bus *__devinit pci_acpi_scan_root (struct acpi_device *device,int domain,int busnum) {struct pci_bus *bus; -struct pci_sysdata *sd; +#ifdef CONFIG_ACPI_NUMA int pxm; - -/* Allocate per-root-bus (not per bus) arch-specific data. -* TODO: leak; this memory is never freed. -* It's arguable whether it's worth the trouble to care. -*/ - sd =kzalloc (sizeof (*sd),GFP_KERNEL ); -if (!sd) { -printk (KERN_ERR "PCI: OOM, not probing PCI bus %02x\n" , busnum); -return NULL ; - } +int node; +#endif if (domain !=0 ) {printk (KERN_WARNING "PCI: Multiple domains not supported\n" ); -kfree (sd);return NULL ; } - sd->node =-1 ; - - pxm =acpi_get_pxm (device->handle);#ifdef CONFIG_ACPI_NUMA -if (pxm >=0 ) - sd->node =pxm_to_node (pxm); + pxm =acpi_get_pxm (device->handle); +if (pxm >=0 ) { + node =pxm_to_node (pxm); +printk (KERN_INFO "bus %02x -> pxm %d -> node %02x\n" , + busnum, pxm, node); +set_mp_bus_to_node (busnum, node); + }#endif - bus =pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); -if (!bus) -kfree (sd); + bus =pcibios_scan_root (busnum); -#ifdef CONFIG_ACPI_NUMA -if (bus !=NULL ) { -if (pxm >=0 ) { -printk ("bus %d -> pxm %d -> node %d\n" , - busnum, pxm, sd->node); - } - } -#endif -return bus; }
arch/i386/pci/common.c +13 -4
@@ -314,9 +314,14 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)return NULL ; } + sd->node =get_mp_bus_to_node (busnum); +printk (KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n" , busnum); + bus =pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); +if (!bus) +kfree (sd); -return pci_scan_bus_parented (NULL , busnum, &pci_root_ops, sd); +return bus; }extern u8 pci_cache_line_size;
@@ -456,7 +461,7 @@ void pcibios_disable_device (struct pci_dev *dev)pcibios_disable_irq (dev); } -struct pci_bus *pci_scan_bus_with_sysdata (int busno) +struct pci_bus *pci_scan_bus_on_node (int busno,struct pci_ops *ops,int node) {struct pci_bus *bus =NULL ;struct pci_sysdata *sd;
@@ -471,11 +476,15 @@ struct pci_bus *pci_scan_bus_with_sysdata(int busno)printk (KERN_ERR "PCI: OOM, skipping PCI bus %02x\n" , busno);return NULL ; } - sd->node =-1 ; - bus =pci_scan_bus (busno, &pci_root_ops, sd); + sd->node = node; + bus =pci_scan_bus (busno, ops, sd);if (!bus)kfree (sd);return bus; } +struct pci_bus *pci_scan_bus_with_sysdata (int busno) +{ +return pci_scan_bus_on_node (busno, &pci_root_ops,-1 ); +}
arch/i386/pci/irq.c +3 -1
@@ -136,9 +136,11 @@ static void __init pirq_peer_trick(void) busmap[e->bus] =1 ; }for (i =1 ; i <256 ; i++) { +int node;if (!busmap[i] ||pci_find_bus (0 , i))continue ; -if (pci_scan_bus_with_sysdata (i)) + node =get_mp_bus_to_node (i); +if (pci_scan_bus_on_node (i, &pci_root_ops, node))printk (KERN_INFO "PCI: Discovered primary peer bus %02x [IRQ]\n" , i); } pcibios_last_bus =-1 ;
arch/i386/pci/legacy.c +5 -1
@@ -12,6 +12,9 @@static void __devinit pcibios_fixup_peer_bridges (void ) {int n, devfn; +struct pci_bus *bus =NULL ; +struct pci_sysdata *sd; +long node;if (pcibios_last_bus <=0 || pcibios_last_bus >=0xff )return ;
@@ -21,12 +24,13 @@ static void __devinit pcibios_fixup_peer_bridges(void)u32 l;if (pci_find_bus (0 , n))continue ; + node =get_mp_bus_to_node (n);for (devfn =0 ; devfn <256 ; devfn +=8 ) {if (!raw_pci_ops->read (0 , n, devfn,PCI_VENDOR_ID ,2 , &l) && l !=0x0000 && l !=0xffff ) {DBG ("Found device at %02x:%02x [%04x]\n" , n, devfn, l);printk (KERN_INFO "PCI: Discovered peer bus %02x\n" , n); -pci_scan_bus_with_sysdata (n); +pci_scan_bus_on_node (n, &pci_root_ops, node);break ; } }
arch/i386/pci/mp_bus_to_node.c new file +23 -0
@@ -0,0 +1,23 @@ +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/topology.h> + +#define BUS_NR 256 + +static unsigned char mp_bus_to_node[BUS_NR ]; + +void set_mp_bus_to_node (int busnum,int node) +{ +if (busnum >=0 && busnum <BUS_NR ) + mp_bus_to_node[busnum] = (unsigned char ) node; +} + +int get_mp_bus_to_node (int busnum) +{ +int node; + +if (busnum <0 || busnum > (BUS_NR -1 ) ) +return 0 ; + node = mp_bus_to_node[busnum]; +return node; +}
-
arch/x86_64/pci/k8-bus.c +57 -26
128 lines not on this page · raw message
include/asm-i386/pci.h +1 -0
@@ -9,6 +9,7 @@ struct pci_sysdata { };/* scan a bus after allocating a pci_sysdata for it */ +extern struct pci_bus *pci_scan_bus_on_node (int busno,struct pci_ops *ops,int node);extern struct pci_bus *pci_scan_bus_with_sysdata (int busno);#include <linux/mm.h> /* for struct page */
include/asm-i386/topology.h +10 -0
@@ -101,7 +101,17 @@ extern unsigned long node_remap_size[];#define node_has_online_mem (nid) (node_start_pfn[nid] != node_end_pfn[nid]) +int get_mp_bus_to_node (int busnum); +void set_mp_bus_to_node (int busnum,int node); +#else /* !CONFIG_NUMA */ +static inline int get_mp_bus_to_node (int busnum) +{ +return 0 ; +} +static inline void set_mp_bus_to_node (int busnum,int node) +{ +}/* * Other i386 platforms should define their own version of the * above macros here.
include/asm-x86_64/pci.h +1 -0
@@ -10,6 +10,7 @@ struct pci_sysdata {void * iommu;/* IOMMU private data */ }; +extern struct pci_bus *pci_scan_bus_on_node (int busno,struct pci_ops *ops,int node);extern struct pci_bus *pci_scan_bus_with_sysdata (int busno);#ifdef CONFIG_CALGARY_IOMMU
include/asm-x86_64/topology.h +13 -0
@@ -53,6 +53,19 @@ extern int __node_distance(int, int); .nr_balance_failed = 0, \ } +int get_mp_bus_to_node (int busnum); +void set_mp_bus_to_node (int busnum,int node); + +#else + +static inline int get_mp_bus_to_node (int busnum) +{ +return 0 ; +} +static inline void set_mp_bus_to_node (int busnum,int node) +{ +} +#endif #ifdef CONFIG_SMP
Re: [PATCH 1/5] x86_64: get mp_bus_to_node as early v3
Quoted 27 lines · Yinghai Lu
please check this one against
pci_scan_bus_with_sysdata[PATCH 1/5]
x86_64: getmp_bus_to_nodeas early v3current on amd k8 system with multi ht chain, the
numa_nodeof pci devices under r/sys/devices/pci0000:80/* always 0, even that chain is on node 1 or 2 or 3.workaround:
pcibus_to_node(bus)is used when we want to get node thatpci_deviceis on.In struct device, we already have
numa_nodemember. and we could usedev_to_node()/set_dev_node() to get and setnuma_nodein the device.set_dev_nodeis called inpci_device_add()withpcibus_to_node(bus). andpcibus_to_nodeusebus->sysdatafor nodeid.the problem is when
pci_add_deviceis called,bus->sysdatais not assigned correct nodeid yet. the result will benuma_nodealways is 0.
pcibios_scan_rootandpci_scan_rootcould take sysdata. So we need to getmp_bus_to_nodemapping before these two are called. andget_mp_bus_to_nodecould get correct node for sysdata in root bus.in scanning of root bus, all child bus will take parent bus sysdata. So all
pci_device->dev.numa_nodewill be assigned correctly automatically.
Quoted 6 lines
later we could use
dev_to_node(&pci_dev->dev)to getnuma_node, and we could also could make other bus specific device get the correctnuma_nodetoo.this is one update version to
pci_sysdata... also reversepci_acpi_scan_rootto usepcibios_scan_rootagain.
Can you explain why this patch (and your other patches in this area) are needed? is this a performance issue? the patches seem complex, is there a good argument for that complexity?
Cheers,
Muli
Re: [PATCH 1/5] x86_64: get mp_bus_to_node as early v3
Quoted 5 lines · Muli Ben-Yehuda
Can you explain why this patch (and your other patches in this area) are needed? is this a performance issue? the patches seem complex, is there a good argument for that complexity?
1. AMD K8 system with two HT chain: when acpi=off or there is not _PXM in DSDT, still make numa_node of device get correct value. ... /sys/devices/pci0000:80/*/numa_node will be correct instead of 0 for all. ---- so far i didn't find one two chain AMD k8 based system have _PXM in DSDT...
2. could use dev_to_node instead of pcibus_to_node.
3. complex? I don't think so. It just try to get bus_to_node mapping from pci conf space and put into one 256 byte array early, and then use it some link pxm_to_node.
4. make it support quad core opteron by change to scan four regs in NB func1 intead of func0.
YH