From owner-freebsd-current@FreeBSD.ORG Sat Feb 9 22:29:47 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 40DA0CB5 for ; Sat, 9 Feb 2013 22:29:47 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com [209.85.217.172]) by mx1.freebsd.org (Postfix) with ESMTP id A333DB07 for ; Sat, 9 Feb 2013 22:29:46 +0000 (UTC) Received: by mail-lb0-f172.google.com with SMTP id n8so3851223lbj.3 for ; Sat, 09 Feb 2013 14:29:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:x-enigmail-version:content-type :x-gm-message-state; bh=MJGHMAPwSlycQEKfVOZpX8x8Gu27YoWX1ZcaLlHxWo4=; b=nzOUCSYeNvkrfkYXw7Ex0q1M5oqNOkbzxxVaz4tU9Qx2AmnQBfqH5gEWIxIA8/CzrX k81Zio7au83SVzusItt6M7n6RIRWN6pdE05/z6RklaCfQ+6/BxiOedxbr5sm2I5IuX6P vaZI2XVGyaS6oopUtz3GSQKNbO38Ae94IgN3GSQwjj8XmFrmS4bBroZTxOH1dfiYeEbM fWZfqXK19qNMEbZgGpVM8WFEdsC428IzU6RZZbNZ265nQN5c78msOcBlDbSEsC7NboNm WPKSSASc8+GIY3EmNKMN8wybWvhEjU2h/fmdkiIJo81qYZYpRGDUMXOXH7j8zRxeP/Iz qsNg== X-Received: by 10.152.144.202 with SMTP id so10mr8852178lab.9.1360448985409; Sat, 09 Feb 2013 14:29:45 -0800 (PST) Received: from zont-osx.local (ppp95-165-158-215.pppoe.spdop.ru. [95.165.158.215]) by mx.google.com with ESMTPS id o2sm11504542lby.11.2013.02.09.14.29.43 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 09 Feb 2013 14:29:44 -0800 (PST) Sender: Andrey Zonov Message-ID: <5116CDD3.4000503@FreeBSD.org> Date: Sun, 10 Feb 2013 02:29:39 +0400 From: Andrey Zonov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Matt Burke Subject: Re: [patch] Userland DTrace References: <51152216.9080905@icritical.com> In-Reply-To: <51152216.9080905@icritical.com> X-Enigmail-Version: 1.5 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2NUDRUTRELJOLVPGVIDEC" X-Gm-Message-State: ALoCoQkGDN9Nf0THPzVz5qaH2J5iVqEeB1SoK0RHR1udj29iZtT7jYKMOeJkJeD8KGugzsG+F7bx Cc: freebsd-current@FreeBSD.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Feb 2013 22:29:47 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2NUDRUTRELJOLVPGVIDEC Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 2/8/13 8:04 PM, Matt Burke wrote: > I've been spending some time trying to get the fasttrap provider to wor= k > on FreeBSD without panicing. I believe I have succeeded, at least to th= e > point where it's no longer panicing. >=20 > There were two panic causes. The first was > http://www.freebsd.org/cgi/query-pr.cgi?pr=3D165541 - the FreeBSD port = of > fasttrap.c caused ftp_rcount to be left >0. To fix this I've got rid of= > the early return and reverted to the opensolaris way. >=20 > A second panic then showed up intermittently when fasttrap_pid_cleanup_= cb > was run while something in userland had locks. Using sx_try_xlock calls= > has stopped the panics and shouldn't affect operation AFAICT. >=20 > This is against r246454. >=20 >=20 > Although this has fixed the panics for me, I'm finding a lot of stuff j= ust > isn't actually working, with dtrace and the traced process just chewing= > CPU. Truss on the dtrace shows a heck of a lot of ptrace() calls and I > have no idea what the target is doing... CPU time is split 2:1 > dtrace:target >=20 Great! This fixes panics for me too, but I still cannot get something useful tracing and after detaching by ctrl+c my programs still segfaults.= Please look at one style comment below. >=20 > Also noteworthy is the LOR on the first time you try to use the fasttra= p > provider: http://www.freebsd.org/cgi/query-pr.cgi?pr=3Dkern/165479 >=20 > The lock order there seems right, so I'm guessing "something else" must= > have done it wrong first? How can I find out what the "something else" > is? >=20 >=20 > Thanks >=20 >=20 > --- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c > +++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c > @@ -7536,9 +7536,23 @@ dtrace_unregister(dtrace_provider_id_t id) > return (EBUSY); > } > } else { > +#if defined(sun) > mutex_enter(&dtrace_provider_lock); > mutex_enter(&mod_lock); > mutex_enter(&dtrace_lock); > +#else > + if (sx_try_xlock(&dtrace_provider_lock) =3D=3D 0) s/sx_try_xlock/mutex_tryenter/ Look at sys/cddl/compat/opensolaris/sys/mutex.h > + return (EBUSY); > + if (sx_try_xlock(&mod_lock) =3D=3D 0) { > + mutex_exit(&dtrace_provider_lock); > + return (EBUSY); > + } > + if (sx_try_xlock(&dtrace_lock) =3D=3D 0) { > + mutex_exit(&mod_lock); > + mutex_exit(&dtrace_provider_lock); > + return (EBUSY); > + } > +#endif > } > =20 > /* > --- a/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c > +++ b/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c > @@ -1116,23 +1116,28 @@ fasttrap_pid_disable(void *arg, dtrace_id_t id,= void *parg) > =20 > ASSERT(id =3D=3D probe->ftp_id); > =20 > - mutex_enter(&provider->ftp_mtx); > - > /* > * We won't be able to acquire a /proc-esque lock on the proces= s > * iff the process is dead and gone. In this case, we rely on t= he > * provider lock as a point of mutual exclusion to prevent othe= r > * DTrace consumers from disabling this probe. > */ > - if ((p =3D pfind(probe->ftp_pid)) =3D=3D NULL) { > - mutex_exit(&provider->ftp_mtx); > - return; > + > +#if defined(sun) > + if ((p =3D sprlock(probe->ftp_pid)) !=3D NULL) { > + ASSERT(!(p->p_flag & SVFORK)); > + mutex_exit(&p->p_lock); > + } > +#else > + if ((p =3D pfind(probe->ftp_pid)) !=3D NULL) { > + _PHOLD(p); > + PROC_UNLOCK(p); > } > -#ifdef __FreeBSD__ > - _PHOLD(p); > - PROC_UNLOCK(p); > #endif > =20 > + mutex_enter(&provider->ftp_mtx); > + > + > /* > * Disable all the associated tracepoints (for fully enabled pr= obes). > */ > @@ -1154,6 +1159,13 @@ fasttrap_pid_disable(void *arg, dtrace_id_t id, = void *parg) > if (provider->ftp_retired && !provider->ftp_marked) > whack =3D provider->ftp_marked =3D 1; > mutex_exit(&provider->ftp_mtx); > + > +#if defined(sun) > + mutex_enter(&p->p_lock); > + sprunlock(p); > +#else > + PRELE(p); > +#endif > } else { > /* > * If the process is dead, we're just waiting for the > @@ -1167,9 +1179,6 @@ fasttrap_pid_disable(void *arg, dtrace_id_t id, v= oid *parg) > if (whack) > fasttrap_pid_cleanup(); > =20 > -#ifdef __FreeBSD__ > - PRELE(p); > -#endif > if (!probe->ftp_enabled) > return; > =20 >=20 --=20 Andrey Zonov ------enig2NUDRUTRELJOLVPGVIDEC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJRFs3WAAoJEBWLemxX/CvT8jMH/0gNWX0R9dTzGVy20Ii0uRLT JoH4AuS8AaGZ+K4TP4BPPZ38ARnUfZMeM7jwzqCiXBuERgVa6LWC0k/uFkPIboCG Uwr0TMq9pCSGl+HqNVBG0gX2rHagh2UbCfl+xCAAnHpdWgO8sdB9tVfj+UEPGJDp eSsVwTQtSegqpR+t7VabBeBFhBs9TbmT8mvhLWd25JK4bSI+gGNrkhgRqvKZOi4b 5i41wLKXnBQhoPQYh6hazLFwXnYJU+ZK3HW35Ezix4kxPwrnzib++QlPOKGCpsWr 4rWuv94xzdAE2KVEG8a2ZGVznoJ1nrTBl0CSeJdazBnLard036E7X/XcR8mpoDE= =FQRp -----END PGP SIGNATURE----- ------enig2NUDRUTRELJOLVPGVIDEC--