-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf pmu: Save detected hybrid pmus to a global pmu list
We identify the cpu_core pmu and cpu_atom pmu by explicitly checking following files: For cpu_core, checks: "/sys/bus/event_source/devices/cpu_core/cpus" For cpu_atom, checks: "/sys/bus/event_source/devices/cpu_atom/cpus" If the 'cpus' file exists and it has data, the pmu exists. But in order not to hardcode the "cpu_core" and "cpu_atom", and make the code in a generic way. So if the path "/sys/bus/event_source/devices/cpu_xxx/cpus" exists, the hybrid pmu exists. All the detected hybrid pmus are linked to a global list 'perf_pmu__hybrid_pmus' and then next we just need to iterate the list to get all hybrid pmu by using perf_pmu__for_each_hybrid_pmu. Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Reviewed-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20210427070139.25256-6-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
- Loading branch information
Jin Yao
authored and
Arnaldo Carvalho de Melo
committed
Apr 29, 2021
1 parent
32705de
commit 4446243
Showing
5 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/list.h> | ||
#include <linux/compiler.h> | ||
#include <linux/string.h> | ||
#include <linux/zalloc.h> | ||
#include <sys/types.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <stdarg.h> | ||
#include <locale.h> | ||
#include <api/fs/fs.h> | ||
#include "fncache.h" | ||
#include "pmu-hybrid.h" | ||
|
||
LIST_HEAD(perf_pmu__hybrid_pmus); | ||
|
||
bool perf_pmu__hybrid_mounted(const char *name) | ||
{ | ||
char path[PATH_MAX]; | ||
const char *sysfs; | ||
FILE *file; | ||
int n, cpu; | ||
|
||
if (strncmp(name, "cpu_", 4)) | ||
return false; | ||
|
||
sysfs = sysfs__mountpoint(); | ||
if (!sysfs) | ||
return false; | ||
|
||
snprintf(path, PATH_MAX, CPUS_TEMPLATE_CPU, sysfs, name); | ||
if (!file_available(path)) | ||
return false; | ||
|
||
file = fopen(path, "r"); | ||
if (!file) | ||
return false; | ||
|
||
n = fscanf(file, "%u", &cpu); | ||
fclose(file); | ||
if (n <= 0) | ||
return false; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef __PMU_HYBRID_H | ||
#define __PMU_HYBRID_H | ||
|
||
#include <linux/perf_event.h> | ||
#include <linux/compiler.h> | ||
#include <linux/list.h> | ||
#include <stdbool.h> | ||
#include "pmu.h" | ||
|
||
extern struct list_head perf_pmu__hybrid_pmus; | ||
|
||
#define perf_pmu__for_each_hybrid_pmu(pmu) \ | ||
list_for_each_entry(pmu, &perf_pmu__hybrid_pmus, hybrid_list) | ||
|
||
bool perf_pmu__hybrid_mounted(const char *name); | ||
|
||
#endif /* __PMU_HYBRID_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters