2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
11 #include <linux/module.h>
13 #include "mali_kernel_common.h"
16 #include "mali_uk_types.h"
17 #include "mali_osk_profiling.h"
18 #include "mali_linux_trace.h"
21 #include "mali_l2_cache.h"
22 #include "mali_user_settings_db.h"
24 _mali_osk_errcode_t _mali_osk_profiling_init(mali_bool auto_start)
26 if (MALI_TRUE == auto_start)
28 mali_set_user_setting(_MALI_UK_USER_SETTING_SW_EVENTS_ENABLE, MALI_TRUE);
31 return _MALI_OSK_ERR_OK;
34 void _mali_osk_profiling_term(void)
39 _mali_osk_errcode_t _mali_osk_profiling_start(u32 * limit)
42 return _MALI_OSK_ERR_OK;
45 _mali_osk_errcode_t _mali_osk_profiling_stop(u32 *count)
48 return _MALI_OSK_ERR_OK;
51 u32 _mali_osk_profiling_get_count(void)
56 _mali_osk_errcode_t _mali_osk_profiling_get_event(u32 index, u64* timestamp, u32* event_id, u32 data[5])
59 return _MALI_OSK_ERR_OK;
62 _mali_osk_errcode_t _mali_osk_profiling_clear(void)
65 return _MALI_OSK_ERR_OK;
68 mali_bool _mali_osk_profiling_is_recording(void)
73 mali_bool _mali_osk_profiling_have_recording(void)
78 void _mali_osk_profiling_report_sw_counters(u32 *counters)
80 trace_mali_sw_counters(_mali_osk_get_pid(), _mali_osk_get_tid(), NULL, counters);
84 _mali_osk_errcode_t _mali_ukk_profiling_start(_mali_uk_profiling_start_s *args)
86 return _mali_osk_profiling_start(&args->limit);
89 _mali_osk_errcode_t _mali_ukk_profiling_add_event(_mali_uk_profiling_add_event_s *args)
91 /* Always add process and thread identificator in the first two data elements for events from user space */
92 _mali_osk_profiling_add_event(args->event_id, _mali_osk_get_pid(), _mali_osk_get_tid(), args->data[2], args->data[3], args->data[4]);
94 return _MALI_OSK_ERR_OK;
97 _mali_osk_errcode_t _mali_ukk_profiling_stop(_mali_uk_profiling_stop_s *args)
99 return _mali_osk_profiling_stop(&args->count);
102 _mali_osk_errcode_t _mali_ukk_profiling_get_event(_mali_uk_profiling_get_event_s *args)
104 return _mali_osk_profiling_get_event(args->index, &args->timestamp, &args->event_id, args->data);
107 _mali_osk_errcode_t _mali_ukk_profiling_clear(_mali_uk_profiling_clear_s *args)
109 return _mali_osk_profiling_clear();
112 _mali_osk_errcode_t _mali_ukk_sw_counters_report(_mali_uk_sw_counters_report_s *args)
114 _mali_osk_profiling_report_sw_counters(args->counters);
115 return _MALI_OSK_ERR_OK;
119 * Called by gator.ko to set HW counters
121 * @param counter_id The counter ID.
122 * @param event_id Event ID that the counter should count (HW counter value from TRM).
124 * @return 1 on success, 0 on failure.
126 int _mali_profiling_set_event(u32 counter_id, s32 event_id)
128 if (COUNTER_VP_C0 == counter_id)
130 if (MALI_TRUE == mali_gp_job_set_gp_counter_src0(event_id))
135 if (COUNTER_VP_C1 == counter_id)
137 if (MALI_TRUE == mali_gp_job_set_gp_counter_src1(event_id))
142 if (COUNTER_FP0_C0 <= counter_id && COUNTER_FP3_C1 >= counter_id)
144 u32 core_id = (counter_id - COUNTER_FP0_C0) >> 1;
145 struct mali_pp_core* pp_core = mali_pp_get_global_pp_core(core_id);
149 if ((COUNTER_FP0_C0 == counter_id) || (COUNTER_FP0_C1 == counter_id))
151 u32 counter_src = (counter_id - COUNTER_FP0_C0) & 1;
152 if (0 == counter_src)
154 if (MALI_TRUE == mali_pp_job_set_pp_counter_src0(event_id))
161 if (MALI_TRUE == mali_pp_job_set_pp_counter_src1(event_id))
163 MALI_DEBUG_PRINT(5, ("MALI PROFILING SET EVENT core 0 counter_id = %d\n",counter_id));
170 if (COUNTER_L2_C0 <= counter_id && COUNTER_L2_C1 >= counter_id)
172 u32 core_id = (counter_id - COUNTER_L2_C0) >> 1;
173 struct mali_l2_cache_core* l2_cache_core = mali_l2_cache_core_get_glob_l2_core(core_id);
175 if (NULL != l2_cache_core)
177 u32 counter_src = (counter_id - COUNTER_L2_C0) & 1;
178 if (0 == counter_src)
180 MALI_DEBUG_PRINT(5, ("SET EVENT L2 0 COUNTER\n"));
181 if (MALI_TRUE == mali_l2_cache_core_set_counter_src0(l2_cache_core, event_id))
188 MALI_DEBUG_PRINT(5, ("SET EVENT L2 1 COUNTER\n"));
189 if (MALI_TRUE == mali_l2_cache_core_set_counter_src1(l2_cache_core, event_id))
201 * Called by gator.ko to retrieve the L2 cache counter values for the first L2 cache.
202 * The L2 cache counters are unique in that they are polled by gator, rather than being
203 * transmitted via the tracepoint mechanism.
205 * @param src0 First L2 cache counter ID.
206 * @param val0 First L2 cache counter value.
207 * @param src1 Second L2 cache counter ID.
208 * @param val1 Second L2 cache counter value.
210 void _mali_profiling_get_counters(u32 *src0, u32 *val0, u32 *src1, u32 *val1)
212 struct mali_l2_cache_core *l2_cache = mali_l2_cache_core_get_glob_l2_core(0);
213 if (NULL != l2_cache)
215 if (MALI_TRUE == mali_l2_cache_lock_power_state(l2_cache))
217 /* It is now safe to access the L2 cache core in order to retrieve the counters */
218 mali_l2_cache_core_get_counter_values(l2_cache, src0, val0, src1, val1);
220 mali_l2_cache_unlock_power_state(l2_cache);
225 * List of possible actions to be controlled by Streamline.
226 * The following numbers are used by gator to control the frame buffer dumping and s/w counter reporting.
227 * We cannot use the enums in mali_uk_types.h because they are unknown inside gator.
229 #define FBDUMP_CONTROL_ENABLE (1)
230 #define FBDUMP_CONTROL_RATE (2)
231 #define SW_COUNTER_ENABLE (3)
232 #define FBDUMP_CONTROL_RESIZE_FACTOR (4)
235 * Called by gator to control the production of profiling information at runtime.
237 void _mali_profiling_control(u32 action, u32 value)
241 case FBDUMP_CONTROL_ENABLE:
242 mali_set_user_setting(_MALI_UK_USER_SETTING_COLORBUFFER_CAPTURE_ENABLED, (value == 0 ? MALI_FALSE : MALI_TRUE));
244 case FBDUMP_CONTROL_RATE:
245 mali_set_user_setting(_MALI_UK_USER_SETTING_BUFFER_CAPTURE_N_FRAMES, value);
247 case SW_COUNTER_ENABLE:
248 mali_set_user_setting(_MALI_UK_USER_SETTING_SW_COUNTER_ENABLED, value);
250 case FBDUMP_CONTROL_RESIZE_FACTOR:
251 mali_set_user_setting(_MALI_UK_USER_SETTING_BUFFER_CAPTURE_RESIZE_FACTOR, value);
254 break; /* Ignore unimplemented actions */
258 EXPORT_SYMBOL(_mali_profiling_set_event);
259 EXPORT_SYMBOL(_mali_profiling_get_counters);
260 EXPORT_SYMBOL(_mali_profiling_control);