common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_rm9000_ops __weak;
  18. extern struct op_mips_model op_model_loongson2_ops __weak;
  19. static struct op_mips_model *model;
  20. static struct op_counter_config ctr[20];
  21. static int op_mips_setup(void)
  22. {
  23. /* Pre-compute the values to stuff in the hardware registers. */
  24. model->reg_setup(ctr);
  25. /* Configure the registers on all cpus. */
  26. on_each_cpu(model->cpu_setup, NULL, 1);
  27. return 0;
  28. }
  29. static int op_mips_create_files(struct super_block *sb, struct dentry *root)
  30. {
  31. int i;
  32. for (i = 0; i < model->num_counters; ++i) {
  33. struct dentry *dir;
  34. char buf[4];
  35. snprintf(buf, sizeof buf, "%d", i);
  36. dir = oprofilefs_mkdir(sb, root, buf);
  37. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  38. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  39. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  40. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  41. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  42. oprofilefs_create_ulong(sb, dir, "exl", &ctr[i].exl);
  43. /* Dummy. */
  44. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  45. }
  46. return 0;
  47. }
  48. static int op_mips_start(void)
  49. {
  50. on_each_cpu(model->cpu_start, NULL, 1);
  51. return 0;
  52. }
  53. static void op_mips_stop(void)
  54. {
  55. /* Disable performance monitoring for all counters. */
  56. on_each_cpu(model->cpu_stop, NULL, 1);
  57. }
  58. int __init oprofile_arch_init(struct oprofile_operations *ops)
  59. {
  60. struct op_mips_model *lmodel = NULL;
  61. int res;
  62. switch (current_cpu_type()) {
  63. case CPU_5KC:
  64. case CPU_20KC:
  65. case CPU_24K:
  66. case CPU_25KF:
  67. case CPU_34K:
  68. case CPU_1004K:
  69. case CPU_74K:
  70. case CPU_SB1:
  71. case CPU_SB1A:
  72. case CPU_R10000:
  73. case CPU_R12000:
  74. case CPU_R14000:
  75. lmodel = &op_model_mipsxx_ops;
  76. break;
  77. case CPU_RM9000:
  78. lmodel = &op_model_rm9000_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. }