common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/errno.h>
  10. #include <linux/init.h>
  11. #include <linux/oprofile.h>
  12. #include <linux/smp.h>
  13. #include <asm/cpu-info.h>
  14. #include "op_impl.h"
  15. extern struct op_mips_model op_model_mipsxx_ops __attribute__((weak));
  16. extern struct op_mips_model op_model_rm9000_ops __attribute__((weak));
  17. extern struct op_mips_model op_model_loongson2_ops __attribute__((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_20KC:
  64. case CPU_24K:
  65. case CPU_25KF:
  66. case CPU_34K:
  67. case CPU_1004K:
  68. case CPU_74K:
  69. case CPU_SB1:
  70. case CPU_SB1A:
  71. case CPU_R10000:
  72. case CPU_R12000:
  73. case CPU_R14000:
  74. lmodel = &op_model_mipsxx_ops;
  75. break;
  76. case CPU_RM9000:
  77. lmodel = &op_model_rm9000_ops;
  78. break;
  79. case CPU_LOONGSON2:
  80. lmodel = &op_model_loongson2_ops;
  81. break;
  82. };
  83. if (!lmodel)
  84. return -ENODEV;
  85. res = lmodel->init();
  86. if (res)
  87. return res;
  88. model = lmodel;
  89. ops->create_files = op_mips_create_files;
  90. ops->setup = op_mips_setup;
  91. //ops->shutdown = op_mips_shutdown;
  92. ops->start = op_mips_start;
  93. ops->stop = op_mips_stop;
  94. ops->cpu_type = lmodel->cpu_type;
  95. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  96. lmodel->cpu_type);
  97. return 0;
  98. }
  99. void oprofile_arch_exit(void)
  100. {
  101. if (model)
  102. model->exit();
  103. }