op_model_ev4.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @file arch/alpha/oprofile/op_model_ev4.c
  3. *
  4. * @remark Copyright 2002 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author Richard Henderson <rth@twiddle.net>
  8. */
  9. #include <linux/oprofile.h>
  10. #include <linux/init.h>
  11. #include <linux/smp.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/system.h>
  14. #include "op_impl.h"
  15. /* Compute all of the registers in preparation for enabling profiling. */
  16. static void
  17. ev4_reg_setup(struct op_register_config *reg,
  18. struct op_counter_config *ctr,
  19. struct op_system_config *sys)
  20. {
  21. unsigned long ctl = 0, count, hilo;
  22. /* Select desired events. We've mapped the event numbers
  23. such that they fit directly into the event selection fields.
  24. Note that there is no "off" setting. In both cases we select
  25. the EXTERNAL event source, hoping that it'll be the lowest
  26. frequency, and set the frequency counter to LOW. The interrupts
  27. for these "disabled" counter overflows are ignored by the
  28. interrupt handler.
  29. This is most irritating, because the hardware *can* enable and
  30. disable the interrupts for these counters independently, but the
  31. wrperfmon interface doesn't allow it. */
  32. ctl |= (ctr[0].enabled ? ctr[0].event << 8 : 14 << 8);
  33. ctl |= (ctr[1].enabled ? (ctr[1].event - 16) << 32 : 7ul << 32);
  34. /* EV4 can not read or write its counter registers. The only
  35. thing one can do at all is see if you overflow and get an
  36. interrupt. We can set the width of the counters, to some
  37. extent. Take the interrupt count selected by the user,
  38. map it onto one of the possible values, and write it back. */
  39. count = ctr[0].count;
  40. if (count <= 4096)
  41. count = 4096, hilo = 1;
  42. else
  43. count = 65536, hilo = 0;
  44. ctr[0].count = count;
  45. ctl |= (ctr[0].enabled && hilo) << 3;
  46. count = ctr[1].count;
  47. if (count <= 256)
  48. count = 256, hilo = 1;
  49. else
  50. count = 4096, hilo = 0;
  51. ctr[1].count = count;
  52. ctl |= (ctr[1].enabled && hilo);
  53. reg->mux_select = ctl;
  54. /* Select performance monitoring options. */
  55. /* ??? Need to come up with some mechanism to trace only
  56. selected processes. EV4 does not have a mechanism to
  57. select kernel or user mode only. For now, enable always. */
  58. reg->proc_mode = 0;
  59. /* Frequency is folded into mux_select for EV4. */
  60. reg->freq = 0;
  61. /* See above regarding no writes. */
  62. reg->reset_values = 0;
  63. reg->need_reset = 0;
  64. }
  65. /* Program all of the registers in preparation for enabling profiling. */
  66. static void
  67. ev4_cpu_setup(void *x)
  68. {
  69. struct op_register_config *reg = x;
  70. wrperfmon(2, reg->mux_select);
  71. wrperfmon(3, reg->proc_mode);
  72. }
  73. static void
  74. ev4_handle_interrupt(unsigned long which, struct pt_regs *regs,
  75. struct op_counter_config *ctr)
  76. {
  77. /* EV4 can't properly disable counters individually.
  78. Discard "disabled" events now. */
  79. if (!ctr[which].enabled)
  80. return;
  81. /* Record the sample. */
  82. oprofile_add_sample(regs, which);
  83. }
  84. struct op_axp_model op_model_ev4 = {
  85. .reg_setup = ev4_reg_setup,
  86. .cpu_setup = ev4_cpu_setup,
  87. .reset_ctr = NULL,
  88. .handle_interrupt = ev4_handle_interrupt,
  89. .cpu_type = "alpha/ev4",
  90. .num_counters = 2,
  91. .can_set_proc_mode = 0,
  92. };