From owner-svn-src-projects@FreeBSD.ORG Thu Dec 13 20:07:12 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2D2F0CC0; Thu, 13 Dec 2012 20:07:12 +0000 (UTC) (envelope-from davide@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id E8EF28FC0A; Thu, 13 Dec 2012 20:07:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBDK7Bp9004968; Thu, 13 Dec 2012 20:07:11 GMT (envelope-from davide@svn.freebsd.org) Received: (from davide@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBDK7B6T004967; Thu, 13 Dec 2012 20:07:11 GMT (envelope-from davide@svn.freebsd.org) Message-Id: <201212132007.qBDK7B6T004967@svn.freebsd.org> From: Davide Italiano Date: Thu, 13 Dec 2012 20:07:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r244190 - projects/calloutng/sys/kern X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Dec 2012 20:07:12 -0000 Author: davide Date: Thu Dec 13 20:07:11 2012 New Revision: 244190 URL: http://svnweb.freebsd.org/changeset/base/244190 Log: Make kern.tc_timepercentage procedural, so that everytime we change its value, the variables which depends from it are changed accordingly. While here, rename the aforementioned sysctl to something more appropriate. Reviewed by: mav Modified: projects/calloutng/sys/kern/kern_tc.c Modified: projects/calloutng/sys/kern/kern_tc.c ============================================================================== --- projects/calloutng/sys/kern/kern_tc.c Thu Dec 13 19:29:44 2012 (r244189) +++ projects/calloutng/sys/kern/kern_tc.c Thu Dec 13 20:07:11 2012 (r244190) @@ -124,9 +124,13 @@ struct bintime halftick_bt; struct bintime tick_bt; int tc_timeexp; int tc_timepercentage = TC_DEFAULTPERC; +TUNABLE_INT("kern.timecounter.allowdeviation", &tc_timepercentage); int tc_timethreshold; -SYSCTL_INT(_kern, OID_AUTO, tc_timepercentage, CTLFLAG_RW, - &tc_timepercentage, 0, "Precision percentage tolerance"); +static int sysctl_kern_timecounter_adjprecision(SYSCTL_HANDLER_ARGS); +SYSCTL_PROC(_kern_timecounter, OID_AUTO, tc_timepercentage, + CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0, + sysctl_kern_timecounter_adjprecision, "I", + "Allowed deviation from absolute value"); static void tc_windup(void); static void cpu_tick_calibrate(int); @@ -1714,11 +1718,38 @@ tc_ticktock(int cnt) tc_windup(); } +static void __inline +tc_adjprecision(void) +{ + struct timespec ts; + int tick_rate; + + tick_rate = hz / tc_tick; + tc_timethreshold = (1000000000 / (tick_rate * tc_timepercentage)) * 100; + tc_timeexp = fls(roundup2(100 / tc_timepercentage, 2)); + ts.tv_sec = tc_timethreshold / 1000000000; + ts.tv_nsec = tc_timethreshold % 1000000000; + timespec2bintime(&ts, &bt_timethreshold); +} + +static int +sysctl_kern_timecounter_adjprecision(SYSCTL_HANDLER_ARGS) +{ + int error, val; + + val = tc_timepercentage; + error = sysctl_handle_int(oidp, &val, 0, req); + if (error != 0 || req->newptr == NULL) + return (error); + tc_timepercentage = val; + tc_adjprecision(); + return (0); +} + static void inittimecounter(void *dummy) { u_int p; - struct timespec ts; int tick_rate; /* @@ -1733,12 +1764,8 @@ inittimecounter(void *dummy) tc_tick = (hz + 500) / 1000; else tc_tick = 1; + tc_adjprecision(); tick_rate = hz / tc_tick; - tc_timethreshold = (1000000000 / (tick_rate * tc_timepercentage)) * 100; - tc_timeexp = fls(roundup2(100 / tc_timepercentage, 2)); - ts.tv_sec = tc_timethreshold / 1000000000; - ts.tv_nsec = tc_timethreshold % 1000000000; - timespec2bintime(&ts, &bt_timethreshold); FREQ2BT(tick_rate, &tick_bt); halftick_bt = tick_bt; bintime_divpow2(&halftick_bt, 1);