* [PATCH 01/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor bus topology information
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 02/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_bus_topology sysfs interface file Kajol Jain
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
The hcall H_GET_PERF_COUNTER_INFO with counter request value as
PROCESSOR_BUS_TOPOLOGY(0XD0), can be used to get the system
topology information. To expose the system topology information,
patch adds sysfs file called "processor_bus_topology" to the
"/sys/devices/hv_gpci/interface/" of hv_gpci pmu driver.
Add macro for PROCESSOR_BUS_TOPOLOGY counter request value
in hv-gpci.h file. Also add a new function called
"systeminfo_gpci_request", to make the H_GET_PERF_COUNTER_INFO hcall
with added macro, and populates the output buffer.
The processor_bus_topology sysfs file is only available for power10
and above platforms. Add a new function called
"add_sysinfo_interface_files", which will add processor_bus_topology
attribute in the interface_attrs array, only for power10 and
above platforms.
Also add macro INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR in hv-gpci.h
file, which points to the index of NULL placefolder, for
processor_bus_topology attribute.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
arch/powerpc/perf/hv-gpci.c | 163 +++++++++++++++++++++++++++++++++++-
arch/powerpc/perf/hv-gpci.h | 6 ++
2 files changed, 167 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index 7ff8ff3509f5..bca24725699e 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -102,6 +102,141 @@ static ssize_t cpumask_show(struct device *dev,
return cpumap_print_to_pagebuf(true, buf, &hv_gpci_cpumask);
}
+static DEFINE_PER_CPU(char, hv_gpci_reqb[HGPCI_REQ_BUFFER_SIZE]) __aligned(sizeof(uint64_t));
+
+static unsigned long systeminfo_gpci_request(u32 req, u32 starting_index,
+ u16 secondary_index, char *buf,
+ size_t *n, struct hv_gpci_request_buffer *arg)
+{
+ unsigned long ret;
+ size_t i, j;
+
+ arg->params.counter_request = cpu_to_be32(req);
+ arg->params.starting_index = cpu_to_be32(starting_index);
+ arg->params.secondary_index = cpu_to_be16(secondary_index);
+
+ ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
+ virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL',
+ * which means that the current buffer size cannot accommodate
+ * all the information and a partial buffer returned.
+ * hcall fails incase of ret value other than H_SUCCESS or H_PARAMETER.
+ *
+ * ret value as H_AUTHORITY implies that partition is not permitted to retrieve
+ * performance information, and required to set
+ * "Enable Performance Information Collection" option.
+ */
+ if (ret == H_AUTHORITY)
+ return -EPERM;
+
+ /*
+ * ret value as H_NOT_AVAILABLE implies that requested system information is
+ * not available for the firmware level and platform.
+ */
+ if (ret == H_NOT_AVAILABLE)
+ return -EOPNOTSUPP;
+
+ /*
+ * hcall can fail with other possible ret value like H_PRIVILEGE/H_HARDWARE
+ * because of invalid buffer-length/address or due to some hardware
+ * error.
+ */
+ if (ret && (ret != H_PARAMETER))
+ return -EIO;
+
+ /*
+ * hcall H_GET_PERF_COUNTER_INFO populates the 'returned_values'
+ * to show the total number of counter_value array elements
+ * returned via hcall.
+ * hcall also populates 'cv_element_size' corresponds to individual
+ * counter_value array element size. Below loop go through all
+ * counter_value array elements as per their size and add it to
+ * the output buffer.
+ */
+ for (i = 0; i < be16_to_cpu(arg->params.returned_values); i++) {
+ j = i * be16_to_cpu(arg->params.cv_element_size);
+
+ for (; j < (i + 1) * be16_to_cpu(arg->params.cv_element_size); j++)
+ *n += sprintf(buf + *n, "%02x", (u8)arg->bytes[j]);
+ *n += sprintf(buf + *n, "\n");
+ }
+
+ if (*n >= PAGE_SIZE) {
+ pr_info("System information exceeds PAGE_SIZE\n");
+ return -EFBIG;
+ }
+
+ return ret;
+}
+
+static ssize_t processor_bus_topology_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct hv_gpci_request_buffer *arg;
+ unsigned long ret;
+ size_t n = 0;
+
+ arg = (void *)get_cpu_var(hv_gpci_reqb);
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * Pass the counter request value 0xD0 corresponds to request
+ * type 'Processor_bus_topology', to retrieve
+ * the system topology information.
+ * starting_index value implies the starting hardware
+ * chip id.
+ */
+ ret = systeminfo_gpci_request(PROCESSOR_BUS_TOPOLOGY, 0, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL', which
+ * implies that buffer can't accommodate all information, and a partial buffer
+ * returned. To handle that, we need to make subsequent requests
+ * with next starting index to retrieve additional (missing) data.
+ * Below loop do subsequent hcalls with next starting index and add it
+ * to buffer util we get all the information.
+ */
+ while (ret == H_PARAMETER) {
+ int returned_values = be16_to_cpu(arg->params.returned_values);
+ int elementsize = be16_to_cpu(arg->params.cv_element_size);
+ int last_element = (returned_values - 1) * elementsize;
+
+ /*
+ * Since the starting index value is part of counter_value
+ * buffer elements, use the starting index value in the last
+ * element and add 1 to make subsequent hcalls.
+ */
+ u32 starting_index = arg->bytes[last_element + 3] +
+ (arg->bytes[last_element + 2] << 8) +
+ (arg->bytes[last_element + 1] << 16) +
+ (arg->bytes[last_element] << 24) + 1;
+
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ ret = systeminfo_gpci_request(PROCESSOR_BUS_TOPOLOGY, starting_index,
+ 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+ }
+
+ return n;
+out:
+ put_cpu_var(hv_gpci_reqb);
+ return ret;
+}
+
static DEVICE_ATTR_RO(kernel_version);
static DEVICE_ATTR_RO(cpumask);
@@ -118,6 +253,11 @@ static struct attribute *interface_attrs[] = {
&hv_caps_attr_expanded.attr,
&hv_caps_attr_lab.attr,
&hv_caps_attr_collect_privileged.attr,
+ /*
+ * This NULL is a placeholder for the processor_bus_topology
+ * attribute, set in init function if applicable.
+ */
+ NULL,
NULL,
};
@@ -143,8 +283,6 @@ static const struct attribute_group *attr_groups[] = {
NULL,
};
-static DEFINE_PER_CPU(char, hv_gpci_reqb[HGPCI_REQ_BUFFER_SIZE]) __aligned(sizeof(uint64_t));
-
static unsigned long single_gpci_request(u32 req, u32 starting_index,
u16 secondary_index, u8 version_in, u32 offset, u8 length,
u64 *value)
@@ -325,6 +463,23 @@ static int hv_gpci_cpu_hotplug_init(void)
ppc_hv_gpci_cpu_offline);
}
+static void add_sysinfo_interface_files(void)
+{
+ struct device_attribute *attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+
+ if (!attr) {
+ pr_info("Memory allocation failed for processor_bug_topology interface file\n");
+ return;
+ }
+
+ /* Add processor_bus_topology attribute in the interface_attrs attribute array */
+ sysfs_attr_init(&attr->attr);
+ attr->attr.name = "processor_bug_topology";
+ attr->attr.mode = 0444;
+ attr->show = processor_bus_topology_show;
+ interface_attrs[INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR] = &attr->attr;
+}
+
static int hv_gpci_init(void)
{
int r;
@@ -388,6 +543,10 @@ static int hv_gpci_init(void)
if (r)
return r;
+ /* sysinfo interface files are only available for power10 and above platforms */
+ if (PVR_VER(mfspr(SPRN_PVR)) >= PVR_POWER10)
+ add_sysinfo_interface_files();
+
return 0;
}
diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
index c72020912dea..ff76bc010823 100644
--- a/arch/powerpc/perf/hv-gpci.h
+++ b/arch/powerpc/perf/hv-gpci.h
@@ -23,6 +23,12 @@ enum {
HV_GPCI_CM_LAB = (1 << 5)
};
+/* Counter request value to retrieve system information */
+#define PROCESSOR_BUS_TOPOLOGY 0XD0
+
+/* Interface attribute array index to store system information */
+#define INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR 6
+
#define REQUEST_FILE "../hv-gpci-requests.h"
#define NAME_LOWER hv_gpci
#define NAME_UPPER HV_GPCI
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 02/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_bus_topology sysfs interface file
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
2023-06-09 11:39 ` [PATCH 01/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor bus topology information Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 03/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor config information Kajol Jain
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
Add details of the new hv-gpci interface file called
"processor_bus_topology" in the ABI documentation.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
.../sysfs-bus-event_source-devices-hv_gpci | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
index 12e2bf92783f..6d633167268e 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
@@ -80,3 +80,32 @@ Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
Description: read only
This sysfs file exposes the cpumask which is designated to make
HCALLs to retrieve hv-gpci pmu event counter data.
+
+What: /sys/devices/hv_gpci/interface/processor_bus_topology
+Date: June 2023
+Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
+Description: admin read only
+ This sysfs file exposes the system topology information by making HCALL
+ H_GET_PERF_COUNTER_INFO. The HCALL is made with counter request value
+ PROCESSOR_BUS_TOPOLOGY(0xD0).
+ * This sysfs file is only be created for power10 and above platforms.
+ * User need root access to read data from this sysfs file.
+ * Incase the HCALL fails with hardware/permission issue, or the support for
+ PROCESSOR_BUS_TOPOLOGY counter request value removed, this sysfs file still be
+ created and give error when reading it.
+ * The end user reading this sysfs file need to decode sysfs file data as per
+ underneath platform/firmware.
+
+ Possible error codes while reading this sysfs file:
+
+ * "-EPERM" : Partition is not permitted to retrieve performance information,
+ required to set "Enable Performance Information Collection" option.
+
+ * "-EOPNOTSUPP" : Requested system information is not available for the firmware
+ level and platform.
+
+ * "-EIO" : Can't retrieve system information because of invalid buffer length/invalid address
+ or because of some hardware error. Refer getPerfCountInfo documentation for
+ more information.
+
+ * "-EFBIG" : System information exceeds PAGE_SIZE.
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 03/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor config information
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
2023-06-09 11:39 ` [PATCH 01/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor bus topology information Kajol Jain
2023-06-09 11:39 ` [PATCH 02/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_bus_topology sysfs interface file Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 04/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_config sysfs interface file Kajol Jain
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
The hcall H_GET_PERF_COUNTER_INFO with counter request value as
PROCESSOR_CONFIG(0X90), can be used to get the system
processor configuration information. To expose the system
processor config information, patch adds sysfs file called
"processor_config" to the "/sys/devices/hv_gpci/interface/"
of hv_gpci pmu driver.
Add macro for PROCESSOR_CONFIG counter request value in hv-gpci.h file.
Also add a new function called "sysinfo_device_attr_create",
which will create and add required device attribute to the
interface_attrs array.
The processor_config sysfs file is only available for power10
and above platforms. Add a new macro called
INTERFACE_PROCESSOR_CONFIG_ATTR, which points to the index of
NULL placefolder, for processor_config attribute in the interface_attrs
array. Also add macro INTERFACE_NULL_ATTR which points to index of NULL
attribute in interface_attrs array.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
arch/powerpc/perf/hv-gpci.c | 110 +++++++++++++++++++++++++++++++++---
arch/powerpc/perf/hv-gpci.h | 5 +-
2 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index bca24725699e..c9fe74373e5f 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -237,6 +237,72 @@ static ssize_t processor_bus_topology_show(struct device *dev, struct device_att
return ret;
}
+static ssize_t processor_config_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct hv_gpci_request_buffer *arg;
+ unsigned long ret;
+ size_t n = 0;
+
+ arg = (void *)get_cpu_var(hv_gpci_reqb);
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * Pass the counter request value 0x90 corresponds to request
+ * type 'Processor_config', to retrieve
+ * the system processor information.
+ * starting_index value implies the starting hardware
+ * processor index.
+ */
+ ret = systeminfo_gpci_request(PROCESSOR_CONFIG, 0, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL', which
+ * implies that buffer can't accommodate all information, and a partial buffer
+ * returned. To handle that, we need to take subsequent requests
+ * with next starting index to retrieve additional (missing) data.
+ * Below loop do subsequent hcalls with next starting index and add it
+ * to buffer util we get all the information.
+ */
+ while (ret == H_PARAMETER) {
+ int returned_values = be16_to_cpu(arg->params.returned_values);
+ int elementsize = be16_to_cpu(arg->params.cv_element_size);
+ int last_element = (returned_values - 1) * elementsize;
+
+ /*
+ * Since the starting index is part of counter_value
+ * buffer elements, use the starting index value in the last
+ * element and add 1 to subsequent hcalls.
+ */
+ u32 starting_index = arg->bytes[last_element + 3] +
+ (arg->bytes[last_element + 2] << 8) +
+ (arg->bytes[last_element + 1] << 16) +
+ (arg->bytes[last_element] << 24) + 1;
+
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ ret = systeminfo_gpci_request(PROCESSOR_CONFIG, starting_index, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+ }
+
+ return n;
+
+out:
+ put_cpu_var(hv_gpci_reqb);
+ return ret;
+}
+
static DEVICE_ATTR_RO(kernel_version);
static DEVICE_ATTR_RO(cpumask);
@@ -258,6 +324,11 @@ static struct attribute *interface_attrs[] = {
* attribute, set in init function if applicable.
*/
NULL,
+ /*
+ * This NULL is a placeholder for the processor_config
+ * attribute, set in init function if applicable.
+ */
+ NULL,
NULL,
};
@@ -463,21 +534,46 @@ static int hv_gpci_cpu_hotplug_init(void)
ppc_hv_gpci_cpu_offline);
}
-static void add_sysinfo_interface_files(void)
+static void sysinfo_device_attr_create(int sysinfo_interface_group_index)
{
- struct device_attribute *attr = kzalloc(sizeof(*attr), GFP_KERNEL);
+ struct device_attribute *attr;
+ if (sysinfo_interface_group_index < INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR ||
+ sysinfo_interface_group_index >= INTERFACE_NULL_ATTR) {
+ pr_info("Wrong interface group index for system information\n");
+ return;
+ }
+
+ attr = kzalloc(sizeof(*attr), GFP_KERNEL);
if (!attr) {
- pr_info("Memory allocation failed for processor_bug_topology interface file\n");
+ pr_info("Mem allocation failed, sysinfo index:%d\n", sysinfo_interface_group_index);
return;
}
- /* Add processor_bus_topology attribute in the interface_attrs attribute array */
sysfs_attr_init(&attr->attr);
- attr->attr.name = "processor_bug_topology";
+
+ switch (sysinfo_interface_group_index) {
+ case INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR:
+ attr->attr.name = "processor_bug_topology";
+ attr->show = processor_bus_topology_show;
+ break;
+ case INTERFACE_PROCESSOR_CONFIG_ATTR:
+ attr->attr.name = "processor_config";
+ attr->show = processor_config_show;
+ break;
+ }
+
attr->attr.mode = 0444;
- attr->show = processor_bus_topology_show;
- interface_attrs[INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR] = &attr->attr;
+ interface_attrs[sysinfo_interface_group_index] = &attr->attr;
+}
+
+static void add_sysinfo_interface_files(void)
+{
+ /* Add processor_bus_topology attribute in the interface_attrs attribute array */
+ sysinfo_device_attr_create(INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR);
+
+ /* Add processor_config attribute in the interface_attrs attribute array */
+ sysinfo_device_attr_create(INTERFACE_PROCESSOR_CONFIG_ATTR);
}
static int hv_gpci_init(void)
diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
index ff76bc010823..0d324a7c684b 100644
--- a/arch/powerpc/perf/hv-gpci.h
+++ b/arch/powerpc/perf/hv-gpci.h
@@ -24,10 +24,13 @@ enum {
};
/* Counter request value to retrieve system information */
-#define PROCESSOR_BUS_TOPOLOGY 0XD0
+#define PROCESSOR_BUS_TOPOLOGY 0XD0
+#define PROCESSOR_CONFIG 0X90
/* Interface attribute array index to store system information */
#define INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR 6
+#define INTERFACE_PROCESSOR_CONFIG_ATTR 7
+#define INTERFACE_NULL_ATTR 8
#define REQUEST_FILE "../hv-gpci-requests.h"
#define NAME_LOWER hv_gpci
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 04/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_config sysfs interface file
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (2 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 03/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show processor config information Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 05/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via virtual processor information Kajol Jain
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
Add details of the new hv-gpci interface file called
"processor_config" in the ABI documentation.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
.../sysfs-bus-event_source-devices-hv_gpci | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
index 6d633167268e..003d94afbbcd 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
@@ -109,3 +109,18 @@ Description: admin read only
more information.
* "-EFBIG" : System information exceeds PAGE_SIZE.
+
+What: /sys/devices/hv_gpci/interface/processor_config
+Date: June 2023
+Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
+Description: admin read only
+ This sysfs file exposes the system topology information by making HCALL
+ H_GET_PERF_COUNTER_INFO. The HCALL is made with counter request value
+ PROCESSOR_CONFIG(0x90).
+ * This sysfs file is only be created for power10 and above platforms.
+ * User need root access to read data from this sysfs file.
+ * Incase the HCALL fails with hardware/permission issue, or the support for
+ PROCESSOR_CONFIG counter request value removed, this sysfs file still be
+ created and give error when reading it.
+ * The end user reading this sysfs file need to decode sysfs file data as per
+ underneath platform/firmware.
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 05/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via virtual processor information
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (3 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 04/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document processor_config sysfs interface file Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 06/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_virtual_processor sysfs interface file Kajol Jain
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
The hcall H_GET_PERF_COUNTER_INFO with counter request value as
AFFINITY_DOMAIN_INFORMATION_BY_VIRTUAL_PROCESSOR(0XA0), can be used to get
the system affinity domain via virtual processor information. To expose
the system affinity domain via virtual processor information, patch adds
sysfs file called "affinity_domain_via_virtual_processor" to the
"/sys/devices/hv_gpci/interface/" of hv_gpci pmu driver.
Add macro for AFFINITY_DOMAIN_VIA_VP, which points to counter request value
for "affinity_domain_via_virtual_processor" in hv-gpci.h file.
The affinity_domain_via_virtual_processor sysfs file is only available for
power10 and above platforms. Add a macro called
INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR, which points to the index of NULL
placeholder, for affinity_domain_via_virtual_processor attribute in
interface_attrs array. Also updated the value of INTERFACE_NULL_ATTR macro
in hv-gpci.h file.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
arch/powerpc/perf/hv-gpci.c | 84 +++++++++++++++++++++++++++++++++++++
arch/powerpc/perf/hv-gpci.h | 4 +-
2 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index c9fe74373e5f..cac726f06221 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -303,6 +303,75 @@ static ssize_t processor_config_show(struct device *dev, struct device_attribute
return ret;
}
+static ssize_t affinity_domain_via_virtual_processor_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct hv_gpci_request_buffer *arg;
+ unsigned long ret;
+ size_t n = 0;
+
+ arg = (void *)get_cpu_var(hv_gpci_reqb);
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * Pass the counter request 0xA0 corresponds to request
+ * type 'Affinity_domain_information_by_virutal_processor',
+ * to retrieve the system affinity domain information.
+ * starting_index value refers to the starting hardware
+ * processor index.
+ */
+ ret = systeminfo_gpci_request(AFFINITY_DOMAIN_VIA_VP, 0, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL', which
+ * implies that buffer can't accommodate all information, and a partial buffer
+ * returned. To handle that, we need to take subsequent requests
+ * with next secondary index to retrieve additional (missing) data.
+ * Below loop do subsequent hcalls with next secondary index and add it
+ * to buffer util we get all the information.
+ */
+ while (ret == H_PARAMETER) {
+ int returned_values = be16_to_cpu(arg->params.returned_values);
+ int elementsize = be16_to_cpu(arg->params.cv_element_size);
+ int last_element = (returned_values - 1) * elementsize;
+
+ /*
+ * Since the starting index and secondary index type is part of the
+ * counter_value buffer elements, use the starting index value in the
+ * last array element as subsequent starting index, and use secondary index
+ * value in the last array element plus 1 as subsequent secondary index.
+ * For counter request '0xA0', starting index points to partition id
+ * and secondary index points to corresponding virtual processor index.
+ */
+ u32 starting_index = arg->bytes[last_element + 1] + (arg->bytes[last_element] << 8);
+ u16 secondary_index = arg->bytes[last_element + 3] +
+ (arg->bytes[last_element + 2] << 8) + 1;
+
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ ret = systeminfo_gpci_request(AFFINITY_DOMAIN_VIA_VP, starting_index,
+ secondary_index, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+ }
+
+ return n;
+
+out:
+ put_cpu_var(hv_gpci_reqb);
+ return ret;
+}
+
static DEVICE_ATTR_RO(kernel_version);
static DEVICE_ATTR_RO(cpumask);
@@ -329,6 +398,11 @@ static struct attribute *interface_attrs[] = {
* attribute, set in init function if applicable.
*/
NULL,
+ /*
+ * This NULL is a placeholder for the affinity_domain_via_virtual_processor
+ * attribute, set in init function if applicable.
+ */
+ NULL,
NULL,
};
@@ -561,6 +635,10 @@ static void sysinfo_device_attr_create(int sysinfo_interface_group_index)
attr->attr.name = "processor_config";
attr->show = processor_config_show;
break;
+ case INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR:
+ attr->attr.name = "affinity_domain_via_virtual_processor";
+ attr->show = affinity_domain_via_virtual_processor_show;
+ break;
}
attr->attr.mode = 0444;
@@ -574,6 +652,12 @@ static void add_sysinfo_interface_files(void)
/* Add processor_config attribute in the interface_attrs attribute array */
sysinfo_device_attr_create(INTERFACE_PROCESSOR_CONFIG_ATTR);
+
+ /*
+ * Add affinity_domain_via_virtual_processor attribute in the
+ * interface_attrs attribute array
+ */
+ sysinfo_device_attr_create(INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR);
}
static int hv_gpci_init(void)
diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
index 0d324a7c684b..c88599fbcaa5 100644
--- a/arch/powerpc/perf/hv-gpci.h
+++ b/arch/powerpc/perf/hv-gpci.h
@@ -26,11 +26,13 @@ enum {
/* Counter request value to retrieve system information */
#define PROCESSOR_BUS_TOPOLOGY 0XD0
#define PROCESSOR_CONFIG 0X90
+#define AFFINITY_DOMAIN_VIA_VP 0xA0 /* affinity domain via virtual processor */
/* Interface attribute array index to store system information */
#define INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR 6
#define INTERFACE_PROCESSOR_CONFIG_ATTR 7
-#define INTERFACE_NULL_ATTR 8
+#define INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR 8
+#define INTERFACE_NULL_ATTR 9
#define REQUEST_FILE "../hv-gpci-requests.h"
#define NAME_LOWER hv_gpci
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 06/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_virtual_processor sysfs interface file
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (4 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 05/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via virtual processor information Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 07/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via domain information Kajol Jain
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
Add details of the new hv-gpci interface file called
"affinity_domain_via_virtual_processor" in the ABI documentation.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
.../sysfs-bus-event_source-devices-hv_gpci | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
index 003d94afbbcd..d8862808c955 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
@@ -124,3 +124,18 @@ Description: admin read only
created and give error when reading it.
* The end user reading this sysfs file need to decode sysfs file data as per
underneath platform/firmware.
+
+What: /sys/devices/hv_gpci/interface/affinity_domain_via_virtual_processor
+Date: June 2023
+Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
+Description: admin read only
+ This sysfs file exposes the system topology information by making HCALL
+ H_GET_PERF_COUNTER_INFO. The HCALL is made with counter request value
+ AFFINITY_DOMAIN_INFORMATION_BY_VIRTUAL_PROCESSOR(0xA0).
+ * This sysfs file is only be created for power10 and above platforms.
+ * User need root access to read data from this sysfs file.
+ * Incase the HCALL fails with hardware/permission issue, or the support for
+ AFFINITY_DOMAIN_INFORMATION_BY_VIRTUAL_PROCESSOR counter request value
+ removed, this sysfs file still be created and give error when reading it.
+ * The end user reading this sysfs file need to decode sysfs file data as per
+ underneath platform/firmware.
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 07/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via domain information
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (5 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 06/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_virtual_processor sysfs interface file Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:39 ` [PATCH 08/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_domain sysfs interface file Kajol Jain
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
The hcall H_GET_PERF_COUNTER_INFO with counter request value as
AFFINITY_DOMAIN_INFORMATION_BY_DOMAIN(0XB0), can be used to get
the system affinity domain via domain information. To expose the system
affinity domain via domain information, patch adds sysfs file called
"affinity_domain_via_domain" to the "/sys/devices/hv_gpci/interface/"
of hv_gpci pmu driver.
Add macro for AFFINITY_DOMAIN_VIA_DOM, which points to the counter
request value for "affinity_domain_via_domain" in hv-gpci.h file.
The affinity_domain_via_domain sysfs file is only available for power10
and above platforms. Add a macro called
INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR, which points to the index of NULL
placeholder, for affinity_domain_via_domain attribute in interface_attrs
array. Also updated the value of INTERFACE_NULL_ATTR macro in hv-gpci.h
file.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
arch/powerpc/perf/hv-gpci.c | 77 +++++++++++++++++++++++++++++++++++++
arch/powerpc/perf/hv-gpci.h | 4 +-
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index cac726f06221..b18f6f2d15b0 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -372,6 +372,71 @@ static ssize_t affinity_domain_via_virtual_processor_show(struct device *dev,
return ret;
}
+static ssize_t affinity_domain_via_domain_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct hv_gpci_request_buffer *arg;
+ unsigned long ret;
+ size_t n = 0;
+
+ arg = (void *)get_cpu_var(hv_gpci_reqb);
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * Pass the counter request 0xB0 corresponds to request
+ * type 'Affinity_domain_information_by_domain',
+ * to retrieve the system affinity domain information.
+ * starting_index value refers to the starting hardware
+ * processor index.
+ */
+ ret = systeminfo_gpci_request(AFFINITY_DOMAIN_VIA_DOM, 0, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL', which
+ * implies that buffer can't accommodate all information, and a partial buffer
+ * returned. To handle that, we need to take subsequent requests
+ * with next starting index to retrieve additional (missing) data.
+ * Below loop do subsequent hcalls with next starting index and add it
+ * to buffer util we get all the information.
+ */
+ while (ret == H_PARAMETER) {
+ int returned_values = be16_to_cpu(arg->params.returned_values);
+ int elementsize = be16_to_cpu(arg->params.cv_element_size);
+ int last_element = (returned_values - 1) * elementsize;
+
+ /*
+ * Since the starting index value is part of counter_value
+ * buffer elements, use the starting index value in the last
+ * element and add 1 to make subsequent hcalls.
+ */
+ u32 starting_index = arg->bytes[last_element + 1] +
+ (arg->bytes[last_element] << 8) + 1;
+
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ ret = systeminfo_gpci_request(AFFINITY_DOMAIN_VIA_DOM,
+ starting_index, 0, buf, &n, arg);
+
+ if (!ret)
+ return n;
+
+ if (ret != H_PARAMETER)
+ goto out;
+ }
+
+ return n;
+
+out:
+ put_cpu_var(hv_gpci_reqb);
+ return ret;
+}
+
static DEVICE_ATTR_RO(kernel_version);
static DEVICE_ATTR_RO(cpumask);
@@ -403,6 +468,11 @@ static struct attribute *interface_attrs[] = {
* attribute, set in init function if applicable.
*/
NULL,
+ /*
+ * This NULL is a placeholder for the affinity_domain_via_domain
+ * attribute, set in init function if applicable.
+ */
+ NULL,
NULL,
};
@@ -639,6 +709,10 @@ static void sysinfo_device_attr_create(int sysinfo_interface_group_index)
attr->attr.name = "affinity_domain_via_virtual_processor";
attr->show = affinity_domain_via_virtual_processor_show;
break;
+ case INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR:
+ attr->attr.name = "affinity_domain_via_domain";
+ attr->show = affinity_domain_via_domain_show;
+ break;
}
attr->attr.mode = 0444;
@@ -658,6 +732,9 @@ static void add_sysinfo_interface_files(void)
* interface_attrs attribute array
*/
sysinfo_device_attr_create(INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR);
+
+ /* Add affinity_domain_via_domain attribute in the interface_attrs attribute array */
+ sysinfo_device_attr_create(INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR);
}
static int hv_gpci_init(void)
diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
index c88599fbcaa5..f01c4716ac33 100644
--- a/arch/powerpc/perf/hv-gpci.h
+++ b/arch/powerpc/perf/hv-gpci.h
@@ -27,12 +27,14 @@ enum {
#define PROCESSOR_BUS_TOPOLOGY 0XD0
#define PROCESSOR_CONFIG 0X90
#define AFFINITY_DOMAIN_VIA_VP 0xA0 /* affinity domain via virtual processor */
+#define AFFINITY_DOMAIN_VIA_DOM 0xB0 /* affinity domain via domain */
/* Interface attribute array index to store system information */
#define INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR 6
#define INTERFACE_PROCESSOR_CONFIG_ATTR 7
#define INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR 8
-#define INTERFACE_NULL_ATTR 9
+#define INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR 9
+#define INTERFACE_NULL_ATTR 10
#define REQUEST_FILE "../hv-gpci-requests.h"
#define NAME_LOWER hv_gpci
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 08/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_domain sysfs interface file
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (6 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 07/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via domain information Kajol Jain
@ 2023-06-09 11:39 ` Kajol Jain
2023-06-09 11:40 ` [PATCH 09/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via partition information Kajol Jain
2023-06-09 11:40 ` [PATCH 10/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_partition sysfs interface file Kajol Jain
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:39 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
Add details of the new hv-gpci interface file called
"affinity_domain_via_domain" in the ABI documentation.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
.../sysfs-bus-event_source-devices-hv_gpci | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
index d8862808c955..1a5636ed3a4b 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
@@ -139,3 +139,18 @@ Description: admin read only
removed, this sysfs file still be created and give error when reading it.
* The end user reading this sysfs file need to decode sysfs file data as per
underneath platform/firmware.
+
+What: /sys/devices/hv_gpci/interface/affinity_domain_via_domain
+Date: June 2023
+Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
+Description: admin read only
+ This sysfs file exposes the system topology information by making HCALL
+ H_GET_PERF_COUNTER_INFO. The HCALL is made with counter request value
+ AFFINITY_DOMAIN_INFORMATION_BY_DOMAIN(0xB0).
+ * This sysfs file is only be created for power10 and above platforms.
+ * User need root access to read data from this sysfs file.
+ * Incase the HCALL fails with hardware/permission issue, or the support for
+ AFFINITY_DOMAIN_INFORMATION_BY_DOMAIN counter request value
+ removed, this sysfs file still be created and give error when reading it.
+ * The end user reading this sysfs file need to decode sysfs file data as per
+ underneath platform/firmware.
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 09/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via partition information
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (7 preceding siblings ...)
2023-06-09 11:39 ` [PATCH 08/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_domain sysfs interface file Kajol Jain
@ 2023-06-09 11:40 ` Kajol Jain
2023-06-09 11:40 ` [PATCH 10/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_partition sysfs interface file Kajol Jain
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:40 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
The hcall H_GET_PERF_COUNTER_INFO with counter request value as
AFFINITY_DOMAIN_INFORMATION_BY_PARTITION(0XB1), can be used to get
the system affinity domain via partition information. To expose the system
affinity domain via partition information, patch adds sysfs file called
"affinity_domain_via_partition" to the "/sys/devices/hv_gpci/interface/"
of hv_gpci pmu driver.
Add macro AFFINITY_DOMAIN_VIA_PAR, which points to the counter request
value for "affinity_domain_via_partition", in hv-gpci.h file. Also add a
new function called "affinity_domain_via_partition_result_parse" to parse
the hcall result and store it in output buffer.
The affinity_domain_via_partition sysfs file is only available for power10
and above platforms. Add a macro called
INTERFACE_AFFINITY_DOMAIN_VIA_PAR_ATTR, which points to the index of NULL
placeholder, for affinity_domain_via_partition attribute in
interface_attrs array. Also updated the value of INTERFACE_NULL_ATTR
macro in hv-gpci.h file.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
arch/powerpc/perf/hv-gpci.c | 164 ++++++++++++++++++++++++++++++++++++
arch/powerpc/perf/hv-gpci.h | 4 +-
2 files changed, 167 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
index b18f6f2d15b0..6e57c6065010 100644
--- a/arch/powerpc/perf/hv-gpci.c
+++ b/arch/powerpc/perf/hv-gpci.c
@@ -437,6 +437,158 @@ static ssize_t affinity_domain_via_domain_show(struct device *dev, struct device
return ret;
}
+static void affinity_domain_via_partition_result_parse(int returned_values,
+ int element_size, char *buf, size_t *last_element,
+ size_t *n, struct hv_gpci_request_buffer *arg)
+{
+ size_t i = 0, j = 0;
+ size_t k, l, m;
+ uint16_t total_affinity_domain_ele, size_of_each_affinity_domain_ele;
+
+ /*
+ * hcall H_GET_PERF_COUNTER_INFO populates the 'returned_values'
+ * to show the total number of counter_value array elements
+ * returned via hcall.
+ * Unlike other request types, the data structure returned by this
+ * request is variable-size. For this counter request type,
+ * hcall populates 'cv_element_size' corresponds to minimum size of
+ * the structure returned i.e; the size of the structure with no domain
+ * information. Below loop go through all counter_value array
+ * to determine the number and size of each domain array element and
+ * add it to the output buffer.
+ */
+ while (i < returned_values) {
+ k = j;
+ for (; k < j + element_size; k++)
+ *n += sprintf(buf + *n, "%02x", (u8)arg->bytes[k]);
+ *n += sprintf(buf + *n, "\n");
+
+ total_affinity_domain_ele = (u8)arg->bytes[k - 2] << 8 | (u8)arg->bytes[k - 3];
+ size_of_each_affinity_domain_ele = (u8)arg->bytes[k] << 8 | (u8)arg->bytes[k - 1];
+
+ for (l = 0; l < total_affinity_domain_ele; l++) {
+ for (m = 0; m < size_of_each_affinity_domain_ele; m++) {
+ *n += sprintf(buf + *n, "%02x", (u8)arg->bytes[k]);
+ k++;
+ }
+ *n += sprintf(buf + *n, "\n");
+ }
+
+ *n += sprintf(buf + *n, "\n");
+ i++;
+ j = k;
+ }
+
+ *last_element = k;
+}
+
+static ssize_t affinity_domain_via_partition_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct hv_gpci_request_buffer *arg;
+ unsigned long ret;
+ size_t n = 0;
+ size_t last_element = 0;
+ u32 starting_index;
+
+ arg = (void *)get_cpu_var(hv_gpci_reqb);
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+
+ /*
+ * Pass the counter request value 0xB1 corresponds to counter request
+ * type 'Affinity_domain_information_by_partition',
+ * to retrieve the system affinity domain by partition information.
+ * starting_index value refers to the starting hardware
+ * processor index.
+ */
+ arg->params.counter_request = cpu_to_be32(AFFINITY_DOMAIN_VIA_PAR);
+ arg->params.starting_index = cpu_to_be32(0);
+
+ ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
+ virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
+
+ if (!ret)
+ goto parse_result;
+
+ /*
+ * ret value as 'H_PARAMETER' implies that the current buffer size
+ * can't accommodate all the information, and a partial buffer
+ * returned. To handle that, we need to make subsequent requests
+ * with next starting index to retrieve additional (missing) data.
+ * Below loop do subsequent hcalls with next starting index and add it
+ * to buffer util we get all the information.
+ */
+ while (ret == H_PARAMETER) {
+ affinity_domain_via_partition_result_parse(
+ be16_to_cpu(arg->params.returned_values) - 1,
+ be16_to_cpu(arg->params.cv_element_size), buf,
+ &last_element, &n, arg);
+
+ if (n >= PAGE_SIZE) {
+ put_cpu_var(hv_gpci_reqb);
+ pr_debug("System information exceeds PAGE_SIZE\n");
+ return -EFBIG;
+ }
+
+ /*
+ * Since the starting index value is part of counter_value
+ * buffer elements, use the starting_index value in the last
+ * element and add 1 to make subsequent hcalls.
+ */
+ starting_index = (u8)arg->bytes[last_element] << 8 |
+ (u8)arg->bytes[last_element + 1];
+
+ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
+ arg->params.counter_request = cpu_to_be32(AFFINITY_DOMAIN_VIA_PAR);
+ arg->params.starting_index = cpu_to_be32(starting_index);
+
+ ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
+ virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
+
+ if (ret && (ret != H_PARAMETER))
+ goto out;
+ }
+
+parse_result:
+ affinity_domain_via_partition_result_parse(
+ be16_to_cpu(arg->params.returned_values),
+ be16_to_cpu(arg->params.cv_element_size),
+ buf, &last_element, &n, arg);
+
+ put_cpu_var(hv_gpci_reqb);
+ return n;
+
+out:
+ put_cpu_var(hv_gpci_reqb);
+
+ /*
+ * ret value as 'H_PARAMETER' corresponds to 'GEN_BUF_TOO_SMALL',
+ * which means that the current buffer size cannot accommodate
+ * all the information and a partial buffer returned.
+ * hcall fails incase of ret value other than H_SUCCESS or H_PARAMETER.
+ *
+ * ret value as H_AUTHORITY implies that partition is not permitted to retrieve
+ * performance information, and required to set
+ * "Enable Performance Information Collection" option.
+ */
+ if (ret == H_AUTHORITY)
+ return -EPERM;
+
+ /*
+ * ret value as H_NOT_AVAILABLE implies that requested system information is
+ * not available for the firmware level and platform.
+ */
+ if (ret == H_NOT_AVAILABLE)
+ return -EOPNOTSUPP;
+
+ /*
+ * hcall can fail with other possible ret value like H_PRIVILEGE/H_HARDWARE
+ * because of invalid buffer-length/address or due to some hardware
+ * error.
+ */
+ return -EIO;
+}
+
static DEVICE_ATTR_RO(kernel_version);
static DEVICE_ATTR_RO(cpumask);
@@ -473,6 +625,11 @@ static struct attribute *interface_attrs[] = {
* attribute, set in init function if applicable.
*/
NULL,
+ /*
+ * This NULL is a placeholder for the affinity_domain_via_partition
+ * attribute, set in init function if applicable.
+ */
+ NULL,
NULL,
};
@@ -713,6 +870,10 @@ static void sysinfo_device_attr_create(int sysinfo_interface_group_index)
attr->attr.name = "affinity_domain_via_domain";
attr->show = affinity_domain_via_domain_show;
break;
+ case INTERFACE_AFFINITY_DOMAIN_VIA_PAR_ATTR:
+ attr->attr.name = "affinity_domain_via_partition";
+ attr->show = affinity_domain_via_partition_show;
+ break;
}
attr->attr.mode = 0444;
@@ -735,6 +896,9 @@ static void add_sysinfo_interface_files(void)
/* Add affinity_domain_via_domain attribute in the interface_attrs attribute array */
sysinfo_device_attr_create(INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR);
+
+ /* Add affinity_domain_via_partition attribute in the interface_attrs attribute array */
+ sysinfo_device_attr_create(INTERFACE_AFFINITY_DOMAIN_VIA_PAR_ATTR);
}
static int hv_gpci_init(void)
diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
index f01c4716ac33..c293f6c2b66c 100644
--- a/arch/powerpc/perf/hv-gpci.h
+++ b/arch/powerpc/perf/hv-gpci.h
@@ -28,13 +28,15 @@ enum {
#define PROCESSOR_CONFIG 0X90
#define AFFINITY_DOMAIN_VIA_VP 0xA0 /* affinity domain via virtual processor */
#define AFFINITY_DOMAIN_VIA_DOM 0xB0 /* affinity domain via domain */
+#define AFFINITY_DOMAIN_VIA_PAR 0xB1 /* affinity domain via partition */
/* Interface attribute array index to store system information */
#define INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR 6
#define INTERFACE_PROCESSOR_CONFIG_ATTR 7
#define INTERFACE_AFFINITY_DOMAIN_VIA_VP_ATTR 8
#define INTERFACE_AFFINITY_DOMAIN_VIA_DOM_ATTR 9
-#define INTERFACE_NULL_ATTR 10
+#define INTERFACE_AFFINITY_DOMAIN_VIA_PAR_ATTR 10
+#define INTERFACE_NULL_ATTR 11
#define REQUEST_FILE "../hv-gpci-requests.h"
#define NAME_LOWER hv_gpci
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 10/10] docs: ABI: sysfs-bus-event_source-devices-hv_gpci: Document affinity_domain_via_partition sysfs interface file
2023-06-09 11:39 [PATCH 00/10] Add sysfs interface files to hv_gpci device to expose system information Kajol Jain
` (8 preceding siblings ...)
2023-06-09 11:40 ` [PATCH 09/10] powerpc/hv_gpci: Add sysfs file inside hv_gpci device to show affinity domain via partition information Kajol Jain
@ 2023-06-09 11:40 ` Kajol Jain
9 siblings, 0 replies; 11+ messages in thread
From: Kajol Jain @ 2023-06-09 11:40 UTC (permalink / raw)
To: mpe; +Cc: disgoel, kjain, atrajeev, maddy, linuxppc-dev
Add details of the new hv-gpci interface file called
"affinity_domain_via_partition" in the ABI documentation.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
---
.../sysfs-bus-event_source-devices-hv_gpci | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
index 1a5636ed3a4b..6bca74cf3220 100644
--- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
+++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-hv_gpci
@@ -154,3 +154,18 @@ Description: admin read only
removed, this sysfs file still be created and give error when reading it.
* The end user reading this sysfs file need to decode sysfs file data as per
underneath platform/firmware.
+
+What: /sys/devices/hv_gpci/interface/affinity_domain_via_partition
+Date: June 2023
+Contact: Linux on PowerPC Developer List <linuxppc-dev@lists.ozlabs.org>
+Description: admin read only
+ This sysfs file exposes the system topology information by making HCALL
+ H_GET_PERF_COUNTER_INFO. The HCALL is made with counter request value
+ AFFINITY_DOMAIN_INFORMATION_BY_PARTITION(0xB1).
+ * This sysfs file is only be created for power10 and above platforms.
+ * User need root access to read data from this sysfs file.
+ * Incase the HCALL fails with hardware/permission issue, or the support for
+ AFFINITY_DOMAIN_INFORMATION_BY_PARTITION counter request value
+ removed, this sysfs file still be created and give error when reading it.
+ * The end user reading this sysfs file need to decode sysfs file data as per
+ underneath platform/firmware.
--
2.35.3
^ permalink raw reply related [flat|nested] 11+ messages in thread