tools/perf/util/kvm-stat.c
Source file repositories/reference/linux-study-clean/tools/perf/util/kvm-stat.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/kvm-stat.c- Extension
.c- Size
- 5851 bytes
- Lines
- 274
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
debug.hevsel.hkvm-stat.hdwarf-regs.h
Detected Declarations
function kvm_exit_eventfunction exit_event_get_keyfunction exit_event_beginfunction kvm_entry_eventfunction exit_event_endfunction exit_event_decode_keyfunction setup_kvm_events_tpfunction cpu_isa_initfunction kvm_add_default_arch_event
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "debug.h"
#include "evsel.h"
#include "kvm-stat.h"
#include <dwarf-regs.h>
bool kvm_exit_event(struct evsel *evsel)
{
uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
return evsel__name_is(evsel, kvm_exit_trace(e_machine));
}
void exit_event_get_key(struct evsel *evsel,
struct perf_sample *sample,
struct event_key *key)
{
uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
key->info = 0;
key->key = evsel__intval(evsel, sample, kvm_exit_reason(e_machine));
}
bool exit_event_begin(struct evsel *evsel,
struct perf_sample *sample, struct event_key *key)
{
if (kvm_exit_event(evsel)) {
exit_event_get_key(evsel, sample, key);
return true;
}
return false;
}
bool kvm_entry_event(struct evsel *evsel)
{
uint16_t e_machine = evsel__e_machine(evsel, /*e_flags=*/NULL);
return evsel__name_is(evsel, kvm_entry_trace(e_machine));
}
bool exit_event_end(struct evsel *evsel,
struct perf_sample *sample __maybe_unused,
struct event_key *key __maybe_unused)
{
return kvm_entry_event(evsel);
}
static const char *get_exit_reason(struct perf_kvm_stat *kvm,
struct exit_reasons_table *tbl,
u64 exit_code)
{
while (tbl->reason != NULL) {
if (tbl->exit_code == exit_code)
return tbl->reason;
tbl++;
}
pr_err("unknown kvm exit code:%lld on %s\n",
(unsigned long long)exit_code, kvm->exit_reasons_isa);
return "UNKNOWN";
}
void exit_event_decode_key(struct perf_kvm_stat *kvm,
struct event_key *key,
char *decode)
{
const char *exit_reason = get_exit_reason(kvm, key->exit_reasons,
key->key);
scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", exit_reason);
}
int setup_kvm_events_tp(struct perf_kvm_stat *kvm, uint16_t e_machine)
{
switch (e_machine) {
case EM_PPC:
case EM_PPC64:
return __setup_kvm_events_tp_powerpc(kvm);
default:
return 0;
}
}
int cpu_isa_init(struct perf_kvm_stat *kvm, uint16_t e_machine, const char *cpuid)
{
switch (e_machine) {
case EM_AARCH64:
return __cpu_isa_init_arm64(kvm);
Annotation
- Immediate include surface: `debug.h`, `evsel.h`, `kvm-stat.h`, `dwarf-regs.h`.
- Detected declarations: `function kvm_exit_event`, `function exit_event_get_key`, `function exit_event_begin`, `function kvm_entry_event`, `function exit_event_end`, `function exit_event_decode_key`, `function setup_kvm_events_tp`, `function cpu_isa_init`, `function kvm_add_default_arch_event`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.