<?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 How can I use rdpmc asm ? in Software Tuning, Performance Optimization &amp; Platform Monitoring</title>
    <link>https://community.intel.com/t5/Software-Tuning-Performance/How-can-I-use-rdpmc-asm/m-p/1521006#M8214</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I want to make an accurate performance measurement for a specific function. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I searched, rdpmc was available, so I implemented c code as follows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;root@linuxnotepc:~/tmp# cat perftest.c&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;int retval;&lt;/P&gt;&lt;P&gt;unsigned long long rdpmc_instructions()&lt;BR /&gt;{&lt;BR /&gt;unsigned a, d, c;&lt;/P&gt;&lt;P&gt;c = (1&amp;lt;&amp;lt;30);&lt;BR /&gt;__asm__ volatile("rdpmc" : "=a" (a), "=d" (d) : "c" (c));&lt;/P&gt;&lt;P&gt;return ((unsigned long)a) | (((unsigned long)d) &amp;lt;&amp;lt; 32);;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void main()&lt;BR /&gt;{&lt;BR /&gt;long long val = rdpmc_instructions();&lt;BR /&gt;printf("%lld\n", val);&lt;BR /&gt;}&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cpu, gcc information is :&lt;/P&gt;&lt;P&gt;root@linuxnotepc:~/tmp# lscpu&lt;BR /&gt;Architecture: x86_64&lt;BR /&gt;CPU op-mode(s): 32-bit, 64-bit&lt;BR /&gt;Address sizes: 39 bits physical, 48 bits virtual&lt;BR /&gt;Byte Order: Little Endian&lt;BR /&gt;CPU(s): 8&lt;BR /&gt;On-line CPU(s) list: 0-7&lt;BR /&gt;Vendor ID: GenuineIntel&lt;BR /&gt;BIOS Vendor ID: Intel&lt;BR /&gt;Model name: Intel(R) Core(TM) i7-4712MQ CPU @ 2.30GHz&lt;BR /&gt;BIOS Model name: Intel(R) Core(TM) i7-4712MQ CPU @ 2.30GHz Fill By OEM CPU @ 2.3GHz&lt;BR /&gt;BIOS CPU family: 198&lt;BR /&gt;CPU family: 6&lt;BR /&gt;Model: 60&lt;BR /&gt;Thread(s) per core: 2&lt;BR /&gt;Core(s) per socket: 4&lt;BR /&gt;Socket(s): 1&lt;BR /&gt;Stepping: 3&lt;BR /&gt;CPU(s) scaling MHz: 33%&lt;BR /&gt;CPU max MHz: 3300.0000&lt;BR /&gt;CPU min MHz: 800.0000&lt;BR /&gt;BogoMIPS: 4589.38&lt;BR /&gt;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 pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopolog&lt;BR /&gt;y nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fa&lt;BR /&gt;ult epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d&lt;BR /&gt;Virtualization features:&lt;BR /&gt;Virtualization: VT-x&lt;BR /&gt;Caches (sum of all):&lt;BR /&gt;L1d: 128 KiB (4 instances)&lt;BR /&gt;L1i: 128 KiB (4 instances)&lt;BR /&gt;L2: 1 MiB (4 instances)&lt;BR /&gt;L3: 6 MiB (1 instance)&lt;BR /&gt;NUMA:&lt;BR /&gt;NUMA node(s): 1&lt;BR /&gt;NUMA node0 CPU(s): 0-7&lt;BR /&gt;Vulnerabilities:&lt;BR /&gt;Itlb multihit: KVM: Mitigation: VMX disabled&lt;BR /&gt;L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable&lt;BR /&gt;Mds: Mitigation; Clear CPU buffers; SMT vulnerable&lt;BR /&gt;Meltdown: Mitigation; PTI&lt;BR /&gt;Mmio stale data: Unknown: No mitigations&lt;BR /&gt;Retbleed: Not affected&lt;BR /&gt;Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl&lt;BR /&gt;Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization&lt;BR /&gt;Spectre v2: Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected&lt;BR /&gt;Srbds: Mitigation; Microcode&lt;BR /&gt;Tsx async abort: Not affected&lt;BR /&gt;root@linuxnotepc:~/tmp# gcc --version&lt;BR /&gt;gcc (Ubuntu 12.2.0-3ubuntu1) 12.2.0&lt;BR /&gt;Copyright (C) 2022 Free Software Foundation, Inc.&lt;BR /&gt;This is free software; see the source for copying conditions. There is NO&lt;BR /&gt;warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And rdpmc is already on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;root@linuxnotepc:/sys/bus/event_source/devices/cpu# cat rdpmc&lt;BR /&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What's the problem?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 08:06:52 GMT</pubDate>
    <dc:creator>kalstein</dc:creator>
    <dc:date>2023-09-06T08:06:52Z</dc:date>
    <item>
      <title>How can I use rdpmc asm ?</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/How-can-I-use-rdpmc-asm/m-p/1521006#M8214</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I want to make an accurate performance measurement for a specific function. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I searched, rdpmc was available, so I implemented c code as follows.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;root@linuxnotepc:~/tmp# cat perftest.c&lt;BR /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;int retval;&lt;/P&gt;&lt;P&gt;unsigned long long rdpmc_instructions()&lt;BR /&gt;{&lt;BR /&gt;unsigned a, d, c;&lt;/P&gt;&lt;P&gt;c = (1&amp;lt;&amp;lt;30);&lt;BR /&gt;__asm__ volatile("rdpmc" : "=a" (a), "=d" (d) : "c" (c));&lt;/P&gt;&lt;P&gt;return ((unsigned long)a) | (((unsigned long)d) &amp;lt;&amp;lt; 32);;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void main()&lt;BR /&gt;{&lt;BR /&gt;long long val = rdpmc_instructions();&lt;BR /&gt;printf("%lld\n", val);&lt;BR /&gt;}&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cpu, gcc information is :&lt;/P&gt;&lt;P&gt;root@linuxnotepc:~/tmp# lscpu&lt;BR /&gt;Architecture: x86_64&lt;BR /&gt;CPU op-mode(s): 32-bit, 64-bit&lt;BR /&gt;Address sizes: 39 bits physical, 48 bits virtual&lt;BR /&gt;Byte Order: Little Endian&lt;BR /&gt;CPU(s): 8&lt;BR /&gt;On-line CPU(s) list: 0-7&lt;BR /&gt;Vendor ID: GenuineIntel&lt;BR /&gt;BIOS Vendor ID: Intel&lt;BR /&gt;Model name: Intel(R) Core(TM) i7-4712MQ CPU @ 2.30GHz&lt;BR /&gt;BIOS Model name: Intel(R) Core(TM) i7-4712MQ CPU @ 2.30GHz Fill By OEM CPU @ 2.3GHz&lt;BR /&gt;BIOS CPU family: 198&lt;BR /&gt;CPU family: 6&lt;BR /&gt;Model: 60&lt;BR /&gt;Thread(s) per core: 2&lt;BR /&gt;Core(s) per socket: 4&lt;BR /&gt;Socket(s): 1&lt;BR /&gt;Stepping: 3&lt;BR /&gt;CPU(s) scaling MHz: 33%&lt;BR /&gt;CPU max MHz: 3300.0000&lt;BR /&gt;CPU min MHz: 800.0000&lt;BR /&gt;BogoMIPS: 4589.38&lt;BR /&gt;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 pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopolog&lt;BR /&gt;y nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fa&lt;BR /&gt;ult epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d&lt;BR /&gt;Virtualization features:&lt;BR /&gt;Virtualization: VT-x&lt;BR /&gt;Caches (sum of all):&lt;BR /&gt;L1d: 128 KiB (4 instances)&lt;BR /&gt;L1i: 128 KiB (4 instances)&lt;BR /&gt;L2: 1 MiB (4 instances)&lt;BR /&gt;L3: 6 MiB (1 instance)&lt;BR /&gt;NUMA:&lt;BR /&gt;NUMA node(s): 1&lt;BR /&gt;NUMA node0 CPU(s): 0-7&lt;BR /&gt;Vulnerabilities:&lt;BR /&gt;Itlb multihit: KVM: Mitigation: VMX disabled&lt;BR /&gt;L1tf: Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable&lt;BR /&gt;Mds: Mitigation; Clear CPU buffers; SMT vulnerable&lt;BR /&gt;Meltdown: Mitigation; PTI&lt;BR /&gt;Mmio stale data: Unknown: No mitigations&lt;BR /&gt;Retbleed: Not affected&lt;BR /&gt;Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl&lt;BR /&gt;Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization&lt;BR /&gt;Spectre v2: Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected&lt;BR /&gt;Srbds: Mitigation; Microcode&lt;BR /&gt;Tsx async abort: Not affected&lt;BR /&gt;root@linuxnotepc:~/tmp# gcc --version&lt;BR /&gt;gcc (Ubuntu 12.2.0-3ubuntu1) 12.2.0&lt;BR /&gt;Copyright (C) 2022 Free Software Foundation, Inc.&lt;BR /&gt;This is free software; see the source for copying conditions. There is NO&lt;BR /&gt;warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And rdpmc is already on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;root@linuxnotepc:/sys/bus/event_source/devices/cpu# cat rdpmc&lt;BR /&gt;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What's the problem?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 08:06:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/How-can-I-use-rdpmc-asm/m-p/1521006#M8214</guid>
      <dc:creator>kalstein</dc:creator>
      <dc:date>2023-09-06T08:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I use rdpmc asm ?</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/How-can-I-use-rdpmc-asm/m-p/1521782#M8215</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;echo "2" &amp;gt; /sys/bus/event_source/devices/cpu/rdpmc&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I input upper cmd, then only 'actual cycle' works.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;static&lt;/SPAN&gt; &lt;SPAN&gt;unsigned&lt;/SPAN&gt; &lt;SPAN&gt;long&lt;/SPAN&gt; &lt;SPAN&gt;long&lt;/SPAN&gt; &lt;SPAN&gt;rdpmc_actual_cycles&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;unsigned&lt;/SPAN&gt; &lt;SPAN&gt;c&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;low&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;high&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&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PAN&gt; &lt;SPAN&gt;32&lt;/SPAN&gt;&lt;SPAN&gt;);;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;when I use c = (1&amp;lt;&amp;lt;30) or c = (1&amp;lt;&amp;lt;30)+2,&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return value is always zero.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Sep 2023 06:12:08 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/How-can-I-use-rdpmc-asm/m-p/1521782#M8215</guid>
      <dc:creator>kalstein</dc:creator>
      <dc:date>2023-09-08T06:12:08Z</dc:date>
    </item>
  </channel>
</rss>

