From owner-svn-src-all@freebsd.org Thu Oct 8 04:29:41 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 17D399D10DB; Thu, 8 Oct 2015 04:29:41 +0000 (UTC) (envelope-from markj@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 mx1.freebsd.org (Postfix) with ESMTPS id E67A0356; Thu, 8 Oct 2015 04:29:40 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t984Tet8098270; Thu, 8 Oct 2015 04:29:40 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t984TdJd098267; Thu, 8 Oct 2015 04:29:39 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201510080429.t984TdJd098267@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 8 Oct 2015 04:29:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r289003 - vendor-sys/illumos/dist/uts/common/dtrace vendor-sys/illumos/dist/uts/common/sys vendor/illumos/dist/cmd/dtrace/test/tst/common/usdt X-SVN-Group: vendor-sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Oct 2015 04:29:41 -0000 Author: markj Date: Thu Oct 8 04:29:39 2015 New Revision: 289003 URL: https://svnweb.freebsd.org/changeset/base/289003 Log: 6271 dtrace caused excessive fork time Author: Bryan Cantrill Reviewed by: Adam Leventhal Reviewed by: Dan McDonald Reviewed by: Richard Lowe Approved by: Gordon Ross illumos/illumos-gate@7bd3c1d12d0c764e1517c3aca62c634409356764 Modified: vendor-sys/illumos/dist/uts/common/dtrace/dtrace.c vendor-sys/illumos/dist/uts/common/dtrace/fasttrap.c vendor-sys/illumos/dist/uts/common/sys/dtrace.h Changes in other areas also in this revision: Added: vendor/illumos/dist/cmd/dtrace/test/tst/common/usdt/tst.sameprovmulti.ksh vendor/illumos/dist/cmd/dtrace/test/tst/common/usdt/tst.sameprovmulti.ksh.out Modified: vendor-sys/illumos/dist/uts/common/dtrace/dtrace.c ============================================================================== --- vendor-sys/illumos/dist/uts/common/dtrace/dtrace.c Thu Oct 8 03:28:15 2015 (r289002) +++ vendor-sys/illumos/dist/uts/common/dtrace/dtrace.c Thu Oct 8 04:29:39 2015 (r289003) @@ -14809,8 +14809,8 @@ dtrace_helper_provider_add(dof_helper_t * Check to make sure this isn't a duplicate. */ for (i = 0; i < help->dthps_nprovs; i++) { - if (dofhp->dofhp_dof == - help->dthps_provs[i]->dthp_prov.dofhp_dof) + if (dofhp->dofhp_addr == + help->dthps_provs[i]->dthp_prov.dofhp_addr) return (EALREADY); } @@ -15162,7 +15162,14 @@ dtrace_helper_slurp(dof_hdr_t *dof, dof_ dtrace_enabling_destroy(enab); if (dhp != NULL && nprovs > 0) { + /* + * Now that this is in-kernel, we change the sense of the + * members: dofhp_dof denotes the in-kernel copy of the DOF + * and dofhp_addr denotes the address at user-level. + */ + dhp->dofhp_addr = dhp->dofhp_dof; dhp->dofhp_dof = (uint64_t)(uintptr_t)dof; + if (dtrace_helper_provider_add(dhp, gen) == 0) { mutex_exit(&dtrace_lock); dtrace_helper_provider_register(curproc, help, dhp); Modified: vendor-sys/illumos/dist/uts/common/dtrace/fasttrap.c ============================================================================== --- vendor-sys/illumos/dist/uts/common/dtrace/fasttrap.c Thu Oct 8 03:28:15 2015 (r289002) +++ vendor-sys/illumos/dist/uts/common/dtrace/fasttrap.c Thu Oct 8 04:29:39 2015 (r289003) @@ -1784,6 +1784,18 @@ fasttrap_meta_provide(void *arg, dtrace_ return (provider); } +/* + * We know a few things about our context here: we know that the probe being + * created doesn't already exist (DTrace won't load DOF at the same address + * twice, even if explicitly told to do so) and we know that we are + * single-threaded with respect to the meta provider machinery. Knowing that + * this is a new probe and that there is no way for us to race with another + * operation on this provider allows us an important optimization: we need not + * lookup a probe before adding it. Saving this lookup is important because + * this code is in the fork path for processes with USDT probes, and lookups + * here are potentially very expensive because of long hash conflicts on + * module, function and name (DTrace doesn't hash on provider name). + */ /*ARGSUSED*/ static void fasttrap_meta_create_probe(void *arg, void *parg, @@ -1820,19 +1832,6 @@ fasttrap_meta_create_probe(void *arg, vo return; } - /* - * Grab the creation lock to ensure consistency between calls to - * dtrace_probe_lookup() and dtrace_probe_create() in the face of - * other threads creating probes. - */ - mutex_enter(&provider->ftp_cmtx); - - if (dtrace_probe_lookup(provider->ftp_provid, dhpb->dthpb_mod, - dhpb->dthpb_func, dhpb->dthpb_name) != 0) { - mutex_exit(&provider->ftp_cmtx); - return; - } - ntps = dhpb->dthpb_noffs + dhpb->dthpb_nenoffs; ASSERT(ntps > 0); @@ -1840,7 +1839,6 @@ fasttrap_meta_create_probe(void *arg, vo if (fasttrap_total > fasttrap_max) { atomic_add_32(&fasttrap_total, -ntps); - mutex_exit(&provider->ftp_cmtx); return; } @@ -1904,8 +1902,6 @@ fasttrap_meta_create_probe(void *arg, vo */ pp->ftp_id = dtrace_probe_create(provider->ftp_provid, dhpb->dthpb_mod, dhpb->dthpb_func, dhpb->dthpb_name, FASTTRAP_OFFSET_AFRAMES, pp); - - mutex_exit(&provider->ftp_cmtx); } /*ARGSUSED*/ Modified: vendor-sys/illumos/dist/uts/common/sys/dtrace.h ============================================================================== --- vendor-sys/illumos/dist/uts/common/sys/dtrace.h Thu Oct 8 03:28:15 2015 (r289002) +++ vendor-sys/illumos/dist/uts/common/sys/dtrace.h Thu Oct 8 04:29:39 2015 (r289003) @@ -2131,12 +2131,18 @@ extern void dtrace_probe(dtrace_id_t, ui * * 1.2.4 Caller's context * - * dtms_create_probe() is called from either ioctl() or module load context. - * The DTrace framework is locked in such a way that meta providers may not - * register or unregister. This means that the meta provider cannot call - * dtrace_meta_register() or dtrace_meta_unregister(). However, the context is - * such that the provider may (and is expected to) call provider-related - * DTrace provider APIs including dtrace_probe_create(). + * dtms_create_probe() is called from either ioctl() or module load context + * in the context of a newly-created provider (that is, a provider that + * is a result of a call to dtms_provide_pid()). The DTrace framework is + * locked in such a way that meta providers may not register or unregister, + * such that no other thread can call into a meta provider operation and that + * atomicity is assured with respect to meta provider operations across + * dtms_provide_pid() and subsequent calls to dtms_create_probe(). + * The context is thus effectively single-threaded with respect to the meta + * provider, and that the meta provider cannot call dtrace_meta_register() + * or dtrace_meta_unregister(). However, the context is such that the + * provider may (and is expected to) call provider-related DTrace provider + * APIs including dtrace_probe_create(). * * 1.3 void *dtms_provide_pid(void *arg, dtrace_meta_provider_t *mprov, * pid_t pid)