From owner-freebsd-current@FreeBSD.ORG Thu Aug 23 15:46:36 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5235E106566B; Thu, 23 Aug 2012 15:46:36 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 0E4F78FC14; Thu, 23 Aug 2012 15:46:34 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 7416B7300A; Thu, 23 Aug 2012 18:05:43 +0200 (CEST) Date: Thu, 23 Aug 2012 18:05:43 +0200 From: Luigi Rizzo To: Attilio Rao Message-ID: <20120823160543.GD3391@onelab2.iet.unipi.it> References: <20120823145420.GB3103@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: current@freebsd.org Subject: Re: TUNABLE_INT vs TUNABLE_INT_FETCH X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Thu, 23 Aug 2012 15:46:36 -0000 On Thu, Aug 23, 2012 at 03:52:56PM +0100, Attilio Rao wrote: > On 8/23/12, Luigi Rizzo wrote: > > Hi, > > I am a bit unclear on what are the pros and cons of using > > TUNABLE_INT vs TUNABLE_INT_FETCH within a device driver. > > TUNABLE_INT is basically the "statically initializer" version of > TUNABLE_INT_FETCH. > In short terms, you will use TUNABLE_INT_FETCH() in normal functions, > while TUNABLE_INT() in data declaration. The thing is, do we need the data declaration at all ? Using getenv_*() to read the value of a tunable (which is what TUNABLE_INT_FETCH() translates into) has the additional making sure that the variable does not change under your feet e.g. as a result of a kenv. FWIW, the reason i do not particularly like the non-fetch version is the way they are defined: #define TUNABLE_INT(path, var) \ static struct tunable_int __CONCAT(__tunable_int_, __LINE__) = { \ (path), \ (var), \ }; \ SYSINIT(__CONCAT(__Tunable_init_, __LINE__), \ SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_int_init, \ &__CONCAT(__tunable_int_, __LINE__)) note how the identifier uses __LINE__ to make it unique, which means that you cannot have more than one TUNABLE_INT() within the body of another macro (this just hit me yesterday). cheers luigi