tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c
Source file repositories/reference/linux-study-clean/tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/kvm-stat-arch/kvm-stat-loongarch.c- Extension
.c- Size
- 4145 bytes
- Lines
- 153
- 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
errno.hmemory.hdwarf-regs.h../kvm-stat.h../parse-events.h../debug.h../evsel.h../evlist.h../pmus.h
Detected Declarations
function event_beginfunction event_endfunction event_gspr_get_keyfunction __cpu_isa_init_loongarch
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <errno.h>
#include <memory.h>
#include <dwarf-regs.h>
#include "../kvm-stat.h"
#include "../parse-events.h"
#include "../debug.h"
#include "../evsel.h"
#include "../evlist.h"
#include "../pmus.h"
#define LOONGARCH_EXCEPTION_INT 0
#define LOONGARCH_EXCEPTION_PIL 1
#define LOONGARCH_EXCEPTION_PIS 2
#define LOONGARCH_EXCEPTION_PIF 3
#define LOONGARCH_EXCEPTION_PME 4
#define LOONGARCH_EXCEPTION_FPD 15
#define LOONGARCH_EXCEPTION_SXD 16
#define LOONGARCH_EXCEPTION_ASXD 17
#define LOONGARCH_EXCEPTION_GSPR 22
#define LOONGARCH_EXCEPTION_CPUCFG 100
#define LOONGARCH_EXCEPTION_CSR 101
#define LOONGARCH_EXCEPTION_IOCSR 102
#define LOONGARCH_EXCEPTION_IDLE 103
#define LOONGARCH_EXCEPTION_OTHERS 104
#define LOONGARCH_EXCEPTION_HVC 23
#define loongarch_exception_type \
{LOONGARCH_EXCEPTION_INT, "Interrupt" }, \
{LOONGARCH_EXCEPTION_PIL, "Mem Read" }, \
{LOONGARCH_EXCEPTION_PIS, "Mem Store" }, \
{LOONGARCH_EXCEPTION_PIF, "Inst Fetch" }, \
{LOONGARCH_EXCEPTION_PME, "Mem Modify" }, \
{LOONGARCH_EXCEPTION_FPD, "FPU" }, \
{LOONGARCH_EXCEPTION_SXD, "LSX" }, \
{LOONGARCH_EXCEPTION_ASXD, "LASX" }, \
{LOONGARCH_EXCEPTION_GSPR, "Privilege Error" }, \
{LOONGARCH_EXCEPTION_HVC, "Hypercall" }, \
{LOONGARCH_EXCEPTION_CPUCFG, "CPUCFG" }, \
{LOONGARCH_EXCEPTION_CSR, "CSR" }, \
{LOONGARCH_EXCEPTION_IOCSR, "IOCSR" }, \
{LOONGARCH_EXCEPTION_IDLE, "Idle" }, \
{LOONGARCH_EXCEPTION_OTHERS, "Others" }
define_exit_reasons_table(loongarch_exit_reasons, loongarch_exception_type);
static const char *kvm_reenter_trace = "kvm:kvm_reenter";
static const char * const __kvm_events_tp[] = {
"kvm:kvm_enter",
"kvm:kvm_reenter",
"kvm:kvm_exit",
"kvm:kvm_exit_gspr",
NULL,
};
static bool event_begin(struct evsel *evsel,
struct perf_sample *sample, struct event_key *key)
{
return exit_event_begin(evsel, sample, key);
}
static bool event_end(struct evsel *evsel,
struct perf_sample *sample __maybe_unused,
struct event_key *key __maybe_unused)
{
/*
* LoongArch kvm is different with other architectures
*
* There is kvm:kvm_reenter or kvm:kvm_enter event adjacent with
* kvm:kvm_exit event.
* kvm:kvm_enter means returning to vmm and then to guest
* kvm:kvm_reenter means returning to guest immediately
*/
return evsel__name_is(evsel, kvm_entry_trace(EM_LOONGARCH)) ||
evsel__name_is(evsel, kvm_reenter_trace);
}
static void event_gspr_get_key(struct evsel *evsel,
struct perf_sample *sample, struct event_key *key)
{
unsigned int insn;
key->key = LOONGARCH_EXCEPTION_OTHERS;
insn = evsel__intval(evsel, sample, "inst_word");
switch (insn >> 24) {
case 0:
/* CPUCFG inst trap */
if ((insn >> 10) == 0x1b)
key->key = LOONGARCH_EXCEPTION_CPUCFG;
Annotation
- Immediate include surface: `errno.h`, `memory.h`, `dwarf-regs.h`, `../kvm-stat.h`, `../parse-events.h`, `../debug.h`, `../evsel.h`, `../evlist.h`.
- Detected declarations: `function event_begin`, `function event_end`, `function event_gspr_get_key`, `function __cpu_isa_init_loongarch`.
- 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.