From owner-freebsd-net@FreeBSD.ORG Wed May 28 00:32:35 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B089C4BA; Wed, 28 May 2014 00:32:35 +0000 (UTC) Received: from mail-we0-x236.google.com (mail-we0-x236.google.com [IPv6:2a00:1450:400c:c03::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1809C26D3; Wed, 28 May 2014 00:32:34 +0000 (UTC) Received: by mail-we0-f182.google.com with SMTP id t60so10221471wes.41 for ; Tue, 27 May 2014 17:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=OAL/nD0p6JU8LHqKqy/dwjG8e1xTkupcJs//dsW9ONc=; b=abrAh2UyiipD4ZTbqgj7czytY9qJ/hIWV/g7zGeZOszCXeZhAy2ZKVZzqPzDV6bs3G LWSzcCZbNALSL5qaLNRXyfw0izEA60FijoQ4CMEGrOznYCwVOU0U9k0cKs/YhY0ngOvB +Rtg2pfOxat5Ojl+8keAWGKhbCl3WEF6XFmqVt8+L1XuyUfYMRXdMk8zj/H3/YI95m1T KcEADHqwaNYfl631ndGlb9qhnYtXO5+Bt7Vpxg0kEw+tbLENLGw03g+H3WJpgqQSc9/y i0bMsreDWGRnoaFUbvDI3d9cl7ppNuPke9enqEGoJocSXFdt2BshQiXjdTl3j21oWB59 vG5A== MIME-Version: 1.0 X-Received: by 10.194.92.7 with SMTP id ci7mr46481720wjb.7.1401237152769; Tue, 27 May 2014 17:32:32 -0700 (PDT) Sender: rizzo.unipi@gmail.com Received: by 10.194.246.130 with HTTP; Tue, 27 May 2014 17:32:32 -0700 (PDT) In-Reply-To: <5385249D.9050501@FreeBSD.org> References: <5385249D.9050501@FreeBSD.org> Date: Wed, 28 May 2014 02:32:32 +0200 X-Google-Sender-Auth: JxG0DtEgfwF76IDZi8UzjKrMzNo Message-ID: Subject: Re: change netmap global lock to sx? From: Luigi Rizzo To: Navdeep Parhar Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: "freebsd-net@freebsd.org" X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2014 00:32:35 -0000 On Wed, May 28, 2014 at 1:49 AM, Navdeep Parhar wrote: > I'd like to change the netmap global lock from a mutex into a sleepable > shared/exclusive lock. This will allow a driver's nm_register hook > (which is called with the global lock held) to sleep if it has to. I've > casually used pkt-gen after this conversion (patch attached) and the > witness hasn't complained about it. > > =E2=80=8Bno objections, let me give this a try on stable/10 stable/9 to make sure we can use the same code there as well cheers luigi =E2=80=8B > Thoughts? > > Regards, > Navdeep > > > diff -r 0300d80260f4 sys/dev/netmap/netmap_kern.h > --- a/sys/dev/netmap/netmap_kern.h Fri May 23 19:00:56 2014 -0700 > +++ b/sys/dev/netmap/netmap_kern.h Sat May 24 12:49:15 2014 -0700 > @@ -43,13 +43,13 @@ > #define unlikely(x) __builtin_expect((long)!!(x), 0L) > > #define NM_LOCK_T struct mtx > -#define NMG_LOCK_T struct mtx > -#define NMG_LOCK_INIT() mtx_init(&netmap_global_lock, \ > - "netmap global lock", NULL, MTX_DEF) > -#define NMG_LOCK_DESTROY() mtx_destroy(&netmap_global_lock) > -#define NMG_LOCK() mtx_lock(&netmap_global_lock) > -#define NMG_UNLOCK() mtx_unlock(&netmap_global_lock) > -#define NMG_LOCK_ASSERT() mtx_assert(&netmap_global_lock, MA_OWNED) > +#define NMG_LOCK_T struct sx > +#define NMG_LOCK_INIT() sx_init(&netmap_global_lock, \ > + "netmap global lock") > +#define NMG_LOCK_DESTROY() sx_destroy(&netmap_global_lock) > +#define NMG_LOCK() sx_xlock(&netmap_global_lock) > +#define NMG_UNLOCK() sx_xunlock(&netmap_global_lock) > +#define NMG_LOCK_ASSERT() sx_assert(&netmap_global_lock, SA_XLOCKED= ) > > #define NM_SELINFO_T struct selinfo > #define MBUF_LEN(m) ((m)->m_pkthdr.len) >