common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. extern struct op_sh_model op_model_sh7750_ops __weak;
  23. extern struct op_sh_model op_model_sh4a_ops __weak;
  24. static struct op_sh_model *model;
  25. static struct op_counter_config ctr[20];
  26. extern void sh_backtrace(struct pt_regs * const regs, unsigned int depth);
  27. static int op_sh_setup(void)
  28. {
  29. /* Pre-compute the values to stuff in the hardware registers. */
  30. model->reg_setup(ctr);
  31. /* Configure the registers on all cpus. */
  32. on_each_cpu(model->cpu_setup, NULL, 1);
  33. return 0;
  34. }
  35. static int op_sh_create_files(struct super_block *sb, struct dentry *root)
  36. {
  37. int i, ret = 0;
  38. for (i = 0; i < model->num_counters; i++) {
  39. struct dentry *dir;
  40. char buf[4];
  41. snprintf(buf, sizeof(buf), "%d", i);
  42. dir = oprofilefs_mkdir(sb, root, buf);
  43. ret |= oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  44. ret |= oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  45. ret |= oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  46. ret |= oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  47. if (model->create_files)
  48. ret |= model->create_files(sb, dir);
  49. else
  50. ret |= oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  51. /* Dummy entries */
  52. ret |= oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  53. }
  54. return ret;
  55. }
  56. static int op_sh_start(void)
  57. {
  58. /* Enable performance monitoring for all counters. */
  59. on_each_cpu(model->cpu_start, NULL, 1);
  60. return 0;
  61. }
  62. static void op_sh_stop(void)
  63. {
  64. /* Disable performance monitoring for all counters. */
  65. on_each_cpu(model->cpu_stop, NULL, 1);
  66. }
  67. int __init oprofile_arch_init(struct oprofile_operations *ops)
  68. {
  69. struct op_sh_model *lmodel = NULL;
  70. int ret;
  71. /*
  72. * Always assign the backtrace op. If the counter initialization
  73. * fails, we fall back to the timer which will still make use of
  74. * this.
  75. */
  76. ops->backtrace = sh_backtrace;
  77. switch (current_cpu_data.type) {
  78. /* SH-4 types */
  79. case CPU_SH7750:
  80. case CPU_SH7750S:
  81. lmodel = &op_model_sh7750_ops;
  82. break;
  83. /* SH-4A types */
  84. case CPU_SH7763:
  85. case CPU_SH7770:
  86. case CPU_SH7780:
  87. case CPU_SH7781:
  88. case CPU_SH7785:
  89. case CPU_SH7786:
  90. case CPU_SH7723:
  91. case CPU_SH7724:
  92. case CPU_SHX3:
  93. lmodel = &op_model_sh4a_ops;
  94. break;
  95. /* SH4AL-DSP types */
  96. case CPU_SH7343:
  97. case CPU_SH7722:
  98. case CPU_SH7366:
  99. lmodel = &op_model_sh4a_ops;
  100. break;
  101. }
  102. if (!lmodel)
  103. return -ENODEV;
  104. if (!(current_cpu_data.flags & CPU_HAS_PERF_COUNTER))
  105. return -ENODEV;
  106. ret = lmodel->init();
  107. if (unlikely(ret != 0))
  108. return ret;
  109. model = lmodel;
  110. ops->setup = op_sh_setup;
  111. ops->create_files = op_sh_create_files;
  112. ops->start = op_sh_start;
  113. ops->stop = op_sh_stop;
  114. ops->cpu_type = lmodel->cpu_type;
  115. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  116. lmodel->cpu_type);
  117. return 0;
  118. }
  119. void oprofile_arch_exit(void)
  120. {
  121. if (model && model->exit)
  122. model->exit();
  123. }