mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-23 14:02:06 -04:00
`perf kvm stat` supports record and report options. By using the arch directory a report for a different machine type cannot be supported. Move the kvm-stat code out of the arch directory and into util/kvm-stat-arch following the pattern of perf-regs and dwarf-regs. Avoid duplicate symbols by renaming functions to have the architecture name within them. For global variables, wrap them in an architecture specific function. Selecting the architecture to use with `perf kvm stat` is selected by EM_HOST, ie no different than before the change. Later the ELF machine can be determined from the session or a header feature (ie EM_HOST at the time of the record). The build and #define HAVE_KVM_STAT_SUPPORT is now redundant so remove across Makefiles and in the build. Opportunistically constify architectural structs and arrays. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Aditya Bodkhe <aditya.b1@linux.ibm.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Jones <ajones@ventanamicro.com> Cc: Anubhav Shelat <ashelat@redhat.com> Cc: Anup Patel <anup@brainfault.org> Cc: Athira Rajeev <atrajeev@linux.ibm.com> Cc: Blake Jones <blakejones@google.com> Cc: Chun-Tse Shao <ctshao@google.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Howard Chu <howardchu95@gmail.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <pjw@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Quan Zhou <zhouquan@iscas.ac.cn> Cc: Shimin Guo <shimin.guo@skydio.com> Cc: Swapnil Sapkal <swapnil.sapkal@amd.com> Cc: Thomas Falcon <thomas.falcon@intel.com> Cc: Will Deacon <will@kernel.org> Cc: Yunseong Kim <ysk@kzalloc.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
229 lines
5.2 KiB
C
229 lines
5.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <errno.h>
|
|
#include "../kvm-stat.h"
|
|
#include "../parse-events.h"
|
|
#include "../debug.h"
|
|
#include "../evsel.h"
|
|
#include "../evlist.h"
|
|
#include "../pmus.h"
|
|
|
|
#include "book3s_hv_exits.h"
|
|
#include "book3s_hcalls.h"
|
|
#include <subcmd/parse-options.h>
|
|
|
|
#define NR_TPS 4
|
|
|
|
define_exit_reasons_table(hv_exit_reasons, kvm_trace_symbol_exit);
|
|
define_exit_reasons_table(hcall_reasons, kvm_trace_symbol_hcall);
|
|
|
|
/* Tracepoints specific to ppc_book3s_hv */
|
|
static const char * const ppc_book3s_hv_kvm_tp[] = {
|
|
"kvm_hv:kvm_guest_enter",
|
|
"kvm_hv:kvm_guest_exit",
|
|
"kvm_hv:kvm_hcall_enter",
|
|
"kvm_hv:kvm_hcall_exit",
|
|
NULL,
|
|
};
|
|
|
|
/* 1 extra placeholder for NULL */
|
|
static const char *__kvm_events_tp[NR_TPS + 1];
|
|
|
|
static void hcall_event_get_key(struct evsel *evsel,
|
|
struct perf_sample *sample,
|
|
struct event_key *key)
|
|
{
|
|
key->info = 0;
|
|
key->key = evsel__intval(evsel, sample, "req");
|
|
}
|
|
|
|
static const char *get_hcall_exit_reason(u64 exit_code)
|
|
{
|
|
struct exit_reasons_table *tbl = hcall_reasons;
|
|
|
|
while (tbl->reason != NULL) {
|
|
if (tbl->exit_code == exit_code)
|
|
return tbl->reason;
|
|
tbl++;
|
|
}
|
|
|
|
pr_debug("Unknown hcall code: %lld\n",
|
|
(unsigned long long)exit_code);
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
static bool hcall_event_end(struct evsel *evsel,
|
|
struct perf_sample *sample __maybe_unused,
|
|
struct event_key *key __maybe_unused)
|
|
{
|
|
return evsel__name_is(evsel, __kvm_events_tp[3]);
|
|
}
|
|
|
|
static bool hcall_event_begin(struct evsel *evsel,
|
|
struct perf_sample *sample, struct event_key *key)
|
|
{
|
|
if (evsel__name_is(evsel, __kvm_events_tp[2])) {
|
|
hcall_event_get_key(evsel, sample, key);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
static void hcall_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
|
|
struct event_key *key,
|
|
char *decode)
|
|
{
|
|
const char *hcall_reason = get_hcall_exit_reason(key->key);
|
|
|
|
scnprintf(decode, KVM_EVENT_NAME_LEN, "%s", hcall_reason);
|
|
}
|
|
|
|
static const struct kvm_events_ops hcall_events = {
|
|
.is_begin_event = hcall_event_begin,
|
|
.is_end_event = hcall_event_end,
|
|
.decode_key = hcall_event_decode_key,
|
|
.name = "HCALL-EVENT",
|
|
};
|
|
|
|
static const struct kvm_events_ops exit_events = {
|
|
.is_begin_event = exit_event_begin,
|
|
.is_end_event = exit_event_end,
|
|
.decode_key = exit_event_decode_key,
|
|
.name = "VM-EXIT"
|
|
};
|
|
|
|
static const struct kvm_reg_events_ops __kvm_reg_events_ops[] = {
|
|
{ .name = "vmexit", .ops = &exit_events },
|
|
{ .name = "hcall", .ops = &hcall_events },
|
|
{ NULL, NULL },
|
|
};
|
|
|
|
static const char * const __kvm_skip_events[] = {
|
|
NULL,
|
|
};
|
|
|
|
|
|
static int is_tracepoint_available(const char *str, struct evlist *evlist)
|
|
{
|
|
struct parse_events_error err;
|
|
int ret;
|
|
|
|
parse_events_error__init(&err);
|
|
ret = parse_events(evlist, str, &err);
|
|
if (ret)
|
|
parse_events_error__print(&err, "tracepoint");
|
|
parse_events_error__exit(&err);
|
|
return ret;
|
|
}
|
|
|
|
static int ppc__setup_book3s_hv(struct perf_kvm_stat *kvm,
|
|
struct evlist *evlist)
|
|
{
|
|
const char * const *events_ptr;
|
|
int i, nr_tp = 0, err = -1;
|
|
|
|
/* Check for book3s_hv tracepoints */
|
|
for (events_ptr = ppc_book3s_hv_kvm_tp; *events_ptr; events_ptr++) {
|
|
err = is_tracepoint_available(*events_ptr, evlist);
|
|
if (err)
|
|
return -1;
|
|
nr_tp++;
|
|
}
|
|
|
|
for (i = 0; i < nr_tp; i++)
|
|
__kvm_events_tp[i] = ppc_book3s_hv_kvm_tp[i];
|
|
|
|
__kvm_events_tp[i] = NULL;
|
|
kvm->exit_reasons = hv_exit_reasons;
|
|
kvm->exit_reasons_isa = "HV";
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Wrapper to setup kvm tracepoints */
|
|
static int ppc__setup_kvm_tp(struct perf_kvm_stat *kvm)
|
|
{
|
|
struct evlist *evlist = evlist__new();
|
|
|
|
if (evlist == NULL)
|
|
return -ENOMEM;
|
|
|
|
/* Right now, only supported on book3s_hv */
|
|
return ppc__setup_book3s_hv(kvm, evlist);
|
|
}
|
|
|
|
int __setup_kvm_events_tp_powerpc(struct perf_kvm_stat *kvm)
|
|
{
|
|
return ppc__setup_kvm_tp(kvm);
|
|
}
|
|
|
|
int __cpu_isa_init_powerpc(struct perf_kvm_stat *kvm)
|
|
{
|
|
int ret;
|
|
|
|
ret = ppc__setup_kvm_tp(kvm);
|
|
if (ret) {
|
|
kvm->exit_reasons = NULL;
|
|
kvm->exit_reasons_isa = NULL;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* In case of powerpc architecture, pmu registers are programmable
|
|
* by guest kernel. So monitoring guest via host may not provide
|
|
* valid samples with default 'cycles' event. It is better to use
|
|
* 'trace_imc/trace_cycles' event for guest profiling, since it
|
|
* can track the guest instruction pointer in the trace-record.
|
|
*
|
|
* Function to parse the arguments and return appropriate values.
|
|
*/
|
|
int __kvm_add_default_arch_event_powerpc(int *argc, const char **argv)
|
|
{
|
|
const char **tmp;
|
|
bool event = false;
|
|
int i, j = *argc;
|
|
|
|
const struct option event_options[] = {
|
|
OPT_BOOLEAN('e', "event", &event, NULL),
|
|
OPT_END()
|
|
};
|
|
|
|
tmp = calloc(j + 1, sizeof(char *));
|
|
if (!tmp)
|
|
return -EINVAL;
|
|
|
|
for (i = 0; i < j; i++)
|
|
tmp[i] = argv[i];
|
|
|
|
parse_options(j, tmp, event_options, NULL, PARSE_OPT_KEEP_UNKNOWN);
|
|
if (!event) {
|
|
if (perf_pmus__have_event("trace_imc", "trace_cycles")) {
|
|
argv[j++] = strdup("-e");
|
|
argv[j++] = strdup("trace_imc/trace_cycles/");
|
|
*argc += 2;
|
|
} else {
|
|
free(tmp);
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
free(tmp);
|
|
return 0;
|
|
}
|
|
|
|
const char * const *__kvm_events_tp_powerpc(void)
|
|
{
|
|
return __kvm_events_tp;
|
|
}
|
|
|
|
const struct kvm_reg_events_ops *__kvm_reg_events_ops_powerpc(void)
|
|
{
|
|
return __kvm_reg_events_ops;
|
|
}
|
|
|
|
const char * const *__kvm_skip_events_powerpc(void)
|
|
{
|
|
return __kvm_skip_events;
|
|
}
|