op_model_ev5.c 5.3 KB

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