op_model_ev5.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /**
  2. * @file arch/alpha/oprofile/op_model_ev5.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. The 21164 (EV5) and 21164PC (PCA65) vary in the bit placement and
  15. meaning of the "CBOX" events. Given that we don't care about meaning
  16. at this point, arrange for the difference in bit placement to be
  17. handled by common code. */
  18. static void
  19. common_reg_setup(struct op_register_config *reg,
  20. struct op_counter_config *ctr,
  21. struct op_system_config *sys,
  22. int cbox1_ofs, int cbox2_ofs)
  23. {
  24. int i, ctl, reset, need_reset;
  25. /* Select desired events. The event numbers are selected such
  26. that they map directly into the event selection fields:
  27. PCSEL0: 0, 1
  28. PCSEL1: 24-39
  29. CBOX1: 40-47
  30. PCSEL2: 48-63
  31. CBOX2: 64-71
  32. There are two special cases, in that CYCLES can be measured
  33. on PCSEL[02], and SCACHE_WRITE can be measured on CBOX[12].
  34. These event numbers are canonicalizes to their first appearance. */
  35. ctl = 0;
  36. for (i = 0; i < 3; ++i) {
  37. unsigned long event = ctr[i].event;
  38. if (!ctr[i].enabled)
  39. continue;
  40. /* Remap the duplicate events, as described above. */
  41. if (i == 2) {
  42. if (event == 0)
  43. event = 12+48;
  44. else if (event == 2+41)
  45. event = 4+65;
  46. }
  47. /* Convert the event numbers onto mux_select bit mask. */
  48. if (event < 2)
  49. ctl |= event << 31;
  50. else if (event < 24)
  51. /* error */;
  52. else if (event < 40)
  53. ctl |= (event - 24) << 4;
  54. else if (event < 48)
  55. ctl |= (event - 40) << cbox1_ofs | 15 << 4;
  56. else if (event < 64)
  57. ctl |= event - 48;
  58. else if (event < 72)
  59. ctl |= (event - 64) << cbox2_ofs | 15;
  60. }
  61. reg->mux_select = ctl;
  62. /* Select processor mode. */
  63. /* ??? Need to come up with some mechanism to trace only selected
  64. processes. For now select from pal, kernel and user mode. */
  65. ctl = 0;
  66. ctl |= !sys->enable_pal << 9;
  67. ctl |= !sys->enable_kernel << 8;
  68. ctl |= !sys->enable_user << 30;
  69. reg->proc_mode = ctl;
  70. /* Select interrupt frequencies. Take the interrupt count selected
  71. by the user, and map it onto one of the possible counter widths.
  72. If the user value is in between, compute a value to which the
  73. counter is reset at each interrupt. */
  74. ctl = reset = need_reset = 0;
  75. for (i = 0; i < 3; ++i) {
  76. unsigned long max, hilo, count = ctr[i].count;
  77. if (!ctr[i].enabled)
  78. continue;
  79. if (count <= 256)
  80. count = 256, hilo = 3, max = 256;
  81. else {
  82. max = (i == 2 ? 16384 : 65536);
  83. hilo = 2;
  84. if (count > max)
  85. count = max;
  86. }
  87. ctr[i].count = count;
  88. ctl |= hilo << (8 - i*2);
  89. reset |= (max - count) << (48 - 16*i);
  90. if (count != max)
  91. need_reset |= 1 << i;
  92. }
  93. reg->freq = ctl;
  94. reg->reset_values = reset;
  95. reg->need_reset = need_reset;
  96. }
  97. static void
  98. ev5_reg_setup(struct op_register_config *reg,
  99. struct op_counter_config *ctr,
  100. struct op_system_config *sys)
  101. {
  102. common_reg_setup(reg, ctr, sys, 19, 22);
  103. }
  104. static void
  105. pca56_reg_setup(struct op_register_config *reg,
  106. struct op_counter_config *ctr,
  107. struct op_system_config *sys)
  108. {
  109. common_reg_setup(reg, ctr, sys, 8, 11);
  110. }
  111. /* Program all of the registers in preparation for enabling profiling. */
  112. static void
  113. ev5_cpu_setup (void *x)
  114. {
  115. struct op_register_config *reg = x;
  116. wrperfmon(2, reg->mux_select);
  117. wrperfmon(3, reg->proc_mode);
  118. wrperfmon(4, reg->freq);
  119. wrperfmon(6, reg->reset_values);
  120. }
  121. /* CTR is a counter for which the user has requested an interrupt count
  122. in between one of the widths selectable in hardware. Reset the count
  123. for CTR to the value stored in REG->RESET_VALUES.
  124. For EV5, this means disabling profiling, reading the current values,
  125. masking in the value for the desired register, writing, then turning
  126. profiling back on.
  127. This can be streamlined if profiling is only enabled for user mode.
  128. In that case we know that the counters are not currently incrementing
  129. (due to being in kernel mode). */
  130. static void
  131. ev5_reset_ctr(struct op_register_config *reg, unsigned long ctr)
  132. {
  133. unsigned long values, mask, not_pk, reset_values;
  134. mask = (ctr == 0 ? 0xfffful << 48
  135. : ctr == 1 ? 0xfffful << 32
  136. : 0x3fff << 16);
  137. not_pk = 1 << 9 | 1 << 8;
  138. reset_values = reg->reset_values;
  139. if ((reg->proc_mode & not_pk) == not_pk) {
  140. values = wrperfmon(5, 0);
  141. values = (reset_values & mask) | (values & ~mask & -2);
  142. wrperfmon(6, values);
  143. } else {
  144. wrperfmon(0, -1);
  145. values = wrperfmon(5, 0);
  146. values = (reset_values & mask) | (values & ~mask & -2);
  147. wrperfmon(6, values);
  148. wrperfmon(1, reg->enable);
  149. }
  150. }
  151. static void
  152. ev5_handle_interrupt(unsigned long which, struct pt_regs *regs,
  153. struct op_counter_config *ctr)
  154. {
  155. /* Record the sample. */
  156. oprofile_add_sample(regs, which);
  157. }
  158. struct op_axp_model op_model_ev5 = {
  159. .reg_setup = ev5_reg_setup,
  160. .cpu_setup = ev5_cpu_setup,
  161. .reset_ctr = ev5_reset_ctr,
  162. .handle_interrupt = ev5_handle_interrupt,
  163. .cpu_type = "alpha/ev5",
  164. .num_counters = 3,
  165. .can_set_proc_mode = 1,
  166. };
  167. struct op_axp_model op_model_pca56 = {
  168. .reg_setup = pca56_reg_setup,
  169. .cpu_setup = ev5_cpu_setup,
  170. .reset_ctr = ev5_reset_ctr,
  171. .handle_interrupt = ev5_handle_interrupt,
  172. .cpu_type = "alpha/pca56",
  173. .num_counters = 3,
  174. .can_set_proc_mode = 1,
  175. };