mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-18 10:35:55 +00:00
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
This commit is contained in:
parent
6743350af7
commit
e6f4757735
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=287115
@ -2538,13 +2538,35 @@ static int
|
|||||||
pmc_find_pmc(pmc_id_t pmcid, struct pmc **pmc)
|
pmc_find_pmc(pmc_id_t pmcid, struct pmc **pmc)
|
||||||
{
|
{
|
||||||
|
|
||||||
struct pmc *pm;
|
struct pmc *pm, *opm;
|
||||||
struct pmc_owner *po;
|
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);
|
PMCDBG1(PMC,FND,1, "find-pmc id=%d", pmcid);
|
||||||
|
|
||||||
if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL)
|
if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL) {
|
||||||
return ESRCH;
|
/*
|
||||||
|
* 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)
|
if ((pm = pmc_find_pmc_descriptor_in_process(po, pmcid)) == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
Loading…
Reference in New Issue
Block a user