ラベル CPU の投稿を表示しています。 すべての投稿を表示
ラベル CPU の投稿を表示しています。 すべての投稿を表示

2008/12/14

Intel CPU: Fixed Performance Counter (FPC)

Fixed Performance Counter(FPC) // 勝手な命名
は固定のパフォーマンスイベントをカウントするMSR.
最大で3つで,CPUがいくつサポートしているかは,以前のエントリ
パフォーマンスカウンタの情報を表示
の "Number of fixed-function PCs" で得られる.

以下FPCの詳細.

[IA32_FIXED_CTR0(MSR_PERF_FIXED_CTR0)]
Register Address: 0x309
Performance Event: Inst_Retired.Any
実行した命令数をカウントする.

[IA32_FIXED_CTR1(MSR_PERF_FIXED_CTR1)]
Register Address: 0x30A
Performance Event: CPU_CLK_Unhalted.Core
CPUがHalt状態でない時のCPUサイクル数をカウントする.

[IA32_FIXED_CTR2(MSR_PERF_FIXED_CTR2)]
Register Address: 0x30B
Performance Event: CPU_CLK_Unhalted.Ref
CPUがHalt状態でない時のバスクロック数をカウントする.


【使用時の注意】
FPCはデフォルトではdisableになっている.
enableにするには,FPCの動作をコントロールするMSRである
IA32_FIXED_CTR_CTL(MSR_PERF_FIXED_CTR_CTL)
Register Address: 0x3BD
の値を変更する必要がある.
IA32_FIXED_CTR_CTLは,3つのFPCのenable/disableの設定を行う.


[bit fields]
0-4: IA32_FIXED_CTR0の設定
0: EN0_OS(CPL=0の時にenable)
1: EN0_Usr(CPL>0の時にenable)
2: Reserved
3: EN0_PMI(カウンタがオーバーフローした時にPMIを発生)
4-7: IA32_FIXED_CTR1の設定,0-3と同様
8-11: IA32_FIXED_CTR2の設定,0-3と同様


[Reference]
IntelR 64 and IA-32 Architectures Software Developer’s Manual Volume 3B: APPENDIX B
MODEL-SPECIFIC REGISTERS (MSRS)

2008/12/11

Intel CPU: パフォーマンスイベントUmask

モニタリングするパフォーマンスイベントのUmaskでTable 18-11, 18-13, 18-14を見るべし.
という指示がちょくちょくあったのでメモ.
intel manual Vol. 3 capter 18 p59-60 より,


[Table 18-11. Core Specificity Encoding]
Bit 15:14
11B All cores
10B Reserved
01B This core
00B Reserved

Some microarchitectural conditions allow detection specificity only at the boundary of physical processors. Some bus events belong to this category, providing specificity between the originating physical processor (a bus agent) versus other agents on the bus. Sub-field encoding for agent specificity is shown in Table 18-12.


[Table 18-12. Agent Specificity Encoding]
Bit 13
0 This agent
1 Include all agents

Some microarchitectural conditions are detectable only from the originating core. In such cases, unit mask does not support core-specificity or agent-specificity encodings. These are referred to as core-only conditions. Some microarchitectural conditions allow detection specificity that includes or excludes the action of hardware prefetches. A two-bit encoding may be supported to qualify hardware prefetch actions. Typically, this applies only to some L2 or bus events. The sub-field encoding for hardware prefetch qualification is shown in Table 18-13.

[Table 18-13. HW Prefetch Qualification Encoding]
Bit 13:12
11B All inclusive
10B Reserved
01B Hardware prefetch only
00B Exclude hardware prefetch

[Table 18-14. MESI Qualification Definitions]
Bit Position 11:8
Bit 11 Counts modified state
Bit 10 Counts exclusive state
Bit 9 Counts shared state
Bit 8 Counts Invalid state

// よく使いそうな16進マスク
//--------------------------------------------------
[Table 18-11. Core Specificity Encoding]
0xc000: All cores
0x4000: This core

[Table 18-12. Agent Specificity Encoding]
0x0000 This agent
0x2000 Include all agents

[Table 18-13. HW Prefetch Qualification Encoding]
0x3000: All inclusive
0x1000: Hardware prefetch only

[Table 18-14. MESI Qualification Definitions]
0x0f00: 全部


// Reference
Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3B: APPENDIX A
PERFORMANCE-MONITORING EVENTS

RDMSR / WRMSR

// RDMSR
ECXで指定したアドレスのMSRを読み込む.
読み込んだデータはEDX:EAXに格納される.
特権レベル0でのみ実行可能.
(ex)
unsigned low, high;
asm volatile("rdmsr" : "=a"(low), "=d"(high) : "c"(msr_addr));

// WRMSR
ECXで指定したアドレスのMSRにEDX:EAXを書き込む.
特権レベル0でのみ実行可能.
(ex)
asm volatile("wrmsr" : : "c"(msr_addr), "=a"(low), "=d"(high) : "memory");

// Reference
wrmsr()/linux2.6 - LinuxKernelHackJapan
rdmsr()/linux2.6 - LinuxKernelHackJapan

2008/12/01

Intel CPU: Hardware Performance Counter(HPC)

intel CPUのハードウェアパフォーマンスカウンタ(HPC)は
自分で監視するイベントを指定できる汎用的なカウンタと
固定のイベントを監視する固定カウンタの二種類がある.

Core 2では汎用カウンタは2個,固定カウンタは3個ある.
固定カウンタで監視するイベントは
Inst_Retired.Any: 完了した命令の数
CPU_CLK_Unhalted.Core: HLT状態でないCPUのクロックサイクル数
CPU_CLK_Unhalted.Ref: 上記のreference cycle版

【用語】
CCCR: Counter Configuration ContRol
ESCRで選択されたイベントをフィルタリングしてカウントする場合に使用する.
CPL: Current Privilege Level
ESCR: Event Selection ContRol
LLC: Last Level Cache
MSR: Model Specific Register
PEBS: Precise Event-Based Sampling
PMC: PerforMance Counter
PMI: Performance Monitoring Interrupt

【命令】
(RD/WR)MSR: MSRをRead/Writeする命令
RDPMC: PMCをReadする命令

【制限】
MSRをRead/Writeする命令を実行できるのは特権モード(ring 0)のみ.
アプリケーション(ring 3)からはPMCのReadのみ可能.

【イベント】
[リタイアイベント]
リタイアしたイベントとは,マシンステートを確定した命令によるイベントのみを含む.

[非リタイアイベント]
非リタイアイベントは,マイクロアーキテクチャーにおける
アウトオブオーダーの推測による流れで発生する.

[L2キャッシュイベント]
・MEM_LOAD_RETIRED.L2_LINE_MISS
L2キャッシュのミスで発生したロード数

・MEM_LOAD_RETIRED.L2_MISS


【参考資料】
インテルCoreマイクロアーキテクチャー・プロセッサーのパフォーマンス・カウンター
MEM_LOAD_RETIRED.L2_LINE_MISS
MEM_LOAD_RETIRED.L2_MISS

rdmsr - 通信用語の基礎知識
CPU-CPUID-MSR - SyncHack
CPU-MSR - SyncHack
linux2.6-include-asm-i386-msr.h - LinuxKernelHackJapan

Intel® 64 and IA-32 Architectures Software Developer's Manuals

2008/11/30

CPUID

【命令】
[引数]
EAX:

[返値]
EAX, EBX, ECX, EDX:


引数の値によって取得できるCPU情報が変わる.
詳しくはintel manual vol.2AのCPUIDの項を参照.


【補足】
linuxではCPUIDから抽出した情報を出力するcpuinfoがある.
# cat /proc/cpuinfo


【例】
unsigned int a, b, c, d;
asm volatile ("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "a"(0));


【参考資料】
Intel® 64 and IA-32 Architectures Software Developer's Manuals
sandpile.org -- IA-32 architecture -- CPUID
LHR-proc-cpuinfo - SyncHack
/proc/cpuinfoの中身 [備忘録]
CPUID - Wikipedia

2008/11/14

Intel CPU: ターボモード

マルチコアCPUで,あるコアがアイドル状態 or 稼働率が低いとき
チップ全体のTDPで考えると,他のコアに余裕ができる.
TDP的に余裕があるため,アクティブな他のコアをオーバークロックすることができる.
ハードウェアを変更することなく,コアの性能を
最大20%近く引き上げることができるため,注目されている技術だそうな.

[Reference]
Nehalemの性能を引き上げる切り札「ターボモード」