common.c 4.1 KB

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