common.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
  60. return 0;
  61. }
  62. static inline void op_powerpc_cpu_stop(void *dummy)
  63. {
  64. model->stop();
  65. }
  66. static void op_powerpc_stop(void)
  67. {
  68. on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
  69. }
  70. static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
  71. {
  72. int i;
  73. #ifdef CONFIG_PPC64
  74. /*
  75. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  76. * all of the counters.
  77. */
  78. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  79. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  80. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  81. #endif
  82. for (i = 0; i < model->num_counters; ++i) {
  83. struct dentry *dir;
  84. char buf[4];
  85. snprintf(buf, sizeof buf, "%d", i);
  86. dir = oprofilefs_mkdir(sb, root, buf);
  87. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  88. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  89. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  90. /*
  91. * Classic PowerPC doesn't support per-counter
  92. * control like this, but the options are
  93. * expected, so they remain. For Freescale
  94. * Book-E style performance monitors, we do
  95. * support them.
  96. */
  97. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  98. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  99. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  100. }
  101. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  102. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  103. /* Default to tracing both kernel and user */
  104. sys.enable_kernel = 1;
  105. sys.enable_user = 1;
  106. return 0;
  107. }
  108. int __init oprofile_arch_init(struct oprofile_operations *ops)
  109. {
  110. if (!cur_cpu_spec->oprofile_cpu_type)
  111. return -ENODEV;
  112. if (firmware_has_feature(FW_FEATURE_ISERIES))
  113. return -ENODEV;
  114. switch (cur_cpu_spec->oprofile_type) {
  115. #ifdef CONFIG_PPC64
  116. case PPC_OPROFILE_RS64:
  117. model = &op_model_rs64;
  118. break;
  119. case PPC_OPROFILE_POWER4:
  120. model = &op_model_power4;
  121. break;
  122. #endif
  123. #ifdef CONFIG_6xx
  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. ops->backtrace = op_powerpc_backtrace;
  144. printk(KERN_DEBUG "oprofile: using %s performance monitoring.\n",
  145. ops->cpu_type);
  146. return 0;
  147. }
  148. void oprofile_arch_exit(void)
  149. {
  150. }