common.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #endif
  111. for (i = 0; i < model->num_counters; ++i) {
  112. struct dentry *dir;
  113. char buf[4];
  114. snprintf(buf, sizeof buf, "%d", i);
  115. dir = oprofilefs_mkdir(sb, root, buf);
  116. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  117. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  118. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  119. /*
  120. * Classic PowerPC doesn't support per-counter
  121. * control like this, but the options are
  122. * expected, so they remain. For Freescale
  123. * Book-E style performance monitors, we do
  124. * support them.
  125. */
  126. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  127. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  128. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  129. }
  130. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  131. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  132. /* Default to tracing both kernel and user */
  133. sys.enable_kernel = 1;
  134. sys.enable_user = 1;
  135. return 0;
  136. }
  137. int __init oprofile_arch_init(struct oprofile_operations *ops)
  138. {
  139. if (!cur_cpu_spec->oprofile_cpu_type)
  140. return -ENODEV;
  141. if (firmware_has_feature(FW_FEATURE_ISERIES))
  142. return -ENODEV;
  143. switch (cur_cpu_spec->oprofile_type) {
  144. #ifdef CONFIG_PPC64
  145. #ifdef CONFIG_OPROFILE_CELL
  146. case PPC_OPROFILE_CELL:
  147. if (firmware_has_feature(FW_FEATURE_LPAR))
  148. return -ENODEV;
  149. model = &op_model_cell;
  150. ops->sync_start = model->sync_start;
  151. ops->sync_stop = model->sync_stop;
  152. break;
  153. #endif
  154. case PPC_OPROFILE_RS64:
  155. model = &op_model_rs64;
  156. break;
  157. case PPC_OPROFILE_POWER4:
  158. model = &op_model_power4;
  159. break;
  160. case PPC_OPROFILE_PA6T:
  161. model = &op_model_pa6t;
  162. break;
  163. #endif
  164. #ifdef CONFIG_6xx
  165. case PPC_OPROFILE_G4:
  166. model = &op_model_7450;
  167. break;
  168. #endif
  169. #if defined(CONFIG_FSL_EMB_PERFMON)
  170. case PPC_OPROFILE_FSL_EMB:
  171. model = &op_model_fsl_emb;
  172. break;
  173. #endif
  174. default:
  175. return -ENODEV;
  176. }
  177. model->num_counters = cur_cpu_spec->num_pmcs;
  178. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  179. ops->create_files = op_powerpc_create_files;
  180. ops->setup = op_powerpc_setup;
  181. ops->shutdown = op_powerpc_shutdown;
  182. ops->start = op_powerpc_start;
  183. ops->stop = op_powerpc_stop;
  184. ops->backtrace = op_powerpc_backtrace;
  185. printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
  186. ops->cpu_type);
  187. return 0;
  188. }
  189. void oprofile_arch_exit(void)
  190. {
  191. }