SystemTap を使用してカーネル モジュールのキャッシュ動作をプロファイリングしたいと考えています (#cache 参照、#cache ミスなど)。SystemTap を使用してパフォーマンス イベントとカウンター (キャッシュ関連のものを含む) を読み取る方法を示すサンプル スクリプトがオンラインにあります: https://sourceware.org/systemtap/examples/profiling/perf.stp
このサンプル スクリプトは、プロセスに対してデフォルトで機能します。
probe perf.hw.cache_references.process("/usr/bin/find").counter("find_insns") {}
process
キーワードを次のように置き換え、module
実行可能ファイルへのパスをカーネル モジュールの名前に置き換えました。
probe perf.hw.cache_references.module(MODULE_NAME).counter("find_insns") {}
私のモジュールにはデバッグ情報があると確信していますが、取得したスクリプトを実行すると:
セマンティック エラー: プローブ ポイントの解決中: perf.stp:14:7 の識別子 'perf' ソース: プローブ perf.hw.instructions.module(MODULE_NAME).counter("find_insns") {}
何が間違っているのでしょうか?
編集:
さて、パフォーマンス カウンターはモジュールではなくプロセスにのみバインドできることに気付きました (ここで説明: https://sourceware.org/systemtap/man/stapprobes.3stap.html )。したがって、次のように変更しました。
probe perf.hw.cache_references.process(PATH_TO_BINARY).counter("find_insns") {}
サンプル スクリプトが示すように、次のようになります。
probe module(MODULE_NAME).function(FUNC_NAME) {
#save counter values on entrance
...
}
しかし、今それを実行すると、次のようになります。
セマンティック エラー: perf カウンター 'find_insns' が定義されていません
編集2:
だからここに私の完全なスクリプトがあります:
#! /usr/bin/env stap
# Usage: stap perf.stp <path-to-binary> <module-name> <function-name>
global cycles_per_insn
global branch_per_insn
global cacheref_per_insn
global insns
global cycles
global branches
global cacherefs
global insn
global cachemisses
global miss_per_insn
probe perf.hw.instructions.process(@1).counter("find_insns") {}
probe perf.hw.cpu_cycles.process(@1).counter("find_cycles") {}
probe perf.hw.branch_instructions.process(@1).counter("find_branches") {}
probe perf.hw.cache_references.process(@1).counter("find_cache_refs") {}
probe perf.hw.cache_misses.process(@1).counter("find_cache_misses") {}
probe module(@2).function(@3)
{
insn["find_insns"] = @perf("find_insns")
insns <<< (insn["find_insns"])
insn["find_cycles"] = @perf("find_cycles")
cycles <<< insn["find_cycles"]
insn["find_branches"] = @perf("find_branches")
branches <<< insn["find_branches"]
insn["find_cache_refs"] = @perf("find_cache_refs")
cacherefs <<< insn["find_cache_refs"]
insn["find_cache_misses"] = @perf("find_cache_misses")
cachemisses <<< insn["find_cache_misses"]
}
probe module(@2).function(@3).return
{
dividend = (@perf("find_cycles") - insn["find_cycles"])
divisor = (@perf("find_insns") - insn["find_insns"])
q = dividend / divisor
if (q > 0)
cycles_per_insn <<< q
dividend = (@perf("find_branches") - insn["find_branches"])
q = dividend / divisor
if (q > 0)
branch_per_insn <<< q
dividend = (@perf("find_cycles") - insn["find_cycles"])
q = dividend / divisor
if (q > 0)
cacheref_per_insn <<< q
dividend = (@perf("find_cache_misses") - insn["find_cache_misses"])
q = dividend / divisor
if (q > 0)
miss_per_insn <<< q
}
probe end
{
if (@count(cycles_per_insn)) {
printf ("Cycles per Insn\n\n")
print (@hist_log(cycles_per_insn))
}
if (@count(branch_per_insn)) {
printf ("\nBranches per Insn\n\n")
print (@hist_log(branch_per_insn))
}
if (@count(cacheref_per_insn)) {
printf ("Cache Refs per Insn\n\n")
print (@hist_log(cacheref_per_insn))
}
if (@count(miss_per_insn)) {
printf ("Cache Misses per Insn\n\n")
print (@hist_log(miss_per_insn))
}
}