<?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>Admon Home &#187; CPU</title>
	<atom:link href="http://www.admon.org/tag/cpu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.admon.org</link>
	<description>Linux System Administration</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:24:20 +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>About CPU: The logical and physical cores</title>
		<link>http://www.admon.org/about-cpu-the-logical-and-physical-cores/</link>
		<comments>http://www.admon.org/about-cpu-the-logical-and-physical-cores/#comments</comments>
		<pubDate>Mon, 31 May 2010 09:52:01 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Hardwares]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[HyperThreading]]></category>
		<category><![CDATA[Logical CPU]]></category>
		<category><![CDATA[Processor]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=605</guid>
		<description><![CDATA[This post will demonstrate a detailed method of enumerating processors in a running linux server. Before delving into the topic, some terms should be defined: Physical Package: The physical package is a microprocessor. For each physical package, it plugs into a physical socket on a mainboard, and may contain one or more processor cores. Processor [...]]]></description>
			<content:encoded><![CDATA[<p>This post will demonstrate a detailed method of enumerating processors in a running linux server. Before delving into the topic, some terms should be defined:</p>
<ul>
<li><strong>Physical Package</strong>: The physical package is a microprocessor. For each physical package, it plugs into a physical socket on a mainboard, and may contain one or more processor cores.<span id="more-605"></span></li>
<li><strong>Processor Core</strong>: The circuitry that provides ability to decode and execute instructions. A processor core may contain one or more logical processors.</li>
<li><strong>Logical Processor</strong>: The basic unit of processor hardware that allows the software executive in the operating system to dispatch a task or execute a thread context. Each logical processor can execute only one thread context at a time.</li>
<li><a href="http://en.wikipedia.org/wiki/Hyper-threading"><strong>Hyper-Threading</strong></a>: A feature within the IA-32 family of processors, where each processor core provides the functionality of more than one logical processor.</li>
<li><strong>Multi-Core Processor</strong>: A physical package that contains more than one processor core.</li>
</ul>
<p><em>(The above definitions come from <a href="http://software.intel.com/en-us/articles/optimal-performance-on-multithreaded-software-with-intel-tools/">Intel&#8217;s website</a>, it would be decent to identify what we&#8217;re talking.)</em></p>
<p>As we know, on a running Linux/UNIX system, a detailed information of CPU can be retrieved from <em>/proc/cpuinfo</em>, but how can we identify the logical processors and the physical cores smartly?  Basically, there are two rules that will help you achieve these info.</p>
<p>1. Any CPU with the same &#8220;core id&#8221; are hyperthreads in the same processor core, which means this process core has Hyper-Threading enabled.<br />
2. The &#8220;physical id&#8221; identifies physical package. Any cpu with the same physical id are threads or cores in the same physical socket.</p>
<p>Let me take <a href="http://www.dell.com/us/en/dfb/servers/pedge_2950/pd.aspx?refid=pedge_2950&amp;cs=28&amp;s=dfb">Dell PowerEdge 2950</a> as an example, we&#8217;re running Red Hat Enterprise Linux AS release 4 Update 7 on this server.</p>
<pre>$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3992.87
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 1
siblings        : 4
core id         : 4
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.03
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 2
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.01
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 1
siblings        : 4
core id         : 6
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.03
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 4
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3989.99
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 5
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 1
siblings        : 4
core id         : 5
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.02
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 6
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 0
siblings        : 4
core id         : 3
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.01
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:                                                                   

processor       : 7
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Xeon(R) CPU           E5405  @ 2.00GHz
stepping        : 10
cpu MHz         : 1995.005
cache size      : 6144 KB
physical id     : 1
siblings        : 4
core id         : 7
cpu cores       : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm pni monitor ds_cpl tm2 cx16 xtpr lahf_lm
bogomips        : 3990.03
clflush size    : 64
cache_alignment : 64
address sizes   : 38 bits physical, 48 bits virtual
power management:</pre>
<p>From the outputs, we can see that, there&#8217;re 8 processor-cores in 2 physical packages (in other words, there&#8217;re two quad-cores CPU on this server), and none of them has Hyper-Threading enabled. Here&#8217;s a quick explanation for some keywords that listed above:</p>
<ul>
<li>The processor entry contains a unique identifier for this logical processor.</li>
<li>The physical id entry contains a unique identifier for each physical package.</li>
<li>The core id entry holds a unique identifier for each core.</li>
<li>The siblings entry lists the number of logical processors that exist on the same physical package.</li>
<li>The cpu cores entry contains the number of cores that exist on the same physical package.</li>
<li>The vendor id entry holds the string. GenuineIntel if the processor is an Intel processor, and AuthenticAMD if it&#8217;s an AMD processor.</li>
</ul>
<p>There are some commands here to help identify these type of information quickly on a running Linux:</p>
<ol>
<li> Total amount of processors including the logical ones:
<pre># cat /proc/cpuinfo | grep "processor"| wc -l</pre>
</li>
<li> Total amount of CPU package:
<pre># cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l</pre>
</li>
<li> How many cores for each CPU. (Here we should call CPU as physical package as we mentioned above):
<pre># cat /proc/cpuinfo | grep "cpu cores" | wc -l</pre>
</li>
<li> For each physical CPU, the amount of Logical CPU (the logical CPU can be physical cores, soft cores like threaded, or both).
<pre># cat /proc/cpuinfo | grep "siblings"</pre>
</li>
</ol>
<p>Finally, please note that the msg from <em>/proc/cpuinfo</em> depends on your operating systems, which means it&#8217;s not always right or up-to-date. If you faced any issues, please create a thread at <a href="http://forum.admon.org/hardware-forum/">our support forum</a>, thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/about-cpu-the-logical-and-physical-cores/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use cpulimit to limit CPU time for process</title>
		<link>http://www.admon.org/use-cpulimit-to-limit-cpu-time-for-process/</link>
		<comments>http://www.admon.org/use-cpulimit-to-limit-cpu-time-for-process/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 06:51:38 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[cpulimit]]></category>
		<category><![CDATA[debian]]></category>

		<guid isPermaLink="false">http://planet.admon.org/?p=371</guid>
		<description><![CDATA[How we can limit the CPU usage of a sepcified process with the CPUlimit utility? Cpulimit is a simple program that attempts to limit the CPU usage of a process. It&#8217;s expressed in percentage, not in cpu time. This is useful to control batch jobs, when you don&#8217;t want them to eat too much CPU [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How we can limit the CPU usage of a sepcified process with the <a href="http://cpulimit.sourceforge.net/">CPUlimit</a></strong> <strong>utility?</strong></p>
<p>Cpulimit is a simple program that attempts to <strong>limit the CPU usage of a process</strong>. It&#8217;s expressed in percentage, not in cpu time.</p>
<p>This is useful to control batch jobs, when you don&#8217;t want them to eat too much CPU resource. It does not act on the nice value or other scheduling priority stuff, but on the real CPU usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.<span id="more-371"></span></p>
<p>If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power. In any case, the percentage is the same of what you see when you run top.</p>
<p>Cpulimit should run at least with the same user running the controlled process. It&#8217;s much better if you run cpulimit as root, in order to have a higher priority and a more precise control.</p>
<p><strong>Installation of CPUlimit</strong></p>
<p>CPUlimit is available for Debian and Ubuntu, so it can be installed by &#8220;<em>aptitude install cpulimit</em>&#8220;. If you&#8217;re running CentOS or other system, you might need to compile it from source code by yourself.</p>
<p>After the installation, let&#8217;s take a look at the cpulimit man page to learn how to use it:</p>
<pre>cpulimit TARGET [OPTIONS...]

TARGET must be exactly one of these:

-p, --pid=N              pid of the process
-e, --exe=FILE           name of the executable program file
-P, --path=PATH          absolute path name of the executable program file

OPTIONS
-l, --limit=N            percentage of CPU allowed from 0 to 100 (mandatory)
-v, --verbose            show control statistics
-z, --lazy               exit if there is no suitable target process, or if it dies
-h, --help               display this help and exit</pre>
<p><strong>Usage of CPUlimit</strong></p>
<p>These examples are from CPUlimit man page as well:</p>
<pre>Assuming  you  have  started "foo --bar" and you find out with top(1) or ps(1) that this process uses all your CPU time you can either

# cpulimit -e foo -l 50
limits the CPU usage of the process by acting on the executable program file. Note: the argument "--bar" is omitted.

# cpulimit -p 1234 -l 50
limits the CPU usage of the process by acting on its PID, as shown by ps(1)

# cpulimit -P /usr/bin/foo -l 50
same as -e but uses the absolute path name</pre>
<p>Now let&#8217;s assume that we want to limit the process httpd to 45%. This is how we do it:</p>
<p>cpulimit -e httpd -l 45</p>
<p>The <em>-e</em> switch takes the name of the executable program file. You can take that name from the output of the top command.</p>
<p>Instead of using the name of the executable program file, we can use the process ID with the -p switch. You can find out the process ID of the httpd process as follows:</p>
<pre>ps aux | grep httpd</pre>
<p>Let&#8217;s assume the httpd process ID is 13500; we can then limit that process to 45% CPU usage as follows:</p>
<pre>cpulimit -p 13500 -l 45</pre>
<p>Instead of using the name of the executable file (-e) of the process ID (-p), we can also pass the absolute path name of the executable program file to cpulimit with the -P switch.</p>
<p>The absolute path name of the httpd executable is /usr/sbin/httpd so we&#8217;d use the following command:</p>
<pre>cpulimit -P /usr/sbin/httpd -l 45</pre>
<p>Please note that cpulimit will run in the foreground of your terminal until you terminate it with CTRL+C &#8211; terminating it will also remove any CPU limits.</p>
<p><strong>Further Readings</strong></p>
<p>CPUlimit Homepage:  <a href="http://cpulimit.sourceforge.net/">http://cpulimit.sourceforge.net/</a></p>
<p>AND Homepage:  <a href="http://and.sourceforge.net/">http://and.sourceforge.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/use-cpulimit-to-limit-cpu-time-for-process/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to bind a certain process to specified core?</title>
		<link>http://www.admon.org/how-to-bind-a-certain-process-to-specified-core/</link>
		<comments>http://www.admon.org/how-to-bind-a-certain-process-to-specified-core/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 11:00:08 +0000</pubDate>
		<dc:creator>joseph</dc:creator>
				<category><![CDATA[System Tuning]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[taskset]]></category>

		<guid isPermaLink="false">http://blog.admon.org/?p=152</guid>
		<description><![CDATA[Taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. Under latest version of Debian / Ubuntu / Redhat Linux taskset is installed by default with util-linux package. The CPU affinity is represented as bitmask, with the [...]]]></description>
			<content:encoded><![CDATA[<div>
<p><strong>Taskset</strong> is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. Under latest version of Debian / Ubuntu / Redhat Linux taskset is installed by default with util-linux package. <span id="more-152"></span></p>
<p>The CPU affinity is represented as bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU. For example:</p>
<p><strong>* 0&#215;00000001 is processor (1st processor)<br />
* 0&#215;00000003 is processors and #1<br />
* 0&#215;00000004 is processors (3rd processor)</strong></p>
<p>To set the processor affinity of process 13545 to processor (1st processor) type following command:</p>
<p><strong># taskset 0&#215;00000001 -p 13545</strong><br />
If you find a bitmask hard to use, then you can specify a numerical list of processors instead of a bitmask using -c flag:<br />
<strong># taskset -c 1 -p 13545<br />
# taskset -c 3,4 -p 13545</strong></p>
<p>Where,<br />
* <strong>-p</strong> : Operate on an existing PID and not launch a new task (default is to launch a new task)</div>
]]></content:encoded>
			<wfw:commentRss>http://www.admon.org/how-to-bind-a-certain-process-to-specified-core/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

