/* * Example usage: * perf stat -e 'hv_gpci/counter_info_version=3,offset=0,length=8, * secondary_index=0,starting_index=0xffffffff,request=0x10/' ...
*/
/* u32 */
EVENT_DEFINE_RANGE_FORMAT(request, config, 0, 31); /* u32 */ /* * Note that starting_index, phys_processor_idx, sibling_part_id, * hw_chip_id, partition_id all refer to the same bit range. They * are basically aliases for the starting_index. The specific alias * used depends on the event. See REQUEST_IDX_KIND in hv-gpci-requests.h
*/
EVENT_DEFINE_RANGE_FORMAT(starting_index, config, 32, 63);
EVENT_DEFINE_RANGE_FORMAT_LITE(phys_processor_idx, config, 32, 63);
EVENT_DEFINE_RANGE_FORMAT_LITE(sibling_part_id, config, 32, 63);
EVENT_DEFINE_RANGE_FORMAT_LITE(hw_chip_id, config, 32, 63);
EVENT_DEFINE_RANGE_FORMAT_LITE(partition_id, config, 32, 63);
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;
/* * 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);
/* * 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(sysinfo_counter_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(sysinfo_counter_request[PROCESSOR_BUS_TOPOLOGY],
starting_index, 0, buf, &n, arg);
/* * 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(sysinfo_counter_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(sysinfo_counter_request[PROCESSOR_CONFIG],
starting_index, 0, buf, &n, arg);
/* * 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(sysinfo_counter_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(sysinfo_counter_request[AFFINITY_DOMAIN_VIA_VP],
starting_index, secondary_index, buf, &n, arg);
/* * 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(sysinfo_counter_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(sysinfo_counter_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;
}
staticvoid 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");
/* * 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(sysinfo_counter_request[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;
if (ret && (ret != H_PARAMETER)) goto out;
/* * 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];
/* * 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;
/* * 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;
}
staticstruct attribute *interface_attrs[] = {
&dev_attr_kernel_version.attr,
&hv_caps_attr_version.attr,
&hv_caps_attr_ga.attr,
&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, /* * This NULL is a placeholder for the processor_config * 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, /* * This NULL is a placeholder for the affinity_domain_via_domain * 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,
};
ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
/* * ret value as 'H_PARAMETER' with detail_rc as 'GEN_BUF_TOO_SMALL', * specifies that the current buffer size cannot accommodate * all the information and a partial buffer returned. * Since in this function we are only accessing data for a given starting index, * we don't need to accommodate whole data and can get required count by * accessing first entry data. * Hence hcall fails only incase the ret value is other than H_SUCCESS or * H_PARAMETER with detail_rc value as GEN_BUF_TOO_SMALL(0x1B).
*/ if (ret == H_PARAMETER && be32_to_cpu(arg->params.detail_rc) == 0x1B)
ret = 0;
if (ret) {
pr_devel("hcall failed: 0x%lx\n", ret); goto out;
}
/* * we verify offset and length are within the zeroed buffer at event * init.
*/
count = 0; for (i = offset; i < offset + length; i++)
count |= (u64)(arg->bytes[i]) << ((length - 1 - (i - offset)) * 8);
/* last byte within the buffer? */ if ((event_get_offset(event) + length) > HGPCI_MAX_DATA_BYTES) {
pr_devel("request outside of buffer: %zu > %zu\n",
(size_t)event_get_offset(event) + length,
HGPCI_MAX_DATA_BYTES); return -EINVAL;
}
/* check if the request works... */
ret = single_gpci_request(event_get_request(event),
event_get_starting_index(event),
event_get_secondary_index(event),
event_get_counter_info_version(event),
event_get_offset(event),
length,
&count);
/* * 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;
if (ret) {
pr_devel("gpci hcall failed\n"); return -EINVAL;
}
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 NULL;
}
/* Check for given counter request value support */
arg = (void *)get_cpu_var(hv_gpci_reqb);
memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
arg->params.counter_request = cpu_to_be32(req);
ret = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
put_cpu_var(hv_gpci_reqb);
/* * Add given counter request value attribute in the interface_attrs * attribute array, only for valid return types.
*/ if (!ret || ret == H_AUTHORITY || ret == H_PARAMETER) {
attr = kzalloc(sizeof(*attr), GFP_KERNEL); if (!attr) return NULL;
/* Get device attribute for a given counter request value */ for (i = 0; i < sysfs_count; i++) {
attr[i] = sysinfo_device_attr_create(i + INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR,
sysinfo_counter_request[i]);
if (!attr[i]) goto out;
}
/* Add sysinfo interface attributes in the interface_attrs attribute array */ for (i = 0; i < sysfs_count; i++)
interface_attrs[i + INTERFACE_PROCESSOR_BUS_TOPOLOGY_ATTR] = &attr[i]->attr;
return;
out: /* * The sysinfo interface attributes will be added, only if hcall passed for * all the counter request values. Free the device attribute array incase * of any hcall failure.
*/ if (i > 0) { while (i >= 0) {
kfree(attr[i]);
i--;
}
}
}
/* * hcall H_GET_PERF_COUNTER_INFO populates the output * counter_info_version value based on the system hypervisor. * Pass the counter request 0x10 corresponds to request type * 'Dispatch_timebase_by_processor', to get the supported * counter_info_version.
*/
arg->params.counter_request = cpu_to_be32(0x10);
r = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE); if (r) {
pr_devel("hcall failed, can't get supported counter_info_version: 0x%x\n", r);
arg->params.counter_info_version_out = 0x8;
}
/* * Use counter_info_version_out value to assign * required hv-gpci event list.
*/ if (arg->params.counter_info_version_out >= 0x8)
event_group.attrs = hv_gpci_event_attrs; else
event_group.attrs = hv_gpci_event_attrs_v6;
put_cpu_var(hv_gpci_reqb);
r = perf_pmu_register(&h_gpci_pmu, h_gpci_pmu.name, -1); 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;
}
device_initcall(hv_gpci_init);
Messung V0.5
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.