common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004, 2005 Ralf Baechle
  7. * Copyright (C) 2005 MIPS Technologies, Inc.
  8. */
  9. #include <linux/compiler.h>
  10. #include <linux/errno.h>
  11. #include <linux/init.h>
  12. #include <linux/oprofile.h>
  13. #include <linux/smp.h>
  14. #include <asm/cpu-info.h>
  15. #include "op_impl.h"
  16. extern struct op_mips_model op_model_mipsxx_ops __weak;
  17. extern struct op_mips_model op_model_loongson2_ops __weak;
  18. static struct op_mips_model *model;
  19. static struct op_counter_config ctr[20];
  20. static int op_mips_setup(void)
  21. {
  22. /* Pre-compute the values to stuff in the hardware registers. */
  23. model->reg_setup(ctr);
  24. /* Configure the registers on all cpus. */
  25. on_each_cpu(model->cpu_setup, NULL, 1);
  26. return 0;
  27. }
  28. static int op_mips_create_files(struct super_block *sb, struct dentry *root)
  29. {
  30. int i;
  31. for (i = 0; i < model->num_counters; ++i) {
  32. struct dentry *dir;
  33. char buf[4];
  34. snprintf(buf, sizeof buf, "%d", i);
  35. dir = oprofilefs_mkdir(sb, root, buf);
  36. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  37. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  38. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  39. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  40. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  41. oprofilefs_create_ulong(sb, dir, "exl", &ctr[i].exl);
  42. /* Dummy. */
  43. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  44. }
  45. return 0;
  46. }
  47. static int op_mips_start(void)
  48. {
  49. on_each_cpu(model->cpu_start, NULL, 1);
  50. return 0;
  51. }
  52. static void op_mips_stop(void)
  53. {
  54. /* Disable performance monitoring for all counters. */
  55. on_each_cpu(model->cpu_stop, NULL, 1);
  56. }
  57. int __init oprofile_arch_init(struct oprofile_operations *ops)
  58. {
  59. struct op_mips_model *lmodel = NULL;
  60. int res;
  61. switch (current_cpu_type()) {
  62. case CPU_5KC:
  63. case CPU_M14KC:
  64. case CPU_M14KEC:
  65. case CPU_20KC:
  66. case CPU_24K:
  67. case CPU_25KF:
  68. case CPU_34K:
  69. case CPU_1004K:
  70. case CPU_74K:
  71. case CPU_LOONGSON1:
  72. case CPU_SB1:
  73. case CPU_SB1A:
  74. case CPU_R10000:
  75. case CPU_R12000:
  76. case CPU_R14000:
  77. case CPU_XLR:
  78. lmodel = &op_model_mipsxx_ops;
  79. break;
  80. case CPU_LOONGSON2:
  81. lmodel = &op_model_loongson2_ops;
  82. break;
  83. };
  84. if (!lmodel)
  85. return -ENODEV;
  86. res = lmodel->init();
  87. if (res)
  88. return res;
  89. model = lmodel;
  90. ops->create_files = op_mips_create_files;
  91. ops->setup = op_mips_setup;
  92. //ops->shutdown = op_mips_shutdown;
  93. ops->start = op_mips_start;
  94. ops->stop = op_mips_stop;
  95. ops->cpu_type = lmodel->cpu_type;
  96. ops->backtrace = op_mips_backtrace;
  97. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  98. lmodel->cpu_type);
  99. return 0;
  100. }
  101. void oprofile_arch_exit(void)
  102. {
  103. if (model)
  104. model->exit();
  105. }