Lines Matching +full:wakeup +full:- +full:event +full:- +full:action
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2005-2007 Joseph Koshy
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
75 * kern.hwpmc.logbuffersize -- size of the per-cpu owner buffers.
83 * kern.hwpmc.nbuffers_pcpu -- number of global log buffers
97 (D)->plb_fence = ((char *)(buf)) + 1024 * pmclog_buffer_size; \
98 (D)->plb_base = (D)->plb_ptr = ((char *)(buf)); \
99 (D)->plb_domain = domain; \
103 (D)->plb_ptr = (D)->plb_base; \
113 #define _PMCLOG_RESERVE_SAFE(PO, TYPE, LEN, ACTION, TSC) do { \ argument
119 ACTION; \
122 ph->pl_header =_PMCLOG_TO_HEADER(TYPE,_len); \
123 ph->pl_tsc = (TSC); \
127 #define _PMCLOG_RESERVE(PO, TYPE, LEN, ACTION) do { \ argument
137 ACTION; \
140 ph->pl_header =_PMCLOG_TO_HEADER(TYPE,_len); \
141 ph->pl_tsc = tsc; \
231 static void pmclog_schedule_io(struct pmc_owner *po, int wakeup);
242 TAILQ_INSERT_HEAD(&pmc_dom_hdrs[plb->plb_domain]->pdbh_head, plb, plb_next); in pmc_plb_rele_unlocked()
248 mtx_lock_spin(&pmc_dom_hdrs[plb->plb_domain]->pdbh_mtx); in pmc_plb_rele()
250 mtx_unlock_spin(&pmc_dom_hdrs[plb->plb_domain]->pdbh_mtx); in pmc_plb_rele()
262 KASSERT(po->po_curbuf[curcpu] == NULL, in pmclog_get_buffer()
267 mtx_lock_spin(&pmc_dom_hdrs[domain]->pdbh_mtx); in pmclog_get_buffer()
268 if ((plb = TAILQ_FIRST(&pmc_dom_hdrs[domain]->pdbh_head)) != NULL) in pmclog_get_buffer()
269 TAILQ_REMOVE(&pmc_dom_hdrs[domain]->pdbh_head, plb, plb_next); in pmclog_get_buffer()
270 mtx_unlock_spin(&pmc_dom_hdrs[domain]->pdbh_mtx); in pmclog_get_buffer()
276 KASSERT(plb->plb_ptr == plb->plb_base && in pmclog_get_buffer()
277 plb->plb_base < plb->plb_fence, in pmclog_get_buffer()
279 "base=%p fence=%p", __LINE__, po, plb->plb_ptr, in pmclog_get_buffer()
280 plb->plb_base, plb->plb_fence)); in pmclog_get_buffer()
283 po->po_curbuf[curcpu] = plb; in pmclog_get_buffer()
307 error = kproc_create(pmclog_loop, ia, &ia->kthr, in pmclog_proc_create()
308 RFHIGHPID, 0, "hwpmc: proc(%d)", td->td_proc->p_pid); in pmclog_proc_create()
321 MPASS(!ia->acted); in pmclog_proc_ignite()
322 MPASS(ia->po == NULL); in pmclog_proc_ignite()
323 MPASS(!ia->exit); in pmclog_proc_ignite()
324 MPASS(ia->kthr != NULL); in pmclog_proc_ignite()
326 ia->exit = true; in pmclog_proc_ignite()
328 ia->po = po; in pmclog_proc_ignite()
329 KASSERT(po->po_kthread == NULL, in pmclog_proc_ignite()
331 __LINE__, po, po->po_kthread)); in pmclog_proc_ignite()
332 po->po_kthread = ia->kthr; in pmclog_proc_ignite()
334 wakeup(ia); in pmclog_proc_ignite()
335 while (!ia->acted) in pmclog_proc_ignite()
369 MPASS(ia->kthr == curproc); in pmclog_loop()
370 MPASS(!ia->acted); in pmclog_loop()
372 while (ia->po == NULL && !ia->exit) in pmclog_loop()
374 if (ia->exit) { in pmclog_loop()
375 ia->acted = true; in pmclog_loop()
376 wakeup(ia); in pmclog_loop()
380 MPASS(ia->po != NULL); in pmclog_loop()
381 po = ia->po; in pmclog_loop()
382 ia->acted = true; in pmclog_loop()
383 wakeup(ia); in pmclog_loop()
387 p = po->po_owner; in pmclog_loop()
388 mycred = td->td_ucred; in pmclog_loop()
391 ownercred = crhold(p->p_ucred); in pmclog_loop()
394 PMCDBG2(LOG,INI,1, "po=%p kt=%p", po, po->po_kthread); in pmclog_loop()
395 KASSERT(po->po_kthread == curthread->td_proc, in pmclog_loop()
397 po, po->po_kthread, curthread->td_proc)); in pmclog_loop()
413 if ((po->po_flags & PMC_PO_OWNS_LOGFILE) == 0) in pmclog_loop()
417 mtx_lock_spin(&po->po_mtx); in pmclog_loop()
418 if ((lb = TAILQ_FIRST(&po->po_logbuffers)) == NULL) { in pmclog_loop()
419 mtx_unlock_spin(&po->po_mtx); in pmclog_loop()
422 if (po->po_flags & PMC_PO_SHUTDOWN) in pmclog_loop()
430 TAILQ_REMOVE(&po->po_logbuffers, lb, plb_next); in pmclog_loop()
431 mtx_unlock_spin(&po->po_mtx); in pmclog_loop()
438 lb->plb_base, lb->plb_ptr); in pmclog_loop()
441 aiov.iov_base = lb->plb_base; in pmclog_loop()
442 aiov.iov_len = nbytes = lb->plb_ptr - lb->plb_base; in pmclog_loop()
446 auio.uio_offset = -1; in pmclog_loop()
452 /* switch thread credentials -- see kern_ktrace.c */ in pmclog_loop()
453 td->td_ucred = ownercred; in pmclog_loop()
454 error = fo_write(po->po_file, &auio, ownercred, 0, td); in pmclog_loop()
455 td->td_ucred = mycred; in pmclog_loop()
466 po->po_error = error; /* save for flush log */ in pmclog_loop()
482 wakeup_one(po->po_kthread); in pmclog_loop()
483 po->po_kthread = NULL; in pmclog_loop()
508 pmclog_release_flags(struct pmc_owner *po, int wakeup) in pmclog_release_flags() argument
512 plb = po->po_curbuf[curcpu]; in pmclog_release_flags()
513 KASSERT(plb->plb_ptr >= plb->plb_base, in pmclog_release_flags()
515 po, plb->plb_ptr, plb->plb_base)); in pmclog_release_flags()
516 KASSERT(plb->plb_ptr <= plb->plb_fence, in pmclog_release_flags()
518 po, plb->plb_ptr, plb->plb_fence)); in pmclog_release_flags()
521 if (plb->plb_ptr >= plb->plb_fence) in pmclog_release_flags()
522 pmclog_schedule_io(po, wakeup); in pmclog_release_flags()
539 * available. Non-null returns do so with the po mutex locked. The
556 if (po->po_flags & PMC_PO_SHUTDOWN) in pmclog_reserve()
559 pplb = &po->po_curbuf[curcpu]; in pmclog_reserve()
567 KASSERT(plb->plb_ptr >= plb->plb_base && in pmclog_reserve()
568 plb->plb_ptr <= plb->plb_fence, in pmclog_reserve()
570 __LINE__, po, plb->plb_ptr, plb->plb_base, in pmclog_reserve()
571 plb->plb_fence)); in pmclog_reserve()
573 oldptr = (uintptr_t) plb->plb_ptr; in pmclog_reserve()
583 if (newptr <= (uintptr_t) plb->plb_fence) { in pmclog_reserve()
584 plb->plb_ptr = (char *) newptr; in pmclog_reserve()
601 KASSERT(plb->plb_ptr != NULL, in pmclog_reserve()
604 KASSERT(plb->plb_ptr == plb->plb_base && in pmclog_reserve()
605 plb->plb_ptr <= plb->plb_fence, in pmclog_reserve()
607 __LINE__, po, plb->plb_ptr, plb->plb_base, in pmclog_reserve()
608 plb->plb_fence)); in pmclog_reserve()
610 oldptr = (uintptr_t) plb->plb_ptr; in pmclog_reserve()
625 pmclog_schedule_io(struct pmc_owner *po, int wakeup) in pmclog_schedule_io() argument
629 plb = po->po_curbuf[curcpu]; in pmclog_schedule_io()
630 po->po_curbuf[curcpu] = NULL; in pmclog_schedule_io()
633 KASSERT(plb->plb_ptr >= plb->plb_base, in pmclog_schedule_io()
635 po, plb->plb_ptr, plb->plb_base)); in pmclog_schedule_io()
636 KASSERT(plb->plb_ptr <= plb->plb_fence, in pmclog_schedule_io()
638 po, plb->plb_ptr, plb->plb_fence)); in pmclog_schedule_io()
644 * wakeup the helper. in pmclog_schedule_io()
646 mtx_lock_spin(&po->po_mtx); in pmclog_schedule_io()
647 TAILQ_INSERT_TAIL(&po->po_logbuffers, plb, plb_next); in pmclog_schedule_io()
648 mtx_unlock_spin(&po->po_mtx); in pmclog_schedule_io()
649 if (wakeup) in pmclog_schedule_io()
662 po->po_flags &= ~PMC_PO_OWNS_LOGFILE; in pmclog_stop_kthread()
663 if (po->po_kthread != NULL) { in pmclog_stop_kthread()
664 PROC_LOCK(po->po_kthread); in pmclog_stop_kthread()
665 kern_psignal(po->po_kthread, SIGHUP); in pmclog_stop_kthread()
666 PROC_UNLOCK(po->po_kthread); in pmclog_stop_kthread()
669 while (po->po_kthread) in pmclog_stop_kthread()
670 msleep(po->po_kthread, &pmc_kthread_mtx, PPAUSE, "pmckstp", 0); in pmclog_stop_kthread()
695 p = po->po_owner; in pmclog_configure_log()
698 if (po->po_flags & PMC_PO_OWNS_LOGFILE) in pmclog_configure_log()
701 KASSERT(po->po_file == NULL, in pmclog_configure_log()
703 po->po_file)); in pmclog_configure_log()
706 error = fget_write(curthread, logfd, &cap_write_rights, &po->po_file); in pmclog_configure_log()
711 po->po_flags |= PMC_PO_OWNS_LOGFILE; in pmclog_configure_log()
715 p->p_flag |= P_HWPMC; in pmclog_configure_log()
722 PMCLOG_EMIT32(md->pmd_cputype); in pmclog_configure_log()
738 KASSERT(po->po_kthread == NULL, ("[pmclog,%d] po=%p kthread not " in pmclog_configure_log()
741 if (po->po_file) in pmclog_configure_log()
742 (void) fdrop(po->po_file, curthread); in pmclog_configure_log()
743 po->po_file = NULL; /* clear file and error state */ in pmclog_configure_log()
744 po->po_error = 0; in pmclog_configure_log()
745 po->po_flags &= ~PMC_PO_OWNS_LOGFILE; in pmclog_configure_log()
752 * De-configure a log file. This will throw away any buffers queued
763 PMCDBG1(LOG,CFG,1, "de-config po=%p", po); in pmclog_deconfigure_log()
765 if ((po->po_flags & PMC_PO_OWNS_LOGFILE) == 0) in pmclog_deconfigure_log()
768 KASSERT(po->po_sscount == 0, in pmclog_deconfigure_log()
770 KASSERT(po->po_file != NULL, in pmclog_deconfigure_log()
776 KASSERT(po->po_kthread == NULL, in pmclog_deconfigure_log()
780 while ((lb = TAILQ_FIRST(&po->po_logbuffers)) != NULL) { in pmclog_deconfigure_log()
781 TAILQ_REMOVE(&po->po_logbuffers, lb, plb_next); in pmclog_deconfigure_log()
789 if ((lb = po->po_curbuf[curcpu]) != NULL) { in pmclog_deconfigure_log()
797 if (po->po_file != NULL) { in pmclog_deconfigure_log()
798 error = fdrop(po->po_file, curthread); in pmclog_deconfigure_log()
799 po->po_file = NULL; in pmclog_deconfigure_log()
802 po->po_error = 0; in pmclog_deconfigure_log()
822 if (po->po_error) in pmclog_flush()
823 return (po->po_error); in pmclog_flush()
831 if ((po->po_flags & PMC_PO_OWNS_LOGFILE) == 0) { in pmclog_flush()
855 plb = po->po_curbuf[cpu]; in pmclog_schedule_one_cond()
856 if (plb && plb->plb_ptr != plb->plb_base) in pmclog_schedule_one_cond()
890 po->po_flags |= PMC_PO_SHUTDOWN; in pmclog_close()
912 PMCDBG3(LOG,SAM,1,"pm=%p pid=%d n=%d", pm, ps->ps_pid, in pmclog_process_callchain()
913 ps->ps_nsamples); in pmclog_process_callchain()
916 ps->ps_nsamples * sizeof(uintfptr_t); in pmclog_process_callchain()
917 po = pm->pm_owner; in pmclog_process_callchain()
918 flags = PMC_CALLCHAIN_TO_CPUFLAGS(ps->ps_cpu,ps->ps_flags); in pmclog_process_callchain()
919 PMCLOG_RESERVE_SAFE(po, PMCLOG_TYPE_CALLCHAIN, recordlen, ps->ps_tsc); in pmclog_process_callchain()
920 PMCLOG_EMIT32(ps->ps_pid); in pmclog_process_callchain()
921 PMCLOG_EMIT32(ps->ps_tid); in pmclog_process_callchain()
922 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_callchain()
924 for (n = 0; n < ps->ps_nsamples; n++) in pmclog_process_callchain()
925 PMCLOG_EMITADDR(ps->ps_pc[n]); in pmclog_process_callchain()
951 KASSERT(path != NULL, ("[pmclog,%d] map-in, null path", __LINE__)); in pmclog_process_map_in()
985 po = pm->pm_owner; in pmclog_process_pmcallocate()
992 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_pmcallocate()
993 PMCLOG_EMIT32(pm->pm_event); in pmclog_process_pmcallocate()
994 PMCLOG_EMIT32(pm->pm_flags); in pmclog_process_pmcallocate()
996 PMCLOG_EMIT64(pm->pm_sc.pm_reloadcount); in pmclog_process_pmcallocate()
997 ps = pmc_soft_ev_acquire(pm->pm_event); in pmclog_process_pmcallocate()
999 PMCLOG_EMITSTRING(ps->ps_ev.pm_ev_name,PMC_NAME_MAX); in pmclog_process_pmcallocate()
1007 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_pmcallocate()
1008 PMCLOG_EMIT32(pm->pm_event); in pmclog_process_pmcallocate()
1009 PMCLOG_EMIT32(pm->pm_flags); in pmclog_process_pmcallocate()
1011 PMCLOG_EMIT64(pm->pm_sc.pm_reloadcount); in pmclog_process_pmcallocate()
1024 po = pm->pm_owner; in pmclog_process_pmcattach()
1030 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_pmcattach()
1043 po = pm->pm_owner; in pmclog_process_pmcdetach()
1047 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_pmcdetach()
1058 PMCLOG_EMIT32(p->p_pid); in pmclog_process_proccreate()
1059 PMCLOG_EMIT32(p->p_flag); in pmclog_process_proccreate()
1060 PMCLOG_EMITSTRING(p->p_comm, MAXCOMLEN+1); in pmclog_process_proccreate()
1065 PMCLOG_EMIT32(p->p_pid); in pmclog_process_proccreate()
1066 PMCLOG_EMIT32(p->p_flag); in pmclog_process_proccreate()
1067 PMCLOG_EMITSTRING(p->p_comm, MAXCOMLEN+1); in pmclog_process_proccreate()
1073 * Log a context switch event to the log file.
1081 KASSERT(pm->pm_flags & PMC_F_LOG_PROCCSW, in pmclog_process_proccsw()
1082 ("[pmclog,%d] log-process-csw called gratuitously", __LINE__)); in pmclog_process_proccsw()
1084 PMCDBG3(LOG,SWO,1,"pm=%p pid=%d v=%jx", pm, pp->pp_proc->p_pid, in pmclog_process_proccsw()
1087 po = pm->pm_owner; in pmclog_process_proccsw()
1092 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_proccsw()
1093 PMCLOG_EMIT32(pp->pp_proc->p_pid); in pmclog_process_proccsw()
1094 PMCLOG_EMIT32(td->td_tid); in pmclog_process_proccsw()
1119 * Log a process exit event (and accumulated pmc value) to the log file.
1129 PMCDBG3(LOG,EXT,1,"pm=%p pid=%d v=%jx", pm, pp->pp_proc->p_pid, in pmclog_process_procexit()
1130 pp->pp_pmcs[ri].pp_pmcval); in pmclog_process_procexit()
1132 po = pm->pm_owner; in pmclog_process_procexit()
1136 PMCLOG_EMIT32(pm->pm_id); in pmclog_process_procexit()
1137 PMCLOG_EMIT32(pp->pp_proc->p_pid); in pmclog_process_procexit()
1138 PMCLOG_EMIT64(pp->pp_pmcs[ri].pp_pmcval); in pmclog_process_procexit()
1143 * Log a fork event.
1157 * Log a process exit event of the form suitable for system-wide PMCs.
1173 p = td->td_proc; in pmclog_process_threadcreate()
1177 PMCLOG_EMIT32(td->td_tid); in pmclog_process_threadcreate()
1178 PMCLOG_EMIT32(p->p_pid); in pmclog_process_threadcreate()
1179 PMCLOG_EMIT32(p->p_flag); in pmclog_process_threadcreate()
1181 PMCLOG_EMITSTRING(td->td_name, MAXCOMLEN+1); in pmclog_process_threadcreate()
1186 PMCLOG_EMIT32(td->td_tid); in pmclog_process_threadcreate()
1187 PMCLOG_EMIT32(p->p_pid); in pmclog_process_threadcreate()
1188 PMCLOG_EMIT32(p->p_flag); in pmclog_process_threadcreate()
1190 PMCLOG_EMITSTRING(td->td_name, MAXCOMLEN+1); in pmclog_process_threadcreate()
1201 PMCLOG_EMIT32(td->td_tid); in pmclog_process_threadexit()
1214 PMCDBG2(LOG,WRI,1, "writelog po=%p ud=0x%x", po, wl->pm_userdata); in pmclog_process_userlog()
1220 PMCLOG_EMIT32(wl->pm_userdata); in pmclog_process_userlog()
1258 ncpus = pmc_dom_hdrs[domain]->pdbh_ncpus; in pmclog_initialize()
1263 pmc_dom_hdrs[domain]->pdbh_plbs = plb; in pmclog_initialize()
1264 for (; total > 0; total--, plb++) { in pmclog_initialize()
1273 mtx_init(&pmc_kthread_mtx, "pmc-kthread", "pmc-sleep", MTX_DEF); in pmclog_initialize()
1291 while ((plb = TAILQ_FIRST(&pmc_dom_hdrs[domain]->pdbh_head)) != NULL) { in pmclog_shutdown()
1292 TAILQ_REMOVE(&pmc_dom_hdrs[domain]->pdbh_head, plb, plb_next); in pmclog_shutdown()
1293 free(plb->plb_base, M_PMC); in pmclog_shutdown()
1295 free(pmc_dom_hdrs[domain]->pdbh_plbs, M_PMC); in pmclog_shutdown()