common.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * PPC 64 oprofile support:
  3. * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
  4. * PPC 32 oprofile support: (based on PPC 64 support)
  5. * Copyright (C) Freescale Semiconductor, Inc 2004
  6. * Author: Andy Fleming
  7. *
  8. * Based on alpha version.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #include <linux/oprofile.h>
  16. #include <linux/init.h>
  17. #include <linux/smp.h>
  18. #include <linux/errno.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/system.h>
  21. #include <asm/pmc.h>
  22. #include <asm/cputable.h>
  23. #include <asm/oprofile_impl.h>
  24. static struct op_powerpc_model *model;
  25. static struct op_counter_config ctr[OP_MAX_COUNTER];
  26. static struct op_system_config sys;
  27. static void op_handle_interrupt(struct pt_regs *regs)
  28. {
  29. model->handle_interrupt(regs, ctr);
  30. }
  31. static int op_powerpc_setup(void)
  32. {
  33. int err;
  34. /* Grab the hardware */
  35. err = reserve_pmc_hardware(op_handle_interrupt);
  36. if (err)
  37. return err;
  38. /* Pre-compute the values to stuff in the hardware registers. */
  39. model->reg_setup(ctr, &sys, model->num_counters);
  40. /* Configure the registers on all cpus. */
  41. on_each_cpu(model->cpu_setup, NULL, 0, 1);
  42. return 0;
  43. }
  44. static void op_powerpc_shutdown(void)
  45. {
  46. release_pmc_hardware();
  47. }
  48. static void op_powerpc_cpu_start(void *dummy)
  49. {
  50. model->start(ctr);
  51. }
  52. static int op_powerpc_start(void)
  53. {
  54. on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
  55. return 0;
  56. }
  57. static inline void op_powerpc_cpu_stop(void *dummy)
  58. {
  59. model->stop();
  60. }
  61. static void op_powerpc_stop(void)
  62. {
  63. on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
  64. }
  65. static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
  66. {
  67. int i;
  68. #ifdef CONFIG_PPC64
  69. /*
  70. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  71. * all of the counters.
  72. */
  73. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  74. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  75. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  76. #endif
  77. for (i = 0; i < model->num_counters; ++i) {
  78. struct dentry *dir;
  79. char buf[3];
  80. snprintf(buf, sizeof buf, "%d", i);
  81. dir = oprofilefs_mkdir(sb, root, buf);
  82. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  83. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  84. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  85. /*
  86. * Classic PowerPC doesn't support per-counter
  87. * control like this, but the options are
  88. * expected, so they remain. For Freescale
  89. * Book-E style performance monitors, we do
  90. * support them.
  91. */
  92. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  93. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  94. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  95. }
  96. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  97. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  98. #ifdef CONFIG_PPC64
  99. oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
  100. &sys.backtrace_spinlocks);
  101. #endif
  102. /* Default to tracing both kernel and user */
  103. sys.enable_kernel = 1;
  104. sys.enable_user = 1;
  105. #ifdef CONFIG_PPC64
  106. /* Turn on backtracing through spinlocks by default */
  107. sys.backtrace_spinlocks = 1;
  108. #endif
  109. return 0;
  110. }
  111. int __init oprofile_arch_init(struct oprofile_operations *ops)
  112. {
  113. if (!cur_cpu_spec->oprofile_cpu_type)
  114. return -ENODEV;
  115. switch (cur_cpu_spec->oprofile_type) {
  116. #ifdef CONFIG_PPC64
  117. case PPC_OPROFILE_RS64:
  118. model = &op_model_rs64;
  119. break;
  120. case PPC_OPROFILE_POWER4:
  121. model = &op_model_power4;
  122. break;
  123. #else
  124. case PPC_OPROFILE_G4:
  125. model = &op_model_7450;
  126. break;
  127. #endif
  128. #ifdef CONFIG_FSL_BOOKE
  129. case PPC_OPROFILE_BOOKE:
  130. model = &op_model_fsl_booke;
  131. break;
  132. #endif
  133. default:
  134. return -ENODEV;
  135. }
  136. model->num_counters = cur_cpu_spec->num_pmcs;
  137. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  138. ops->create_files = op_powerpc_create_files;
  139. ops->setup = op_powerpc_setup;
  140. ops->shutdown = op_powerpc_shutdown;
  141. ops->start = op_powerpc_start;
  142. ops->stop = op_powerpc_stop;
  143. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  144. ops->cpu_type);
  145. return 0;
  146. }
  147. void oprofile_arch_exit(void)
  148. {
  149. }