From owner-freebsd-current@FreeBSD.ORG Fri Jun 27 09:28:02 2014 Return-Path: Delivered-To: current@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 28E275DA for ; Fri, 27 Jun 2014 09:28:02 +0000 (UTC) Received: from smtp.fagskolen.gjovik.no (smtp.fagskolen.gjovik.no [IPv6:2001:700:1100:1:200:ff:fe00:b]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "smtp.fagskolen.gjovik.no", Issuer "Fagskolen i Gj??vik" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id A106726A3 for ; Fri, 27 Jun 2014 09:28:01 +0000 (UTC) Received: from mail.fig.ol.no (localhost [127.0.0.1]) by mail.fig.ol.no (8.14.9/8.14.9) with ESMTP id s5R9RuV9000854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 27 Jun 2014 11:27:56 +0200 (CEST) (envelope-from trond@fagskolen.gjovik.no) Received: from localhost (trond@localhost) by mail.fig.ol.no (8.14.9/8.14.9/Submit) with ESMTP id s5R9RurM000851; Fri, 27 Jun 2014 11:27:56 +0200 (CEST) (envelope-from trond@fagskolen.gjovik.no) X-Authentication-Warning: mail.fig.ol.no: trond owned process doing -bs Date: Fri, 27 Jun 2014 11:27:56 +0200 (CEST) From: =?ISO-8859-1?Q?Trond_Endrest=F8l?= Sender: Trond.Endrestol@fagskolen.gjovik.no To: Luigi Rizzo Subject: Re: do we have a generic string-number sysctl mapping library ? In-Reply-To: <20140627091459.GA50710@onelab2.iet.unipi.it> Message-ID: References: <20140627091459.GA50710@onelab2.iet.unipi.it> User-Agent: Alpine 2.11 (BSF 23 2013-08-11) Organization: Fagskolen Innlandet OpenPGP: url=http://fig.ol.no/~trond/trond.key MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.fig.ol.no Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.18 Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 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: Fri, 27 Jun 2014 09:28:02 -0000 On Fri, 27 Jun 2014 11:14+0200, Luigi Rizzo wrote: > Hi, > I have frequently found myself using sysctls to control some kernel > feature where a string would be a better (and sometimes the only) > option than using a numeric value, yet the internal representation > should be numeric for speed and robustness. > Examples are the kern.timecounter, the default scheduler in dummynet, > and now in netmap the selection between native and emulated mode. > I am sure many of you can come up with other cases. > > I wonder if we have some support for that already in the sysctl code, > or i should build a generic one next time i need to do that. In C, according to sysctl(3) you could use sysctlnametomib(). I might have misinterpreted the problem domain. > Feel free to criticise the approach and suggest better ones. > Right now i am using sysctls because i have a set of macros > and wrapper functions that let me convert them to sysfs > entries when building kernel code on linux, so I have a > portable solutions. > > For the details, I'd like to have a mechanism that requires the > kernel programmer supply a (possibly extensible) table of > supported values, and matching constants to be used within > the kernel. A single declaration should generate entries > to get/set the current value as well as list options. > We can discuss frills (such as wildcards, multiple values,etc). > > cheers > luigi -- +-------------------------------+------------------------------------+ | Vennlig hilsen, | Best regards, | | Trond Endrestøl, | Trond Endrestøl, | | IT-ansvarlig, | System administrator, | | Fagskolen Innlandet, | Gjøvik Technical College, Norway, | | tlf. mob. 952 62 567, | Cellular...: +47 952 62 567, | | sentralbord 61 14 54 00. | Switchboard: +47 61 14 54 00. | +-------------------------------+------------------------------------+ From owner-freebsd-current@FreeBSD.ORG Fri Jun 27 09:47:05 2014 Return-Path: Delivered-To: current@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 E9F83AEF for ; Fri, 27 Jun 2014 09:47:05 +0000 (UTC) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id ABE10288F for ; Fri, 27 Jun 2014 09:47:05 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id ED5837300A; Fri, 27 Jun 2014 11:50:29 +0200 (CEST) Date: Fri, 27 Jun 2014 11:50:29 +0200 From: Luigi Rizzo To: Trond Endrest?l Subject: Re: do we have a generic string-number sysctl mapping library ? Message-ID: <20140627095029.GF50710@onelab2.iet.unipi.it> References: <20140627091459.GA50710@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.5.20 (2009-06-14) Cc: current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 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: Fri, 27 Jun 2014 09:47:06 -0000 On Fri, Jun 27, 2014 at 11:27:56AM +0200, Trond Endrest?l wrote: > On Fri, 27 Jun 2014 11:14+0200, Luigi Rizzo wrote: > > > Hi, > > I have frequently found myself using sysctls to control some kernel > > feature where a string would be a better (and sometimes the only) > > option than using a numeric value, yet the internal representation > > should be numeric for speed and robustness. > > Examples are the kern.timecounter, the default scheduler in dummynet, > > and now in netmap the selection between native and emulated mode. > > I am sure many of you can come up with other cases. > > > > I wonder if we have some support for that already in the sysctl code, > > or i should build a generic one next time i need to do that. > > In C, according to sysctl(3) you could use sysctlnametomib(). > I might have misinterpreted the problem domain. different problem. Example below: right now i have dev.netmap.admode which can assume integer values, i do not need a special handler, and the code in the kernel uses 1, 2 or "everything else" to decide what to do (resetting "everything else" to 0 opportunistically). I want to have a generic handler that accepts a set of predefined string values (specifically "any native emulated") and converts them to integers through some user-specificed mapping so the kernel can still do the quick tests but users don't have to remember what '2' means cheers luigi