<?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>twam.info &#187; Scheduling</title>
	<atom:link href="http://www.twam.info/tag/scheduling/feed" rel="self" type="application/rss+xml" />
	<link>http://www.twam.info</link>
	<description>My computer, physics, electronics &#38; photography blog</description>
	<lastBuildDate>Wed, 25 Jan 2012 20:49:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Changing scheduling parameters in Linux</title>
		<link>http://www.twam.info/linux/changing-scheduling-parameters-in-linux</link>
		<comments>http://www.twam.info/linux/changing-scheduling-parameters-in-linux#comments</comments>
		<pubDate>Mon, 04 May 2009 11:36:05 +0000</pubDate>
		<dc:creator>twam</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Scheduling]]></category>

		<guid isPermaLink="false">http://www.twam.info/?p=369</guid>
		<description><![CDATA[Process scheduling within Linux is done by the kernel, following different aspects. Usually it&#8217;s goal is to share all resources fairly among all running processes. Sometimes, there&#8217;s a need to tell the kernel explicitly to prior some process, bind some process to a special CPU and so on. Changing process priorities is commonly known: nice [...]]]></description>
			<content:encoded><![CDATA[<p>Process scheduling within Linux is done by the kernel, following different aspects. Usually it&#8217;s goal is to share all resources fairly among all running processes.</p>
<p>Sometimes, there&#8217;s a need to tell the kernel explicitly to prior some process, bind some process to a special CPU and so on.</p>
<p>Changing process priorities is commonly known:</p>
<pre>nice -n 10 make</pre>
<p>runs the program make with a priority of 10 (-20 meaning most favorable and 19 least favorable scheduling). If you want to change a priority of a running program, <em>renice</em> is your choice.<span id="more-369"></span></p>
<h3>schedtool</h3>
<p>Nowadays multiprocessor machines get more and more in common. So it&#8217;s sometimes desirable to bind a process to one or more CPUs. This is done by <a href="http://freequaos.host.sk/schedtool"><em>schedtool</em></a>, which is not part of common distros. You can install it on Gentoo by</p>
<pre>emerge -va schedtool</pre>
<p><em>schedtool</em> allows you to view, and change the process CPU affinity. Try</p>
<pre>schedtool PID</pre>
<p>where PID is the process ID. For example, process 6702 of my system shows:</p>
<pre>PID  6702: PRIO   0, POLICY N: SCHED_NORMAL  , NICE   0, AFFINITY 0x3</pre>
<p>meaning it&#8217;s CPU affinity mask is 0&#215;03. Each bit of the affinity mask corresponds to a CPU in the system and a bit value of 1 meaning this CPU is allowed to use. So, 0&#215;03 = 0b00000011 means that CPU0 and CPU1 are allowed to use. You can change the CPU affinity by</p>
<pre>schedtool -a AFFINITY_MASK PID</pre>
<p>where PID is the process ID and AFFINITY_MASK the affinity mask (must be in hexadecimal) or a list of (decimal) comma separated CPU numbers. Be careful not to use affinity 0&#215;00 especially on viral processes. <img src='http://www.twam.info/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>schedtool</em> also allows the change of schedule policy for a single job. This is useful e.g. for long-running non-interactive jobs. You can enable the SCHED_BATCH policy for them by</p>
<pre>schedtool -B PID</pre>
<p>where PID is the process ID. Notice that you need a least kernel 2.6.16 for SCHED_BATCH support. There are different schedule policies for Real Time or Idle applications. See <a href="http://linux.die.net/man/8/schedtool">man schedtool</a> for detailed information.</p>
<h3>taskset</h3>
<p>Another program for setting process&#8217;s CPU affinity is <em>taskset</em>. It&#8217;s included in <a href="http://www.kernel.org/pub/linux/utils/util-linux-ng/">util-linux-ng</a>, which is part of most common distros. taskset is only capable of changing/viewing CPU affinity, not priorities or scheduling policies.</p>
<p>To view a process CPU affinity try</p>
<pre>taskset -p PID</pre>
<p>where PID is the process ID. For the same process as above my systems shows:</p>
<pre>pid 6702's current affinity mask: 3</pre>
<p>You can change CPU affinity easily by</p>
<pre>taskset -p AFFINITY_MASK PID</pre>
<p>where PID is the process ID and AFFINITY_MASK the affinity mask. If you wish the use a command seperated CPU list you have to</p>
<pre>taskset -c -p CPU_LIST PID</pre>
<p>where PID is the process ID and CPU_LIST the CPU list like 1,3,4-6.</p>
<p>Unlike schedtool taskset is capable of starting programs with a specific CPU affinity mask by</p>
<pre>taskset AFFINITY_MASK COMMAND</pre>
<p>where AFFINITY_MASK is the affinity mask and COMMAND and command to execute. Seed <a href="http://linux.die.net/man/1/taskset">man taskset</a> for detailed information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twam.info/linux/changing-scheduling-parameters-in-linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

