common.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * PPC 32 oprofile support
  3. * Based on PPC64 oprofile support
  4. * Copyright (C) 2004 Anton Blanchard <anton@au.ibm.com>, IBM
  5. *
  6. * Copyright (C) Freescale Semiconductor, Inc 2004
  7. *
  8. * Author: Andy Fleming
  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/slab.h>
  17. #include <linux/init.h>
  18. #include <linux/smp.h>
  19. #include <linux/errno.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/system.h>
  22. #include <asm/perfmon.h>
  23. #include <asm/cputable.h>
  24. #include "op_impl.h"
  25. static struct op_ppc32_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_ppc32_setup(void)
  33. {
  34. /* Install our interrupt handler into the existing hook. */
  35. if(request_perfmon_irq(&op_handle_interrupt))
  36. return -EBUSY;
  37. mb();
  38. /* Pre-compute the values to stuff in the hardware registers. */
  39. model->reg_setup(ctr, &sys, model->num_counters);
  40. #if 0
  41. /* FIXME: Make multi-cpu work */
  42. /* Configure the registers on all cpus. */
  43. on_each_cpu(model->reg_setup, NULL, 0, 1);
  44. #endif
  45. return 0;
  46. }
  47. static void op_ppc32_shutdown(void)
  48. {
  49. mb();
  50. /* Remove our interrupt handler. We may be removing this module. */
  51. free_perfmon_irq();
  52. }
  53. static void op_ppc32_cpu_start(void *dummy)
  54. {
  55. model->start(ctr);
  56. }
  57. static int op_ppc32_start(void)
  58. {
  59. on_each_cpu(op_ppc32_cpu_start, NULL, 0, 1);
  60. return 0;
  61. }
  62. static inline void op_ppc32_cpu_stop(void *dummy)
  63. {
  64. model->stop();
  65. }
  66. static void op_ppc32_stop(void)
  67. {
  68. on_each_cpu(op_ppc32_cpu_stop, NULL, 0, 1);
  69. }
  70. static int op_ppc32_create_files(struct super_block *sb, struct dentry *root)
  71. {
  72. int i;
  73. for (i = 0; i < model->num_counters; ++i) {
  74. struct dentry *dir;
  75. char buf[3];
  76. snprintf(buf, sizeof buf, "%d", i);
  77. dir = oprofilefs_mkdir(sb, root, buf);
  78. oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled);
  79. oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event);
  80. oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count);
  81. oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel);
  82. oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user);
  83. /* FIXME: Not sure if this is used */
  84. oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask);
  85. }
  86. oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel);
  87. oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user);
  88. /* Default to tracing both kernel and user */
  89. sys.enable_kernel = 1;
  90. sys.enable_user = 1;
  91. return 0;
  92. }
  93. static struct oprofile_operations oprof_ppc32_ops = {
  94. .create_files = op_ppc32_create_files,
  95. .setup = op_ppc32_setup,
  96. .shutdown = op_ppc32_shutdown,
  97. .start = op_ppc32_start,
  98. .stop = op_ppc32_stop,
  99. .cpu_type = NULL /* To be filled in below. */
  100. };
  101. int __init oprofile_arch_init(struct oprofile_operations *ops)
  102. {
  103. char *name;
  104. int cpu_id = smp_processor_id();
  105. #ifdef CONFIG_FSL_BOOKE
  106. model = &op_model_fsl_booke;
  107. #else
  108. return -ENODEV;
  109. #endif
  110. name = kmalloc(32, GFP_KERNEL);
  111. if (NULL == name)
  112. return -ENOMEM;
  113. sprintf(name, "ppc/%s", cur_cpu_spec[cpu_id]->cpu_name);
  114. oprof_ppc32_ops.cpu_type = name;
  115. model->num_counters = cur_cpu_spec[cpu_id]->num_pmcs;
  116. *ops = oprof_ppc32_ops;
  117. printk(KERN_INFO "oprofile: using %s performance monitoring.\n",
  118. oprof_ppc32_ops.cpu_type);
  119. return 0;
  120. }
  121. void oprofile_arch_exit(void)
  122. {
  123. kfree(oprof_ppc32_ops.cpu_type);
  124. oprof_ppc32_ops.cpu_type = NULL;
  125. }