CINXE.COM

LKML: john stultz: [PATCH 1/11] Time: Reduced NTP rework (part 1)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>LKML: john stultz: [PATCH 1/11] Time: Reduced NTP rework (part 1)</title><link href="/css/message.css" rel="stylesheet" type="text/css" /><link href="/css/wrap.css" rel="alternate stylesheet" type="text/css" title="wrap" /><link href="/css/nowrap.css" rel="stylesheet" type="text/css" title="nowrap" /><link href="/favicon.ico" rel="shortcut icon" /><script src="/js/simple-calendar.js" type="text/javascript"></script><script src="/js/styleswitcher.js" type="text/javascript"></script><link rel="alternate" type="application/rss+xml" title="lkml.org : last 100 messages" href="/rss.php" /><link rel="alternate" type="application/rss+xml" title="lkml.org : last messages by john stultz" href="/groupie.php?aid=1263" /><!--Matomo--><script> var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["setDoNotTrack", true]); _paq.push(["disableCookies"]); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() { var u="//m.lkml.org/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); </script><!--End Matomo Code--></head><body onload="es.jasper.simpleCalendar.init();" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"><table border="0" cellpadding="0" cellspacing="0"><tr><td width="180" align="center"><a href="/"><img style="border:0;width:135px;height:32px" src="/images/toprowlk.gif" alt="lkml.org" /></a></td><td width="32">聽</td><td class="nb"><div><a class="nb" href="/lkml"> [lkml]</a> 聽 <a class="nb" href="/lkml/2005"> [2005]</a> 聽 <a class="nb" href="/lkml/2005/12"> [Dec]</a> 聽 <a class="nb" href="/lkml/2005/12/15"> [15]</a> 聽 <a class="nb" href="/lkml/last100"> [last100]</a> 聽 <a href="/rss.php"><img src="/images/rss-or.gif" border="0" alt="RSS Feed" /></a></div><div>Views: <a href="#" class="nowrap" onclick="setActiveStyleSheet('wrap');return false;">[wrap]</a><a href="#" class="wrap" onclick="setActiveStyleSheet('nowrap');return false;">[no wrap]</a> 聽 <a class="nb" href="/lkml/mheaders/2005/12/15/404" onclick="this.href='/lkml/headers'+'/2005/12/15/404';">[headers]</a>聽 <a href="/lkml/bounce/2005/12/15/404">[forward]</a>聽 </div></td><td width="32">聽</td></tr><tr><td valign="top"><div class="es-jasper-simpleCalendar" baseurl="/lkml/"></div><div class="threadlist">Messages in this thread</div><ul class="threadlist"><li class="root"><a href="/lkml/2005/12/15/405">First message in thread</a></li><li><a href="/lkml/2005/12/15/405">john stultz</a><ul><li class="origin"><a href="">john stultz</a></li><li><a href="/lkml/2005/12/15/406">john stultz</a></li><li><a href="/lkml/2005/12/15/407">john stultz</a><ul><li><a href="/lkml/2006/1/3/509">Andrew Morton</a><ul><li><a href="/lkml/2006/1/4/72">john stultz</a><ul><li><a href="/lkml/2006/1/4/76">Andrew Morton</a></li></ul></li></ul></li></ul></li><li><a href="/lkml/2005/12/15/408">john stultz</a></li><li><a href="/lkml/2005/12/15/409">john stultz</a></li><li><a href="/lkml/2005/12/15/410">john stultz</a></li><li><a href="/lkml/2005/12/15/411">john stultz</a></li><li><a href="/lkml/2005/12/15/412">john stultz</a></li><li><a href="/lkml/2005/12/15/413">john stultz</a></li><li><a href="/lkml/2005/12/15/414">john stultz</a></li><li><a href="/lkml/2005/12/15/415">john stultz</a></li></ul></li></ul><div class="threadlist">Patch in this message</div><ul class="threadlist"><li><a href="/lkml/diff/2005/12/15/404/1">Get diff 1</a></li></ul></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerl.gif" width="32" height="32" alt="/" /></td><td class="c" rowspan="2" valign="top" style="padding-top: 1em"><table><tr><td><table><tr><td class="lp">Date</td><td class="rp" itemprop="datePublished">Thu, 15 Dec 2005 18:07:07 -0700</td></tr><tr><td class="lp">From</td><td class="rp" itemprop="author">john stultz &lt;&gt;</td></tr><tr><td class="lp">Subject</td><td class="rp" itemprop="name">[PATCH 1/11] Time: Reduced NTP rework (part 1)</td></tr></table></td><td></td></tr></table><pre itemprop="articleBody">Andrew, All,<br /> With Roman's suggestions, I've been working on reducing the <br />footprint of my timeofday patches. This is the first of two patches <br />that reworks some of the interrupt time NTP adjustments so that it <br />could be re-used with the timeofday patches. The motivation of the <br />change is to logically separate the code which adjusts xtime and the <br />code that decides, based on the NTP state variables, how much per tick <br />to adjust xtime. <br /><br />Thus this patch should not affect the existing behavior, but just <br />separate the logical functionality so it can be re-used.<br /><br />Andrew, please consider for inclusion into your tree.<br /><br />thanks<br />-john<br /><br />Signed-off-by: John Stultz &lt;johnstul&#64;us.ibm.com&gt;<br /><br /> timer.c | 123 ++++++++++++++++++++++++++++++++++++++++++++--------------------<br /> 1 files changed, 85 insertions(+), 38 deletions(-)<br /><br />linux-2.6.15-rc5_timeofday-ntp-part1_B14.patch<br />============================================<br />diff --git a/kernel/timer.c b/kernel/timer.c<br />index 91572cf..2a0a549 100644<br />--- a/kernel/timer.c<br />+++ b/kernel/timer.c<br />&#64;&#64; -589,6 +589,7 &#64;&#64; static long time_adj; /* tick adjust (<br /> long time_reftime; /* time at last adjustment (s) */<br /> long time_adjust;<br /> long time_next_adjust;<br />+long time_adjust_step; /* per tick time_adjust step */<br /> <br /> /*<br /> * this routine handles the overflow of the microsecond field<br />&#64;&#64; -716,45 +717,86 &#64;&#64; static void second_overflow(void)<br /> #endif<br /> }<br /> <br />-/* in the NTP reference this is called "hardclock()" */<br />-static void update_wall_time_one_tick(void)<br />+/**<br />+ * ntp_advance - increments the NTP state machine<br />+ * &#64;interval_ns: interval, in nanoseconds<br />+ *<br />+ * Must be holding the xtime writelock when calling.<br />+ */<br />+static void ntp_advance(unsigned long interval_ns)<br /> {<br />- long time_adjust_step, delta_nsec;<br />+ static unsigned long interval_sum;<br /> <br />- if ((time_adjust_step = time_adjust) != 0 ) {<br />- /*<br />- * We are doing an adjtime thing. Prepare time_adjust_step to<br />- * be within bounds. Note that a positive time_adjust means we<br />- * want the clock to run faster.<br />- *<br />- * Limit the amount of the step to be in the range<br />- * -tickadj .. +tickadj<br />- */<br />- time_adjust_step = min(time_adjust_step, (long)tickadj);<br />- time_adjust_step = max(time_adjust_step, (long)-tickadj);<br />+ /* increment the interval sum: */<br />+ interval_sum += interval_ns;<br />+<br />+ /* calculate the per tick singleshot adjtime adjustment step: */<br />+ while (interval_ns &gt;= tick_nsec) {<br />+ time_adjust_step = time_adjust;<br />+ if (time_adjust_step) {<br />+ /*<br />+ * We are doing an adjtime thing.<br />+ *<br />+ * Prepare time_adjust_step to be within bounds.<br />+ * Note that a positive time_adjust means we want<br />+ * the clock to run faster.<br />+ *<br />+ * Limit the amount of the step to be in the range<br />+ * -tickadj .. +tickadj:<br />+ */<br />+ time_adjust_step = min(time_adjust_step, (long)tickadj);<br />+ time_adjust_step = max(time_adjust_step,<br />+ (long)-tickadj);<br /> <br />- /* Reduce by this step the amount of time left */<br />- time_adjust -= time_adjust_step;<br />- }<br />- delta_nsec = tick_nsec + time_adjust_step * 1000;<br />- /*<br />- * Advance the phase, once it gets to one microsecond, then<br />- * advance the tick more.<br />- */<br />- time_phase += time_adj;<br />- if ((time_phase &gt;= FINENSEC) || (time_phase &lt;= -FINENSEC)) {<br />- long ltemp = shift_right(time_phase, (SHIFT_SCALE - 10));<br />- time_phase -= ltemp &lt;&lt; (SHIFT_SCALE - 10);<br />- delta_nsec += ltemp;<br />+ /* Reduce by this step the amount of time left: */<br />+ time_adjust -= time_adjust_step;<br />+ }<br />+ interval_ns -= tick_nsec;<br /> }<br />- xtime.tv_nsec += delta_nsec;<br />- time_interpolator_update(delta_nsec);<br /> <br /> /* Changes by adjtime() do not take effect till next tick. */<br /> if (time_next_adjust != 0) {<br /> time_adjust = time_next_adjust;<br /> time_next_adjust = 0;<br /> }<br />+<br />+ while (interval_sum &gt;= NSEC_PER_SEC) {<br />+ interval_sum -= NSEC_PER_SEC;<br />+ second_overflow();<br />+ }<br />+}<br />+<br />+/**<br />+ * phase_advance - advance the phase<br />+ *<br />+ * advance the phase, once it gets to one nanosecond advance the tick more.<br />+ */<br />+static inline long phase_advance(void)<br />+{<br />+ long delta = 0;<br />+<br />+ time_phase += time_adj;<br />+<br />+ if ((time_phase &gt;= FINENSEC) || (time_phase &lt;= -FINENSEC)) {<br />+ delta = shift_right(time_phase, (SHIFT_SCALE - 10));<br />+ time_phase -= delta &lt;&lt; (SHIFT_SCALE - 10);<br />+ }<br />+<br />+ return delta;<br />+}<br />+<br />+/**<br />+ * xtime_advance - advance xtime<br />+ * &#64;delta_nsec: adjustment in nsecs<br />+ */<br />+static inline void xtime_advance(long delta_nsec)<br />+{<br />+ xtime.tv_nsec += delta_nsec;<br />+ if (likely(xtime.tv_nsec &lt; NSEC_PER_SEC))<br />+ return;<br />+<br />+ xtime.tv_nsec -= NSEC_PER_SEC;<br />+ xtime.tv_sec++;<br /> }<br /> <br /> /*<br />&#64;&#64; -762,19 +804,24 &#64;&#64; static void update_wall_time_one_tick(vo<br /> * usually just one (we shouldn't be losing ticks,<br /> * we're doing this this way mainly for interrupt<br /> * latency reasons, not because we think we'll<br />- * have lots of lost timer ticks<br />+ * have lots of lost timer ticks)<br /> */<br /> static void update_wall_time(unsigned long ticks)<br /> {<br /> do {<br />- ticks--;<br />- update_wall_time_one_tick();<br />- if (xtime.tv_nsec &gt;= 1000000000) {<br />- xtime.tv_nsec -= 1000000000;<br />- xtime.tv_sec++;<br />- second_overflow();<br />- }<br />- } while (ticks);<br />+ /*<br />+ * Calculate the nsec delta using the precomputed NTP<br />+ * adjustments:<br />+ * tick_nsec, time_adjust_step, time_adj<br />+ */<br />+ long delta_nsec = tick_nsec + time_adjust_step * 1000;<br />+ delta_nsec += phase_advance();<br />+<br />+ xtime_advance(delta_nsec);<br />+ ntp_advance(tick_nsec);<br />+ time_interpolator_update(delta_nsec);<br />+<br />+ } while (--ticks);<br /> }<br /> <br /> /*<br />-<br />To unsubscribe from this list: send the line "unsubscribe linux-kernel" in<br />the body of a message to majordomo&#64;vger.kernel.org<br />More majordomo info at <a href="http://vger.kernel.org/majordomo-info.html">http://vger.kernel.org/majordomo-info.html</a><br />Please read the FAQ at <a href="http://www.tux.org/lkml/">http://www.tux.org/lkml/</a><br /></pre></td><td width="32" rowspan="2" class="c" valign="top"><img src="/images/icornerr.gif" width="32" height="32" alt="\" /></td></tr><tr><td align="right" valign="bottom"> 聽 </td></tr><tr><td align="right" valign="bottom">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerl.gif" width="32" height="32" alt="\" /></td><td class="c">聽</td><td class="c" valign="bottom" style="padding-bottom: 0px"><img src="/images/bcornerr.gif" width="32" height="32" alt="/" /></td></tr><tr><td align="right" valign="top" colspan="2"> 聽 </td><td class="lm">Last update: 2005-12-16 02:10 聽聽 [from the cache]<br />漏2003-2020 <a href="http://blog.jasper.es/"><span itemprop="editor">Jasper Spaans</span></a>|hosted at <a href="https://www.digitalocean.com/?refcode=9a8e99d24cf9">Digital Ocean</a> and my Meterkast|<a href="http://blog.jasper.es/categories.html#lkml-ref">Read the blog</a></td><td>聽</td></tr></table><script language="javascript" src="/js/styleswitcher.js" type="text/javascript"></script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10