op_model_ev5.c 5.3 KB

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