1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
21 #if (GKI_DEBUG == TRUE)
23 const INT8 * const OSTaskStates[] =
25 (INT8 *)"DEAD", /* 0 */
26 (INT8 *)"REDY", /* 1 */
27 (INT8 *)"WAIT", /* 2 */
29 (INT8 *)"DELY", /* 4 */
33 (INT8 *)"SUSP", /* 8 */
37 /*******************************************************************************
39 ** Function GKI_PrintBufferUsage
41 ** Description Displays Current Buffer Pool summary
45 *******************************************************************************/
46 void GKI_PrintBufferUsage(UINT8 *p_num_pools, UINT16 *p_cur_used)
50 UINT8 num = gki_cb.com.curr_total_no_of_pools;
51 UINT16 cur[GKI_NUM_TOTAL_BUF_POOLS];
54 GKI_TRACE_0("--- GKI Buffer Pool Summary (R - restricted, P - public) ---");
56 GKI_TRACE_0("POOL SIZE USED MAXU TOTAL");
57 GKI_TRACE_0("------------------------------");
58 for (i = 0; i < gki_cb.com.curr_total_no_of_pools; i++)
60 p = &gki_cb.com.freeq[i];
61 if ((1 << i) & gki_cb.com.pool_access_mask)
63 GKI_TRACE_5("%02d: (R), %4d, %3d, %3d, %3d",
64 i, p->size, p->cur_cnt, p->max_cnt, p->total);
68 GKI_TRACE_5("%02d: (P), %4d, %3d, %3d, %3d",
69 i, p->size, p->cur_cnt, p->max_cnt, p->total);
76 memcpy(p_cur_used, cur, num*2);
79 /*******************************************************************************
81 ** Function GKI_PrintBuffer
83 ** Description Called internally by OSS to print the buffer pools
87 *******************************************************************************/
88 void GKI_PrintBuffer(void)
91 for(i=0; i<GKI_NUM_TOTAL_BUF_POOLS; i++)
93 GKI_TRACE_5("pool:%4u free %4u cur %3u max %3u total%3u", i, gki_cb.com.freeq[i].size,
94 gki_cb.com.freeq[i].cur_cnt, gki_cb.com.freeq[i].max_cnt, gki_cb.com.freeq[i].total);
98 /*******************************************************************************
100 ** Function gki_calc_stack
102 ** Description This function tries to calculate the amount of
103 ** stack used by looking non magic num. Magic num is consider
104 ** the first byte in the stack.
106 ** Returns the number of unused byte on the stack. 4 in case of stack overrun
108 *******************************************************************************/
109 UINT16 gki_calc_stack (UINT8 task)
115 stacksize = (int) gki_cb.com.OSStackSize[task];
116 p = (UINT32 *)gki_cb.com.OSStack[task]; /* assume stack is aligned, */
119 for(j = 0; j < stacksize; j++)
121 if(*p++ != MagicNum) break;
124 return (j * sizeof(UINT32));
127 /*******************************************************************************
129 ** Function GKI_print_task
131 ** Description Print task stack usage.
135 *******************************************************************************/
136 void GKI_print_task(void)
139 GKI_TRACE_0("Service not available under insight");
143 GKI_TRACE_0("TID TASKNAME STATE FREE_STACK STACK");
144 for(TaskId=0; TaskId < GKI_MAX_TASKS; TaskId++)
146 if (gki_cb.com.OSRdyTbl[TaskId] != TASK_DEAD)
148 GKI_TRACE_5("%2u %-8s %-5s 0x%04X 0x%04X Bytes",
149 (UINT16)TaskId, gki_cb.com.OSTName[TaskId],
150 OSTaskStates[gki_cb.com.OSRdyTbl[TaskId]],
151 gki_calc_stack(TaskId), gki_cb.com.OSStackSize[TaskId]);
159 /*******************************************************************************
161 ** Function gki_print_buffer_statistics
163 ** Description Called internally by OSS to print the buffer pools statistics
167 *******************************************************************************/
168 void gki_print_buffer_statistics(FP_PRINT print, INT16 pool)
172 UINT16 size,act_size,maxbuffs;
175 if (pool > GKI_NUM_TOTAL_BUF_POOLS || pool < 0)
177 print("Not a valid Buffer pool\n");
181 size = gki_cb.com.freeq[pool].size;
182 maxbuffs = gki_cb.com.freeq[pool].total;
183 act_size = size + BUFFER_PADDING_SIZE;
184 print("Buffer Pool[%u] size=%u cur_cnt=%u max_cnt=%u total=%u\n",
185 pool, gki_cb.com.freeq[pool].size,
186 gki_cb.com.freeq[pool].cur_cnt, gki_cb.com.freeq[pool].max_cnt, gki_cb.com.freeq[pool].total);
188 print(" Owner State Sanity\n");
189 print("----------------------------\n");
190 hdr = (BUFFER_HDR_T *)(gki_cb.com.pool_start[pool]);
191 for(i=0; i<maxbuffs; i++)
193 magic = (UINT32 *)((UINT8 *)hdr + BUFFER_HDR_SIZE + size);
194 print("%3d: 0x%02x %4d %10s\n", i, hdr->task_id, hdr->status, (*magic == MAGIC_NO)?"OK":"CORRUPTED");
195 hdr = (BUFFER_HDR_T *)((UINT8 *)hdr + act_size);
201 /*******************************************************************************
203 ** Function gki_print_used_bufs
205 ** Description Dumps used buffers in the particular pool
207 *******************************************************************************/
208 GKI_API void gki_print_used_bufs (FP_PRINT print, UINT8 pool_id)
219 if ((pool_id >= GKI_NUM_TOTAL_BUF_POOLS) || (gki_cb.com.pool_start[pool_id] != 0))
221 print("Not a valid Buffer pool\n");
225 p_start = gki_cb.com.pool_start[pool_id];
226 buf_size = gki_cb.com.freeq[pool_id].size + BUFFER_PADDING_SIZE;
227 num_bufs = gki_cb.com.freeq[pool_id].total;
229 for (i = 0; i < num_bufs; i++, p_start += buf_size)
231 p_hdr = (BUFFER_HDR_T *)p_start;
232 magic = (UINT32 *)((UINT8 *)p_hdr + buf_size - sizeof(UINT32));
233 p = (UINT16 *) p_hdr;
235 if (p_hdr->status != BUF_STATUS_FREE)
237 print ("%d:0x%x (Q:%d,Task:%s,Stat:%d,%s) %04x %04x %04x %04x %04x %04x %04x %04x\n",
240 GKI_map_taskname(p_hdr->task_id),
242 (*magic == MAGIC_NO)? "OK" : "CORRUPTED",
243 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
249 /*******************************************************************************
251 ** Function gki_print_task
253 ** Description This function prints the task states.
257 *******************************************************************************/
258 void gki_print_task (FP_PRINT print)
262 print("TID VID TASKNAME STATE WAIT WAITFOR TIMEOUT STACK\n");
263 print("-------------------------------------------------\n");
264 for(i=0; i<GKI_MAX_TASKS; i++)
266 if (gki_cb.com.OSRdyTbl[i] != TASK_DEAD)
268 print("%2u %-8s %-5s %04X %04X %7u %u/%u Bytes\n",
269 (UINT16)i, gki_cb.com.OSTName[i],
270 OSTaskStates[gki_cb.com.OSRdyTbl[i]],
271 gki_cb.com.OSWaitEvt[i], gki_cb.com.OSWaitForEvt[i],
272 gki_cb.com.OSWaitTmr[i], gki_calc_stack(i), gki_cb.com.OSStackSize[i]);
278 /*******************************************************************************
280 ** Function gki_print_exception
282 ** Description This function prints the exception information.
286 *******************************************************************************/
287 void gki_print_exception(FP_PRINT print)
292 print ("GKI Exceptions:\n");
293 for (i = 0; i < gki_cb.com.ExceptionCnt; i++)
295 pExp = &gki_cb.com.Exception[i];
296 print("%d: Type=%d, Task=%d: %s\n", i,
297 (INT32)pExp->type, (INT32)pExp->taskid, (INT8 *)pExp->msg);
302 /*****************************************************************************/
303 void gki_dump (UINT8 *s, UINT16 len, FP_PRINT print)
307 for(i=0, j=0; i<len; i++)
310 print("\n%lX: %02X, ", &s[i], s[i]);
312 print("%02X, ", s[i]);
314 print("%02X, ", s[i]);
321 void gki_dump2 (UINT16 *s, UINT16 len, FP_PRINT print)
325 for(i=0, j=0; i<len; i++)
328 print("\n%lX: %04X, ", &s[i], s[i]);
330 print("%04X, ", s[i]);
337 void gki_dump4 (UINT32 *s, UINT16 len, FP_PRINT print)
341 for(i=0, j=0; i<len; i++)
344 print("\n%lX: %08lX, ", &s[i], s[i]);
346 print("%08lX, ", s[i]);