common.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
  3. *
  4. * Based on alpha version.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/oprofile.h>
  12. #include <linux/init.h>
  13. #include <linux/smp.h>
  14. #include <linux/errno.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/system.h>
  17. #include <asm/pmc.h>
  18. #include <asm/cputable.h>
  19. #include <asm/oprofile_impl.h>
  20. static struct op_ppc64_model *model;
  21. static struct op_counter_config ctr[OP_MAX_COUNTER];
  22. static struct op_system_config sys;
  23. static void op_handle_interrupt(struct pt_regs *regs)
  24. {
  25. model->handle_interrupt(regs, ctr);
  26. }
  27. static int op_ppc64_setup(void)
  28. {
  29. int err;
  30. /* Grab the hardware */
  31. err = reserve_pmc_hardware(op_handle_interrupt);
  32. if (err)
  33. return err;
  34. /* Pre-compute the values to stuff in the hardware registers. */
  35. model->reg_setup(ctr, &sys, model->num_counters);
  36. /* Configure the registers on all cpus. */
  37. on_each_cpu(model->cpu_setup, NULL, 0, 1);
  38. return 0;
  39. }
  40. static void op_ppc64_shutdown(void)
  41. {
  42. release_pmc_hardware();
  43. }
  44. static void op_ppc64_cpu_start(void *dummy)
  45. {
  46. model->start(ctr);
  47. }
  48. static int op_ppc64_start(void)
  49. {
  50. on_each_cpu(op_ppc64_cpu_start, NULL, 0, 1);
  51. return 0;
  52. }
  53. static inline void op_ppc64_cpu_stop(void *dummy)
  54. {
  55. model->stop();
  56. }
  57. static void op_ppc64_stop(void)
  58. {
  59. on_each_cpu(op_ppc64_cpu_stop, NULL, 0, 1);
  60. }
  61. static int op_ppc64_create_files(struct super_block *sb, struct dentry *root)
  62. {
  63. int i;
  64. /*
  65. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  66. * all of the counters.
  67. */
  68. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  69. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  70. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  71. for (i = 0; i < model->num_counters; ++i) {
  72. struct dentry *dir;
  73. char buf[3];
  74. snprintf(buf, sizeof buf, "%d", i);
  75. dir = oprofilefs_mkdir(sb, root, buf);
  76. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  77. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  78. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  79. /*
  80. * We dont support per counter user/kernel selection, but
  81. * we leave the entries because userspace expects them
  82. */
  83. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  84. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  85. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  86. }
  87. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  88. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  89. oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
  90. &sys.backtrace_spinlocks);
  91. /* Default to tracing both kernel and user */
  92. sys.enable_kernel = 1;
  93. sys.enable_user = 1;
  94. /* Turn on backtracing through spinlocks by default */
  95. sys.backtrace_spinlocks = 1;
  96. return 0;
  97. }
  98. int __init oprofile_arch_init(struct oprofile_operations *ops)
  99. {
  100. if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type)
  101. return -ENODEV;
  102. model = cur_cpu_spec->oprofile_model;
  103. model->num_counters = cur_cpu_spec->num_pmcs;
  104. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  105. ops->create_files = op_ppc64_create_files;
  106. ops->setup = op_ppc64_setup;
  107. ops->shutdown = op_ppc64_shutdown;
  108. ops->start = op_ppc64_start;
  109. ops->stop = op_ppc64_stop;
  110. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  111. ops->cpu_type);
  112. return 0;
  113. }
  114. void oprofile_arch_exit(void)
  115. {
  116. }