git: f4fac946c6a5 - main - hwpmc: split out PMC_OP_PMCRELEASE
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 14 Jun 2023 16:46:44 UTC
The branch main has been updated by mhorne:
URL: https://cgit.FreeBSD.org/src/commit/?id=f4fac946c6a5f682130b16e17bb4d9ffe219ea32
commit f4fac946c6a5f682130b16e17bb4d9ffe219ea32
Author: Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-06-14 16:33:35 +0000
Commit: Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-06-14 16:34:21 +0000
hwpmc: split out PMC_OP_PMCRELEASE
Split out the functional logic from the syscall handler into a helper
function. This keeps it separate from the syscall control-flow logic,
resulting in better readability overall. It also wins back a level of
indentation.
Reviewed by: jkoshy
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D40293
---
sys/dev/hwpmc/hwpmc_mod.c | 66 +++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 28 deletions(-)
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index fb6aa3ad4588..f9ea87769cae 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -3622,6 +3622,40 @@ pmc_do_op_pmcdetach(struct thread *td, struct pmc_op_pmcattach a)
return (error);
}
+/*
+ * Main body of PMC_OP_PMCRELEASE.
+ */
+static int
+pmc_do_op_pmcrelease(pmc_id_t pmcid)
+{
+ struct pmc_owner *po;
+ struct pmc *pm;
+ int error;
+
+ /*
+ * Find PMC pointer for the named PMC.
+ *
+ * Use pmc_release_pmc_descriptor() to switch off the
+ * PMC, remove all its target threads, and remove the
+ * PMC from its owner's list.
+ *
+ * Remove the owner record if this is the last PMC
+ * owned.
+ *
+ * Free up space.
+ */
+ error = pmc_find_pmc(pmcid, &pm);
+ if (error != 0)
+ return (error);
+
+ po = pm->pm_owner;
+ pmc_release_pmc_descriptor(pm);
+ pmc_maybe_remove_owner(po);
+ pmc_destroy_pmc_descriptor(pm);
+
+ return (error);
+}
+
static int
pmc_syscall_handler(struct thread *td, void *syscall_args)
{
@@ -4205,41 +4239,17 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
break;
/*
- * Release an allocated PMC
+ * Release an allocated PMC.
*/
-
case PMC_OP_PMCRELEASE:
{
- pmc_id_t pmcid;
- struct pmc *pm;
- struct pmc_owner *po;
struct pmc_op_simple sp;
- /*
- * Find PMC pointer for the named PMC.
- *
- * Use pmc_release_pmc_descriptor() to switch off the
- * PMC, remove all its target threads, and remove the
- * PMC from its owner's list.
- *
- * Remove the owner record if this is the last PMC
- * owned.
- *
- * Free up space.
- */
-
- if ((error = copyin(arg, &sp, sizeof(sp))) != 0)
- break;
-
- pmcid = sp.pm_pmcid;
-
- if ((error = pmc_find_pmc(pmcid, &pm)) != 0)
+ error = copyin(arg, &sp, sizeof(sp));
+ if (error != 0)
break;
- po = pm->pm_owner;
- pmc_release_pmc_descriptor(pm);
- pmc_maybe_remove_owner(po);
- pmc_destroy_pmc_descriptor(pm);
+ error = pmc_do_op_pmcrelease(sp.pm_pmcid);
}
break;