hvCall_inst.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <linux/kernel.h>
  21. #include <linux/percpu.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/cpumask.h>
  25. #include <asm/hvcall.h>
  26. #include <asm/firmware.h>
  27. #include <asm/cputable.h>
  28. DEFINE_PER_CPU(struct hcall_stats[HCALL_STAT_ARRAY_SIZE], hcall_stats);
  29. /*
  30. * Routines for displaying the statistics in debugfs
  31. */
  32. static void *hc_start(struct seq_file *m, loff_t *pos)
  33. {
  34. if ((int)*pos < (HCALL_STAT_ARRAY_SIZE-1))
  35. return (void *)(unsigned long)(*pos + 1);
  36. return NULL;
  37. }
  38. static void *hc_next(struct seq_file *m, void *p, loff_t * pos)
  39. {
  40. ++*pos;
  41. return hc_start(m, pos);
  42. }
  43. static void hc_stop(struct seq_file *m, void *p)
  44. {
  45. }
  46. static int hc_show(struct seq_file *m, void *p)
  47. {
  48. unsigned long h_num = (unsigned long)p;
  49. struct hcall_stats *hs = (struct hcall_stats *)m->private;
  50. if (hs[h_num].num_calls) {
  51. if (cpu_has_feature(CPU_FTR_PURR))
  52. seq_printf(m, "%lu %lu %lu %lu\n", h_num<<2,
  53. hs[h_num].num_calls,
  54. hs[h_num].tb_total,
  55. hs[h_num].purr_total);
  56. else
  57. seq_printf(m, "%lu %lu %lu\n", h_num<<2,
  58. hs[h_num].num_calls,
  59. hs[h_num].tb_total);
  60. }
  61. return 0;
  62. }
  63. static struct seq_operations hcall_inst_seq_ops = {
  64. .start = hc_start,
  65. .next = hc_next,
  66. .stop = hc_stop,
  67. .show = hc_show
  68. };
  69. static int hcall_inst_seq_open(struct inode *inode, struct file *file)
  70. {
  71. int rc;
  72. struct seq_file *seq;
  73. rc = seq_open(file, &hcall_inst_seq_ops);
  74. seq = file->private_data;
  75. seq->private = file->f_path.dentry->d_inode->i_private;
  76. return rc;
  77. }
  78. static const struct file_operations hcall_inst_seq_fops = {
  79. .open = hcall_inst_seq_open,
  80. .read = seq_read,
  81. .llseek = seq_lseek,
  82. .release = seq_release,
  83. };
  84. #define HCALL_ROOT_DIR "hcall_inst"
  85. #define CPU_NAME_BUF_SIZE 32
  86. static int __init hcall_inst_init(void)
  87. {
  88. struct dentry *hcall_root;
  89. struct dentry *hcall_file;
  90. char cpu_name_buf[CPU_NAME_BUF_SIZE];
  91. int cpu;
  92. if (!firmware_has_feature(FW_FEATURE_LPAR))
  93. return 0;
  94. hcall_root = debugfs_create_dir(HCALL_ROOT_DIR, NULL);
  95. if (!hcall_root)
  96. return -ENOMEM;
  97. for_each_possible_cpu(cpu) {
  98. snprintf(cpu_name_buf, CPU_NAME_BUF_SIZE, "cpu%d", cpu);
  99. hcall_file = debugfs_create_file(cpu_name_buf, S_IRUGO,
  100. hcall_root,
  101. per_cpu(hcall_stats, cpu),
  102. &hcall_inst_seq_fops);
  103. if (!hcall_file)
  104. return -ENOMEM;
  105. }
  106. return 0;
  107. }
  108. __initcall(hcall_inst_init);