<?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>Java Tuning &#187; hardware</title>
	<atom:link href="http://www.javatuning.com/category/hardware/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javatuning.com</link>
	<description>Software Development, Java, and some more.</description>
	<lastBuildDate>Tue, 29 Jun 2010 10:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Why is Thread.sleep() inherently inaccurate</title>
		<link>http://www.javatuning.com/why-is-thread-sleep-inherently-inaccurate/</link>
		<comments>http://www.javatuning.com/why-is-thread-sleep-inherently-inaccurate/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 19:06:09 +0000</pubDate>
		<dc:creator>Gili Nachum</dc:creator>
				<category><![CDATA[Multi Threading]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[estimating]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[milliseconds]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[operating system]]></category>
		<category><![CDATA[sleep]]></category>
		<category><![CDATA[time measurment]]></category>
		<category><![CDATA[windows services]]></category>

		<guid isPermaLink="false">http://www.javatuning.com/?p=172</guid>
		<description><![CDATA[Avi Ribchinsky, a friend and a college of mien, is transitioning from C++ to the Java world. He had been playing with Thread.sleep(), when he noticed that the sleep method might oversleep more than ordered, and moreover, it could also under sleep (see Fig 1). Coming from the C++ world, that surely caught him surprised [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.linkedin.com/in/aviribchinsky">Avi Ribchinsky</a>, a friend and a college of mien, is transitioning from C++ to the Java world. He had been playing with Thread.sleep(), when he noticed that the sleep method might oversleep more than ordered, and moreover, it could also <strong>under sleep</strong> (see Fig 1). Coming from the C++ world, that surely caught him surprised <img src='http://www.javatuning.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Fig 1.</p>
<div id="attachment_173" class="wp-caption alignleft" style="width: 594px"><a href="http://www.javatuning.com/wp-content/uploads/2009/08/sleep.JPG"><img class="size-full wp-image-173" title="sleep" src="http://www.javatuning.com/wp-content/uploads/2009/08/sleep.JPG" alt="Thread.sleep() under sleeping" width="584" height="463" /></a><p class="wp-caption-text">Thread.sleep() under sleeping</p></div>
<h2>How is sleep implemented in Java anyway?</h2>
<p>Avi came asking me if I knew anything about it, I was wondering myself how such a common and important method could be faking in the way shown above. Is it the OS? a Bug in the specific JRE version used? Maybe the API doesn&#8217;t guarantee milliseconds precision to begin with?<br />
Thinking about all of these factors, we realized that we don&#8217;t really know how the JVM implements the sleep method functionality, my best guess would have been that the process registers itself in the OS for a wake up call, and the OS wakes the process via a software interrupt. OK, time to search the web.</p>
<p>The <a href="http://www.javamex.com/tutorials/threads/sleep.shtml">following article</a> gives a very detailed answer, explaining that sleep is implemented by a thread giving up its OS scheduling quantum back to the scheduler, on the next execution quantum the thread gets, it has the chance to wake up and continue processing, or again continue sleeping.<br />
Therefore, the accuracy resolution of sleep is directly dependent on the process scheduling resolution of the operating system in usage. Since windows XP process scheduling resolution is roughly 10ms, the sleep mechanism, in the Avi&#8217;s example, might had prefered to under sleep &#8220;a little&#8221; rather than oversleeping &#8220;a lot&#8221;, by waking himself in the current scheduling cycle quantum, rather than in the next, future, quantum.</p>
<p>The article also mentions that the inaccuracies are worsened when a process with a higher scheduling priority, than the sleeping process, is in a runnable state.</p>
<p>I assume that, running on a Hypervisor with course grained process scheduling would also produce greater inaccuracies.</p>
<p><a href="http://www.javatuning.com/wp-content/uploads/2009/08/sleeping.jpeg"><img class="alignleft size-medium wp-image-174" title="sleeping" src="http://www.javatuning.com/wp-content/uploads/2009/08/sleeping-300x229.jpg" alt="sleeping" width="300" height="229" /></a></p>
<h2>Conclusion</h2>
<p>You can&#8217;t rely on the millisecond accuracy of the sleep method. Take a before and after time measurament to find the actual time spent sleeping, in order to avoid ever increasing inacurracies.<br />
Sleep tight <img src='http://www.javatuning.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javatuning.com/why-is-thread-sleep-inherently-inaccurate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How does hardware evolution affect progamming language design?</title>
		<link>http://www.javatuning.com/how-does-hardware-evolution-affect-progamming-language-design/</link>
		<comments>http://www.javatuning.com/how-does-hardware-evolution-affect-progamming-language-design/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 23:28:19 +0000</pubDate>
		<dc:creator>Gili Nachum</dc:creator>
				<category><![CDATA[Multi Threading]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[a glimpse into the future]]></category>
		<category><![CDATA[computer language]]></category>
		<category><![CDATA[multithreading]]></category>

		<guid isPermaLink="false">http://www.javatuning.com/?p=17</guid>
		<description><![CDATA[I&#8217;ve recently watched the interesting webcast Programming Language Design and Analysis Motivated by Hardware Evolution by Professor Alan Mycroft (Webcast&#8217;s link is accessible only from within the IBM Intranet). Ahead are a few keynotes I&#8217;ve kept. Not everything is kept linear As chip designers continue to scale down chips and transistors, they begin hitting design [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently watched the interesting webcast <span><a title="webcast link" href="http://videoex.watson.ibm.com/Mediasite/Viewer/Viewers/Viewer240TL3Banner.aspx?mode=Default&amp;peid=80107d32-a383-4cfe-9766-2772e4396566&amp;playerType=WM7&amp;mode=Default&amp;shouldResize=true&amp;pid=f70ca9fe-5231-4db0-b496-4f56b368bb8c&amp;playerType=WM7#" class="broken_link">Programming Language Design and Analysis Motivated by Hardware Evolution</a> </span>by Professor <a title="Alan Mycroft homepage" href="http://www.cl.cam.ac.uk/~am21/" target="_blank">Alan Mycroft</a> (Webcast&#8217;s link is accessible only from within the IBM Intranet). Ahead are a few keynotes I&#8217;ve kept.</p>
<p><strong>Not everything is kept linear<br />
</strong>As chip designers continue to scale down chips and transistors, they begin hitting design walls. Some of these walls are related to the fact that as the transistors` physical size is scaled down, some other properties of the chip do not scale linearly as well. This simplest example of this are dimensions, consider length Vs surface area: reducing a square side to 50% of its original size, will causes the square surface space to reduced by 75%, not a linear change. Different electricity characteristics might change at different rates than the rate in which length is changed.</p>
<p><a title="pl.gif" href="http://www.javatuning.com/wp-content/uploads/2008/03/pl.gif"><img src="http://www.javatuning.com/wp-content/uploads/2008/03/pl.gif" alt="pl.gif" /></a></p>
<p><strong>Where is my 12Ghz  CPU?</strong><br />
<a title="moor's law" href="http://en.wikipedia.org/wiki/Moore%27s_law" target="_blank">Moore&#8217;s law</a>, which predicts the doubling of transistors quantity on a chip every ~18 months is still in effect, sadly, this doesn&#8217;t translate into clock speed. Although that, when transistors are miniaturized the distances within the chip reduces as well, and this should mean an increase in speed, but, due to heat dispersion problems (not all dimensions shrink at the same rate, generated heat is one of them, remember?) chip designers are forced to reduce the voltage in which the chip components operate. Therefore no clock speed gain.<br />
This enables us, however, to squeeze in more cores into that optimal one cm^2 silicon pad. Hence, the multi-core technological path that the industry had resorted to in the last couple of years.</p>
<p><a title="Quad core" href="http://www.javatuning.com/wp-content/uploads/2008/03/quad.jpg"><img src="http://www.javatuning.com/wp-content/uploads/2008/03/quad.jpg" alt="Quad core" /></a></p>
<p><strong>There&#8217;s always a trade-off</strong><br />
As the voltage in which the chip operates drops, chip designers are starting to face computation inaccuracy problems. How could we live in peace with these imprecision? the professor ponders, do we must insist on absolute accuracy? Consider the task of rendering video, do we really care about the correctness of each pixel on each of the frames, probably not, just remember those old analog VCR and audio cassettes, they were highly inaccurate and still were able to deliver the goods. We might decide to compromise on accuracy, some of the time, in order to benefit on speed, just another type of trade-off. Programming language designers should assist chip designers by developing programming languages that are able to operate in a world of non absolute  certainty.<br />
Also think about the build-in error correction mechanisms put in to network protocol stacks.</p>
<p><strong>Better on one world, worse on the other</strong><br />
A major problem with multi-core chips processing, is that although inter-cores communication enjoy a high bandwidth (2.5GB/s), it is stained by a high latency (~75 clock cycles) .<br />
Another problem is that programs are written based on a shared memory model, in which all cores must coordinate when accessing the shared main memory, core&#8217;s caches must also be refreshed quite often. While this doesn&#8217;t seems a major problem for  dual or quad cores, think on how this heavily limits performance on a, not so futuristic anymore, 128 cores chip.<br />
Trying to refrain from shared main memory access might turn the table on some of the disciplines we got accustomed to think of as obvious. For example, when you code a parametrized function you declare how parameters are passed; either by reference, or by value. Declaring this during coding time (rather then deciding this during runtime) can be regarded as &#8220;early-binding&#8221;. From a performance perspective, everybody knows that passing by reference is, almost always, faster than passing by value (assuming you don&#8217;t intend on changing the passed value). This preferred way of action might not hold true on a multi-core system that will have to incur an expensive overhead when it access the data which the reference point to in the shared main memory, no such price has to be paid if the parameter is past by value. One way in which future programming languages might deal with this is to allow for late-binding of the parameters passing method. When running on a chip with only a few cores, a pass by reference will occur, just as, when running on a cores enriched chip a pass by value will be selected. This is true when the pass by reference/value makes no difference to the program logic (no changes to the parameter&#8217;s data are visible to the method caller, nor the parameter data is accessed concurrently), and therefore both could be used interchangeably.<br />
Future languages will need to support this &#8220;late-binding&#8221; feature and others like it.</p>
<p><strong>Summing up</strong><br />
It will be interesting to keep follow of these hardware to software trends of  mutual influences.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javatuning.com/how-does-hardware-evolution-affect-progamming-language-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
