From owner-freebsd-net@FreeBSD.ORG Tue May 27 23:49:51 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 8CFB8A4E for ; Tue, 27 May 2014 23:49:51 +0000 (UTC) Received: from mail-pb0-x234.google.com (mail-pb0-x234.google.com [IPv6:2607:f8b0:400e:c01::234]) (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 62CC7231A for ; Tue, 27 May 2014 23:49:51 +0000 (UTC) Received: by mail-pb0-f52.google.com with SMTP id rr13so10156862pbb.11 for ; Tue, 27 May 2014 16:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=q89WN56I5/uZf/fweXFkGCcnOcdPD0L94O4wjROjDCs=; b=nq13mzVV51nAEhlcYjN6mawEwa0nA0shUu+CFgH2ad3YjDU5mjaXaU5791Nm2EsAse wmZjd94ZDq/+1EBZxsIe0W4+5WNZK2eKQt8g+LhQqGujYTqy6jBoYh570aosgA3atHvh JtXrkjdDyu28vCbY+bPE4q08jJymSll9upu4ZoQPL7/MDGbJrdVdbVUpj2mexqH9QS8D QLw6YD5cn+Gv+Vqdrig0rS6MBtE+xR0uqQ7GJBM2QsybpvNKh3B3iHNEdts0MQuMdiSu lKFkvhjXIbzP2RamfLO+pSyAYvs0YTATSdlpKrzgctt9LrbN9RxQufGl1/CnITnrMDKR F6cw== X-Received: by 10.68.197.134 with SMTP id iu6mr17709091pbc.164.1401234591012; Tue, 27 May 2014 16:49:51 -0700 (PDT) Received: from [10.192.166.0] (stargate.chelsio.com. [67.207.112.58]) by mx.google.com with ESMTPSA id uk1sm79781328pac.26.2014.05.27.16.49.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 May 2014 16:49:50 -0700 (PDT) Sender: Navdeep Parhar Message-ID: <5385249D.9050501@FreeBSD.org> Date: Tue, 27 May 2014 16:49:49 -0700 From: Navdeep Parhar User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Luigi Rizzo , "freebsd-net@freebsd.org" Subject: change netmap global lock to sx? Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: Tue, 27 May 2014 23:49:51 -0000 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. 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)