<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monk's Blog</title>
	<atom:link href="http://people.summit-servers.com/monk/feed/" rel="self" type="application/rss+xml" />
	<link>http://people.summit-servers.com/monk</link>
	<description>GSP Info</description>
	<lastBuildDate>Fri, 13 Jan 2012 21:06:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>CSS FPS unlocker</title>
		<link>http://people.summit-servers.com/monk/2012/01/13/css-fps-unlocker/</link>
		<comments>http://people.summit-servers.com/monk/2012/01/13/css-fps-unlocker/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 21:06:51 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=228</guid>
		<description><![CDATA[$99 one time fee. It&#8217;s update proof! No binary patching of files, everything is done IN memory. Works on x86 and x86_64, all flavors of linux. No root required!]]></description>
			<content:encoded><![CDATA[<p>$99 one time fee. It&#8217;s update proof! No binary patching of files, everything is done IN memory. Works on x86 and x86_64, all flavors of linux. No root required!</p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2012/01/13/css-fps-unlocker/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Modern Warfare 3 boosting module.. coming</title>
		<link>http://people.summit-servers.com/monk/2011/12/23/modern-warfare-3-boosting-module-coming/</link>
		<comments>http://people.summit-servers.com/monk/2011/12/23/modern-warfare-3-boosting-module-coming/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 04:23:57 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=225</guid>
		<description><![CDATA[I&#8217;ve decided I didn&#8217;t like the built-in engine lack that IW/Activison inherited from the quake 3 engine, so I&#8217;ve written a module to remove the built in lag by reducing it. This should only be used on servers were the average latency of all users is under]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided I didn&#8217;t like the built-in engine lack that IW/Activison inherited from the quake 3 engine, so I&#8217;ve written a module to remove the built in lag by reducing it. This should only be used on servers were the average latency of all users is under <100mS because it will cause some aliasing. </p>
<p>Coming soon. </p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2011/12/23/modern-warfare-3-boosting-module-coming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Monk strikes again.. Unlocked FPS on CSS for linux</title>
		<link>http://people.summit-servers.com/monk/2011/10/30/monk-strikes-again-unlocked-fps-on-css-for-linux/</link>
		<comments>http://people.summit-servers.com/monk/2011/10/30/monk-strikes-again-unlocked-fps-on-css-for-linux/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 19:17:50 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=220</guid>
		<description><![CDATA[I&#8217;ve done it. I had to do some LD_PRELOAD magic to byte patch the address range of a file to get it to work correctly.. I was able to remove the 66fps/hz from the linux binary..]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve done it. I had to do some LD_PRELOAD magic to byte patch the address range of a file to get it to work correctly..</p>
<p><a href="http://people.summit-servers.com/monk/wp-content/uploads/2011/10/10000-fps.bmp"><img src="http://people.summit-servers.com/monk/wp-content/uploads/2011/10/10000-fps.bmp" alt="" title="10000-fps" class="alignnone size-full wp-image-221" /></a></p>
<p>I was able to remove the 66fps/hz from the linux binary..</p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2011/10/30/monk-strikes-again-unlocked-fps-on-css-for-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hosting</title>
		<link>http://people.summit-servers.com/monk/2010/12/03/hosting/</link>
		<comments>http://people.summit-servers.com/monk/2010/12/03/hosting/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 08:11:42 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=215</guid>
		<description><![CDATA[I plan on doing some moving of my stuff off this server so I can speak a little more freely. Anyone want to donate some hosting to me, that would be great. I get about few thousand pageviews a month, not much.]]></description>
			<content:encoded><![CDATA[<p>I plan on doing some moving of my stuff off this server so I can speak a little more freely. Anyone want to donate some hosting to me, that would be great. I get about few thousand pageviews a month, not much. </p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/12/03/hosting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SRCDS Memory Usage</title>
		<link>http://people.summit-servers.com/monk/2010/11/09/srcds-memory-usage/</link>
		<comments>http://people.summit-servers.com/monk/2010/11/09/srcds-memory-usage/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 22:23:27 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=213</guid>
		<description><![CDATA[So you&#8217;ve got a server, and (over time?) it seems to consume a large amount of virtual memory? &#160; blah 22011 3.9 6.5 1368616 165440 ? Rl 04:02 31:40 ./srcds_linux -game cstrike -console +ip 1.2.3.4 -port 27015 +tv_port 28020 +maxplayers 12 +map de_dust2 -autoupdate See the &#8217;1368616&#8242; number? That&#8217;s your virtual memory aka mapped memory. [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve got a server, and (over time?) it seems to consume a large amount of virtual memory?</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
blah  <span style="color: #0000dd;">22011</span>  <span style="color:#800080;">3.9</span>  <span style="color:#800080;">6.5</span> <span style="color: #0000dd;">1368616</span> <span style="color: #0000dd;">165440</span> <span style="color: #339933;">?</span>       Rl   <span style="color: #208080;">04</span><span style="color: #339933;">:</span><span style="color: #208080;">02</span>  <span style="color: #0000dd;">31</span><span style="color: #339933;">:</span><span style="color: #0000dd;">40</span> .<span style="color: #339933;">/</span>srcds_linux <span style="color: #339933;">-</span>game cstrike <span style="color: #339933;">-</span>console <span style="color: #339933;">+</span>ip 1.2.3.4 <span style="color: #339933;">-</span>port <span style="color: #0000dd;">27015</span> <span style="color: #339933;">+</span>tv_port <span style="color: #0000dd;">28020</span> <span style="color: #339933;">+</span>maxplayers <span style="color: #0000dd;">12</span> <span style="color: #339933;">+</span>map de_dust2 <span style="color: #339933;">-</span>autoupdate</pre></div></div>

<p>See the &#8217;1368616&#8242; number? That&#8217;s your virtual memory aka mapped memory. That number is usually larger on glibc 2.3.2+ because of NPTL&#8217;s stack size, which is usually this (x86_64):</p>
<p>stack size              (kbytes, -s) 8192</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>gary@dallas ~<span style="color: #009900;">&#93;</span>$ ulimit <span style="color: #339933;">-</span>s
<span style="color: #0000dd;">8192</span></pre></div></div>

<p>That is just way too large for gameservers. AIX and Solaris use 96 and 64, respectively, and 8192 is just way too large.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>gary@dallas ~<span style="color: #009900;">&#93;</span>$ ulimit <span style="color: #339933;">-</span>s <span style="color: #0000dd;">512</span>
<span style="color: #339933;">&lt;/</span>pre lang<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #339933;">&gt;</span>
blah     <span style="color: #0000dd;">31008</span>  <span style="color:#800080;">6.7</span>  <span style="color:#800080;">0.5</span> <span style="color: #0000dd;">126440</span> <span style="color: #0000dd;">21528</span> pts<span style="color: #339933;">/</span><span style="color: #0000dd;">4</span>    Sl<span style="color: #339933;">+</span>  <span style="color: #0000dd;">17</span><span style="color: #339933;">:</span><span style="color: #0000dd;">20</span>   <span style="color: #208080;">01</span><span style="color: #339933;">:</span><span style="color: #0000dd;">40</span> .<span style="color: #339933;">/</span>srcds_linux <span style="color: #339933;">-</span>game cstrike <span style="color: #339933;">-</span>console <span style="color: #339933;">+</span>ip 1.2.3.4 <span style="color: #339933;">-</span>port <span style="color: #0000dd;">27015</span> <span style="color: #339933;">+</span>tv_port <span style="color: #0000dd;">28020</span> <span style="color: #339933;">+</span>maxplayers <span style="color: #0000dd;">12</span> <span style="color: #339933;">+</span>map de_dust2 <span style="color: #339933;">-</span>autoupdate</pre></div></div>

<p>Much better:</p>
<p>Old:<br />
mapped: 368616K    writeable/private: 326688K    shared: 0K<br />
New:<br />
mapped: 168044K    writeable/private: 130164K    shared: 0K</p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/11/09/srcds-memory-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&gt;1000FPS on Windows</title>
		<link>http://people.summit-servers.com/monk/2010/09/03/1000fps-on-windows/</link>
		<comments>http://people.summit-servers.com/monk/2010/09/03/1000fps-on-windows/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 04:02:39 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=208</guid>
		<description><![CDATA[Over 1000FPS is possible on windows.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.summit-servers.com/project10.bmp">Over 1000FPS is possible on windows.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/09/03/1000fps-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HPET / RDTSC based userland gettimeofday</title>
		<link>http://people.summit-servers.com/monk/2010/07/26/hpet-rdtsc-based-userland-gettimeofday/</link>
		<comments>http://people.summit-servers.com/monk/2010/07/26/hpet-rdtsc-based-userland-gettimeofday/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 16:56:11 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=197</guid>
		<description><![CDATA[&#160; /*- * Copyright (c) 2007, 2008, 2009, 2010 Gary &#34;Monk&#34; Stanley * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">/*-
 * Copyright (c) 2007, 2008, 2009, 2010 Gary &quot;Monk&quot; Stanley
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. This software may not be used by individuals associated with 
 *    fpsmeter.com / fragaholics.de
 * 4. Neither the name of the Author may be used to endorse or promote products 
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      
 */</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/* Proof of concept code for Linux. MAY work on other distros, but it will only use rdtsc */</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;dlfcn.h&gt;</span>
<span style="color: #339933;">#include &lt;stdint.h&gt;</span>
<span style="color: #339933;">#include &lt;sched.h&gt;</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
&nbsp;
&nbsp;
<span style="color: #339933;">#include &lt;assert.h&gt;</span>
<span style="color: #339933;">#include &lt;errno.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;sys/ioctl.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/time.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/types.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/wait.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;linux/hpet.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/rtc.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define STACK_SIZE (1 * 1024 * 1024)</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> initialised<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1 = use HPET, 2 = use CPU counter.</span>
	<span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>system_gettimeofday<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> timeval <span style="color: #339933;">*</span>tp<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>tzp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> timeval cachedTime<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> frequency<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> ticksPerUsec<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> childPid<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> parentPid<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> fd<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> childStack<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> details<span style="color: #339933;">;</span>
<span style="color: #993333;">static</span> uint64_t lastTSCCount <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">inline</span> uint64_t RDTSC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> hi<span style="color: #339933;">,</span> lo<span style="color: #339933;">;</span>
	uint64_t result<span style="color: #339933;">;</span>
	__asm__ <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;rdtsc&quot;</span> <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;=a&quot;</span><span style="color: #009900;">&#40;</span>lo<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;=d&quot;</span><span style="color: #009900;">&#40;</span>hi<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>uint64_t<span style="color: #009900;">&#41;</span> hi <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">32</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> lo<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Return ticks per usec.</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> calibrate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #993333;">long</span> startClock<span style="color: #339933;">,</span> endClock<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> timeval startTime<span style="color: #339933;">,</span> endTime<span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> t1<span style="color: #339933;">,</span> t2<span style="color: #339933;">,</span> diff<span style="color: #339933;">;</span>
&nbsp;
	details.<span style="color: #202020;">system_gettimeofday</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>startTime<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	startClock <span style="color: #339933;">=</span> RDTSC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">100000</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		__asm__ __volatile__ <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;nop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	details.<span style="color: #202020;">system_gettimeofday</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>endTime<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	endClock <span style="color: #339933;">=</span> RDTSC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	t1 <span style="color: #339933;">=</span> startTime.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">*</span> <span style="color:#800080;">1000000.0</span> <span style="color: #339933;">+</span> startTime.<span style="color: #202020;">tv_usec</span><span style="color: #339933;">;</span>
	t2 <span style="color: #339933;">=</span> endTime.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">*</span> <span style="color:#800080;">1000000.0</span> <span style="color: #339933;">+</span> endTime.<span style="color: #202020;">tv_usec</span><span style="color: #339933;">;</span>
&nbsp;
	diff <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>endClock <span style="color: #339933;">-</span> startClock<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>t2 <span style="color: #339933;">-</span> t1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> diff <span style="color: #339933;">+</span> <span style="color:#800080;">0.5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Round up to avoid time going backwards</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span>
hpet_trigger<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> dummy<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	details.<span style="color: #202020;">system_gettimeofday</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>details.<span style="color: #202020;">cachedTime</span><span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>
hpet_thread<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #339933;">*</span> dummy<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">struct</span> sigaction foo<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Dummy thread to accept HPET async signals</span>
	<span style="color: #666666; font-style: italic;">// this should help to avoid interrupting sleep() calls and</span>
	<span style="color: #666666; font-style: italic;">// friends in other threads.</span>
&nbsp;
	<span style="color: #993333;">int</span> result <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	foo.<span style="color: #202020;">sa_flags</span> <span style="color: #339933;">=</span> SA_RESTART<span style="color: #339933;">;</span>
	sigemptyset<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>foo.<span style="color: #202020;">sa_mask</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	foo.<span style="color: #202020;">sa_handler</span> <span style="color: #339933;">=</span> hpet_trigger<span style="color: #339933;">;</span>
	result <span style="color: #339933;">=</span> sigaction<span style="color: #009900;">&#40;</span>SIGIO<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>foo<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>result <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		pause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>
init_hpet<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> freq<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> fdFlags<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> hpet_info info<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Child will have a new signal handler table, but share the same memory space</span>
	<span style="color: #666666; font-style: italic;">// (new thread is created to avoid signal handler conflicts,</span>
	<span style="color: #666666; font-style: italic;">// and to avoid waking the main thread up due to the hpet signals)</span>
	details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>STACK_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> clone<span style="color: #009900;">&#40;</span>hpet_thread<span style="color: #339933;">,</span> details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">+</span> STACK_SIZE <span style="color: #339933;">-</span> <span style="color: #0000dd;">64</span><span style="color: #339933;">,</span> CLONE_VM<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/hpet&quot;</span><span style="color: #339933;">,</span> O_RDONLY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> HPET_IRQFREQ<span style="color: #339933;">,</span> freq<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> HPET_INFO<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>info<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>info.<span style="color: #202020;">hi_flags</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> HPET_EPI<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #339933;">||</span> ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> HPET_IE_ON<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_SETOWN<span style="color: #339933;">,</span> details.<span style="color: #202020;">childPid</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fdFlags <span style="color: #339933;">=</span> fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_GETFL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
		<span style="color: #009900;">&#40;</span>fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_SETFL<span style="color: #339933;">,</span> fdFlags <span style="color: #339933;">|</span> O_ASYNC<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
	out<span style="color: #339933;">:</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		close<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		kill<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		waitpid<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		free<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span>
init_rtc<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> freq<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> fdFlags<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Child will have a new signal handler table, but share the same memory space</span>
	<span style="color: #666666; font-style: italic;">// (new thread is created to avoid signal handler conflicts,</span>
	<span style="color: #666666; font-style: italic;">// and to avoid waking the main thread up due to the hpet signals)</span>
	details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>STACK_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	assert<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> clone<span style="color: #009900;">&#40;</span>hpet_thread<span style="color: #339933;">,</span> details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">+</span> STACK_SIZE <span style="color: #339933;">-</span> <span style="color: #0000dd;">64</span><span style="color: #339933;">,</span> CLONE_VM<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/rtc&quot;</span><span style="color: #339933;">,</span> O_RDONLY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> RTC_IRQP_SET<span style="color: #339933;">,</span> freq<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> RTC_PIE_ON<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_SETOWN<span style="color: #339933;">,</span> details.<span style="color: #202020;">childPid</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
		<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fdFlags <span style="color: #339933;">=</span> fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_GETFL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
		<span style="color: #009900;">&#40;</span>fcntl<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #339933;">,</span> F_SETFL<span style="color: #339933;">,</span> fdFlags <span style="color: #339933;">|</span> O_ASYNC<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
	out<span style="color: #339933;">:</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		close<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		kill<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		waitpid<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		free<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>constructor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> msg<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> freqEnv<span style="color: #339933;">;</span>
	<span style="color: #993333;">char</span><span style="color: #339933;">*</span> altEnv<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> rawFreq<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">initialised</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;libfasttime.so: Already initialised!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	details.<span style="color: #202020;">initialised</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">system_gettimeofday</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	details.<span style="color: #202020;">cachedTime</span>.<span style="color: #202020;">tv_sec</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">cachedTime</span>.<span style="color: #202020;">tv_usec</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">frequency</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">parentPid</span> <span style="color: #339933;">=</span> getpid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	details.<span style="color: #202020;">ticksPerUsec</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
	details.<span style="color: #202020;">system_gettimeofday</span> <span style="color: #339933;">=</span> dlsym<span style="color: #009900;">&#40;</span>RTLD_NEXT<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;gettimeofday&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>msg <span style="color: #339933;">=</span> dlerror<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;libfasttime.so: gettimeofday: dlopen failed: %s&quot;</span><span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	details.<span style="color: #202020;">ticksPerUsec</span> <span style="color: #339933;">=</span> calibrate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//fprintf(stderr, &quot;Ticks per usec = %d\n&quot;, details.ticksPerUsec);</span>
&nbsp;
	freqEnv <span style="color: #339933;">=</span> getenv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;FASTTIME_FREQ&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>freqEnv<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		rawFreq <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>freqEnv<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		rawFreq <span style="color: #339933;">=</span> <span style="color: #0000dd;">1024</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Hz</span>
	<span style="color: #009900;">&#125;</span>
	details.<span style="color: #202020;">frequency</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rawFreq <span style="color: #339933;">*</span> <span style="color:#800080;">1e6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> details.<span style="color: #202020;">ticksPerUsec</span><span style="color: #339933;">;</span>
&nbsp;
	altEnv <span style="color: #339933;">=</span> getenv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;FASTTIME_ALT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>altEnv <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">*</span>altEnv<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">goto</span> fallback<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>init_hpet<span style="color: #009900;">&#40;</span>rawFreq<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		details.<span style="color: #202020;">initialised</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;libfasttime.so: initialized using hpet<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>init_rtc<span style="color: #009900;">&#40;</span>rawFreq<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		details.<span style="color: #202020;">initialised</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;libfasttime.so: initialized using rtc<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	fallback<span style="color: #339933;">:</span>
	lastTSCCount <span style="color: #339933;">=</span> RDTSC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	details.<span style="color: #202020;">initialised</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
	fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;libfasttime.so: using alternative time method<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	out<span style="color: #339933;">:</span>
	details.<span style="color: #202020;">system_gettimeofday</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>details.<span style="color: #202020;">cachedTime</span><span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>destructor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
cleanup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		close<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">fd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">fd</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		free<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childStack</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childStack</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		kill<span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">childPid</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		details.<span style="color: #202020;">childPid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span>
gettimeofday<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> timeval <span style="color: #339933;">*</span>__restrict tp<span style="color: #339933;">,</span> __timezone_ptr_t tzp<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Copy declaration from sys/time.h</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>details.<span style="color: #202020;">initialised</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		uint64_t currentCount <span style="color: #339933;">=</span> RDTSC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		int64_t diff <span style="color: #339933;">=</span> currentCount <span style="color: #339933;">-</span> lastTSCCount<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>diff <span style="color: #339933;">&gt;</span> details.<span style="color: #202020;">frequency</span> <span style="color: #339933;">||</span> diff <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			details.<span style="color: #202020;">system_gettimeofday</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>details.<span style="color: #202020;">cachedTime</span><span style="color: #339933;">,</span> tzp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			lastTSCCount <span style="color: #339933;">=</span> currentCount<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	tp<span style="color: #339933;">-&gt;</span>tv_sec <span style="color: #339933;">=</span> details.<span style="color: #202020;">cachedTime</span>.<span style="color: #202020;">tv_sec</span><span style="color: #339933;">;</span>
	tp<span style="color: #339933;">-&gt;</span>tv_usec <span style="color: #339933;">=</span> details.<span style="color: #202020;">cachedTime</span>.<span style="color: #202020;">tv_usec</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/07/26/hpet-rdtsc-based-userland-gettimeofday/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Wtf..</title>
		<link>http://people.summit-servers.com/monk/2010/07/22/wtf/</link>
		<comments>http://people.summit-servers.com/monk/2010/07/22/wtf/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 11:33:56 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=195</guid>
		<description><![CDATA[Does anyone think running realtime kernels for gameservers is a complete waste of time? Realtime kernels on x86 is slow, because of interrupt latency]]></description>
			<content:encoded><![CDATA[<p>Does anyone think running realtime kernels for gameservers is a complete waste of time?</p>
<p>Realtime kernels on x86 is slow, because of interrupt latency <img src='http://people.summit-servers.com/monk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/07/22/wtf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Latest project</title>
		<link>http://people.summit-servers.com/monk/2010/07/20/latest-project/</link>
		<comments>http://people.summit-servers.com/monk/2010/07/20/latest-project/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 19:39:24 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Main]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=193</guid>
		<description><![CDATA[http://people.summit-servers.com/monk.pdf]]></description>
			<content:encoded><![CDATA[<p>http://people.summit-servers.com/monk.pdf</p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/07/20/latest-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated Services</title>
		<link>http://people.summit-servers.com/monk/2010/06/24/css-beta/</link>
		<comments>http://people.summit-servers.com/monk/2010/06/24/css-beta/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 07:56:57 +0000</pubDate>
		<dc:creator>Monk</dc:creator>
				<category><![CDATA[Game Stuff]]></category>

		<guid isPermaLink="false">http://people.summit-servers.com/monk/?p=189</guid>
		<description><![CDATA[I&#8217;ve expanded my services Support for the following OS&#8217;s - CentOS - Fedora - Gentoo - FreeBSD - NetBSD Features for Linux - Optimized kernel package with different headers - Optimized i686 glibc packages for x86_64 that are faster and lower CPU usage on large servers. I have personally used these in production and they [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve expanded my services</p>
<p>Support for the following OS&#8217;s<br />
- CentOS<br />
- Fedora<br />
- Gentoo<br />
- FreeBSD<br />
- NetBSD</p>
<p>Features for Linux<br />
- Optimized kernel package with different headers<br />
- Optimized i686 glibc packages for x86_64 that are faster and lower CPU usage on large servers. I have personally used these in production and they are much faster. As soon as I have enough time, I&#8217;ll post some benchmarks (I/O etc)<br />
- PaX / SSP / Security Packages available (BETA)<br />
- uboost plugin that optimized gameservers:<br />
  &#8211; SSE2 memory copies<br />
  &#8211; Userland timecounter support. Avoids overhead calling time over and over and caches last timestamp if it hasn&#8217;t changed and uses that value.<br />
  &#8211; Free updates, access to beta test code, and newer kernels. Unlimited support.<br />
Features for FreeBSD + Linux emulation</p>
<p>- Custom rewritten timecounter code that gives very excellent tickrate / FPS behavior<br />
- SSE2 based bcopy/bzero support<br />
- A bunch of other things <img src='http://people.summit-servers.com/monk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>Pricing for all services: </p>
<p>$99 USD one time fee. Refunds are NOT available, but I&#8217;ve never had a request for a refund. </p>
]]></content:encoded>
			<wfw:commentRss>http://people.summit-servers.com/monk/2010/06/24/css-beta/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

