common.c 4.0 KB

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