Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Mike Kravetz IBM Corporation |
| 3 | * |
| 4 | * Hypervisor Call Instrumentation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/percpu.h> |
| 23 | #include <linux/debugfs.h> |
| 24 | #include <linux/seq_file.h> |
| 25 | #include <linux/cpumask.h> |
| 26 | #include <asm/hvcall.h> |
| 27 | #include <asm/firmware.h> |
| 28 | #include <asm/cputable.h> |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 29 | #include <asm/trace.h> |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 30 | #include <asm/machdep.h> |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 31 | |
| 32 | DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats); |
| 33 | |
| 34 | /* |
| 35 | * Routines for displaying the statistics in debugfs |
| 36 | */ |
| 37 | static void *hc_start(struct seq_file *m, loff_t *pos) |
| 38 | { |
Anton Blanchard | dc40127 | 2007-01-09 02:43:02 +1100 | [diff] [blame] | 39 | if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1)) |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 40 | return (void *)(unsigned long)(*pos + 1); |
| 41 | |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | static void *hc_next(struct seq_file *m, void *p, loff_t * pos) |
| 46 | { |
| 47 | ++*pos; |
| 48 | |
| 49 | return hc_start(m, pos); |
| 50 | } |
| 51 | |
| 52 | static void hc_stop(struct seq_file *m, void *p) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | static int hc_show(struct seq_file *m, void *p) |
| 57 | { |
| 58 | unsigned long h_num = (unsigned long)p; |
matt mooney | 6d2ad1e | 2010-09-27 19:04:44 -0700 | [diff] [blame] | 59 | struct hcall_stats *hs = m->private; |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 60 | |
| 61 | if (hs[h_num].num_calls) { |
Anton Blanchard | dc40127 | 2007-01-09 02:43:02 +1100 | [diff] [blame] | 62 | if (cpu_has_feature(CPU_FTR_PURR)) |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 63 | seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2, |
| 64 | hs[h_num].num_calls, |
| 65 | hs[h_num].tb_total, |
| 66 | hs[h_num].purr_total); |
| 67 | else |
| 68 | seq_printf(m, "%lu %lu %lu\n", h_num<<2, |
| 69 | hs[h_num].num_calls, |
| 70 | hs[h_num].tb_total); |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 76 | static const struct seq_operations hcall_inst_seq_ops = { |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 77 | .start = hc_start, |
| 78 | .next = hc_next, |
| 79 | .stop = hc_stop, |
| 80 | .show = hc_show |
| 81 | }; |
| 82 | |
| 83 | static int hcall_inst_seq_open(struct inode *inode, struct file *file) |
| 84 | { |
| 85 | int rc; |
| 86 | struct seq_file *seq; |
| 87 | |
| 88 | rc = seq_open(file, &hcall_inst_seq_ops); |
| 89 | seq = file->private_data; |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 90 | seq->private = file_inode(file)->i_private; |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 91 | |
| 92 | return rc; |
| 93 | } |
| 94 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 95 | static const struct file_operations hcall_inst_seq_fops = { |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 96 | .open = hcall_inst_seq_open, |
| 97 | .read = seq_read, |
| 98 | .llseek = seq_lseek, |
| 99 | .release = seq_release, |
| 100 | }; |
| 101 | |
| 102 | #define HCALL_ROOT_DIR "hcall_inst" |
| 103 | #define CPU_NAME_BUF_SIZE 32 |
| 104 | |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 105 | |
Stephen Rothwell | 969ea5c | 2010-05-28 15:05:00 +1000 | [diff] [blame] | 106 | static void probe_hcall_entry(void *ignored, unsigned long opcode, unsigned long *args) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 107 | { |
| 108 | struct hcall_stats *h; |
| 109 | |
| 110 | if (opcode > MAX_HCALL_OPCODE) |
| 111 | return; |
| 112 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 113 | h = this_cpu_ptr(&hcall_stats[opcode / 4]); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 114 | h->tb_start = mftb(); |
| 115 | h->purr_start = mfspr(SPRN_PURR); |
| 116 | } |
| 117 | |
Stephen Rothwell | 969ea5c | 2010-05-28 15:05:00 +1000 | [diff] [blame] | 118 | static void probe_hcall_exit(void *ignored, unsigned long opcode, unsigned long retval, |
Anton Blanchard | 6f26353 | 2009-10-26 18:51:09 +0000 | [diff] [blame] | 119 | unsigned long *retbuf) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 120 | { |
| 121 | struct hcall_stats *h; |
| 122 | |
| 123 | if (opcode > MAX_HCALL_OPCODE) |
| 124 | return; |
| 125 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 126 | h = this_cpu_ptr(&hcall_stats[opcode / 4]); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 127 | h->num_calls++; |
Will Schmidt | 25ef231 | 2009-11-25 06:12:09 +0000 | [diff] [blame] | 128 | h->tb_total += mftb() - h->tb_start; |
| 129 | h->purr_total += mfspr(SPRN_PURR) - h->purr_start; |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 132 | static int __init hcall_inst_init(void) |
| 133 | { |
| 134 | struct dentry *hcall_root; |
| 135 | struct dentry *hcall_file; |
| 136 | char cpu_name_buf[CPU_NAME_BUF_SIZE]; |
| 137 | int cpu; |
| 138 | |
| 139 | if (!firmware_has_feature(FW_FEATURE_LPAR)) |
| 140 | return 0; |
| 141 | |
Stephen Rothwell | 969ea5c | 2010-05-28 15:05:00 +1000 | [diff] [blame] | 142 | if (register_trace_hcall_entry(probe_hcall_entry, NULL)) |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | |
Stephen Rothwell | 969ea5c | 2010-05-28 15:05:00 +1000 | [diff] [blame] | 145 | if (register_trace_hcall_exit(probe_hcall_exit, NULL)) { |
| 146 | unregister_trace_hcall_entry(probe_hcall_entry, NULL); |
Anton Blanchard | c8cd093 | 2009-10-26 18:50:29 +0000 | [diff] [blame] | 147 | return -EINVAL; |
| 148 | } |
| 149 | |
Mike Kravetz | 57852a8 | 2006-09-06 16:23:12 -0700 | [diff] [blame] | 150 | hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL); |
| 151 | if (!hcall_root) |
| 152 | return -ENOMEM; |
| 153 | |
| 154 | for_each_possible_cpu(cpu) { |
| 155 | snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu); |
| 156 | hcall_file = debugfs_create_file(cpu_name_buf, S_IRUGO, |
| 157 | hcall_root, |
| 158 | per_cpu(hcall_stats, cpu), |
| 159 | &hcall_inst_seq_fops); |
| 160 | if (!hcall_file) |
| 161 | return -ENOMEM; |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | } |
Michael Ellerman | 8e83e90 | 2014-07-16 12:02:43 +1000 | [diff] [blame] | 166 | machine_device_initcall(pseries, hcall_inst_init); |