common.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. #include <asm/firmware.h>
  25. static struct op_powerpc_model *model;
  26. static struct op_counter_config ctr[OP_MAX_COUNTER];
  27. static struct op_system_config sys;
  28. static int op_per_cpu_rc;
  29. static void op_handle_interrupt(struct pt_regs *regs)
  30. {
  31. model->handle_interrupt(regs, ctr);
  32. }
  33. static void op_powerpc_cpu_setup(void *dummy)
  34. {
  35. int ret;
  36. ret = model->cpu_setup(ctr);
  37. if (ret != 0)
  38. op_per_cpu_rc = ret;
  39. }
  40. static int op_powerpc_setup(void)
  41. {
  42. int err;
  43. op_per_cpu_rc = 0;
  44. /* Grab the hardware */
  45. err = reserve_pmc_hardware(op_handle_interrupt);
  46. if (err)
  47. return err;
  48. /* Pre-compute the values to stuff in the hardware registers. */
  49. op_per_cpu_rc = model->reg_setup(ctr, &sys, model->num_counters);
  50. if (op_per_cpu_rc)
  51. goto out;
  52. /* Configure the registers on all cpus. If an error occurs on one
  53. * of the cpus, op_per_cpu_rc will be set to the error */
  54. on_each_cpu(op_powerpc_cpu_setup, NULL, 1);
  55. out: if (op_per_cpu_rc) {
  56. /* error on setup release the performance counter hardware */
  57. release_pmc_hardware();
  58. }
  59. return op_per_cpu_rc;
  60. }
  61. static void op_powerpc_shutdown(void)
  62. {
  63. release_pmc_hardware();
  64. }
  65. static void op_powerpc_cpu_start(void *dummy)
  66. {
  67. /* If any of the cpus have return an error, set the
  68. * global flag to the error so it can be returned
  69. * to the generic OProfile caller.
  70. */
  71. int ret;
  72. ret = model->start(ctr);
  73. if (ret != 0)
  74. op_per_cpu_rc = ret;
  75. }
  76. static int op_powerpc_start(void)
  77. {
  78. op_per_cpu_rc = 0;
  79. if (model->global_start)
  80. return model->global_start(ctr);
  81. if (model->start) {
  82. on_each_cpu(op_powerpc_cpu_start, NULL, 1);
  83. return op_per_cpu_rc;
  84. }
  85. return -EIO; /* No start function is defined for this
  86. power architecture */
  87. }
  88. static inline void op_powerpc_cpu_stop(void *dummy)
  89. {
  90. model->stop();
  91. }
  92. static void op_powerpc_stop(void)
  93. {
  94. if (model->stop)
  95. on_each_cpu(op_powerpc_cpu_stop, NULL, 1);
  96. if (model->global_stop)
  97. model->global_stop();
  98. }
  99. static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
  100. {
  101. int i;
  102. #ifdef CONFIG_PPC64
  103. /*
  104. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  105. * all of the counters.
  106. */
  107. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  108. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  109. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  110. #ifdef CONFIG_OPROFILE_CELL
  111. /* create a file the user tool can check to see what level of profiling
  112. * support exits with this kernel. Initialize bit mask to indicate
  113. * what support the kernel has:
  114. * bit 0 - Supports SPU event profiling in addition to PPU
  115. * event and cycles; and SPU cycle profiling
  116. * bits 1-31 - Currently unused.
  117. *
  118. * If the file does not exist, then the kernel only supports SPU
  119. * cycle profiling, PPU event and cycle profiling.
  120. */
  121. oprofilefs_create_ulong(sb, root, "cell_support", &sys.cell_support);
  122. sys.cell_support = 0x1; /* Note, the user OProfile tool must check
  123. * that this bit is set before attempting to
  124. * user SPU event profiling. Older kernels
  125. * will not have this file, hence the user
  126. * tool is not allowed to do SPU event
  127. * profiling on older kernels. Older kernels
  128. * will accept SPU events but collected data
  129. * is garbage.
  130. */
  131. #endif
  132. #endif
  133. for (i = 0; i < model->num_counters; ++i) {
  134. struct dentry *dir;
  135. char buf[4];
  136. snprintf(buf, sizeof buf, "%d", i);
  137. dir = oprofilefs_mkdir(sb, root, buf);
  138. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  139. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  140. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  141. /*
  142. * Classic PowerPC doesn't support per-counter
  143. * control like this, but the options are
  144. * expected, so they remain. For Freescale
  145. * Book-E style performance monitors, we do
  146. * support them.
  147. */
  148. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  149. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  150. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  151. }
  152. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  153. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  154. /* Default to tracing both kernel and user */
  155. sys.enable_kernel = 1;
  156. sys.enable_user = 1;
  157. return 0;
  158. }
  159. int __init oprofile_arch_init(struct oprofile_operations *ops)
  160. {
  161. if (!cur_cpu_spec->oprofile_cpu_type)
  162. return -ENODEV;
  163. if (firmware_has_feature(FW_FEATURE_ISERIES))
  164. return -ENODEV;
  165. switch (cur_cpu_spec->oprofile_type) {
  166. #ifdef CONFIG_PPC64
  167. #ifdef CONFIG_OPROFILE_CELL
  168. case PPC_OPROFILE_CELL:
  169. if (firmware_has_feature(FW_FEATURE_LPAR))
  170. return -ENODEV;
  171. model = &op_model_cell;
  172. ops->sync_start = model->sync_start;
  173. ops->sync_stop = model->sync_stop;
  174. break;
  175. #endif
  176. case PPC_OPROFILE_RS64:
  177. model = &op_model_rs64;
  178. break;
  179. case PPC_OPROFILE_POWER4:
  180. model = &op_model_power4;
  181. break;
  182. case PPC_OPROFILE_PA6T:
  183. model = &op_model_pa6t;
  184. break;
  185. #endif
  186. #ifdef CONFIG_6xx
  187. case PPC_OPROFILE_G4:
  188. model = &op_model_7450;
  189. break;
  190. #endif
  191. #if defined(CONFIG_FSL_EMB_PERFMON)
  192. case PPC_OPROFILE_FSL_EMB:
  193. model = &op_model_fsl_emb;
  194. break;
  195. #endif
  196. default:
  197. return -ENODEV;
  198. }
  199. model->num_counters = cur_cpu_spec->num_pmcs;
  200. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  201. ops->create_files = op_powerpc_create_files;
  202. ops->setup = op_powerpc_setup;
  203. ops->shutdown = op_powerpc_shutdown;
  204. ops->start = op_powerpc_start;
  205. ops->stop = op_powerpc_stop;
  206. ops->backtrace = op_powerpc_backtrace;
  207. printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
  208. ops->cpu_type);
  209. return 0;
  210. }
  211. void oprofile_arch_exit(void)
  212. {
  213. }