common.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 __attribute__((weak));
  16. extern struct op_mips_model op_model_rm9000 __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, 0, 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[3];
  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. lmodel = &op_model_mipsxx;
  66. break;
  67. case CPU_RM9000:
  68. lmodel = &op_model_rm9000;
  69. break;
  70. };
  71. if (!lmodel)
  72. return -ENODEV;
  73. res = lmodel->init();
  74. if (res)
  75. return res;
  76. model = lmodel;
  77. ops->create_files = op_mips_create_files;
  78. ops->setup = op_mips_setup;
  79. //ops->shutdown = op_mips_shutdown;
  80. ops->start = op_mips_start;
  81. ops->stop = op_mips_stop;
  82. ops->cpu_type = lmodel->cpu_type;
  83. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  84. lmodel->cpu_type);
  85. return 0;
  86. }
  87. void oprofile_arch_exit(void)
  88. {
  89. model->exit();
  90. }