Skip to contentSkip to conversation

platform/x86: ISST: PUNIT device mapping with Sub-NUMA clustering

PATCH Superseded Srinivas Pandruvada 2 participants 5 messages Jun 27, 2022 – Jun 29, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH 1/1 platform/x86: ISST: PUNIT device mapping with Sub-NUMA clustering

On a multiple package system using Sub-NUMA clustering, there is an issue in mapping Linux CPU number to PUNIT PCI device when manufacturer decided to reuse the PCI bus number across packages. Bus number can be reused as long as they are in different domain or segment. In this case some CPU will fail to find a PCI device to issue SST requests.

When bus numbers are reused across CPU packages, we are using proximity information by matching CPU numa node id to PUNIT PCI device numa node id. But on a package there can be only one PUNIT PCI device, but multiple numa nodes (one for each sub cluster). So, the numa node ID of the PUNIT PCI device can only match with one numa node id of CPUs in a sub cluster in the package.

Since there can be only one PUNIT PCI device per package, if we match with numa node id of any sub cluster in that package, we can use that mapping for any CPU in that package. So, store the match information in a per package data structure and return the information when there is no match.

---
 .../intel/speed_select_if/isst_if_common.c    | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +22 -0
index e8424e70d81d..f3cd1be3283a 100644
@@ -286,11 +286,18 @@ struct isst_if_cpu_info {
 	int numa_node;
 };
 
+struct isst_if_pkg_info {
+	struct pci_dev *pci_dev[2];
+};
+
 static struct isst_if_cpu_info *isst_cpu_info;
+static struct isst_if_pkg_info *isst_pkg_info;
+
 #define ISST_MAX_PCI_DOMAINS	8
 
 static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn)
 {
+	int pkg_id = topology_physical_package_id(cpu);
 	struct pci_dev *matched_pci_dev = NULL;
 	struct pci_dev *pci_dev = NULL;
 	int no_matches = 0;
@@ -324,6 +331,8 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 		}
 
 		if (node == isst_cpu_info[cpu].numa_node) {
+			isst_pkg_info[pkg_id].pci_dev[bus_no] = _pci_dev;
+
 			pci_dev = _pci_dev;
 			break;
 		}
@@ -342,6 +351,9 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 	if (!pci_dev && no_matches == 1)
 		pci_dev = matched_pci_dev;
 
+	if (!pci_dev)
+		pci_dev = isst_pkg_info[pkg_id].pci_dev[bus_no];
+
 	return pci_dev;
 }
 
@@ -417,10 +429,19 @@ static int isst_if_cpu_info_init(void)
 	if (!isst_cpu_info)
 		return -ENOMEM;
 
+	isst_pkg_info = kcalloc(topology_max_packages(),
+				sizeof(*isst_pkg_info),
+				GFP_KERNEL);
+	if (!isst_pkg_info) {
+		kfree(isst_cpu_info);
+		return -ENOMEM;
+	}
+
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				"platform/x86/isst-if:online",
 				isst_if_cpu_online, NULL);
 	if (ret < 0) {
+		kfree(isst_pkg_info);
 		kfree(isst_cpu_info);
 		return ret;
 	}
@@ -433,6 +454,7 @@ static int isst_if_cpu_info_init(void)
 static void isst_if_cpu_info_exit(void)
 {
 	cpuhp_remove_state(isst_if_online_id);
+	kfree(isst_pkg_info);
 	kfree(isst_cpu_info);
 };
 
Signature · 1 line
2.31.1
#1 lore raw

Hi,

Quoted 29 lines · Srinivas Pandruvada

On a multiple package system using Sub-NUMA clustering, there is an issue in mapping Linux CPU number to PUNIT PCI device when manufacturer decided to reuse the PCI bus number across packages. Bus number can be reused as long as they are in different domain or segment. In this case some CPU will fail to find a PCI device to issue SST requests.

When bus numbers are reused across CPU packages, we are using proximity information by matching CPU numa node id to PUNIT PCI device numa node id. But on a package there can be only one PUNIT PCI device, but multiple numa nodes (one for each sub cluster). So, the numa node ID of the PUNIT PCI device can only match with one numa node id of CPUs in a sub cluster in the package.

Since there can be only one PUNIT PCI device per package, if we match with numa node id of any sub cluster in that package, we can use that mapping for any CPU in that package. So, store the match information in a per package data structure and return the information when there is no match.

---
 .../intel/speed_select_if/isst_if_common.c    | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +0 -0
index e8424e70d81d..f3cd1be3283a 100644

drivers/platform/x86/intel/speed_select_if/isst_if_common.c struct isst_if_cpu_info { · line 290

Quoted 5 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
@@ -286,11 +286,18 @@ struct isst_if_cpu_info {
 	int numa_node;
 };
 
+struct isst_if_pkg_info {
+	struct pci_dev *pci_dev[2];

This and (continued below) ...

Quoted 14 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +5 -0
+};
+
 static struct isst_if_cpu_info *isst_cpu_info;
+static struct isst_if_pkg_info *isst_pkg_info;
+
 #define ISST_MAX_PCI_DOMAINS	8
 
 static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn)
 {
+	int pkg_id = topology_physical_package_id(cpu);
 	struct pci_dev *matched_pci_dev = NULL;
 	struct pci_dev *pci_dev = NULL;
 	int no_matches = 0;

drivers/platform/x86/intel/speed_select_if/isst_if_common.c static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn · line 335

Quoted 5 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
@@ -324,6 +331,8 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 		}
 
 		if (node == isst_cpu_info[cpu].numa_node) {
+			isst_pkg_info[pkg_id].pci_dev[bus_no] = _pci_dev;
+

This and ...

drivers/platform/x86/intel/speed_select_if/isst_if_common.c static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn · line 356

Quoted 10 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +3 -0
 			pci_dev = _pci_dev;
 			break;
 		}
@@ -342,6 +351,9 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 	if (!pci_dev && no_matches == 1)
 		pci_dev = matched_pci_dev;
 
+	if (!pci_dev)
+		pci_dev = isst_pkg_info[pkg_id].pci_dev[bus_no];
+

This assumes that bus_no is never > 1, is this assumption enforced somewhere?

Also maybe make the 2 in:

drivers/platform/x86/intel/speed_select_if/isst_if_common.c struct isst_if_cpu_info { · line 290

Quoted 2 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
+struct isst_if_pkg_info {
+	struct pci_dev *pci_dev[2];

a #define ?

Regards,

Hans

Quoted 31 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +10 -0
 	return pci_dev;
 }
@@ -417,10 +429,19 @@ static int isst_if_cpu_info_init(void)
 	if (!isst_cpu_info)
 		return -ENOMEM;
 
+	isst_pkg_info = kcalloc(topology_max_packages(),
+				sizeof(*isst_pkg_info),
+				GFP_KERNEL);
+	if (!isst_pkg_info) {
+		kfree(isst_cpu_info);
+		return -ENOMEM;
+	}
+
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				"platform/x86/isst-if:online",
 				isst_if_cpu_online, NULL);
 	if (ret < 0) {
+		kfree(isst_pkg_info);
 		kfree(isst_cpu_info);
 		return ret;
 	}
@@ -433,6 +454,7 @@ static int isst_if_cpu_info_init(void)
 static void isst_if_cpu_info_exit(void)
 {
 	cpuhp_remove_state(isst_if_online_id);
+	kfree(isst_pkg_info);
 	kfree(isst_cpu_info);
 };
 
#2 lore raw
In reply to Srinivas Pandruvada

Hi,

Quoted 29 lines · Srinivas Pandruvada

On a multiple package system using Sub-NUMA clustering, there is an issue in mapping Linux CPU number to PUNIT PCI device when manufacturer decided to reuse the PCI bus number across packages. Bus number can be reused as long as they are in different domain or segment. In this case some CPU will fail to find a PCI device to issue SST requests.

When bus numbers are reused across CPU packages, we are using proximity information by matching CPU numa node id to PUNIT PCI device numa node id. But on a package there can be only one PUNIT PCI device, but multiple numa nodes (one for each sub cluster). So, the numa node ID of the PUNIT PCI device can only match with one numa node id of CPUs in a sub cluster in the package.

Since there can be only one PUNIT PCI device per package, if we match with numa node id of any sub cluster in that package, we can use that mapping for any CPU in that package. So, store the match information in a per package data structure and return the information when there is no match.

---
 .../intel/speed_select_if/isst_if_common.c    | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +0 -0
index e8424e70d81d..f3cd1be3283a 100644

drivers/platform/x86/intel/speed_select_if/isst_if_common.c struct isst_if_cpu_info { · line 290

Quoted 5 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
@@ -286,11 +286,18 @@ struct isst_if_cpu_info {
 	int numa_node;
 };
 
+struct isst_if_pkg_info {
+	struct pci_dev *pci_dev[2];

This and (continued below) ...

Quoted 14 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +5 -0
+};
+
 static struct isst_if_cpu_info *isst_cpu_info;
+static struct isst_if_pkg_info *isst_pkg_info;
+
 #define ISST_MAX_PCI_DOMAINS	8
 
 static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn)
 {
+	int pkg_id = topology_physical_package_id(cpu);
 	struct pci_dev *matched_pci_dev = NULL;
 	struct pci_dev *pci_dev = NULL;
 	int no_matches = 0;

drivers/platform/x86/intel/speed_select_if/isst_if_common.c static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn · line 335

Quoted 5 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
@@ -324,6 +331,8 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 		}
 
 		if (node == isst_cpu_info[cpu].numa_node) {
+			isst_pkg_info[pkg_id].pci_dev[bus_no] = _pci_dev;
+

This and ...

drivers/platform/x86/intel/speed_select_if/isst_if_common.c static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn · line 356

Quoted 10 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +3 -0
 			pci_dev = _pci_dev;
 			break;
 		}
@@ -342,6 +351,9 @@ static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn
 	if (!pci_dev && no_matches == 1)
 		pci_dev = matched_pci_dev;
 
+	if (!pci_dev)
+		pci_dev = isst_pkg_info[pkg_id].pci_dev[bus_no];
+

This assumes that bus_no is never > 1, is this assumption enforced somewhere?

Also maybe make the 2 in:

drivers/platform/x86/intel/speed_select_if/isst_if_common.c struct isst_if_cpu_info { · line 290

Quoted 2 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
+struct isst_if_pkg_info {
+	struct pci_dev *pci_dev[2];

a #define ?

Regards,

Hans

Quoted 31 lines
drivers/platform/x86/intel/speed_select_if/isst_if_common.c +10 -0
 	return pci_dev;
 }
@@ -417,10 +429,19 @@ static int isst_if_cpu_info_init(void)
 	if (!isst_cpu_info)
 		return -ENOMEM;
 
+	isst_pkg_info = kcalloc(topology_max_packages(),
+				sizeof(*isst_pkg_info),
+				GFP_KERNEL);
+	if (!isst_pkg_info) {
+		kfree(isst_cpu_info);
+		return -ENOMEM;
+	}
+
 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				"platform/x86/isst-if:online",
 				isst_if_cpu_online, NULL);
 	if (ret < 0) {
+		kfree(isst_pkg_info);
 		kfree(isst_cpu_info);
 		return ret;
 	}
@@ -433,6 +454,7 @@ static int isst_if_cpu_info_init(void)
 static void isst_if_cpu_info_exit(void)
 {
 	cpuhp_remove_state(isst_if_online_id);
+	kfree(isst_pkg_info);
 	kfree(isst_cpu_info);
 };
 
author maintainer
#3 lore raw

Hi Hans,

Thanks for the review.

Quoted 4 lines · Hans de Goede

Hi,

Quoted 1 line · Srinivas Pandruvada

[...]

Quoted 6 lines
Quoted 3 lines


+struct isst_if_pkg_info {
+       struct pci_dev *pci_dev[2];

This and (continued below) ...

Didn't understand the comment.

Quoted 16 lines
Quoted 16 lines
(quoted diff) +2 -0
+};
+

 static struct isst_if_cpu_info *isst_cpu_info;

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
+static struct isst_if_pkg_info *isst_pkg_info;
+

 #define ISST_MAX_PCI_DOMAINS   8

 static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn)
 {
+       int pkg_id = topology_physical_package_id(cpu); struct pci_dev *matched_pci_dev = NULL;
        struct pci_dev *pci_dev = NULL;
        int no_matches = 0;

(quoted diff) +0 -0
@@ -324,6 +331,8 @@ static struct pci_dev *_isst_if_get_pci_dev(int

cpu, int bus_no, int dev, int fn

Quoted 9 lines
Quoted 6 lines

                }

                if (node == isst_cpu_info[cpu].numa_node) { +                       isst_pkg_info[pkg_id].pci_dev[bus_no] = _pci_dev;
+

This and ...

Please explain the comment.

Quoted 6 lines
Quoted 6 lines

                        pci_dev = _pci_dev;
                        break;
                }

(quoted diff) +0 -0
@@ -342,6 +351,9 @@ static struct pci_dev *_isst_if_get_pci_dev(int

cpu, int bus_no, int dev, int fn
        if (!pci_dev && no_matches == 1)

Quoted 9 lines
Quoted 5 lines

                pci_dev = matched_pci_dev;

+       if (!pci_dev)
+               pci_dev = isst_pkg_info[pkg_id].pci_dev[bus_no]; +

This assumes that bus_no is never > 1, is this assumption enforced somewhere?

Yes. That is checked at the beginning of function
if (bus_no < 0 || bus_no > 1 || cpu < 0 || cpu >= nr_cpu_ids ||

            cpu >= num_possible_cpus())
	 return NULL;
Quoted 6 lines

Also maybe make the 2 in:

Quoted 2 lines

+struct isst_if_pkg_info {
+       struct pci_dev *pci_dev[2];

a #define ?

I will.

Thanks,
Srinivas

Quoted 38 lines

Regards,

Hans

Quoted 31 lines

        return pci_dev;
 }

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +0 -0
@@ -417,10 +429,19 @@ static int isst_if_cpu_info_init(void)
         if (!isst_cpu_info)
                 return -ENOMEM;


+       isst_pkg_info = kcalloc(topology_max_packages(), +                               sizeof(*isst_pkg_info), +                               GFP_KERNEL);
+       if (!isst_pkg_info) {
+               kfree(isst_cpu_info);
+               return -ENOMEM;
+       }
+
        ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "platform/x86/isst-if:online", isst_if_cpu_online, NULL); if (ret < 0) {
+               kfree(isst_pkg_info); kfree(isst_cpu_info);
                return ret;
        }

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +1 -0
@@ -433,6 +454,7 @@ static int isst_if_cpu_info_init(void)
  static void isst_if_cpu_info_exit(void)
  {
         cpuhp_remove_state(isst_if_online_id);
+       kfree(isst_pkg_info);
         kfree(isst_cpu_info);
  };

#4 lore raw

Hi,

Quoted 11 lines · srinivas pandruvada

Hi Hans,

Thanks for the review.

Quoted 4 lines · Hans de Goede

Hi,

Quoted 1 line · Srinivas Pandruvada

[...]

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines


+struct isst_if_pkg_info {
+       struct pci_dev *pci_dev[2];

This and (continued below) ...

Didn't understand the comment.

What I was trying to say here is that this is all
one long comment (continued further down/below
in the email) about checking the bounds
of this array.

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
(quoted diff) +2 -0
+};
+

 static struct isst_if_cpu_info *isst_cpu_info;

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +2 -0
+static struct isst_if_pkg_info *isst_pkg_info;
+

 #define ISST_MAX_PCI_DOMAINS   8

 static struct pci_dev *_isst_if_get_pci_dev(int cpu, int bus_no, int dev, int fn)
 {
+       int pkg_id = topology_physical_package_id(cpu); struct pci_dev *matched_pci_dev = NULL;
        struct pci_dev *pci_dev = NULL;
        int no_matches = 0;

(quoted diff) +0 -0
@@ -324,6 +331,8 @@ static struct pci_dev *_isst_if_get_pci_dev(int

cpu, int bus_no, int dev, int fn

Quoted 9 lines
Quoted 6 lines

                }

                if (node == isst_cpu_info[cpu].numa_node) { +                       isst_pkg_info[pkg_id].pci_dev[bus_no] = _pci_dev;
+

This and ...

Quoted 1 line

Please explain the comment.

Idem.

Quoted 16 lines
Quoted 16 lines
Quoted 5 lines

                        pci_dev = _pci_dev;
                        break;
                }

(quoted diff) +0 -0
@@ -342,6 +351,9 @@ static struct pci_dev *_isst_if_get_pci_dev(int
Quoted 7 lines

cpu, int bus_no, int dev, int fn
        if (!pci_dev && no_matches == 1)
                pci_dev = matched_pci_dev;

+       if (!pci_dev)
+               pci_dev = isst_pkg_info[pkg_id].pci_dev[bus_no]; +

This assumes that bus_no is never > 1, is this assumption enforced somewhere?

Quoted 4 lines

Yes. That is checked at the beginning of function
if (bus_no < 0 || bus_no > 1 || cpu < 0 || cpu >= nr_cpu_ids ||

            cpu >= num_possible_cpus())
	 return NULL;

Ah, good.

Quoted 7 lines
Quoted 6 lines

Also maybe make the 2 in:

Quoted 2 lines

+struct isst_if_pkg_info {
+       struct pci_dev *pci_dev[2];

a #define ?

I will.

Great; then also please update the "bus_no > 1" in the bounds check to use this define.

Regards,

Hans

Quoted 43 lines

Thanks,
Srinivas

Quoted 38 lines

Regards,

Hans

Quoted 31 lines

        return pci_dev;
 }

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +0 -0
@@ -417,10 +429,19 @@ static int isst_if_cpu_info_init(void)
         if (!isst_cpu_info)
                 return -ENOMEM;


+       isst_pkg_info = kcalloc(topology_max_packages(), +                               sizeof(*isst_pkg_info), +                               GFP_KERNEL);
+       if (!isst_pkg_info) {
+               kfree(isst_cpu_info);
+               return -ENOMEM;
+       }
+
        ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "platform/x86/isst-if:online", isst_if_cpu_online, NULL); if (ret < 0) {
+               kfree(isst_pkg_info); kfree(isst_cpu_info);
                return ret;
        }

drivers/platform/x86/intel/speed_select_if/isst_if_common.c +1 -0
@@ -433,6 +454,7 @@ static int isst_if_cpu_info_init(void)
  static void isst_if_cpu_info_exit(void)
  {
         cpuhp_remove_state(isst_if_online_id);
+       kfree(isst_pkg_info);
         kfree(isst_cpu_info);
  };