hwpmc: on process exit, ensure that the owned log is closed

Tested by:	pho (previous version)
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41521
This commit is contained in:
Konstantin Belousov 2023-08-13 16:42:49 +03:00
parent 1fd8c845b8
commit 3c872a70b8

View file

@ -4989,13 +4989,13 @@ pmc_process_exit(void *arg __unused, struct proc *p)
}
PMC_EPOCH_EXIT();
if (!is_using_hwpmcs)
return;
PMC_GET_SX_XLOCK();
PMCDBG3(PRC,EXT,1,"process-exit proc=%p (%d, %s)", p, p->p_pid,
p->p_comm);
if (!is_using_hwpmcs)
goto out;
/*
* Since this code is invoked by the last thread in an exiting process,
* we would have context switched IN at some prior point. However, with
@ -5116,6 +5116,8 @@ out:
* If the process owned PMCs, free them up and free up memory.
*/
if ((po = pmc_find_owner_descriptor(p)) != NULL) {
if ((po->po_flags & PMC_PO_OWNS_LOGFILE) != 0)
pmclog_close(po);
pmc_remove_owner(po);
pmc_destroy_owner_descriptor(po);
}