common.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 void op_handle_interrupt(struct pt_regs *regs)
  29. {
  30. model->handle_interrupt(regs, ctr);
  31. }
  32. static void op_powerpc_cpu_setup(void *dummy)
  33. {
  34. model->cpu_setup(ctr);
  35. }
  36. static int op_powerpc_setup(void)
  37. {
  38. int err;
  39. /* Grab the hardware */
  40. err = reserve_pmc_hardware(op_handle_interrupt);
  41. if (err)
  42. return err;
  43. /* Pre-compute the values to stuff in the hardware registers. */
  44. model->reg_setup(ctr, &sys, model->num_counters);
  45. /* Configure the registers on all cpus. */
  46. on_each_cpu(op_powerpc_cpu_setup, NULL, 0, 1);
  47. return 0;
  48. }
  49. static void op_powerpc_shutdown(void)
  50. {
  51. release_pmc_hardware();
  52. }
  53. static void op_powerpc_cpu_start(void *dummy)
  54. {
  55. model->start(ctr);
  56. }
  57. static int op_powerpc_start(void)
  58. {
  59. if (model->global_start)
  60. model->global_start(ctr);
  61. if (model->start)
  62. on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
  63. return 0;
  64. }
  65. static inline void op_powerpc_cpu_stop(void *dummy)
  66. {
  67. model->stop();
  68. }
  69. static void op_powerpc_stop(void)
  70. {
  71. if (model->stop)
  72. on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
  73. if (model->global_stop)
  74. model->global_stop();
  75. }
  76. static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
  77. {
  78. int i;
  79. #ifdef CONFIG_PPC64
  80. /*
  81. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  82. * all of the counters.
  83. */
  84. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  85. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  86. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  87. #endif
  88. for (i = 0; i < model->num_counters; ++i) {
  89. struct dentry *dir;
  90. char buf[4];
  91. snprintf(buf, sizeof buf, "%d", i);
  92. dir = oprofilefs_mkdir(sb, root, buf);
  93. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  94. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  95. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  96. /*
  97. * Classic PowerPC doesn't support per-counter
  98. * control like this, but the options are
  99. * expected, so they remain. For Freescale
  100. * Book-E style performance monitors, we do
  101. * support them.
  102. */
  103. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  104. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  105. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  106. }
  107. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  108. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  109. /* Default to tracing both kernel and user */
  110. sys.enable_kernel = 1;
  111. sys.enable_user = 1;
  112. return 0;
  113. }
  114. int __init oprofile_arch_init(struct oprofile_operations *ops)
  115. {
  116. if (!cur_cpu_spec->oprofile_cpu_type)
  117. return -ENODEV;
  118. if (firmware_has_feature(FW_FEATURE_ISERIES))
  119. return -ENODEV;
  120. switch (cur_cpu_spec->oprofile_type) {
  121. #ifdef CONFIG_PPC64
  122. #ifdef CONFIG_PPC_CELL_NATIVE
  123. case PPC_OPROFILE_CELL:
  124. if (firmware_has_feature(FW_FEATURE_LPAR))
  125. return -ENODEV;
  126. model = &op_model_cell;
  127. break;
  128. #endif
  129. case PPC_OPROFILE_RS64:
  130. model = &op_model_rs64;
  131. break;
  132. case PPC_OPROFILE_POWER4:
  133. model = &op_model_power4;
  134. break;
  135. #endif
  136. #ifdef CONFIG_6xx
  137. case PPC_OPROFILE_G4:
  138. model = &op_model_7450;
  139. break;
  140. #endif
  141. #ifdef CONFIG_FSL_BOOKE
  142. case PPC_OPROFILE_BOOKE:
  143. model = &op_model_fsl_booke;
  144. break;
  145. #endif
  146. default:
  147. return -ENODEV;
  148. }
  149. model->num_counters = cur_cpu_spec->num_pmcs;
  150. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  151. ops->create_files = op_powerpc_create_files;
  152. ops->setup = op_powerpc_setup;
  153. ops->shutdown = op_powerpc_shutdown;
  154. ops->start = op_powerpc_start;
  155. ops->stop = op_powerpc_stop;
  156. ops->backtrace = op_powerpc_backtrace;
  157. printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
  158. ops->cpu_type);
  159. return 0;
  160. }
  161. void oprofile_arch_exit(void)
  162. {
  163. }