op_model_ev6.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @file arch/alpha/oprofile/op_model_ev6.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/smp.h>
  11. #include <asm/ptrace.h>
  12. #include "op_impl.h"
  13. /* Compute all of the registers in preparation for enabling profiling. */
  14. static void
  15. ev6_reg_setup(struct op_register_config *reg,
  16. struct op_counter_config *ctr,
  17. struct op_system_config *sys)
  18. {
  19. unsigned long ctl, reset, need_reset, i;
  20. /* Select desired events. We've mapped the event numbers
  21. such that they fit directly into the event selection fields. */
  22. ctl = 0;
  23. if (ctr[0].enabled && ctr[0].event)
  24. ctl |= (ctr[0].event & 1) << 4;
  25. if (ctr[1].enabled)
  26. ctl |= (ctr[1].event - 2) & 15;
  27. reg->mux_select = ctl;
  28. /* Select logging options. */
  29. /* ??? Need to come up with some mechanism to trace only
  30. selected processes. EV6 does not have a mechanism to
  31. select kernel or user mode only. For now, enable always. */
  32. reg->proc_mode = 0;
  33. /* EV6 cannot change the width of the counters as with the
  34. other implementations. But fortunately, we can write to
  35. the counters and set the value such that it will overflow
  36. at the right time. */
  37. reset = need_reset = 0;
  38. for (i = 0; i < 2; ++i) {
  39. unsigned long count = ctr[i].count;
  40. if (!ctr[i].enabled)
  41. continue;
  42. if (count > 0x100000)
  43. count = 0x100000;
  44. ctr[i].count = count;
  45. reset |= (0x100000 - count) << (i ? 6 : 28);
  46. if (count != 0x100000)
  47. need_reset |= 1 << i;
  48. }
  49. reg->reset_values = reset;
  50. reg->need_reset = need_reset;
  51. }
  52. /* Program all of the registers in preparation for enabling profiling. */
  53. static void
  54. ev6_cpu_setup (void *x)
  55. {
  56. struct op_register_config *reg = x;
  57. wrperfmon(2, reg->mux_select);
  58. wrperfmon(3, reg->proc_mode);
  59. wrperfmon(6, reg->reset_values | 3);
  60. }
  61. /* CTR is a counter for which the user has requested an interrupt count
  62. in between one of the widths selectable in hardware. Reset the count
  63. for CTR to the value stored in REG->RESET_VALUES. */
  64. static void
  65. ev6_reset_ctr(struct op_register_config *reg, unsigned long ctr)
  66. {
  67. wrperfmon(6, reg->reset_values | (1 << ctr));
  68. }
  69. static void
  70. ev6_handle_interrupt(unsigned long which, struct pt_regs *regs,
  71. struct op_counter_config *ctr)
  72. {
  73. /* Record the sample. */
  74. oprofile_add_sample(regs, which);
  75. }
  76. struct op_axp_model op_model_ev6 = {
  77. .reg_setup = ev6_reg_setup,
  78. .cpu_setup = ev6_cpu_setup,
  79. .reset_ctr = ev6_reset_ctr,
  80. .handle_interrupt = ev6_handle_interrupt,
  81. .cpu_type = "alpha/ev6",
  82. .num_counters = 2,
  83. .can_set_proc_mode = 0,
  84. };