diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile index 47f82a6f7cc9..5520bf3b4707 100644 --- a/lib/libpmc/Makefile +++ b/lib/libpmc/Makefile @@ -91,6 +91,7 @@ MLINKS+= \ pmc_capabilities.3 pmc_pmcinfo.3 \ pmc_capabilities.3 pmc_cpuinfo.3 \ pmc_capabilities.3 pmc_width.3 \ + pmc_configure_logfile.3 pmc_close_logfile.3 \ pmc_configure_logfile.3 pmc_flush_logfile.3 \ pmc_configure_logfile.3 pmc_writelog.3 \ pmc_disable.3 pmc_enable.3 \ diff --git a/sys/dev/hwpmc/hwpmc_logging.c b/sys/dev/hwpmc/hwpmc_logging.c index e76aa9b710eb..f9e1d2f6942a 100644 --- a/sys/dev/hwpmc/hwpmc_logging.c +++ b/sys/dev/hwpmc/hwpmc_logging.c @@ -404,7 +404,6 @@ pmclog_loop(void *arg) lb = NULL; - /* * Loop waiting for I/O requests to be added to the owner * struct's queue. The loop is exited when the log file @@ -414,28 +413,25 @@ pmclog_loop(void *arg) mtx_lock(&pmc_kthread_mtx); for (;;) { - /* check if we've been asked to exit */ if ((po->po_flags & PMC_PO_OWNS_LOGFILE) == 0) break; - if (lb == NULL) { /* look for a fresh buffer to write */ - mtx_lock_spin(&po->po_mtx); - if ((lb = TAILQ_FIRST(&po->po_logbuffers)) == NULL) { - mtx_unlock_spin(&po->po_mtx); - - /* No more buffers and shutdown required. */ - if (po->po_flags & PMC_PO_SHUTDOWN) - break; + /* look for a fresh buffer to write */ + mtx_lock_spin(&po->po_mtx); + if ((lb = TAILQ_FIRST(&po->po_logbuffers)) == NULL) { + mtx_unlock_spin(&po->po_mtx); - (void) msleep(po, &pmc_kthread_mtx, PWAIT, - "pmcloop", 250); - continue; - } + /* No more buffers and shutdown required. */ + if (po->po_flags & PMC_PO_SHUTDOWN) + break; - TAILQ_REMOVE(&po->po_logbuffers, lb, plb_next); - mtx_unlock_spin(&po->po_mtx); + (void)msleep(po, &pmc_kthread_mtx, PWAIT, "pmcloop", + 250); + continue; } + TAILQ_REMOVE(&po->po_logbuffers, lb, plb_next); + mtx_unlock_spin(&po->po_mtx); mtx_unlock(&pmc_kthread_mtx); @@ -487,7 +483,7 @@ pmclog_loop(void *arg) wakeup_one(po->po_kthread); po->po_kthread = NULL; - + po->po_flags &= ~PMC_PO_SHUTDOWN; mtx_unlock(&pmc_kthread_mtx); /* return the current I/O buffer to the global pool */ @@ -665,7 +661,7 @@ pmclog_stop_kthread(struct pmc_owner *po) { mtx_lock(&pmc_kthread_mtx); - po->po_flags &= ~PMC_PO_OWNS_LOGFILE; + po->po_flags &= ~(PMC_PO_OWNS_LOGFILE | PMC_PO_INITIAL_MAPPINGS_DONE); if (po->po_kthread != NULL) { PROC_LOCK(po->po_kthread); kern_psignal(po->po_kthread, SIGHUP); @@ -693,7 +689,6 @@ pmclog_configure_log(struct pmc_mdep *md, struct pmc_owner *po, int logfd) { struct proc *p; struct timespec ts; - uint64_t tsc; int error; sx_assert(&pmc_sx, SA_XLOCKED); @@ -722,7 +717,6 @@ pmclog_configure_log(struct pmc_mdep *md, struct pmc_owner *po, int logfd) p->p_flag |= P_HWPMC; PROC_UNLOCK(p); nanotime(&ts); - tsc = pmc_rdtsc(); /* create a log initialization entry */ PMCLOG_RESERVE_WITH_ERROR(po, INITIALIZE, sizeof(struct pmclog_initialize)); @@ -891,23 +885,24 @@ pmclog_close(struct pmc_owner *po) PMCDBG1(LOG,CLO,1, "po=%p", po); - pmclog_process_closelog(po); - mtx_lock(&pmc_kthread_mtx); - /* - * Initiate shutdown: no new data queued, - * thread will close file on last block. - */ - po->po_flags |= PMC_PO_SHUTDOWN; - /* give time for all to see */ - DELAY(50); - - /* - * Schedule the current buffer. - */ - pmclog_schedule_all(po); - wakeup_one(po); - + if (po->po_kthread != NULL) { + pmclog_process_closelog(po); + + /* + * Initiate shutdown: no new data queued, + * thread will close file on last block. + */ + po->po_flags |= PMC_PO_SHUTDOWN; + /* give time for all to see */ + DELAY(50); + + /* + * Schedule the current buffer. + */ + pmclog_schedule_all(po); + wakeup_one(po); + } mtx_unlock(&pmc_kthread_mtx); return (0); diff --git a/sys/sys/pmc.h b/sys/sys/pmc.h index f7831f0ec4b2..5826890b142f 100644 --- a/sys/sys/pmc.h +++ b/sys/sys/pmc.h @@ -880,8 +880,11 @@ struct pmc_owner { }; #define PMC_PO_OWNS_LOGFILE 0x00000001 /* has a log file */ -#define PMC_PO_SHUTDOWN 0x00000010 /* in the process of shutdown */ -#define PMC_PO_INITIAL_MAPPINGS_DONE 0x00000020 +#define PMC_PO_SHUTDOWN 0x00000010 /* shutting down */ +#define PMC_PO_INITIAL_MAPPINGS_DONE 0x00000020 /* + * kernel mappings have been + * logged + */ /* * struct pmc_hw -- describe the state of the PMC hardware