git: be75e578549f - main - libpmc: expand PMC_OP* defines

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Thu, 01 Jun 2023 18:20:38 UTC
The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=be75e578549fcc1da3754a29fc0e7b63672e7b44

commit be75e578549fcc1da3754a29fc0e7b63672e7b44
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-06-01 18:19:22 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-01 18:20:13 +0000

    libpmc: expand PMC_OP* defines
    
    When performing the syscall, specify the full name of the desired
    operation. This improves grep-ability.
    
    No functional change.
    
    Reviewed by:    jkoshy
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D40334
---
 lib/libpmc/libpmc.c | 47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c
index 4a8e02fafbfe..57b9c90de256 100644
--- a/lib/libpmc/libpmc.c
+++ b/lib/libpmc/libpmc.c
@@ -78,8 +78,7 @@ static int powerpc_allocate_pmc(enum pmc_event _pe, char* ctrspec,
 			     struct pmc_op_pmcallocate *_pmc_config);
 #endif /* __powerpc__ */
 
-#define PMC_CALL(cmd, params)				\
-	syscall(pmc_syscall, PMC_OP_##cmd, (params))
+#define PMC_CALL(op, params)	syscall(pmc_syscall, (op), (params))
 
 /*
  * Event aliases provide a way for the user to ask for generic events
@@ -1152,7 +1151,7 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
 	}
 
 found:
-	if (PMC_CALL(PMCALLOCATE, &pmc_config) == 0) {
+	if (PMC_CALL(PMC_OP_PMCALLOCATE, &pmc_config) == 0) {
 		*pmcid = pmc_config.pm_pmcid;
 		retval = 0;
 	}
@@ -1171,7 +1170,7 @@ pmc_attach(pmc_id_t pmc, pid_t pid)
 	pmc_attach_args.pm_pmc = pmc;
 	pmc_attach_args.pm_pid = pid;
 
-	return (PMC_CALL(PMCATTACH, &pmc_attach_args));
+	return (PMC_CALL(PMC_OP_PMCATTACH, &pmc_attach_args));
 }
 
 int
@@ -1197,7 +1196,7 @@ pmc_configure_logfile(int fd)
 
 	cla.pm_flags = 0;
 	cla.pm_logfd = fd;
-	if (PMC_CALL(CONFIGURELOG, &cla) < 0)
+	if (PMC_CALL(PMC_OP_CONFIGURELOG, &cla) < 0)
 		return (-1);
 	return (0);
 }
@@ -1221,7 +1220,7 @@ pmc_detach(pmc_id_t pmc, pid_t pid)
 
 	pmc_detach_args.pm_pmc = pmc;
 	pmc_detach_args.pm_pid = pid;
-	return (PMC_CALL(PMCDETACH, &pmc_detach_args));
+	return (PMC_CALL(PMC_OP_PMCDETACH, &pmc_detach_args));
 }
 
 int
@@ -1232,7 +1231,7 @@ pmc_disable(int cpu, int pmc)
 	ssa.pm_cpu = cpu;
 	ssa.pm_pmc = pmc;
 	ssa.pm_state = PMC_STATE_DISABLED;
-	return (PMC_CALL(PMCADMIN, &ssa));
+	return (PMC_CALL(PMC_OP_PMCADMIN, &ssa));
 }
 
 int
@@ -1243,7 +1242,7 @@ pmc_enable(int cpu, int pmc)
 	ssa.pm_cpu = cpu;
 	ssa.pm_pmc = pmc;
 	ssa.pm_state = PMC_STATE_FREE;
-	return (PMC_CALL(PMCADMIN, &ssa));
+	return (PMC_CALL(PMC_OP_PMCADMIN, &ssa));
 }
 
 /*
@@ -1355,13 +1354,13 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
 int
 pmc_flush_logfile(void)
 {
-	return (PMC_CALL(FLUSHLOG,0));
+	return (PMC_CALL(PMC_OP_FLUSHLOG, 0));
 }
 
 int
 pmc_close_logfile(void)
 {
-	return (PMC_CALL(CLOSELOG,0));
+	return (PMC_CALL(PMC_OP_CLOSELOG, 0));
 }
 
 int
@@ -1369,7 +1368,7 @@ pmc_get_driver_stats(struct pmc_driverstats *ds)
 {
 	struct pmc_op_getdriverstats gms;
 
-	if (PMC_CALL(GETDRIVERSTATS, &gms) < 0)
+	if (PMC_CALL(PMC_OP_GETDRIVERSTATS, &gms) < 0)
 		return (-1);
 
 	/* copy out fields in the current userland<->library interface */
@@ -1390,7 +1389,7 @@ pmc_get_msr(pmc_id_t pmc, uint32_t *msr)
 	struct pmc_op_getmsr gm;
 
 	gm.pm_pmcid = pmc;
-	if (PMC_CALL(PMCGETMSR, &gm) < 0)
+	if (PMC_CALL(PMC_OP_PMCGETMSR, &gm) < 0)
 		return (-1);
 	*msr = gm.pm_msr;
 	return (0);
@@ -1420,7 +1419,7 @@ pmc_init(void)
 
 	/* check the kernel module's ABI against our compiled-in version */
 	abi_version = PMC_VERSION;
-	if (PMC_CALL(GETMODULEVERSION, &abi_version) < 0)
+	if (PMC_CALL(PMC_OP_GETMODULEVERSION, &abi_version) < 0)
 		return (pmc_syscall = -1);
 
 	/* ignore patch & minor numbers for the comparison */
@@ -1430,7 +1429,7 @@ pmc_init(void)
 	}
 
 	bzero(&op_cpu_info, sizeof(op_cpu_info));
-	if (PMC_CALL(GETCPUINFO, &op_cpu_info) < 0)
+	if (PMC_CALL(PMC_OP_GETCPUINFO, &op_cpu_info) < 0)
 		return (pmc_syscall = -1);
 
 	cpu_info.pm_cputype = op_cpu_info.pm_cputype;
@@ -1451,7 +1450,7 @@ pmc_init(void)
 	 * Get soft events list.
 	 */
 	soft_event_info.pm_class = PMC_CLASS_SOFT;
-	if (PMC_CALL(GETDYNEVENTINFO, &soft_event_info) < 0)
+	if (PMC_CALL(PMC_OP_GETDYNEVENTINFO, &soft_event_info) < 0)
 		return (pmc_syscall = -1);
 
 	/* Map soft events to static list. */
@@ -1833,7 +1832,7 @@ pmc_pmcinfo(int cpu, struct pmc_pmcinfo **ppmci)
 
 	pmci->pm_cpu  = cpu;
 
-	if (PMC_CALL(GETPMCINFO, pmci) < 0) {
+	if (PMC_CALL(PMC_OP_GETPMCINFO, pmci) < 0) {
 		free(pmci);
 		return (-1);
 	}
@@ -1852,7 +1851,7 @@ pmc_read(pmc_id_t pmc, pmc_value_t *value)
 	pmc_read_op.pm_flags = PMC_F_OLDVALUE;
 	pmc_read_op.pm_value = -1;
 
-	if (PMC_CALL(PMCRW, &pmc_read_op) < 0)
+	if (PMC_CALL(PMC_OP_PMCRW, &pmc_read_op) < 0)
 		return (-1);
 
 	*value = pmc_read_op.pm_value;
@@ -1865,7 +1864,7 @@ pmc_release(pmc_id_t pmc)
 	struct pmc_op_simple	pmc_release_args;
 
 	pmc_release_args.pm_pmcid = pmc;
-	return (PMC_CALL(PMCRELEASE, &pmc_release_args));
+	return (PMC_CALL(PMC_OP_PMCRELEASE, &pmc_release_args));
 }
 
 int
@@ -1877,7 +1876,7 @@ pmc_rw(pmc_id_t pmc, pmc_value_t newvalue, pmc_value_t *oldvaluep)
 	pmc_rw_op.pm_flags = PMC_F_NEWVALUE | PMC_F_OLDVALUE;
 	pmc_rw_op.pm_value = newvalue;
 
-	if (PMC_CALL(PMCRW, &pmc_rw_op) < 0)
+	if (PMC_CALL(PMC_OP_PMCRW, &pmc_rw_op) < 0)
 		return (-1);
 
 	*oldvaluep = pmc_rw_op.pm_value;
@@ -1892,7 +1891,7 @@ pmc_set(pmc_id_t pmc, pmc_value_t value)
 	sc.pm_pmcid = pmc;
 	sc.pm_count = value;
 
-	if (PMC_CALL(PMCSETCOUNT, &sc) < 0)
+	if (PMC_CALL(PMC_OP_PMCSETCOUNT, &sc) < 0)
 		return (-1);
 	return (0);
 }
@@ -1903,7 +1902,7 @@ pmc_start(pmc_id_t pmc)
 	struct pmc_op_simple	pmc_start_args;
 
 	pmc_start_args.pm_pmcid = pmc;
-	return (PMC_CALL(PMCSTART, &pmc_start_args));
+	return (PMC_CALL(PMC_OP_PMCSTART, &pmc_start_args));
 }
 
 int
@@ -1912,7 +1911,7 @@ pmc_stop(pmc_id_t pmc)
 	struct pmc_op_simple	pmc_stop_args;
 
 	pmc_stop_args.pm_pmcid = pmc;
-	return (PMC_CALL(PMCSTOP, &pmc_stop_args));
+	return (PMC_CALL(PMC_OP_PMCSTOP, &pmc_stop_args));
 }
 
 int
@@ -1939,7 +1938,7 @@ pmc_write(pmc_id_t pmc, pmc_value_t value)
 	pmc_write_op.pm_pmcid = pmc;
 	pmc_write_op.pm_flags = PMC_F_NEWVALUE;
 	pmc_write_op.pm_value = value;
-	return (PMC_CALL(PMCRW, &pmc_write_op));
+	return (PMC_CALL(PMC_OP_PMCRW, &pmc_write_op));
 }
 
 int
@@ -1948,5 +1947,5 @@ pmc_writelog(uint32_t userdata)
 	struct pmc_op_writelog wl;
 
 	wl.pm_userdata = userdata;
-	return (PMC_CALL(WRITELOG, &wl));
+	return (PMC_CALL(PMC_OP_WRITELOG, &wl));
 }