common.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. static struct op_mips_model *model;
  18. static struct op_counter_config ctr[20];
  19. static int op_mips_setup(void)
  20. {
  21. /* Pre-compute the values to stuff in the hardware registers. */
  22. model->reg_setup(ctr);
  23. /* Configure the registers on all cpus. */
  24. on_each_cpu(model->cpu_setup, NULL, 0, 1);
  25. return 0;
  26. }
  27. static int op_mips_create_files(struct super_block * sb, struct dentry * root)
  28. {
  29. int i;
  30. for (i = 0; i < model->num_counters; ++i) {
  31. struct dentry *dir;
  32. char buf[4];
  33. snprintf(buf, sizeof buf, "%d", i);
  34. dir = oprofilefs_mkdir(sb, root, buf);
  35. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  36. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  37. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  38. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  39. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  40. oprofilefs_create_ulong(sb, dir, "exl", &ctr[i].exl);
  41. /* Dummy. */
  42. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  43. }
  44. return 0;
  45. }
  46. static int op_mips_start(void)
  47. {
  48. on_each_cpu(model->cpu_start, NULL, 0, 1);
  49. return 0;
  50. }
  51. static void op_mips_stop(void)
  52. {
  53. /* Disable performance monitoring for all counters. */
  54. on_each_cpu(model->cpu_stop, NULL, 0, 1);
  55. }
  56. int __init oprofile_arch_init(struct oprofile_operations *ops)
  57. {
  58. struct op_mips_model *lmodel = NULL;
  59. int res;
  60. switch (current_cpu_data.cputype) {
  61. case CPU_5KC:
  62. case CPU_20KC:
  63. case CPU_24K:
  64. case CPU_25KF:
  65. case CPU_34K:
  66. case CPU_74K:
  67. case CPU_SB1:
  68. case CPU_SB1A:
  69. lmodel = &op_model_mipsxx_ops;
  70. break;
  71. case CPU_RM9000:
  72. lmodel = &op_model_rm9000_ops;
  73. break;
  74. };
  75. if (!lmodel)
  76. return -ENODEV;
  77. res = lmodel->init();
  78. if (res)
  79. return res;
  80. model = lmodel;
  81. ops->create_files = op_mips_create_files;
  82. ops->setup = op_mips_setup;
  83. //ops->shutdown = op_mips_shutdown;
  84. ops->start = op_mips_start;
  85. ops->stop = op_mips_stop;
  86. ops->cpu_type = lmodel->cpu_type;
  87. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  88. lmodel->cpu_type);
  89. return 0;
  90. }
  91. void oprofile_arch_exit(void)
  92. {
  93. if (model)
  94. model->exit();
  95. }