common.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifndef __powerpc64__
  17. #include <linux/slab.h>
  18. #endif /* ! __powerpc64__ */
  19. #include <linux/init.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/system.h>
  24. #include <asm/pmc.h>
  25. #include <asm/cputable.h>
  26. #include <asm/oprofile_impl.h>
  27. static struct op_powerpc_model *model;
  28. static struct op_counter_config ctr[OP_MAX_COUNTER];
  29. static struct op_system_config sys;
  30. #ifndef __powerpc64__
  31. static char *cpu_type;
  32. #endif /* ! __powerpc64__ */
  33. static void op_handle_interrupt(struct pt_regs *regs)
  34. {
  35. model->handle_interrupt(regs, ctr);
  36. }
  37. static int op_powerpc_setup(void)
  38. {
  39. int err;
  40. /* Grab the hardware */
  41. err = reserve_pmc_hardware(op_handle_interrupt);
  42. if (err)
  43. return err;
  44. /* Pre-compute the values to stuff in the hardware registers. */
  45. model->reg_setup(ctr, &sys, model->num_counters);
  46. /* Configure the registers on all cpus. */
  47. #ifdef __powerpc64__
  48. on_each_cpu(model->cpu_setup, NULL, 0, 1);
  49. #else /* __powerpc64__ */
  50. #if 0
  51. /* FIXME: Make multi-cpu work */
  52. on_each_cpu(model->reg_setup, NULL, 0, 1);
  53. #endif
  54. #endif /* __powerpc64__ */
  55. return 0;
  56. }
  57. static void op_powerpc_shutdown(void)
  58. {
  59. release_pmc_hardware();
  60. }
  61. static void op_powerpc_cpu_start(void *dummy)
  62. {
  63. model->start(ctr);
  64. }
  65. static int op_powerpc_start(void)
  66. {
  67. on_each_cpu(op_powerpc_cpu_start, NULL, 0, 1);
  68. return 0;
  69. }
  70. static inline void op_powerpc_cpu_stop(void *dummy)
  71. {
  72. model->stop();
  73. }
  74. static void op_powerpc_stop(void)
  75. {
  76. on_each_cpu(op_powerpc_cpu_stop, NULL, 0, 1);
  77. }
  78. static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
  79. {
  80. int i;
  81. #ifdef __powerpc64__
  82. /*
  83. * There is one mmcr0, mmcr1 and mmcra for setting the events for
  84. * all of the counters.
  85. */
  86. oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0);
  87. oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1);
  88. oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra);
  89. #endif /* __powerpc64__ */
  90. for (i = 0; i < model->num_counters; ++i) {
  91. struct dentry *dir;
  92. char buf[3];
  93. snprintf(buf, sizeof buf, "%d", i);
  94. dir = oprofilefs_mkdir(sb, root, buf);
  95. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  96. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  97. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  98. #ifdef __powerpc64__
  99. /*
  100. * We dont support per counter user/kernel selection, but
  101. * we leave the entries because userspace expects them
  102. */
  103. #endif /* __powerpc64__ */
  104. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  105. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  106. #ifndef __powerpc64__
  107. /* FIXME: Not sure if this is used */
  108. #endif /* ! __powerpc64__ */
  109. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  110. }
  111. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  112. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  113. #ifdef __powerpc64__
  114. oprofilefs_create_ulong(sb, root, "backtrace_spinlocks",
  115. &sys.backtrace_spinlocks);
  116. #endif /* __powerpc64__ */
  117. /* Default to tracing both kernel and user */
  118. sys.enable_kernel = 1;
  119. sys.enable_user = 1;
  120. #ifdef __powerpc64__
  121. /* Turn on backtracing through spinlocks by default */
  122. sys.backtrace_spinlocks = 1;
  123. #endif /* __powerpc64__ */
  124. return 0;
  125. }
  126. int __init oprofile_arch_init(struct oprofile_operations *ops)
  127. {
  128. #ifndef __powerpc64__
  129. #ifdef CONFIG_FSL_BOOKE
  130. model = &op_model_fsl_booke;
  131. #else
  132. return -ENODEV;
  133. #endif
  134. cpu_type = kmalloc(32, GFP_KERNEL);
  135. if (NULL == cpu_type)
  136. return -ENOMEM;
  137. sprintf(cpu_type, "ppc/%s", cur_cpu_spec->cpu_name);
  138. model->num_counters = cur_cpu_spec->num_pmcs;
  139. ops->cpu_type = cpu_type;
  140. #else /* __powerpc64__ */
  141. if (!cur_cpu_spec->oprofile_model || !cur_cpu_spec->oprofile_cpu_type)
  142. return -ENODEV;
  143. model = cur_cpu_spec->oprofile_model;
  144. model->num_counters = cur_cpu_spec->num_pmcs;
  145. ops->cpu_type = cur_cpu_spec->oprofile_cpu_type;
  146. #endif /* __powerpc64__ */
  147. ops->create_files = op_powerpc_create_files;
  148. ops->setup = op_powerpc_setup;
  149. ops->shutdown = op_powerpc_shutdown;
  150. ops->start = op_powerpc_start;
  151. ops->stop = op_powerpc_stop;
  152. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  153. ops->cpu_type);
  154. return 0;
  155. }
  156. void oprofile_arch_exit(void)
  157. {
  158. #ifndef __powerpc64__
  159. kfree(cpu_type);
  160. cpu_type = NULL;
  161. #endif /* ! __powerpc64__ */
  162. }