common.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * arch/sh/oprofile/init.c
  3. *
  4. * Copyright (C) 2003 - 2008 Paul Mundt
  5. *
  6. * Based on arch/mips/oprofile/common.c:
  7. *
  8. * Copyright (C) 2004, 2005 Ralf Baechle
  9. * Copyright (C) 2005 MIPS Technologies, Inc.
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file "COPYING" in the main directory of this archive
  13. * for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/oprofile.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/smp.h>
  20. #include <asm/processor.h>
  21. #include "op_impl.h"
  22. static struct op_sh_model *model;
  23. static struct op_counter_config ctr[20];
  24. extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth);
  25. static int op_sh_setup(void)
  26. {
  27. /* Pre-compute the values to stuff in the hardware registers. */
  28. model->reg_setup(ctr);
  29. /* Configure the registers on all cpus. */
  30. on_each_cpu(model->cpu_setup, NULL, 1);
  31. return 0;
  32. }
  33. static int op_sh_create_files(struct super_block *sb, struct dentry *root)
  34. {
  35. int i, ret = 0;
  36. for (i = 0; i < model->num_counters; i++) {
  37. struct dentry *dir;
  38. char buf[4];
  39. snprintf(buf, sizeof(buf), "%d", i);
  40. dir = oprofilefs_mkdir(sb, root, buf);
  41. ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  42. ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  43. ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  44. ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  45. if (model->create_files)
  46. ret |= model->create_files(sb, dir);
  47. else
  48. ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  49. /* Dummy entries */
  50. ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  51. }
  52. return ret;
  53. }
  54. static int op_sh_start(void)
  55. {
  56. /* Enable performance monitoring for all counters. */
  57. on_each_cpu(model->cpu_start, NULL, 1);
  58. return 0;
  59. }
  60. static void op_sh_stop(void)
  61. {
  62. /* Disable performance monitoring for all counters. */
  63. on_each_cpu(model->cpu_stop, NULL, 1);
  64. }
  65. int __init oprofile_arch_init(struct oprofile_operations *ops)
  66. {
  67. struct op_sh_model *lmodel = NULL;
  68. int ret;
  69. /*
  70. * Always assign the backtrace op. If the counter initialization
  71. * fails, we fall back to the timer which will still make use of
  72. * this.
  73. */
  74. ops->backtrace = sh_backtrace;
  75. /*
  76. * XXX
  77. *
  78. * All of the SH7750/SH-4A counters have been converted to perf,
  79. * this infrastructure hook is left for other users until they've
  80. * had a chance to convert over, at which point all of this
  81. * will be deleted.
  82. */
  83. if (!lmodel)
  84. return -ENODEV;
  85. if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER))
  86. return -ENODEV;
  87. ret = lmodel->init();
  88. if (unlikely(ret != 0))
  89. return ret;
  90. model = lmodel;
  91. ops->setup = op_sh_setup;
  92. ops->create_files = op_sh_create_files;
  93. ops->start = op_sh_start;
  94. ops->stop = op_sh_stop;
  95. ops->cpu_type = lmodel->cpu_type;
  96. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  97. lmodel->cpu_type);
  98. return 0;
  99. }
  100. void oprofile_arch_exit(void)
  101. {
  102. if (model && model->exit)
  103. model->exit();
  104. }