Date: Thu, 1 Dec 2011 07:19:14 +0000 (UTC) From: Lawrence Stewart <lstewart@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r228173 - in head/sys: kern sys Message-ID: <201112010719.pB17JEb6033366@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: lstewart Date: Thu Dec 1 07:19:13 2011 New Revision: 228173 URL: http://svn.freebsd.org/changeset/base/228173 Log: Revise the sysctl handling code and restructure the hierarchy of sysctls introduced when feed-forward clock support is enabled in the kernel: - Rename the "choice" variable to "available". - Streamline the implementation of the "active" variable's sysctl handler function. - Create a kern.sysclock sysctl node for general sysclock related configuration options. Place the "available" and "active" variables under this node. - Create a kern.sysclock.ffclock sysctl node for feed-forward clock specific configuration options. Place the "version" and "ffcounter_bypass" variables under this node. - Tweak some of the description strings. Discussed with: Julien Ridoux (jridoux at unimelb edu au) Modified: head/sys/kern/kern_ffclock.c head/sys/sys/timeffc.h Modified: head/sys/kern/kern_ffclock.c ============================================================================== --- head/sys/kern/kern_ffclock.c Thu Dec 1 05:54:22 2011 (r228172) +++ head/sys/kern/kern_ffclock.c Thu Dec 1 07:19:13 2011 (r228173) @@ -148,31 +148,33 @@ ffclock_difftime(ffcounter ffdelta, stru } /* - * Sysctl for the Feed-Forward Clock. + * Create a new kern.sysclock sysctl node, which will be home to some generic + * sysclock configuration variables. Feed-forward clock specific variables will + * live under the ffclock subnode. */ -static int ffclock_version = 2; -SYSCTL_NODE(_kern, OID_AUTO, ffclock, CTLFLAG_RW, 0, - "Feed-Forward Clock Support"); -SYSCTL_INT(_kern_ffclock, OID_AUTO, version, CTLFLAG_RD, &ffclock_version, 0, - "Version of Feed-Forward Clock Support"); - -/* - * Sysctl to select which clock is read when calling any of the - * [get]{bin,nano,micro}[up]time() functions. - */ -char *sysclocks[] = {"feedback", "feed-forward"}; +SYSCTL_NODE(_kern, OID_AUTO, sysclock, CTLFLAG_RW, 0, + "System clock related configuration"); +SYSCTL_NODE(_kern_sysclock, OID_AUTO, ffclock, CTLFLAG_RW, 0, + "Feed-forward clock configuration"); +static char *sysclocks[] = {"feedback", "feed-forward"}; +#define MAX_SYSCLOCK_NAME_LEN 16 #define NUM_SYSCLOCKS (sizeof(sysclocks) / sizeof(*sysclocks)) -/* Report or change the active timecounter hardware. */ +static int ffclock_version = 2; +SYSCTL_INT(_kern_sysclock_ffclock, OID_AUTO, version, CTLFLAG_RD, + &ffclock_version, 0, "Feed-forward clock kernel version"); + +/* List available sysclocks. */ static int -sysctl_kern_ffclock_choice(SYSCTL_HANDLER_ARGS) +sysctl_kern_sysclock_available(SYSCTL_HANDLER_ARGS) { struct sbuf *s; int clk, error; - s = sbuf_new_for_sysctl(NULL, NULL, 16 * NUM_SYSCLOCKS, req); + s = sbuf_new_for_sysctl(NULL, NULL, + MAX_SYSCLOCK_NAME_LEN * NUM_SYSCLOCKS, req); if (s == NULL) return (ENOMEM); @@ -187,47 +189,51 @@ sysctl_kern_ffclock_choice(SYSCTL_HANDLE return (error); } -SYSCTL_PROC(_kern_ffclock, OID_AUTO, choice, CTLTYPE_STRING | CTLFLAG_RD, - 0, 0, sysctl_kern_ffclock_choice, "A", "Clock paradigms available"); +SYSCTL_PROC(_kern_sysclock, OID_AUTO, available, CTLTYPE_STRING | CTLFLAG_RD, + 0, 0, sysctl_kern_sysclock_available, "A", + "List of available system clocks"); +/* + * Return the name of the active system clock if read, or attempt to change + * the active system clock to the user specified one if written to. The active + * system clock is read when calling any of the [get]{bin,nano,micro}[up]time() + * functions. + */ static int -sysctl_kern_ffclock_active(SYSCTL_HANDLER_ARGS) +sysctl_kern_sysclock_active(SYSCTL_HANDLER_ARGS) { - char newclock[32]; - int error; + char newclock[MAX_SYSCLOCK_NAME_LEN]; + int clk, error; - switch (sysclock_active) { - case SYSCLOCK_FBCK: - strlcpy(newclock, sysclocks[SYSCLOCK_FBCK], sizeof(newclock)); - break; - case SYSCLOCK_FFWD: - strlcpy(newclock, sysclocks[SYSCLOCK_FFWD], sizeof(newclock)); - break; + if (req->newptr == NULL) { + /* Return the name of the current active sysclock. */ + strlcpy(newclock, sysclocks[sysclock_active], sizeof(newclock)); + error = sysctl_handle_string(oidp, newclock, + sizeof(newclock), req); + } else { + /* Change the active sysclock to the user specified one. */ + error = EINVAL; + for (clk = 0; clk < NUM_SYSCLOCKS; clk++) { + if (strncmp((char *)req->newptr, sysclocks[clk], + strlen(sysclocks[clk])) == 0) { + sysclock_active = clk; + error = 0; + break; + } + } } - error = sysctl_handle_string(oidp, &newclock[0], sizeof(newclock), req); - if (error != 0 || req->newptr == NULL) - return (error); - if (strncmp(newclock, sysclocks[SYSCLOCK_FBCK], - sizeof(sysclocks[SYSCLOCK_FBCK])) == 0) - sysclock_active = SYSCLOCK_FBCK; - else if (strncmp(newclock, sysclocks[SYSCLOCK_FFWD], - sizeof(sysclocks[SYSCLOCK_FFWD])) == 0) - sysclock_active = SYSCLOCK_FFWD; - else - return (EINVAL); - return (error); } -SYSCTL_PROC(_kern_ffclock, OID_AUTO, active, CTLTYPE_STRING | CTLFLAG_RW, - 0, 0, sysctl_kern_ffclock_active, "A", "Kernel clock selected"); - -int sysctl_kern_ffclock_ffcounter_bypass = 0; +SYSCTL_PROC(_kern_sysclock, OID_AUTO, active, CTLTYPE_STRING | CTLFLAG_RW, + 0, 0, sysctl_kern_sysclock_active, "A", + "Name of the active system clock which is currently serving time"); -SYSCTL_INT(_kern_ffclock, OID_AUTO, ffcounter_bypass, CTLFLAG_RW, +static int sysctl_kern_ffclock_ffcounter_bypass = 0; +SYSCTL_INT(_kern_sysclock_ffclock, OID_AUTO, ffcounter_bypass, CTLFLAG_RW, &sysctl_kern_ffclock_ffcounter_bypass, 0, - "Use reliable hardware timecounter as the Feed-Forward Counter"); + "Use reliable hardware timecounter as the feed-forward counter"); /* * High level functions to access the Feed-Forward Clock. Modified: head/sys/sys/timeffc.h ============================================================================== --- head/sys/sys/timeffc.h Thu Dec 1 05:54:22 2011 (r228172) +++ head/sys/sys/timeffc.h Thu Dec 1 07:19:13 2011 (r228173) @@ -55,6 +55,12 @@ struct ffclock_estimate { #if __BSD_VISIBLE #ifdef _KERNEL +/* Define the kern.sysclock sysctl tree. */ +SYSCTL_DECL(_kern_sysclock); + +/* Define the kern.sysclock.ffclock sysctl tree. */ +SYSCTL_DECL(_kern_sysclock_ffclock); + /* * Index into the sysclocks array for obtaining the ASCII name of a particular * sysclock.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112010719.pB17JEb6033366>