Path: blob/master/arch/powerpc/platforms/pseries/hvCall_inst.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 2006 Mike Kravetz IBM Corporation3*4* Hypervisor Call Instrumentation5*/67#include <linux/kernel.h>8#include <linux/percpu.h>9#include <linux/debugfs.h>10#include <linux/seq_file.h>11#include <linux/cpumask.h>12#include <asm/hvcall.h>13#include <asm/firmware.h>14#include <asm/cputable.h>15#include <asm/trace.h>16#include <asm/machdep.h>1718/* For hcall instrumentation. One structure per-hcall, per-CPU */19struct hcall_stats {20unsigned long num_calls; /* number of calls (on this CPU) */21unsigned long tb_total; /* total wall time (mftb) of calls. */22unsigned long purr_total; /* total cpu time (PURR) of calls. */23unsigned long tb_start;24unsigned long purr_start;25};26#define HCALL_STAT_ARRAY_SIZE ((MAX_HCALL_OPCODE >> 2) + 1)2728static DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);2930/*31* Routines for displaying the statistics in debugfs32*/33static void *hc_start(struct seq_file *m, loff_t *pos)34{35if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))36return (void *)(unsigned long)(*pos + 1);3738return NULL;39}4041static void *hc_next(struct seq_file *m, void *p, loff_t * pos)42{43++*pos;4445return hc_start(m, pos);46}4748static void hc_stop(struct seq_file *m, void *p)49{50}5152static int hc_show(struct seq_file *m, void *p)53{54unsigned long h_num = (unsigned long)p;55struct hcall_stats *hs = m->private;5657if (hs[h_num].num_calls) {58if (cpu_has_feature(CPU_FTR_PURR))59seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2,60hs[h_num].num_calls,61hs[h_num].tb_total,62hs[h_num].purr_total);63else64seq_printf(m, "%lu %lu %lu\n", h_num<<2,65hs[h_num].num_calls,66hs[h_num].tb_total);67}6869return 0;70}7172static const struct seq_operations hcall_inst_sops = {73.start = hc_start,74.next = hc_next,75.stop = hc_stop,76.show = hc_show77};7879DEFINE_SEQ_ATTRIBUTE(hcall_inst);8081#define HCALL_ROOT_DIR "hcall_inst"82#define CPU_NAME_BUF_SIZE 32838485static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args)86{87struct hcall_stats *h;8889if (opcode > MAX_HCALL_OPCODE)90return;9192h = this_cpu_ptr(&hcall_stats[opcode / 4]);93h->tb_start = mftb();94h->purr_start = mfspr(SPRN_PURR);95}9697static void probe_hcall_exit(void *ignored, unsigned long opcode, long retval,98unsigned long *retbuf)99{100struct hcall_stats *h;101102if (opcode > MAX_HCALL_OPCODE)103return;104105h = this_cpu_ptr(&hcall_stats[opcode / 4]);106h->num_calls++;107h->tb_total += mftb() - h->tb_start;108h->purr_total += mfspr(SPRN_PURR) - h->purr_start;109}110111static int __init hcall_inst_init(void)112{113struct dentry *hcall_root;114char cpu_name_buf[CPU_NAME_BUF_SIZE];115int cpu;116117if (!firmware_has_feature(FW_FEATURE_LPAR))118return 0;119120if (register_trace_hcall_entry(probe_hcall_entry, NULL))121return -EINVAL;122123if (register_trace_hcall_exit(probe_hcall_exit, NULL)) {124unregister_trace_hcall_entry(probe_hcall_entry, NULL);125return -EINVAL;126}127128hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);129130for_each_possible_cpu(cpu) {131snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);132debugfs_create_file(cpu_name_buf, 0444, hcall_root,133per_cpu(hcall_stats, cpu),134&hcall_inst_fops);135}136137return 0;138}139machine_device_initcall(pseries, hcall_inst_init);140141142