Date: Mon, 24 Aug 2015 18:57:33 +0000 (UTC) From: "Bjoern A. Zeeb" <bz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287115 - head/sys/dev/hwpmc Message-ID: <201508241857.t7OIvXu2078764@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bz Date: Mon Aug 24 18:57:32 2015 New Revision: 287115 URL: https://svnweb.freebsd.org/changeset/base/287115 Log: 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 Modified: head/sys/dev/hwpmc/hwpmc_mod.c Modified: head/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_mod.c Mon Aug 24 17:58:11 2015 (r287114) +++ head/sys/dev/hwpmc/hwpmc_mod.c Mon Aug 24 18:57:32 2015 (r287115) @@ -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, + PMC_FLAG_NONE)) == NULL) { + 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| + PMC_F_DESCENDANTS)) != (PMC_F_ATTACHED_TO_OWNER| + PMC_F_DESCENDANTS)) + return ESRCH; + po = opm->pm_owner; + } + } if ((pm = pmc_find_pmc_descriptor_in_process(po, pmcid)) == NULL) return EINVAL;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508241857.t7OIvXu2078764>