From owner-svn-src-head@freebsd.org Mon May 28 23:12:27 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 77A20EFD8D2; Mon, 28 May 2018 23:12:27 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 296F669337; Mon, 28 May 2018 23:12:27 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0BFB013E16; Mon, 28 May 2018 23:12:27 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4SNCQIk001160; Mon, 28 May 2018 23:12:26 GMT (envelope-from mmacy@FreeBSD.org) Received: (from mmacy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4SNCQEe001158; Mon, 28 May 2018 23:12:26 GMT (envelope-from mmacy@FreeBSD.org) Message-Id: <201805282312.w4SNCQEe001158@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmacy set sender to mmacy@FreeBSD.org using -f From: Matt Macy Date: Mon, 28 May 2018 23:12:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334298 - head/sys/dev/hwpmc X-SVN-Group: head X-SVN-Commit-Author: mmacy X-SVN-Commit-Paths: head/sys/dev/hwpmc X-SVN-Commit-Revision: 334298 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 23:12:27 -0000 Author: mmacy Date: Mon May 28 23:12:26 2018 New Revision: 334298 URL: https://svnweb.freebsd.org/changeset/base/334298 Log: hwpmc_logging.c: don't call wakeup_one with thread lock held, don't malloc(M_WAITOK) in an epoch section Modified: head/sys/dev/hwpmc/hwpmc_logging.c head/sys/dev/hwpmc/hwpmc_mod.c Modified: head/sys/dev/hwpmc/hwpmc_logging.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_logging.c Mon May 28 21:05:00 2018 (r334297) +++ head/sys/dev/hwpmc/hwpmc_logging.c Mon May 28 23:12:26 2018 (r334298) @@ -166,13 +166,17 @@ static struct mtx pmc_kthread_mtx; /* sleep lock */ pmclog_release((PO)); \ } while (0) +#define PMCLOG_DESPATCH_SCHED_LOCK(PO) \ + pmclog_release_flags((PO), 0); \ + } while (0) + #define PMCLOG_DESPATCH(PO) \ pmclog_release((PO)); \ spinlock_exit(); \ } while (0) #define PMCLOG_DESPATCH_SYNC(PO) \ - pmclog_schedule_io((PO)); \ + pmclog_schedule_io((PO), 1); \ spinlock_exit(); \ } while (0) @@ -224,7 +228,7 @@ static int pmclog_get_buffer(struct pmc_owner *po); static void pmclog_loop(void *arg); static void pmclog_release(struct pmc_owner *po); static uint32_t *pmclog_reserve(struct pmc_owner *po, int length); -static void pmclog_schedule_io(struct pmc_owner *po); +static void pmclog_schedule_io(struct pmc_owner *po, int wakeup); static void pmclog_schedule_all(struct pmc_owner *po); static void pmclog_stop_kthread(struct pmc_owner *po); @@ -422,7 +426,7 @@ pmclog_loop(void *arg) break; (void) msleep(po, &pmc_kthread_mtx, PWAIT, - "pmcloop", 0); + "pmcloop", 250); continue; } @@ -504,7 +508,7 @@ pmclog_loop(void *arg) */ static void -pmclog_release(struct pmc_owner *po) +pmclog_release_flags(struct pmc_owner *po, int wakeup) { struct pmclog_buffer *plb; @@ -518,12 +522,19 @@ pmclog_release(struct pmc_owner *po) /* schedule an I/O if we've filled a buffer */ if (plb->plb_ptr >= plb->plb_fence) - pmclog_schedule_io(po); + pmclog_schedule_io(po, wakeup); PMCDBG1(LOG,REL,1, "po=%p", po); } +static void +pmclog_release(struct pmc_owner *po) +{ + pmclog_release_flags(po, 1); +} + + /* * Attempt to reserve 'length' bytes of space in an owner's log * buffer. The function returns a pointer to 'length' bytes of space @@ -583,7 +594,7 @@ pmclog_reserve(struct pmc_owner *po, int length) * Otherwise, schedule the current buffer for output and get a * fresh buffer. */ - pmclog_schedule_io(po); + pmclog_schedule_io(po, 0); if (pmclog_get_buffer(po) != 0) goto fail; @@ -621,7 +632,7 @@ pmclog_reserve(struct pmc_owner *po, int length) */ static void -pmclog_schedule_io(struct pmc_owner *po) +pmclog_schedule_io(struct pmc_owner *po, int wakeup) { struct pmclog_buffer *plb; @@ -645,7 +656,8 @@ pmclog_schedule_io(struct pmc_owner *po) mtx_lock_spin(&po->po_mtx); TAILQ_INSERT_TAIL(&po->po_logbuffers, plb, plb_next); mtx_unlock_spin(&po->po_mtx); - wakeup_one(po); + if (wakeup) + wakeup_one(po); } /* @@ -841,7 +853,7 @@ pmclog_schedule_one_cond(void *arg) PMC_CALL_HOOK_UNLOCKED(curthread, PMC_FN_DO_SAMPLES, NULL); plb = po->po_curbuf[curcpu]; if (plb && plb->plb_ptr != plb->plb_base) - pmclog_schedule_io(po); + pmclog_schedule_io(po, 1); spinlock_exit(); } @@ -1048,12 +1060,12 @@ pmclog_process_proccsw(struct pmc *pm, struct pmc_proc po = pm->pm_owner; - PMCLOG_RESERVE(po, PROCCSW, sizeof(struct pmclog_proccsw)); + PMCLOG_RESERVE_SAFE(po, PROCCSW, sizeof(struct pmclog_proccsw)); PMCLOG_EMIT32(pm->pm_id); PMCLOG_EMIT64(v); PMCLOG_EMIT32(pp->pp_proc->p_pid); PMCLOG_EMIT32(td->td_tid); - PMCLOG_DESPATCH(po); + PMCLOG_DESPATCH_SCHED_LOCK(po); } void Modified: head/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_mod.c Mon May 28 21:05:00 2018 (r334297) +++ head/sys/dev/hwpmc/hwpmc_mod.c Mon May 28 23:12:26 2018 (r334298) @@ -2406,8 +2406,10 @@ pmc_find_thread_descriptor(struct pmc_process *pp, str */ if (mode & PMC_FLAG_ALLOCATE) { if ((ptnew = pmc_thread_descriptor_pool_alloc()) == NULL) { - wait_flag = (mode & PMC_FLAG_NOWAIT) ? M_NOWAIT : - M_WAITOK; + wait_flag = M_WAITOK; + if ((mode & PMC_FLAG_NOWAIT) || in_epoch()) + wait_flag = M_NOWAIT; + ptnew = malloc(THREADENTRY_SIZE, M_PMC, wait_flag|M_ZERO); }