<?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>open-nandra &#187; high resolution timer</title>
	<atom:link href="http://open-nandra.com/tag/high-resolution-timer/feed/" rel="self" type="application/rss+xml" />
	<link>http://open-nandra.com</link>
	<description>open source</description>
	<lastBuildDate>Thu, 09 Sep 2010 11:28:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ctimer pushed to github.com</title>
		<link>http://open-nandra.com/2009/01/ctimer-pushed-to-githubcom/</link>
		<comments>http://open-nandra.com/2009/01/ctimer-pushed-to-githubcom/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 12:51:26 +0000</pubDate>
		<dc:creator>Marek Belisko</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[high resolution timer]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://open-nandra.com/?p=60</guid>
		<description><![CDATA[More about project can be found at Projects page. Source can be browsed here and downloaded from github.com: git clone git://github.com/nandra/ctimer.git ctimer]]></description>
			<content:encoded><![CDATA[<p>More about project can be found at Projects page.</p>
<p>Source can be browsed <a href="https://github.com/nandra/ctimer/tree" target="_blank">here</a> and downloaded from github.com:</p>
<pre>git clone <span class="git_url_facebox">git://github.com/nandra/ctimer.git</span> ctimer</pre>
]]></content:encoded>
			<wfw:commentRss>http://open-nandra.com/2009/01/ctimer-pushed-to-githubcom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing POSIX high resolution timers.</title>
		<link>http://open-nandra.com/2008/12/testing-posix-high-resolution-timers/</link>
		<comments>http://open-nandra.com/2008/12/testing-posix-high-resolution-timers/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 09:36:43 +0000</pubDate>
		<dc:creator>Marek Belisko</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[high resolution timer]]></category>

		<guid isPermaLink="false">http://open-nandra.com/?p=8</guid>
		<description><![CDATA[High resolution timers was implemented in kernel 2.6.16 and provide better resolution like 1 jiffy. Code was created by Ingo Molnar and Thomas Greixner. Implementation should provide high precision timers (with granularity ~1us) for userspace applications.Simple code below  check what is precise of resolution of high resolution timers implemented in kernel. It is also example [...]]]></description>
			<content:encoded><![CDATA[<p>High resolution timers was implemented in kernel 2.6.16 and provide better resolution like 1 jiffy. Code was created by Ingo Molnar and Thomas Greixner. Implementation should provide high precision timers (with granularity ~1us) for userspace applications.<span id="more-8"></span>Simple code below  check what is precise of resolution of high resolution timers implemented in kernel. It is also example program how to create periodic timer with high resolution in userspace.</p>
<pre>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;signal.h&gt;
#include &lt;unistd.h&gt;

#define NSEC_PER_SEC 1000000000L

#define timerdiff(a,b) ((float)((a)-&gt;tv_sec - (b)-&gt;tv_sec) + \
((float)((a)-&gt;tv_nsec - (b)-&gt;tv_nsec))/NSEC_PER_SEC)

static struct timespec prev = {.tv_sec=0,.tv_nsec=0};
static int count = 5;

void handler( signo )
{
struct timespec now;

clock_gettime(CLOCK_MONOTONIC, &amp;now);
printf("[%d]Diff time:%lf\n", count, timerdiff(&amp;now, &amp;prev));
prev = now;
count --;
}

int main(int argc, char *argv[])
{
int i = 0;
timer_t t_id;

struct itimerspec tim_spec = {.it_interval= {.tv_sec=1,.tv_nsec=10000},
.it_value = {.tv_sec=1,.tv_nsec=10000}};

struct sigaction act;
sigset_t set;

sigemptyset( &amp;set );
sigaddset( &amp;set, SIGALRM );

act.sa_flags = 0;
act.sa_mask = set;
act.sa_handler = &amp;handler;

sigaction( SIGALRM, &amp;act, NULL );

if (timer_create(CLOCK_MONOTONIC, NULL, &amp;t_id))
perror("timer_create");

if (timer_settime(t_id, 0, &amp;tim_spec, NULL))
perror("timer_settime");

clock_gettime(CLOCK_MONOTONIC, &amp;prev);

for (; ; )
{
if(count == 0)
break;
}

return 0;
}</pre>
<p>Program explanation:</p>
<p>- define sigaction for signal SIGALRM which is received if timer expired</p>
<p>- create timer (timer is not started)</p>
<p>- set timer (this function start timer)</p>
<p>- wait for 5 periods and then exit</p>
<p>In output you should see values for 5 period of timer. Timer is set to 1 seconds and 1us interval.</p>
<p>Note: for compiling please add to CFLAGS option: -lrt (realtime library).</p>
<p>Source for download: <a title="test_timer" href="http://open-nandra.com/wp-content/uploads/test_timerc.bz2">test_timerc</a></p>
<p>Marek</p>
]]></content:encoded>
			<wfw:commentRss>http://open-nandra.com/2008/12/testing-posix-high-resolution-timers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
