mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libcpumf: Function to return PMU name
Return the PMU name as found in the sysfs tree given a PMU type number. Signed-off-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
acdce2a7a9
commit
a58460b5c7
@@ -30,6 +30,20 @@
|
||||
*/
|
||||
int libcpumf_pmutype(const char *dirname);
|
||||
|
||||
/**
|
||||
* Read out the PMU name from a given type.
|
||||
*
|
||||
* Return the PMU name this PMU was registered in kernel. If the PMU was
|
||||
* registered without a name, it is not listed in the directory.
|
||||
* The caller must free the memory returned by name.
|
||||
*
|
||||
* @param[in] wanted_type Type number of the PMU
|
||||
* @param[out] name Name of the PMU (when retval is 0)
|
||||
* @retval 0 PMU wanted_type detected and PMU name valid
|
||||
* @retval -1 No PMU with wanted_type
|
||||
*/
|
||||
int libcpumf_pmuname(unsigned int wanted_type, char **name);
|
||||
|
||||
/**
|
||||
* Read out the CPU list from a given file name, for example from files
|
||||
* /sys/devices/system/cpu/online or /sys/devices/system/cpu/possible.
|
||||
|
||||
@@ -13,7 +13,7 @@ $(lib): $(objects)
|
||||
|
||||
install: all
|
||||
|
||||
libcpumf_example: libcpumf_example.o $(lib)
|
||||
libcpumf_example: libcpumf_example.o $(lib) $(rootdir)/libutil/libutil.a
|
||||
|
||||
clean:
|
||||
rm -f *.o $(lib) $(examples)
|
||||
|
||||
@@ -14,6 +14,7 @@ int main(void)
|
||||
{
|
||||
unsigned long min, max, speed, sfb_min, sfb_max;
|
||||
int rc, pmu, cfvn, csvn, auth;
|
||||
char *pmuname;
|
||||
cpu_set_t set;
|
||||
|
||||
pmu = libcpumf_pmutype(S390_CPUMF_CF);
|
||||
@@ -74,5 +75,13 @@ int main(void)
|
||||
putchar('\n');
|
||||
|
||||
printf("PAI crypto support %d\n", libcpumf_have_pai_crypto());
|
||||
|
||||
rc = libcpumf_pmuname(10, &pmuname);
|
||||
if (rc) {
|
||||
printf("PMU type 10 PMU name lookup error %d\n", rc);
|
||||
} else {
|
||||
printf("PMU type 10 PMU name %s\n", pmuname);
|
||||
free(pmuname);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,16 @@
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib/util_file.h"
|
||||
#include "lib/util_libc.h"
|
||||
#include "lib/util_path.h"
|
||||
#include "lib/util_scandir.h"
|
||||
#include "lib/libcpumf.h"
|
||||
|
||||
int libcpumf_pmutype(const char *dirname)
|
||||
@@ -31,3 +37,36 @@ int libcpumf_pmutype(const char *dirname)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int libcpumf_pmuname(unsigned int wanted_type, char **name)
|
||||
{
|
||||
struct dirent **de_vec;
|
||||
unsigned int type;
|
||||
char *dirname;
|
||||
char *path;
|
||||
int count;
|
||||
int rc;
|
||||
|
||||
path = util_path_sysfs("devices");
|
||||
count = util_scandir(&de_vec, alphasort, path, "(pai|cpum_).*");
|
||||
free(path);
|
||||
|
||||
*name = NULL;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (de_vec[i]->d_type == DT_DIR) {
|
||||
dirname = de_vec[i]->d_name;
|
||||
path = util_path_sysfs("devices/%s/type", dirname);
|
||||
rc = util_file_read_ui(&type, 10, path);
|
||||
if (rc)
|
||||
warn("Failed to open %s", path);
|
||||
free(path);
|
||||
if (!rc && type == wanted_type) {
|
||||
*name = util_strdup(dirname);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
util_scandir_free(de_vec, count);
|
||||
return *name ? 0 : -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user