mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
libcpumf: Move perf_event_open to reduce code duplication
Relocated the perf_event_open logic into a shared helper to eliminate redundant implementations across multiple files. Enhances consistency, reduces maintenance overhead, and lowers structural complexity. Acked-by: Thomas Richter <tmricht@linux.ibm.com> Reviewed-by: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Jan Polensky <japo@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
82603e589a
commit
5aa1824eef
@@ -22,7 +22,7 @@ ALL_CPPFLAGS += -DVERSION=$(VERSION)
|
||||
all: check_dep cpacfstats cpacfstatsd
|
||||
|
||||
cpacfstatsd: cpacfstatsd.o stats_sock.o perf_crypto.o cpacfstats_common.o \
|
||||
$(rootdir)/libutil/libutil.a
|
||||
$(rootdir)/libcpumf/libcpumf.a $(rootdir)/libutil/libutil.a
|
||||
$(LINK) $(ALL_LDFLAGS) $^ $(LDLIBS) -ludev -lpthread -o $@
|
||||
|
||||
cpacfstats: cpacfstats.o stats_sock.o cpacfstats_common.o
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <libudev.h>
|
||||
|
||||
#include "cpacfstats.h"
|
||||
#include "lib/libcpumf.h"
|
||||
#include "../include/lib/zt_common.h"
|
||||
|
||||
/* correlation between counter and perf counter string */
|
||||
@@ -123,16 +124,6 @@ static struct percpucounter *findcpu(unsigned int cpunum, int unlinkflag)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
|
||||
int cpu, int group_fd, unsigned long flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,
|
||||
group_fd, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int perf_supported(void)
|
||||
{
|
||||
return !access("/proc/sys/kernel/perf_event_paranoid", R_OK);
|
||||
|
||||
@@ -59,14 +59,6 @@ static struct util_list list_pai_event;
|
||||
static struct util_list list_pmu_event;
|
||||
static bool summary;
|
||||
|
||||
/* System call to perf_event_open(2) */
|
||||
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
|
||||
int cpu, int group_fd, unsigned long flags)
|
||||
{
|
||||
return syscall(__NR_perf_event_open, hw_event, pid, cpu,
|
||||
group_fd, flags);
|
||||
}
|
||||
|
||||
static void ev_dealloc(void)
|
||||
{
|
||||
struct pai_event *next, *p;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <sched.h>
|
||||
#include <stdbool.h>
|
||||
#include <asm/unistd.h>
|
||||
#include <linux/perf_event.h>
|
||||
|
||||
#define S390_CPUMF_CF "devices/cpum_cf/"
|
||||
#define S390_CPUMF_CFDIAG "devices/cpum_cf_diag/"
|
||||
@@ -182,4 +184,22 @@ bool libcpumf_have_pai_ext(void);
|
||||
* @retval false PAI_NNPA counter Facility is not available
|
||||
*/
|
||||
bool libcpumf_have_pai_nnpa(void);
|
||||
|
||||
/**
|
||||
* Wrapper for the perf_event_open syscall used to configure performance events.
|
||||
* This function simplifies usage of perf_event_open and provides a consistent
|
||||
* interface for libcpumf internals.
|
||||
*
|
||||
* @param hw_event Pointer to perf_event_attr structure describing the event
|
||||
* @param pid Target process ID (0 for current process)
|
||||
* @param cpu Target CPU (-1 for all CPUs)
|
||||
* @param group_fd File descriptor of event group leader, or -1 if none
|
||||
* @param flags Additional flags (usually 0)
|
||||
*
|
||||
* @return File descriptor for the opened event on success
|
||||
* @return -1 on failure, errno is set appropriately
|
||||
*/
|
||||
|
||||
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd,
|
||||
unsigned long flags);
|
||||
#endif
|
||||
|
||||
@@ -169,3 +169,9 @@ bool libcpumf_have_pai_nnpa(void)
|
||||
{
|
||||
return libcpumf_have_pai_sysfs(S390_SYSFS_PAI_NNPA);
|
||||
}
|
||||
|
||||
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd,
|
||||
unsigned long flags)
|
||||
{
|
||||
return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user