<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Understanding L1, L2, L3 misses in Software Tuning, Performance Optimization &amp; Platform Monitoring</title>
    <link>https://community.intel.com/t5/Software-Tuning-Performance/Understanding-L1-L2-L3-misses/m-p/1056573#M4991</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am running a blocked MM code on a Haswell server.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;Performance counter stats for 'taskset -c 0 binaries/matmul/matmul_tiled_sse_128.12.1536':&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; 17,354,925,885 &amp;nbsp; &amp;nbsp; &amp;nbsp;cycles &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[25.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; 47,163,342,001 &amp;nbsp; &amp;nbsp; &amp;nbsp;instructions &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;# &amp;nbsp; &amp;nbsp;2.72 &amp;nbsp;insns per cycle &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; 15,629,057,840 &amp;nbsp; &amp;nbsp; &amp;nbsp;L1-dcache-loads &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp;2,125,485,010 &amp;nbsp; &amp;nbsp; &amp;nbsp;L1-dcache-load-misses &amp;nbsp; &amp;nbsp; # &amp;nbsp; 13.60% of all L1-dcache hits &amp;nbsp; [30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp;1,179,936,318 &amp;nbsp; &amp;nbsp; &amp;nbsp;r53e124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22,469,151 &amp;nbsp; &amp;nbsp; &amp;nbsp;r532124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 49,919,592 &amp;nbsp; &amp;nbsp; &amp;nbsp;r504f2e &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[19.99%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4,875,407 &amp;nbsp; &amp;nbsp; &amp;nbsp;r50412e &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[20.19%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;189,994,023 &amp;nbsp; &amp;nbsp; &amp;nbsp;LLC-prefetches &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [20.17%]&lt;/P&gt;

&lt;P&gt;Specifically I want to see how blocking affect L1,L2 and L3 reference/misses.&lt;/P&gt;

&lt;P&gt;I used perf list and selected the following events for L2&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Umask-00 : 0x21 : PMU : [DEMAND_DATA_RD_MISS] : None : Demand Data Read requests that miss L2 cache&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Umask-01 : 0x41 : PMU : [DEMAND_DATA_RD_HIT] : None : Demand Data Read requests that hit L2 cache&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Umask-12 : 0xe1 : PMU : [ALL_DEMAND_DATA_RD] : None : Any data read request to L2 cache&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;However, the numbers do not make sense to me.&lt;/P&gt;

&lt;P&gt;First, amount of L2 reads (r53e124) is lower than l1-dcache-misses. I checked l1-icache-misses as well. But L2 reads exceeds the sum by a large amount. One reason can be L1 miss colaescing, where processor sends lot of L1 miss requests quickly to L2 and all belong to same cache line. Since it is a matrix multiplication code, those kind of patterns are expected? Is it right way to explain those numbers?&lt;/P&gt;

&lt;P&gt;Second, L3 refereces (r504f2e) is much higher than L2 misses (r532124). I can't think of any reason here.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Are I thinking in the right direction? Have I chosen the right hardware counters?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2015 20:14:51 GMT</pubDate>
    <dc:creator>Animesh_J_</dc:creator>
    <dc:date>2015-05-07T20:14:51Z</dc:date>
    <item>
      <title>Understanding L1, L2, L3 misses</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/Understanding-L1-L2-L3-misses/m-p/1056573#M4991</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am running a blocked MM code on a Haswell server.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;Performance counter stats for 'taskset -c 0 binaries/matmul/matmul_tiled_sse_128.12.1536':&lt;/P&gt;

&lt;P&gt;&amp;nbsp; &amp;nbsp; 17,354,925,885 &amp;nbsp; &amp;nbsp; &amp;nbsp;cycles &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[25.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; 47,163,342,001 &amp;nbsp; &amp;nbsp; &amp;nbsp;instructions &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;# &amp;nbsp; &amp;nbsp;2.72 &amp;nbsp;insns per cycle &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; 15,629,057,840 &amp;nbsp; &amp;nbsp; &amp;nbsp;L1-dcache-loads &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp;2,125,485,010 &amp;nbsp; &amp;nbsp; &amp;nbsp;L1-dcache-load-misses &amp;nbsp; &amp;nbsp; # &amp;nbsp; 13.60% of all L1-dcache hits &amp;nbsp; [30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp;1,179,936,318 &amp;nbsp; &amp;nbsp; &amp;nbsp;r53e124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22,469,151 &amp;nbsp; &amp;nbsp; &amp;nbsp;r532124 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[30.03%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 49,919,592 &amp;nbsp; &amp;nbsp; &amp;nbsp;r504f2e &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[19.99%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4,875,407 &amp;nbsp; &amp;nbsp; &amp;nbsp;r50412e &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[20.19%]&lt;BR /&gt;
	&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;189,994,023 &amp;nbsp; &amp;nbsp; &amp;nbsp;LLC-prefetches &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [20.17%]&lt;/P&gt;

&lt;P&gt;Specifically I want to see how blocking affect L1,L2 and L3 reference/misses.&lt;/P&gt;

&lt;P&gt;I used perf list and selected the following events for L2&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Umask-00 : 0x21 : PMU : [DEMAND_DATA_RD_MISS] : None : Demand Data Read requests that miss L2 cache&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;Umask-01 : 0x41 : PMU : [DEMAND_DATA_RD_HIT] : None : Demand Data Read requests that hit L2 cache&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Umask-12 : 0xe1 : PMU : [ALL_DEMAND_DATA_RD] : None : Any data read request to L2 cache&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;However, the numbers do not make sense to me.&lt;/P&gt;

&lt;P&gt;First, amount of L2 reads (r53e124) is lower than l1-dcache-misses. I checked l1-icache-misses as well. But L2 reads exceeds the sum by a large amount. One reason can be L1 miss colaescing, where processor sends lot of L1 miss requests quickly to L2 and all belong to same cache line. Since it is a matrix multiplication code, those kind of patterns are expected? Is it right way to explain those numbers?&lt;/P&gt;

&lt;P&gt;Second, L3 refereces (r504f2e) is much higher than L2 misses (r532124). I can't think of any reason here.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Are I thinking in the right direction? Have I chosen the right hardware counters?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 20:14:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/Understanding-L1-L2-L3-misses/m-p/1056573#M4991</guid>
      <dc:creator>Animesh_J_</dc:creator>
      <dc:date>2015-05-07T20:14:51Z</dc:date>
    </item>
    <item>
      <title>In order to interpret these</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/Understanding-L1-L2-L3-misses/m-p/1056574#M4992</link>
      <description>&lt;P&gt;In order to interpret these results we need to know exactly which events are programmed with the named events: L1-dcache-loads, L1-dcache-load-misses, and LLC-prefetches.&lt;/P&gt;

&lt;P&gt;Unfortunately the structure of the performance counter subsystem of the Linux kernel appears deliberately designed to obfuscate the specific meaning of named events.&amp;nbsp;&amp;nbsp; Sometimes I am able to find the location in the kernel source where these events are defined, but today I am not having any luck.&lt;/P&gt;

&lt;P&gt;As a horrible hack, I often resort to reading the values from the performance counter event select registers manually.&amp;nbsp;&amp;nbsp; For example:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;# start a process under "perf stat" that stalls waiting on stdin and put it in the background
# bind the process to core 1 so I know where to look for the counter programming
taskset -c 1 perf stat -e L1-dcache-loads cat &amp;gt;/dev/null &amp;amp;

# Now read the counters manually -- since the process context has changed, the
# counters will be disabled, but "perf stat" typically does not modify the other bits
# of the PERF_EVT_SEL MSRs
rdmsr -p 1 0x186
rdmsr -p 1 0x187
rdmsr -p 1 0x188
rdmsr -p 1 0x189
rdmsr -p 1 0x18a
rdmsr -p 1 0x18b
rdmsr -p 1 0x18c
rdmsr -p 1 0x18d&lt;/PRE&gt;

&lt;P&gt;Since the definitions of the events are hard-coded into the kernel (and can change from revision to revision) I can't guarantee that the events on your system are the same as the events on my system.&lt;/P&gt;

&lt;P&gt;On one of my Haswell systems running RHEL6.6 (&amp;nbsp;2.6.32-504.1.3.el6.x86_64) I found:&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;L1-dcache-loads is programmed incorrectly as Event 0xd0, Umask 0xf1
		&lt;UL&gt;
			&lt;LI&gt;The event is OK&lt;/LI&gt;
			&lt;LI&gt;The umask for counting "all loads" should be 0x81, not 0xf1&lt;/LI&gt;
			&lt;LI&gt;I don't know if setting the extra Umask bits causes the counter to be incorrect, but it would be better to explicitly program the desired event
				&lt;UL&gt;
					&lt;LI&gt;The value of one load every 3 instructions seems reasonable for a matrix multiplication kernel -- you can check this against the inner loop of the assembly code to see if it looks right for your implementation.&lt;/LI&gt;
				&lt;/UL&gt;
			&lt;/LI&gt;
		&lt;/UL&gt;
	&lt;/LI&gt;
	&lt;LI&gt;L1-dcache-load-misses is programmed incorrectly as Event 0x51, Umask 0x01
		&lt;UL&gt;
			&lt;LI&gt;This Event+Umask is L1D.REPLACEMENT, which is the wrong event&lt;/LI&gt;
			&lt;LI&gt;L1D.REPLACEMENT will include L1 dcache refills due to any cause -- demand load misses, demand store misses, prefetch load misses, etc.&lt;/LI&gt;
		&lt;/UL&gt;
	&lt;/LI&gt;
	&lt;LI&gt;LLC-prefetches is incorrectly programmed&amp;nbsp; using an OFF_CORE_RESPONSE event.
		&lt;UL&gt;
			&lt;LI&gt;The auxiliary MSR (0x1a6) is programmed to 0x00010030
				&lt;UL&gt;
					&lt;LI&gt;Bit 5 says to count RFO requests (store misses) generated by the L2 prefetchers&lt;/LI&gt;
					&lt;LI&gt;Bit 6 says to count code reads generated by the L2 prefetchers&lt;/LI&gt;
					&lt;LI&gt;Bit 16 says to count for any data supplier (local L3 hit, remote cache hit, memory, etc)&lt;/LI&gt;
				&lt;/UL&gt;
			&lt;/LI&gt;
			&lt;LI&gt;The bits that are programmed appear to be correct, but the most important bit is missing -- bit 4 for read prefetches generated by the L2 prefetchers!&lt;/LI&gt;
			&lt;LI&gt;It is not clear whether bits 7,8,9 should also be set -- if I understand correctly, these are the bits that cause the counter to increment for L2 hardware prefetches that fetch data into the LLC (but not directly into the L2).&lt;/LI&gt;
		&lt;/UL&gt;
	&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So the "named" events are correct in 0 of 3 cases --- way to go Ingo Molnar!!!!!&lt;/P&gt;

&lt;P&gt;If I recall correctly, a blocked matrix multiply kernel will have 1/2 load misses and 1/2 store misses, which means that your actual L1 data cache read miss rate is a close match to the L2 demand read access rate.&lt;/P&gt;

&lt;P&gt;Using the explicitly programmed L2 demand data read and demand data read miss counters it looks like you have a 2% L2 miss rate.&amp;nbsp; This is what I would expect for a matrix multiplication kernel with a block size of 100.&lt;/P&gt;

&lt;P&gt;If I recall correctly, the 0x2e events (LONGEST_LAT_CACHE references and misses) also count access due to demand load misses and demand RFO (store) misses, so these need to be considered carefully as well.&amp;nbsp; Dividing the misses by two (assuming 1/2 were due to store misses) brings the numbers much closer to the L2 demand read miss value.&amp;nbsp; It is still about 11% high, but it is hard to tell what is going on from this counter set.&amp;nbsp; Getting the actual L2 demand RFO miss rate would allow you to compare L2 misses with LLC references.&lt;/P&gt;

&lt;P&gt;It is going to take a fair amount of careful directed testing to understand these counters, but it looks like you are making a good start.&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2015 15:54:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/Understanding-L1-L2-L3-misses/m-p/1056574#M4992</guid>
      <dc:creator>McCalpinJohn</dc:creator>
      <dc:date>2015-05-21T15:54:26Z</dc:date>
    </item>
  </channel>
</rss>

