From owner-p4-projects@FreeBSD.ORG Thu Sep 25 21:25:41 2014 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DEF43F3B; Thu, 25 Sep 2014 21:25:40 +0000 (UTC) Delivered-To: perforce@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 9F426F39 for ; Thu, 25 Sep 2014 21:25:40 +0000 (UTC) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:1900:2254:2068::682:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7F50C23E for ; Thu, 25 Sep 2014 21:25:40 +0000 (UTC) Received: from skunkworks.freebsd.org ([127.0.1.74]) by skunkworks.freebsd.org (8.14.9/8.14.9) with ESMTP id s8PLPeZ8035725 for ; Thu, 25 Sep 2014 21:25:40 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.9/8.14.9/Submit) id s8PLPeHK035722 for perforce@freebsd.org; Thu, 25 Sep 2014 21:25:40 GMT (envelope-from jhb@freebsd.org) Date: Thu, 25 Sep 2014 21:25:40 GMT Message-Id: <201409252125.s8PLPeHK035722@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin Subject: PERFORCE change 1200789 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.18-1 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Sep 2014 21:25:41 -0000 http://p4web.freebsd.org/@@1200789?ac=10 Change 1200789 by jhb@jhb_jhbbsd on 2014/09/25 21:25:21 Checkpoint. Affected files ... .. //depot/projects/smpng/share/man/man9/timeout.9#13 edit Differences ... ==== //depot/projects/smpng/share/man/man9/timeout.9#13 (text+ko) ==== @@ -291,16 +291,64 @@ are silently converted to the value .Sq 1 . The -.Fa sbr , +.Fa sbt , .Fa pr , and .Fa flags arguments provide more control over the scheduled time including -support for higher resolution times and setting an absolute deadline -instead of a relative timeout. - -XXX sbt and pr - +support for higher resolution times, +specifying a precision of the scheduled time, +and setting an absolute deadline instead of a relative timeout. +The callout is scheduled to execute in a time window which begins at +the time specified in +.Fa sbt +and extends for the amount of time specified in +.Fa pr . +If +.Fa sbt +specifies a time in the past, +the window is adjusted to start at the current time. +A non-zero value for +.Fa pr +allows the callout subsystem to coalesce callouts scheduled close to each +other into fewer timer interrupts reducing processing overhead and power +consumption. +The following +.Fa flags +may be specified to adjust the interpretation of +.Fa sbt +and +.Fa pr : +.Bl -tag -width ".Dv C_DIRECT_EXEC" +.It Dv C_ABSOLUTE +Handle the +.Fa sbt +argument as an absolute time since boot. +By default, +.Fa sbt +is treated as a relative amount of time similar to +.Fa ticks . +.It Dv C_DIRECT_EXEC +Run handler directly from hardware interrupt context instead of from the +softclock thread. +This reduces latency and overhead, but puts more constraints on the callout +function. +Callout functions run in this context may use only spin mutexes for locking +and should be as small as possible because they run with absolute priority. +.It Fn C_PREL +Specifies relative event time precision as binary logarithm of time interval +divided by acceptable time deviation: 1 -- 1/2, 2 -- 1/4, etc. +Note that the larger of +.Fa pr +or this value is used as the length of the time window. +Smaller values +.Pq which result in larger time intervals +allow the callout subsystem to aggregate more events in one timer interrupt. +.It Dv C_HARDCLOCK +Align the timeouts to +.Fn hardclock +calls if possible. +.El .Pp The .Fn callout_reset @@ -329,59 +377,33 @@ .Fn callout_schedule functions can be used. - .Pp -The functions -.Fn callout_reset_on +Normally callouts are scheduled to execute on the softclock thread they +were associated with previously. +Callouts that have not been scheduled are associated with the softclock +thread for CPU 0. +The +.Fn callout_reset_on , +.Fn callout_reset_sbt_on , and .Fn callout_schedule_on -are equivalent to -.Fn callout_reset -and -.Fn callout_schedule -but take an extra parameter specifying the target CPU for the callout. - -.Pp -The function -.Fn callout_reset_sbt_on -allows to get higher time resolution, taking relative or absolute time -and precision instead of relative ticks count. -If specified time is in past, it will be silently converted to present -to run handler as soon as possible. -.Pp -The following -.Fa flags -may be specified: -.Bl -tag -width ".Dv C_DIRECT_EXEC" -.It Dv C_ABSOLUTE -Handle the -.Fa sbt -argument as absolute time of the event since boot, or relative time otherwise. -.It Dv C_DIRECT_EXEC -Run handler directly from hardware interrupt context instead of softclock swi. -It is faster, but puts more constraints on handlers. -Handlers may use only spin mutexes for locking, and they must be fast because -they run with absolute priority. -.It Fn C_PREL -Specifies relative event time precision as binary logarithm of time interval -divided by acceptable time deviation: 1 -- 1/2, 2 -- 1/4, etc. -Smaller value allows to aggregate more events in one timer interrupt to -reduce processing overhead and power consumption. -.It Dv C_HARDCLOCK -Align the timeouts, if possible, to -.Fn hardclock -calls. -.El -.Pp -The functions -.Fn callout_reset_curcpu +functions accept an additional argument which associates the callout with +the softclock thread for CPU +.Fa cpu . +The +.Fn callout_reset_curcpu , +.Fn callout_reset_sbt_curpu , and .Fn callout_schedule_curcpu -are wrappers for -.Fn callout_reset_on -and -.Fn callout_schedule_on -using the current CPU as the target CPU. +functions associate the callout with the softclock thread for the current CPU. +The softclock threads are not pinned to their respective CPUs by default. +The softclock thread for CPU 0 can be pinned to CPU by setting the +.Va kern.pin_default_swi +loader tunable to a non-zero value. +The softclock threads for CPUs other than zero can be pinned to their +respective CPUs by setting the +.Va kern.pin_pcpu_swi +loader tunable to a non-zero value. .Pp The macros .Fn callout_pending , @@ -389,10 +411,6 @@ and .Fn callout_deactivate provide access to the current state of the callout. -Careful use of these macros can avoid many of the race conditions -that are inherent in asynchronous timer facilities; see -.Sx "Avoiding Race Conditions" -below for further details. The .Fn callout_pending macro checks whether a callout is @@ -405,7 +423,8 @@ .Fn callout_pending will return .Dv FALSE -even though the callout function may not have finished (or even begun) +even though the callout function may not have finished +.Pq or even begun executing. The .Fn callout_active @@ -428,6 +447,9 @@ .Em does not clear it when a callout expires normally via the execution of the callout function. + + + .Ss "Avoiding Race Conditions" The callout subsystem invokes callout functions from its own timer context.