path: root/sys
diff options
authorBjoern A. Zeeb <bz@FreeBSD.org>2015-08-24 18:57:32 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2015-08-24 18:57:32 +0000
commite6f4757735e4094ad273996cef58a1763a9ea9b6 (patch)
treec51beef1bde8b09c181319031e4dd0f2ce2ddab2 /sys
parent6743350af74b113fc67d395844a1d5bcb0d1c987 (diff)
When forking a child process with PMC_F_DESCENDANTS set in pmc_attach()
in the parent, we will inherit the pmcids but cannot execute any operations on them in the child. The reason for this is that pmc_find_pmc() only tries to find the current process on the owners hash list, but given the child does not own the attachment, we cannot find it. Thus, in case the initial lookup fails, try to find the pmc_process state affiliated with the child process, lookup the pmc from there using the row index, and get the owner process from that pmc. Then continue as normal and lookup the pmc context of the owner (process). This allows us to call, e.g., pmc_start() in the child process before we start the work there, but to collect the accumulated results later in the parent. Sponsored by: DARPA,AFRL Obtained from: L41 Tested by: rwatson, L41 MFC after: 4 weeks Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D2052
Notes: svn path=/head/; revision=287115
Diffstat (limited to 'sys')
1 files changed, 25 insertions, 3 deletions
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 131eb3575e24..a5df748073a0 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -2538,13 +2538,35 @@ static int
pmc_find_pmc(pmc_id_t pmcid, struct pmc **pmc)
- struct pmc *pm;
+ struct pmc *pm, *opm;
struct pmc_owner *po;
+ struct pmc_process *pp;
+ KASSERT(PMC_ID_TO_ROWINDEX(pmcid) < md->pmd_npmc,
+ ("[pmc,%d] Illegal pmc index %d (max %d)", __LINE__,
+ PMC_ID_TO_ROWINDEX(pmcid), md->pmd_npmc));
PMCDBG1(PMC,FND,1, "find-pmc id=%d", pmcid);
- if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL)
- return ESRCH;
+ if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL) {
+ /*
+ * In case of PMC_F_DESCENDANTS child processes we will not find
+ * the current process in the owners hash list. Find the owner
+ * process first and from there lookup the po.
+ */
+ if ((pp = pmc_find_process_descriptor(curthread->td_proc,
+ return ESRCH;
+ } else {
+ opm = pp->pp_pmcs[PMC_ID_TO_ROWINDEX(pmcid)].pp_pmc;
+ if (opm == NULL)
+ return ESRCH;
+ if ((opm->pm_flags & (PMC_F_ATTACHED_TO_OWNER|
+ return ESRCH;
+ po = opm->pm_owner;
+ }
+ }
if ((pm = pmc_find_pmc_descriptor_in_process(po, pmcid)) == NULL)
return EINVAL;