2 * Copyright (C) 2012-2016 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.
12 #include "mali_osk_list.h"
13 #include "mali_session.h"
15 #ifdef MALI_MEM_SWAP_TRACKING
16 #include "mali_memory_swap_alloc.h"
19 _MALI_OSK_LIST_HEAD(mali_sessions);
20 static u32 mali_session_count = 0;
22 _mali_osk_spinlock_irq_t *mali_sessions_lock = NULL;
23 wait_queue_head_t pending_queue;
25 _mali_osk_errcode_t mali_session_initialize(void)
27 _MALI_OSK_INIT_LIST_HEAD(&mali_sessions);
28 /* init wait queue for big varying job */
29 init_waitqueue_head(&pending_queue);
31 mali_sessions_lock = _mali_osk_spinlock_irq_init(
32 _MALI_OSK_LOCKFLAG_ORDERED,
33 _MALI_OSK_LOCK_ORDER_SESSIONS);
34 if (NULL == mali_sessions_lock) {
35 return _MALI_OSK_ERR_NOMEM;
38 return _MALI_OSK_ERR_OK;
41 void mali_session_terminate(void)
43 if (NULL != mali_sessions_lock) {
44 _mali_osk_spinlock_irq_term(mali_sessions_lock);
45 mali_sessions_lock = NULL;
49 void mali_session_add(struct mali_session_data *session)
52 _mali_osk_list_add(&session->link, &mali_sessions);
54 mali_session_unlock();
57 void mali_session_remove(struct mali_session_data *session)
60 _mali_osk_list_delinit(&session->link);
62 mali_session_unlock();
65 u32 mali_session_get_count(void)
67 return mali_session_count;
70 wait_queue_head_t *mali_session_get_wait_queue(void)
72 return &pending_queue;
76 * Get the max completed window jobs from all active session,
77 * which will be used in window render frame per sec calculate
79 #if defined(CONFIG_MALI_DVFS)
80 u32 mali_session_max_window_num(void)
82 struct mali_session_data *session, *tmp;
83 u32 max_window_num = 0;
88 MALI_SESSION_FOREACH(session, tmp, link) {
89 tmp_number = _mali_osk_atomic_xchg(
90 &session->number_of_window_jobs, 0);
91 if (max_window_num < tmp_number) {
92 max_window_num = tmp_number;
96 mali_session_unlock();
98 return max_window_num;
102 void mali_session_memory_tracking(_mali_osk_print_ctx *print_ctx)
104 struct mali_session_data *session, *tmp;
106 u32 total_mali_mem_size;
107 #ifdef MALI_MEM_SWAP_TRACKING
109 u32 swap_unlock_size;
112 MALI_DEBUG_ASSERT_POINTER(print_ctx);
114 MALI_SESSION_FOREACH(session, tmp, link) {
115 #ifdef MALI_MEM_SWAP_TRACKING
116 _mali_osk_ctxprintf(print_ctx, " %-25s %-10u %-10u %-15u %-15u %-10u %-10u %-10u\n",
117 session->comm, session->pid,
118 (atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE,
119 (unsigned int)session->max_mali_mem_allocated_size,
120 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE),
121 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE),
122 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE),
123 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_SWAP])) * _MALI_OSK_MALI_PAGE_SIZE)
126 _mali_osk_ctxprintf(print_ctx, " %-25s %-10u %-10u %-15u %-15u %-10u %-10u \n",
127 session->comm, session->pid,
128 (unsigned int)((atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE),
129 (unsigned int)session->max_mali_mem_allocated_size,
130 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE),
131 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE),
132 (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE)
136 mali_session_unlock();
137 mali_mem_usage = _mali_ukk_report_memory_usage();
138 total_mali_mem_size = _mali_ukk_report_total_memory_size();
139 _mali_osk_ctxprintf(print_ctx, "Mali mem usage: %u\nMali mem limit: %u\n", mali_mem_usage, total_mali_mem_size);
140 #ifdef MALI_MEM_SWAP_TRACKING
141 mali_mem_swap_tracking(&swap_pool_size, &swap_unlock_size);
142 _mali_osk_ctxprintf(print_ctx, "Mali swap mem pool : %u\nMali swap mem unlock: %u\n", swap_pool_size, swap_unlock_size);