summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'driver/gator_events_mali_4xx.c')
-rw-r--r--driver/gator_events_mali_4xx.c144
1 files changed, 45 insertions, 99 deletions
diff --git a/driver/gator_events_mali_4xx.c b/driver/gator_events_mali_4xx.c
index 85d4764..9e1c706 100644
--- a/driver/gator_events_mali_4xx.c
+++ b/driver/gator_events_mali_4xx.c
@@ -18,17 +18,27 @@
18#include "gator_events_mali_4xx.h" 18#include "gator_events_mali_4xx.h"
19 19
20/* 20/*
21 * There are (currently) four different variants of the comms between gator and Mali: 21* There have been four different variants of the comms between gator and Mali depending on driver version:
22 * 1 (deprecated): No software counter support 22* # | DDK vsn range | Support | Notes
23 * 2 (deprecated): Tracepoint called for each separate s/w counter value as it appears 23*
24 * 3 (default): Single tracepoint for all s/w counters in a bundle. 24* 1 | (obsolete) | No software counter support | Obsolete patches
25 * Interface style 3 is the default if no other is specified. 1 and 2 will be eliminated when 25* 2 | (obsolete) | Tracepoint called for each separate s/w counter value as it appears | Obsolete patches
26 * existing Mali DDKs are upgraded. 26* 3 | r3p0-04rel0 - r3p2-01rel2 | Single tracepoint for all s/w counters in a bundle. |
27 * 4. As above, but for the Utgard (Mali-450) driver. 27* 4 | r3p2-01rel3 - date | As above but with extensions for MP devices (Mali-450) | At least r4p0-00rel1
28 */ 28*/
29 29
30#if !defined(GATOR_MALI_INTERFACE_STYLE) 30#if !defined(GATOR_MALI_INTERFACE_STYLE)
31#define GATOR_MALI_INTERFACE_STYLE (3) 31#define GATOR_MALI_INTERFACE_STYLE (4)
32#endif
33
34#if GATOR_MALI_INTERFACE_STYLE == 1
35#error GATOR_MALI_INTERFACE_STYLE 1 is obsolete
36#elif GATOR_MALI_INTERFACE_STYLE == 2
37#error GATOR_MALI_INTERFACE_STYLE 2 is obsolete
38#elif GATOR_MALI_INTERFACE_STYLE >= 3
39// Valid GATOR_MALI_INTERFACE_STYLE
40#else
41#error Unknown GATOR_MALI_INTERFACE_STYLE option.
32#endif 42#endif
33 43
34#if GATOR_MALI_INTERFACE_STYLE < 4 44#if GATOR_MALI_INTERFACE_STYLE < 4
@@ -44,6 +54,8 @@
44#error MALI_SUPPORT set to an invalid device code: expecting MALI_4xx 54#error MALI_SUPPORT set to an invalid device code: expecting MALI_4xx
45#endif 55#endif
46 56
57static const char mali_name[] = "Mali-4xx";
58
47/* gatorfs variables for counter enable state, 59/* gatorfs variables for counter enable state,
48 * the event the counter should count and the 60 * the event the counter should count and the
49 * 'key' (a unique id set by gatord and returned 61 * 'key' (a unique id set by gatord and returned
@@ -63,6 +75,7 @@ static u32 *counter_address[NUMBER_OF_EVENTS];
63 */ 75 */
64static unsigned long counter_dump[NUMBER_OF_EVENTS * 2]; 76static unsigned long counter_dump[NUMBER_OF_EVENTS * 2];
65static unsigned long counter_prev[NUMBER_OF_EVENTS]; 77static unsigned long counter_prev[NUMBER_OF_EVENTS];
78static bool prev_set[NUMBER_OF_EVENTS];
66 79
67/* Note whether tracepoints have been registered */ 80/* Note whether tracepoints have been registered */
68static int trace_registered; 81static int trace_registered;
@@ -76,18 +89,11 @@ static unsigned int n_vp_cores = MAX_NUM_VP_CORES;
76static unsigned int n_l2_cores = MAX_NUM_L2_CACHE_CORES; 89static unsigned int n_l2_cores = MAX_NUM_L2_CACHE_CORES;
77static unsigned int n_fp_cores = MAX_NUM_FP_CORES; 90static unsigned int n_fp_cores = MAX_NUM_FP_CORES;
78 91
79/** 92extern mali_counter mali_activity[2];
80 * Calculate the difference and handle the overflow. 93static const char* const mali_activity_names[] = {
81 */ 94 "fragment",
82static u32 get_difference(u32 start, u32 end) 95 "vertex",
83{ 96};
84 if (start - end >= 0) {
85 return start - end;
86 }
87
88 // Mali counters are unsigned 32 bit values that wrap.
89 return (4294967295u - end) + start;
90}
91 97
92/** 98/**
93 * Returns non-zero if the given counter ID is an activity counter. 99 * Returns non-zero if the given counter ID is an activity counter.
@@ -112,40 +118,6 @@ static inline int is_hw_counter(unsigned int event_id)
112typedef void _mali_profiling_get_mali_version_type(struct _mali_profiling_mali_version *values); 118typedef void _mali_profiling_get_mali_version_type(struct _mali_profiling_mali_version *values);
113typedef u32 _mali_profiling_get_l2_counters_type(_mali_profiling_l2_counter_values *values); 119typedef u32 _mali_profiling_get_l2_counters_type(_mali_profiling_l2_counter_values *values);
114 120
115#if GATOR_MALI_INTERFACE_STYLE == 2
116/**
117 * Returns non-zero if the given counter ID is a software counter.
118 */
119static inline int is_sw_counter(unsigned int event_id)
120{
121 return (event_id >= FIRST_SW_COUNTER && event_id <= LAST_SW_COUNTER);
122}
123#endif
124
125#if GATOR_MALI_INTERFACE_STYLE == 2
126/*
127 * The Mali DDK uses s64 types to contain software counter values, but gator
128 * can only use a maximum of 32 bits. This function scales a software counter
129 * to an appropriate range.
130 */
131static u32 scale_sw_counter_value(unsigned int event_id, signed long long value)
132{
133 u32 scaled_value;
134
135 switch (event_id) {
136 case COUNTER_GLES_UPLOAD_TEXTURE_TIME:
137 case COUNTER_GLES_UPLOAD_VBO_TIME:
138 scaled_value = (u32)div_s64(value, 1000000);
139 break;
140 default:
141 scaled_value = (u32)value;
142 break;
143 }
144
145 return scaled_value;
146}
147#endif
148
149/* Probe for continuously sampled counter */ 121/* Probe for continuously sampled counter */
150#if 0 //WE_DONT_CURRENTLY_USE_THIS_SO_SUPPRESS_WARNING 122#if 0 //WE_DONT_CURRENTLY_USE_THIS_SO_SUPPRESS_WARNING
151GATOR_DEFINE_PROBE(mali_sample_address, TP_PROTO(unsigned int event_id, u32 *addr)) 123GATOR_DEFINE_PROBE(mali_sample_address, TP_PROTO(unsigned int event_id, u32 *addr))
@@ -172,16 +144,6 @@ GATOR_DEFINE_PROBE(mali_hw_counter, TP_PROTO(unsigned int event_id, unsigned int
172 } 144 }
173} 145}
174 146
175#if GATOR_MALI_INTERFACE_STYLE == 2
176GATOR_DEFINE_PROBE(mali_sw_counter, TP_PROTO(unsigned int event_id, signed long long value))
177{
178 if (is_sw_counter(event_id)) {
179 counter_data[event_id] = scale_sw_counter_value(event_id, value);
180 }
181}
182#endif /* GATOR_MALI_INTERFACE_STYLE == 2 */
183
184#if GATOR_MALI_INTERFACE_STYLE >= 3
185GATOR_DEFINE_PROBE(mali_sw_counters, TP_PROTO(pid_t pid, pid_t tid, void *surface_id, unsigned int *counters)) 147GATOR_DEFINE_PROBE(mali_sw_counters, TP_PROTO(pid_t pid, pid_t tid, void *surface_id, unsigned int *counters))
186{ 148{
187 u32 i; 149 u32 i;
@@ -193,7 +155,6 @@ GATOR_DEFINE_PROBE(mali_sw_counters, TP_PROTO(pid_t pid, pid_t tid, void *surfac
193 } 155 }
194 } 156 }
195} 157}
196#endif /* GATOR_MALI_INTERFACE_STYLE >= 3 */
197 158
198/** 159/**
199 * Create a single filesystem entry for a specified event. 160 * Create a single filesystem entry for a specified event.
@@ -254,6 +215,7 @@ static void initialise_version_info(void)
254 symbol_put(_mali_profiling_get_mali_version); 215 symbol_put(_mali_profiling_get_mali_version);
255 } else { 216 } else {
256 printk("gator: mali online _mali_profiling_get_mali_version symbol not found\n"); 217 printk("gator: mali online _mali_profiling_get_mali_version symbol not found\n");
218 printk("gator: check your Mali DDK version versus the GATOR_MALI_INTERFACE_STYLE setting\n");
257 } 219 }
258} 220}
259#endif 221#endif
@@ -261,7 +223,6 @@ static void initialise_version_info(void)
261static int create_files(struct super_block *sb, struct dentry *root) 223static int create_files(struct super_block *sb, struct dentry *root)
262{ 224{
263 int event; 225 int event;
264 const char *mali_name = gator_mali_get_mali_name();
265 226
266 char buf[40]; 227 char buf[40];
267 int core_id; 228 int core_id;
@@ -278,6 +239,14 @@ static int create_files(struct super_block *sb, struct dentry *root)
278 initialise_version_info(); 239 initialise_version_info();
279#endif 240#endif
280 241
242 mali_activity[0].cores = n_fp_cores;
243 mali_activity[1].cores = n_vp_cores;
244 for (event = 0; event < ARRAY_SIZE(mali_activity); event++) {
245 if (gator_mali_create_file_system(mali_name, mali_activity_names[event], sb, root, &mali_activity[event], NULL) != 0) {
246 return -1;
247 }
248 }
249
281 /* Vertex processor counters */ 250 /* Vertex processor counters */
282 for (core_id = 0; core_id < n_vp_cores; core_id++) { 251 for (core_id = 0; core_id < n_vp_cores; core_id++) {
283 int activity_counter_id = ACTIVITY_VP_0; 252 int activity_counter_id = ACTIVITY_VP_0;
@@ -413,7 +382,6 @@ static void init_counters(unsigned int from_counter, unsigned int to_counter)
413static void mali_counter_initialize(void) 382static void mali_counter_initialize(void)
414{ 383{
415 int i; 384 int i;
416 int core_id;
417 385
418 mali_profiling_control_type *mali_control; 386 mali_profiling_control_type *mali_control;
419 387
@@ -463,15 +431,10 @@ static void mali_counter_initialize(void)
463 n_l2_cores = 0; 431 n_l2_cores = 0;
464 } 432 }
465 433
466 for (core_id = 0; core_id < n_l2_cores; core_id++) {
467 int counter_id = COUNTER_L2_0_C0 + (2 * core_id);
468 counter_prev[counter_id] = 0;
469 counter_prev[counter_id + 1] = 0;
470 }
471
472 /* Clear counters in the start */ 434 /* Clear counters in the start */
473 for (i = 0; i < NUMBER_OF_EVENTS; i++) { 435 for (i = 0; i < NUMBER_OF_EVENTS; i++) {
474 counter_data[i] = 0; 436 counter_data[i] = 0;
437 prev_set[i] = false;
475 } 438 }
476} 439}
477 440
@@ -528,23 +491,11 @@ static int start(void)
528 return -1; 491 return -1;
529 } 492 }
530 493
531#if GATOR_MALI_INTERFACE_STYLE == 1
532 /* None. */
533#elif GATOR_MALI_INTERFACE_STYLE == 2
534 /* For patched Mali driver. */
535 if (GATOR_REGISTER_TRACE(mali_sw_counter)) {
536 printk("gator: mali_sw_counter tracepoint failed to activate\n");
537 return -1;
538 }
539#elif GATOR_MALI_INTERFACE_STYLE >= 3
540 /* For Mali drivers with built-in support. */ 494 /* For Mali drivers with built-in support. */
541 if (GATOR_REGISTER_TRACE(mali_sw_counters)) { 495 if (GATOR_REGISTER_TRACE(mali_sw_counters)) {
542 printk("gator: mali_sw_counters tracepoint failed to activate\n"); 496 printk("gator: mali_sw_counters tracepoint failed to activate\n");
543 return -1; 497 return -1;
544 } 498 }
545#else
546#error Unknown GATOR_MALI_INTERFACE_STYLE option.
547#endif
548 499
549 trace_registered = 1; 500 trace_registered = 1;
550 501
@@ -561,17 +512,8 @@ static void stop(void)
561 if (trace_registered) { 512 if (trace_registered) {
562 GATOR_UNREGISTER_TRACE(mali_hw_counter); 513 GATOR_UNREGISTER_TRACE(mali_hw_counter);
563 514
564#if GATOR_MALI_INTERFACE_STYLE == 1
565 /* None. */
566#elif GATOR_MALI_INTERFACE_STYLE == 2
567 /* For patched Mali driver. */
568 GATOR_UNREGISTER_TRACE(mali_sw_counter);
569#elif GATOR_MALI_INTERFACE_STYLE >= 3
570 /* For Mali drivers with built-in support. */ 515 /* For Mali drivers with built-in support. */
571 GATOR_UNREGISTER_TRACE(mali_sw_counters); 516 GATOR_UNREGISTER_TRACE(mali_sw_counters);
572#else
573#error Unknown GATOR_MALI_INTERFACE_STYLE option.
574#endif
575 517
576 pr_debug("gator: mali timeline tracepoint deactivated\n"); 518 pr_debug("gator: mali timeline tracepoint deactivated\n");
577 519
@@ -636,21 +578,23 @@ static int read(int **buffer)
636 578
637 per_core = &cache_values.cores[cache_id]; 579 per_core = &cache_values.cores[cache_id];
638 580
639 if (counter_enabled[counter_id_0]) { 581 if (counter_enabled[counter_id_0] && prev_set[counter_id_0]) {
640 // Calculate and save src0's counter val0 582 // Calculate and save src0's counter val0
641 counter_dump[len++] = counter_key[counter_id_0]; 583 counter_dump[len++] = counter_key[counter_id_0];
642 counter_dump[len++] = get_difference(per_core->value0, counter_prev[counter_id_0]); 584 counter_dump[len++] = per_core->value0 - counter_prev[counter_id_0];
643 } 585 }
644 586
645 if (counter_enabled[counter_id_1]) { 587 if (counter_enabled[counter_id_1] && prev_set[counter_id_1]) {
646 // Calculate and save src1's counter val1 588 // Calculate and save src1's counter val1
647 counter_dump[len++] = counter_key[counter_id_1]; 589 counter_dump[len++] = counter_key[counter_id_1];
648 counter_dump[len++] = get_difference(per_core->value1, counter_prev[counter_id_1]); 590 counter_dump[len++] = per_core->value1 - counter_prev[counter_id_1];
649 } 591 }
650 592
651 // Save the previous values for the counters. 593 // Save the previous values for the counters.
652 counter_prev[counter_id_0] = per_core->value0; 594 counter_prev[counter_id_0] = per_core->value0;
595 prev_set[counter_id_0] = true;
653 counter_prev[counter_id_1] = per_core->value1; 596 counter_prev[counter_id_1] = per_core->value1;
597 prev_set[counter_id_1] = true;
654 } 598 }
655 } 599 }
656 600
@@ -709,6 +653,8 @@ int gator_events_mali_init(void)
709 653
710 pr_debug("gator: mali init\n"); 654 pr_debug("gator: mali init\n");
711 655
656 gator_mali_initialise_counters(mali_activity, ARRAY_SIZE(mali_activity));
657
712 for (cnt = 0; cnt < NUMBER_OF_EVENTS; cnt++) { 658 for (cnt = 0; cnt < NUMBER_OF_EVENTS; cnt++) {
713 counter_enabled[cnt] = 0; 659 counter_enabled[cnt] = 0;
714 counter_event[cnt] = 0; 660 counter_event[cnt] = 0;