blob: cf9cceae1ff68018f4b08d17e7d8329ae877b6ec [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * stack_config.c
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This file provides a template for .c files. This space
49 * should be used to describe the file contents.
50 *
51 * Author:
52 * -------
53 * -------
54 *
55 *============================================================================
56 * HISTORY
57 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
58 *------------------------------------------------------------------------------
59 * removed!
60 * removed!
61 * removed!
62 *
63 * removed!
64 * removed!
65 * removed!
66 * removed!
67 *
68 * removed!
69 * removed!
70 * removed!
71 * removed!
72 *
73 * removed!
74 * removed!
75 * removed!
76 * removed!
77 *
78 * removed!
79 * removed!
80 * removed!
81 *
82 * removed!
83 * removed!
84 * removed!
85 *
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 *
94 * removed!
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 * removed!
105 *
106 * removed!
107 * removed!
108 * removed!
109 *
110 * removed!
111 * removed!
112 * removed!
113 *
114 * removed!
115 * removed!
116 * removed!
117 *
118 * removed!
119 * removed!
120 * removed!
121 *
122 * removed!
123 * removed!
124 * removed!
125 *
126 * removed!
127 * removed!
128 * removed!
129 *
130 * removed!
131 * removed!
132 * removed!
133 *
134 * removed!
135 * removed!
136 * removed!
137 *
138 * removed!
139 * removed!
140 * removed!
141 *
142 * removed!
143 * removed!
144 * removed!
145 *
146 * removed!
147 * removed!
148 * removed!
149 *
150 * removed!
151 * removed!
152 * removed!
153 *
154 * removed!
155 * removed!
156 * removed!
157 *
158 * removed!
159 * removed!
160 * removed!
161 *
162 * removed!
163 * removed!
164 * removed!
165 *
166 * removed!
167 * removed!
168 * removed!
169 *
170 * removed!
171 * removed!
172 * removed!
173 *
174 * removed!
175 * removed!
176 * removed!
177 *
178 * removed!
179 * removed!
180 * removed!
181 *
182 * removed!
183 * removed!
184 * removed!
185 *
186 * removed!
187 * removed!
188 * removed!
189 *
190 * removed!
191 * removed!
192 * removed!
193 *
194 * removed!
195 * removed!
196 * removed!
197 *
198 * removed!
199 * removed!
200 * removed!
201 *
202 * removed!
203 * removed!
204 * removed!
205 *
206 * removed!
207 * removed!
208 * removed!
209 *
210 * removed!
211 * removed!
212 * removed!
213 *
214 * removed!
215 * removed!
216 * removed!
217 *
218 * removed!
219 * removed!
220 * removed!
221 *
222 * removed!
223 * removed!
224 * removed!
225 *
226 * removed!
227 * removed!
228 * removed!
229 *
230 * removed!
231 * removed!
232 * removed!
233 *
234 * removed!
235 * removed!
236 * removed!
237 *
238 * removed!
239 * removed!
240 * removed!
241 *
242 * removed!
243 * removed!
244 * removed!
245 *
246 * removed!
247 * removed!
248 * removed!
249 *
250 * removed!
251 * removed!
252 * removed!
253 *
254 * removed!
255 * removed!
256 * removed!
257 *
258 * removed!
259 * removed!
260 * removed!
261 *
262 * removed!
263 * removed!
264 * removed!
265 *
266 * removed!
267 * removed!
268 * removed!
269 *
270 * removed!
271 * removed!
272 * removed!
273 *
274 * removed!
275 * removed!
276 * removed!
277 *
278 * removed!
279 * removed!
280 * removed!
281 *
282 * removed!
283 * removed!
284 * removed!
285 *
286 * removed!
287 * removed!
288 * removed!
289 *
290 * removed!
291 * removed!
292 * removed!
293 *
294 * removed!
295 * removed!
296 * removed!
297 *
298 * removed!
299 * removed!
300 * removed!
301 *
302 * removed!
303 * removed!
304 * removed!
305 *
306 * removed!
307 * removed!
308 * removed!
309 *
310 * removed!
311 * removed!
312 * removed!
313 *
314 * removed!
315 * removed!
316 * removed!
317 *
318 * removed!
319 * removed!
320 * removed!
321 *
322 * removed!
323 * removed!
324 * removed!
325 *
326 * removed!
327 * removed!
328 * removed!
329 *
330 * removed!
331 * removed!
332 * removed!
333 *
334 * removed!
335 * removed!
336 * removed!
337 *
338 * removed!
339 * removed!
340 * removed!
341 *
342 * removed!
343 * removed!
344 * removed!
345 *
346 * removed!
347 * removed!
348 * removed!
349 * removed!
350 * removed!
351 * removed!
352 * removed!
353 * removed!
354 * removed!
355 * removed!
356 * removed!
357 * removed!
358 * removed!
359 * removed!
360 * removed!
361 * removed!
362 * removed!
363 * removed!
364 * removed!
365 * removed!
366 * removed!
367 * removed!
368 * removed!
369 * removed!
370 * removed!
371 * removed!
372 * removed!
373 * removed!
374 * removed!
375 * removed!
376 * removed!
377 * removed!
378 * removed!
379 * removed!
380 * removed!
381 * removed!
382 * removed!
383 * removed!
384 * removed!
385 * removed!
386 * removed!
387 * removed!
388 * removed!
389 * removed!
390 * removed!
391 * removed!
392 * removed!
393 * removed!
394 * removed!
395 * removed!
396 * removed!
397 * removed!
398 * removed!
399 *------------------------------------------------------------------------------
400 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
401 *============================================================================
402 ****************************************************************************/
403
404/*********************************************************************
405 (C) _____ (year of first publication) Sasken communication
406 Technologies Limited, All rights reserved.
407* This file provides a template for .c files. This space
408* should be used to describe the file contents
409* Component-specific prefix : xxxx
410*********************************************************************/
411
412/*************************************************************************
413 * Included header files
414 *************************************************************************/
415//#include "kal_release.h"
416//#include "init_time_cfg.h"
417
418//#include "stack_common.h"
419//#include "stack_msgs.h"
420//#include "app_ltlcom.h"
421#include "lcd_ip_cqueue.h"
422//#include "stack_types.h"
423#include "task_config.h"
424
425#include "stack_buff_pool.h"
426#include "ctrl_buff_pool.h"
427
428#include "sysconf_statistics.h"
429#include "dspsys_statistics.h"
430
431//#if defined(DEBUG_KAL) && ( defined(DEBUG_BUF1) || defined(DEBUG_BUF2) )
432//#include "kal_debug.h"
433//#endif /* DEBUG_KAL && ( DEBUG_BUF1 || DEBUG_BUF2 ) */
434/*RHR*/
435#include "kal_general_types.h"
436#include "kal_os.h"
437#include "kal_buff_mgr.h"
438#include "kal_internal_api.h"
439#include "kal_internal_def.h"
440//#include "kal_common_defs.h"
441#include "stack_config.h"
442#include "kal_public_defs.h"
443#include "stdlib.h"
444/*RHR*/
445#include "event_shed.h"
446
447#ifdef __MTK_TARGET__
448#include "sys_mem_size.h"
449#else
450#include "sys_mem_size_modis.h"
451#endif /* __MTK_TARGET__*/
452
453#include "cpu.h"
454#include "cache_sw.h"
455#include "us_timer.h"
456
457#include "SST_intrCtrl.h"
458
459/*************************************************************************
460 * Global data definitions
461 *************************************************************************/
462stack_statistics_struct sys_stats;
463
464/*************************************************************************
465 * Definitions of Imported Globals
466 *************************************************************************/
467extern kal_uint32 KALTotalTasks;
468extern kal_uint32 KALTotalModules;
469
470extern kal_uint32 sys_mem_total_size;
471extern kal_uint32 sys_mem_left_size;
472
473#ifdef DEBUG_KAL
474extern kal_uint32 debug_mem_total_size;
475extern kal_uint32 debug_mem_left_size;
476#endif /* DEBUG_KAL */
477
478extern kal_internal_hisrid kal_hisr_ptrs_g[];
479extern kal_uint8 num_hisr_created_g;
480
481/*************************************************************************
482* FUNCTION
483* stack_config
484*
485* DESCRIPTION
486* This function implements to config Protocol Stack's configuration
487*
488* PARAMETERS
489*
490* RETURNS
491*
492* GLOBALS AFFECTED
493*
494*************************************************************************/
495kal_bool stack_config(void)
496{
497#if defined(__TST_MODULE__) && defined(__DSP_FCORE4__)
498 init_dspsys_stat();
499#endif
500 return KAL_TRUE;
501}
502
503
504/*************************************************************************
505* FUNCTION
506* stack_get_statistics_struct_size
507*
508* DESCRIPTION
509* This function implements to get stack_statistics_struct size
510*
511* PARAMETERS
512*
513* RETURNS
514*
515* GLOBALS AFFECTED
516*
517*************************************************************************/
518
519kal_uint32 stack_get_statistics_struct_size(void)
520{
521 kal_uint32 nSize = 0;
522
523 nSize = sizeof(stack_statistics_struct);
524
525 return nSize;
526}
527
528
529/*************************************************************************
530* FUNCTION
531* stack_update_sys_statistics
532*
533* DESCRIPTION
534* This function implements to compare with statistics saved in FLASH, and
535* update if necessary.
536*
537* PARAMETERS
538*
539* RETURNS
540*
541* GLOBALS AFFECTED
542*
543*************************************************************************/
544#ifdef DEBUG_KAL
545kal_uint32 kal_kal_timer_g;
546kal_uint32 kal_es_timer_g;
547kal_uint32 kal_max_event_number;
548kal_uint32 kal_max_mutex_number;
549kal_uint32 kal_max_semaphore_number;
550kal_uint32 kal_max_enhmutex_number;
551kal_uint32 kal_max_eventgroup_number;
552kal_uint32 kal_max_spinlock_number;
553kal_uint32 kal_max_protect_number;
554#endif
555
556#if defined(DEBUG_KAL) && defined(DEBUG_TIMER2)
557kal_uint16 kal_timer_count_debug[LAST_MOD_ID];
558kal_uint16 kal_timer_count_debug_tmp[LAST_MOD_ID];
559
560
561/*Sort in decresing order*/
562static kal_int32 timer_count_cmp(const void *a, const void *b)
563{
564 kal_uint16 a_int16 = *((kal_uint16 *)a);
565 kal_uint16 b_int16 = *((kal_uint16 *)b);
566
567 if (a_int16 > b_int16) {
568 return -1;
569 } else if (a_int16 == b_int16) {
570 return 0;
571 } else {
572 return 1;
573 }
574}
575#endif
576
577kal_bool stack_update_sys_statistics(stack_statistics_struct *prev_stats)
578{
579 kal_bool f_modified = KAL_FALSE;
580 kal_uint32 i, *stack_start, *stack_ptr, *stack_end;
581 kal_uint32 time_us_high, time_us_low;
582/* kal_uint32 stack_size; fix compile warning */
583#if defined(DEBUG_KAL) && defined(DEBUG_TIMER2)
584 kal_int32 key = 0;
585 kal_int32 count = 0;
586#endif
587#if defined(FURTHER_STATISTIC) && defined(__MTK_TARGET__)
588 kal_internal_taskid taskid = NULL;
589 extern kal_uint8 system_resource_amount[];
590#endif
591
592#if defined(DEBUG_KAL) && (defined(DEBUG_BUF1) || defined(DEBUG_BUF2))
593 kal_pool_statistics pool_stats;
594 buff_pool_info_struct *pool_info;
595#endif /* DEBUG_KAL && ( DEBUG_BUF1 || DEBUG_BUF2 ) */
596
597#if defined(FURTHER_STATISTIC) && defined(__MTK_TARGET__)
598 extern ADM_PROFILE top_adm[];
599 extern ADM_PROFILE top_adm_user[];
600 extern AFM_PROFILE top_afm[];
601 extern AFM_PROFILE top_afm_user[];
602 extern kal_uint32 kicked_out_smallest_adm_user_size[];
603 extern kal_uint32 kicked_out_adm_user_number;
604#if defined(__HARD_REAL_TIME_CHECK_LOG_LEVEL__)
605 extern HRTQbitFailLogStruct HRTQbitFailLog_VPE0[HRTQbitFailLogSize];
606 extern HRTQbitFailLogStruct HRTQbitFailLog_VPE1[HRTQbitFailLogSize];
607 extern HRTQbitFailLogStruct HRTQbitFailLog_VPE2[HRTQbitFailLogSize];
608 extern HRTQbitFailLogStruct HRTQbitFailLog_VPE3[HRTQbitFailLogSize];
609#endif
610#endif
611
612 /* memory management statistics */
613
614 sys_stats.memory_pool.max_sys_mem_used = sys_mem_total_size - sys_mem_left_size;
615 if (sys_stats.memory_pool.max_sys_mem_used >
616 prev_stats->memory_pool.max_sys_mem_used) {
617 prev_stats->memory_pool.max_sys_mem_used =
618 sys_stats.memory_pool.max_sys_mem_used;
619 f_modified = KAL_TRUE;
620 }
621
622#ifdef DEBUG_KAL
623 sys_stats.memory_pool.max_sysdebug_mem_used =
624 debug_mem_total_size - debug_mem_left_size;
625
626 if (sys_stats.memory_pool.max_sysdebug_mem_used >
627 prev_stats->memory_pool.max_sysdebug_mem_used) {
628 prev_stats->memory_pool.max_sysdebug_mem_used =
629 sys_stats.memory_pool.max_sysdebug_mem_used;
630 f_modified = KAL_TRUE;
631 }
632
633 sys_stats.memory_pool.max_event_number_used = kal_max_event_number;
634 if (sys_stats.memory_pool.max_event_number_used >
635 prev_stats->memory_pool.max_event_number_used) {
636 prev_stats->memory_pool.max_event_number_used =
637 sys_stats.memory_pool.max_event_number_used;
638 f_modified = KAL_TRUE;
639 }
640
641#endif /* DEBUG_KAL */
642
643 /* task stack size statistics */
644 for (i = 0; i < KALTotalTasks; i++) {
645
646 if (task_info_g[i].task_id == NULL)
647 continue;
648
649#if defined(KAL_ON_OSCAR)
650 sys_stats.runtime_max_amount_task[i].stack = 0;
651#elif defined(KAL_ON_MERTOS)
652 (void)stack_start; (void)stack_ptr, (void)stack_end; // To make compiler happy
653 (void)time_us_low; (void)time_us_high;
654#endif
655
656 if (sys_stats.runtime_max_amount_task[i].stack >
657 prev_stats->runtime_max_amount_task[i].stack) {
658 prev_stats->runtime_max_amount_task[i].stack =
659 sys_stats.runtime_max_amount_task[i].stack;
660 f_modified = KAL_TRUE;
661 }
662 }
663
664 /* HISR stack size statistics */
665 for (i = 0; i < KAL_MAX_NUM_HISRS; i++) {
666
667#if !defined(KAL_ON_MERTOS)
668 if (kal_hisr_ptrs_g[i] == NULL)
669 continue;
670#endif
671
672#if defined(KAL_ON_OSCAR)
673 sys_stats.runtime_max_amount_hisr[i].stack = 0;
674#endif
675
676 if (sys_stats.runtime_max_amount_hisr[i].stack >
677 prev_stats->runtime_max_amount_hisr[i].stack) {
678 prev_stats->runtime_max_amount_hisr[i].stack =
679 sys_stats.runtime_max_amount_hisr[i].stack;
680 f_modified = KAL_TRUE;
681 }
682 }
683
684/* Queue management statistics */
685#if defined(DEBUG_ITC) && defined(DEBUG_KAL)
686 for (i = 0; i < KALTotalTasks; i++) {
687 if (task_info_g[i].task_ext_qid == NULL)
688 continue;
689
690 sys_stats.runtime_max_amount_task[i].ext_queue =
691 ((kal_internal_msgqid)task_info_g[i].task_ext_qid)
692 ->q_stat->max_num_msgs_enqued;
693
694 if (sys_stats.runtime_max_amount_task[i].ext_queue >
695 prev_stats->runtime_max_amount_task[i].ext_queue) {
696 prev_stats->runtime_max_amount_task[i].ext_queue =
697 sys_stats.runtime_max_amount_task[i].ext_queue;
698 f_modified = KAL_TRUE;
699 }
700 }
701 for (i = 0; i < KALTotalTasks; i++) {
702 if (task_info_g[i].task_int_qid_ptr == NULL) {
703 continue;
704 }
705
706 sys_stats.runtime_max_amount_task[i].int_queue = 0;
707
708 LCD_IP_CQUEUE_UPDATE_MAX((*(int_q_type *)task_info_g[i].task_int_qid_ptr),
709 sys_stats.runtime_max_amount_task[i].int_queue);
710
711 if (sys_stats.runtime_max_amount_task[i].int_queue >
712 prev_stats->runtime_max_amount_task[i].int_queue) {
713 prev_stats->runtime_max_amount_task[i].int_queue =
714 sys_stats.runtime_max_amount_task[i].int_queue;
715 f_modified = KAL_TRUE;
716 }
717 }
718
719#endif /* DEBUG_ITC && DEBUG_KAL */
720
721/* Buffer management statistics */
722#if defined(DEBUG_KAL) && (defined(DEBUG_BUF1) || defined(DEBUG_BUF2))
723 for (i = 0; i < RPS_CREATED_CTRL_BUFF_POOLS; i++) {
724 pool_info = &ctrl_buff_pool_info_g[i];
725 if (pool_info->pool_id == NULL)
726 continue;
727
728 pool_stats = KAL_GET_POOL_STATISTICS_ADDR(pool_info->pool_id);
729 sys_stats.max_ctrl_buff_num_allocated[i] = pool_stats->max_num_allocated;
730
731 if (sys_stats.max_ctrl_buff_num_allocated[i] >
732 prev_stats->max_ctrl_buff_num_allocated[i]) {
733 prev_stats->max_ctrl_buff_num_allocated[i] =
734 sys_stats.max_ctrl_buff_num_allocated[i];
735 f_modified = KAL_TRUE;
736 }
737 }
738
739#endif /* DEBUG_KAL && ( DEBUG_BUF1 || DEBUG_BUF2 ) */
740
741
742#ifdef DEBUG_KAL
743 sys_stats.runtime_max_amount_total.kal_timer = kal_kal_timer_g - kal_es_timer_g;
744 if (sys_stats.runtime_max_amount_total.kal_timer >
745 prev_stats->runtime_max_amount_total.kal_timer) {
746 prev_stats->runtime_max_amount_total.kal_timer =
747 sys_stats.runtime_max_amount_total.kal_timer;
748 f_modified = KAL_TRUE;
749 }
750 sys_stats.runtime_max_amount_total.event_scheduler = kal_es_timer_g;
751 if (sys_stats.runtime_max_amount_total.event_scheduler >
752 prev_stats->runtime_max_amount_total.event_scheduler) {
753 prev_stats->runtime_max_amount_total.event_scheduler =
754 sys_stats.runtime_max_amount_total.event_scheduler;
755 f_modified = KAL_TRUE;
756 }
757 sys_stats.runtime_max_amount_total.mutex = kal_max_mutex_number;
758 if (sys_stats.runtime_max_amount_total.mutex >
759 prev_stats->runtime_max_amount_total.mutex) {
760 prev_stats->runtime_max_amount_total.mutex =
761 sys_stats.runtime_max_amount_total.mutex;
762 f_modified = KAL_TRUE;
763 }
764 sys_stats.runtime_max_amount_total.semaphore = kal_max_semaphore_number;
765 if (sys_stats.runtime_max_amount_total.semaphore >
766 prev_stats->runtime_max_amount_total.semaphore) {
767 prev_stats->runtime_max_amount_total.semaphore =
768 sys_stats.runtime_max_amount_total.semaphore;
769 f_modified = KAL_TRUE;
770 }
771 sys_stats.runtime_max_amount_total.event_group = kal_max_eventgroup_number;
772 if (sys_stats.runtime_max_amount_total.event_group >
773 prev_stats->runtime_max_amount_total.event_group) {
774 prev_stats->runtime_max_amount_total.event_group =
775 sys_stats.runtime_max_amount_total.event_group;
776 f_modified = KAL_TRUE;
777 }
778 sys_stats.runtime_max_amount_total.spinlock = kal_max_spinlock_number;
779 if (sys_stats.runtime_max_amount_total.spinlock >
780 prev_stats->runtime_max_amount_total.spinlock) {
781 prev_stats->runtime_max_amount_total.spinlock =
782 sys_stats.runtime_max_amount_total.spinlock;
783 f_modified = KAL_TRUE;
784 }
785 sys_stats.runtime_max_amount_total.protect = kal_max_protect_number;
786 if (sys_stats.runtime_max_amount_total.protect >
787 prev_stats->runtime_max_amount_total.protect) {
788 prev_stats->runtime_max_amount_total.protect =
789 sys_stats.runtime_max_amount_total.protect;
790 f_modified = KAL_TRUE;
791 }
792#endif
793
794
795/* runtime resource sysmem statistics */
796#if defined(FURTHER_STATISTIC) && defined(__MTK_TARGET__)
797 prev_stats->primitive_size.event_scheduler =
798 sys_stats.primitive_size.event_scheduler = KAL_RT_SYSMEM_SIZE_EVSHED;
799 prev_stats->primitive_size.mutex = sys_stats.primitive_size.mutex =
800 KAL_RT_SYSMEM_SIZE_MUTEX;
801 prev_stats->primitive_size.semaphore = sys_stats.primitive_size.semaphore =
802 KAL_RT_SYSMEM_SIZE_SEM;
803 prev_stats->primitive_size.event_group = sys_stats.primitive_size.event_group =
804 KAL_RT_SYSMEM_SIZE_EVENT_GROUP;
805 prev_stats->primitive_size.kal_timer = sys_stats.primitive_size.kal_timer =
806 KAL_RT_SYSMEM_SIZE_KAL_TIMER;
807 prev_stats->primitive_size.spinlock = sys_stats.primitive_size.spinlock =
808 KAL_RT_SYSMEM_SIZE_SPINLOCK;
809 prev_stats->primitive_size.protect = sys_stats.primitive_size.protect =
810 KAL_RT_SYSMEM_SIZE_PROTECT;
811
812 sys_stats.runtime_max_amount_system.event_scheduler =
813 system_resource_amount[KAL_RT_RESOURCE_EVSHED];
814 if (sys_stats.runtime_max_amount_system.event_scheduler >
815 prev_stats->runtime_max_amount_system.event_scheduler) {
816 prev_stats->runtime_max_amount_system.event_scheduler =
817 sys_stats.runtime_max_amount_system.event_scheduler;
818 f_modified = KAL_TRUE;
819 }
820 sys_stats.runtime_max_amount_system.mutex =
821 system_resource_amount[KAL_RT_RESOURCE_MUTEX];
822 if (sys_stats.runtime_max_amount_system.mutex >
823 prev_stats->runtime_max_amount_system.mutex) {
824 prev_stats->runtime_max_amount_system.mutex =
825 sys_stats.runtime_max_amount_system.mutex;
826 f_modified = KAL_TRUE;
827 }
828 sys_stats.runtime_max_amount_system.semaphore =
829 system_resource_amount[KAL_RT_RESOURCE_SEM];
830 if (sys_stats.runtime_max_amount_system.semaphore >
831 prev_stats->runtime_max_amount_system.semaphore) {
832 prev_stats->runtime_max_amount_system.semaphore =
833 sys_stats.runtime_max_amount_system.semaphore;
834 f_modified = KAL_TRUE;
835 }
836 sys_stats.runtime_max_amount_system.event_group =
837 system_resource_amount[KAL_RT_RESOURCE_EVENT_GROUP];
838 if (sys_stats.runtime_max_amount_system.event_group >
839 prev_stats->runtime_max_amount_system.event_group) {
840 prev_stats->runtime_max_amount_system.event_group =
841 sys_stats.runtime_max_amount_system.event_group;
842 f_modified = KAL_TRUE;
843 }
844 sys_stats.runtime_max_amount_system.kal_timer =
845 system_resource_amount[KAL_RT_RESOURCE_KAL_TIMER] -
846 system_resource_amount[KAL_RT_RESOURCE_EVSHED];
847 if (sys_stats.runtime_max_amount_system.kal_timer >
848 prev_stats->runtime_max_amount_system.kal_timer) {
849 prev_stats->runtime_max_amount_system.kal_timer =
850 sys_stats.runtime_max_amount_system.kal_timer;
851 f_modified = KAL_TRUE;
852 }
853 sys_stats.runtime_max_amount_system.spinlock =
854 system_resource_amount[KAL_RT_RESOURCE_SPINLOCK];
855 if (sys_stats.runtime_max_amount_system.spinlock >
856 prev_stats->runtime_max_amount_system.spinlock) {
857 prev_stats->runtime_max_amount_system.spinlock =
858 sys_stats.runtime_max_amount_system.spinlock;
859 f_modified = KAL_TRUE;
860 }
861 sys_stats.runtime_max_amount_system.protect =
862 system_resource_amount[KAL_RT_RESOURCE_PROTECT];
863 if (sys_stats.runtime_max_amount_system.protect >
864 prev_stats->runtime_max_amount_system.protect) {
865 prev_stats->runtime_max_amount_system.protect =
866 sys_stats.runtime_max_amount_system.protect;
867 f_modified = KAL_TRUE;
868 }
869
870
871 for (i = 0; i < KALTotalTasks; i++) {
872 if (task_info_g[i].task_id == NULL)
873 continue;
874
875 taskid = (kal_internal_taskid)(task_info_g[i].task_id);
876
877 memcpy(&(sys_stats.runtime_max_amount_task[i].name),
878 task_info_g[i].task_name_ptr,
879 sizeof(sys_stats.runtime_max_amount_task[i].name));
880 memcpy(&(prev_stats->runtime_max_amount_task[i].name),
881 task_info_g[i].task_name_ptr,
882 sizeof(prev_stats->runtime_max_amount_task[i].name));
883
884 sys_stats.runtime_max_amount_task[i].event_scheduler =
885 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_EVSHED];
886 if (sys_stats.runtime_max_amount_task[i].event_scheduler >
887 prev_stats->runtime_max_amount_task[i].event_scheduler) {
888 prev_stats->runtime_max_amount_task[i].event_scheduler =
889 sys_stats.runtime_max_amount_task[i].event_scheduler;
890 f_modified = KAL_TRUE;
891 }
892
893 sys_stats.runtime_max_amount_task[i].mutex =
894 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_MUTEX];
895 if (sys_stats.runtime_max_amount_task[i].mutex >
896 prev_stats->runtime_max_amount_task[i].mutex) {
897 prev_stats->runtime_max_amount_task[i].mutex =
898 sys_stats.runtime_max_amount_task[i].mutex;
899 f_modified = KAL_TRUE;
900 }
901
902 sys_stats.runtime_max_amount_task[i].semaphore =
903 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_SEM];
904 if (sys_stats.runtime_max_amount_task[i].semaphore >
905 prev_stats->runtime_max_amount_task[i].semaphore) {
906 prev_stats->runtime_max_amount_task[i].semaphore =
907 sys_stats.runtime_max_amount_task[i].semaphore;
908 f_modified = KAL_TRUE;
909 }
910
911 sys_stats.runtime_max_amount_task[i].event_group =
912 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_EVENT_GROUP];
913 if (sys_stats.runtime_max_amount_task[i].event_group >
914 prev_stats->runtime_max_amount_task[i].event_group) {
915 prev_stats->runtime_max_amount_task[i].event_group =
916 sys_stats.runtime_max_amount_task[i].event_group;
917 f_modified = KAL_TRUE;
918 }
919
920 sys_stats.runtime_max_amount_task[i].kal_timer =
921 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_KAL_TIMER] -
922 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_EVSHED];
923 if (sys_stats.runtime_max_amount_task[i].kal_timer >
924 prev_stats->runtime_max_amount_task[i].kal_timer) {
925 prev_stats->runtime_max_amount_task[i].kal_timer =
926 sys_stats.runtime_max_amount_task[i].kal_timer;
927 f_modified = KAL_TRUE;
928 }
929 sys_stats.runtime_max_amount_task[i].spinlock =
930 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_SPINLOCK];
931 if (sys_stats.runtime_max_amount_task[i].spinlock >
932 prev_stats->runtime_max_amount_task[i].spinlock) {
933 prev_stats->runtime_max_amount_task[i].spinlock =
934 sys_stats.runtime_max_amount_task[i].spinlock;
935 f_modified = KAL_TRUE;
936 }
937 sys_stats.runtime_max_amount_task[i].protect =
938 taskid->task_runtime_resource_amount[KAL_RT_RESOURCE_PROTECT];
939 if (sys_stats.runtime_max_amount_task[i].protect >
940 prev_stats->runtime_max_amount_task[i].protect) {
941 prev_stats->runtime_max_amount_task[i].protect =
942 sys_stats.runtime_max_amount_task[i].protect;
943 f_modified = KAL_TRUE;
944 }
945 }
946
947 for (i = 0; i < KAL_MAX_NUM_HISRS; i++) {
948
949 if (kal_hisr_ptrs_g[i] == NULL)
950 continue;
951
952 memcpy(&(sys_stats.runtime_max_amount_hisr[i].name),
953 kal_hisr_ptrs_g[i]->hisr_name,
954 sizeof(sys_stats.runtime_max_amount_hisr[i].name));
955
956 memcpy(&(prev_stats->runtime_max_amount_hisr[i].name),
957 kal_hisr_ptrs_g[i]->hisr_name,
958 sizeof(prev_stats->runtime_max_amount_hisr[i].name));
959 }
960
961 /* ADM runtime statistics */
962 for (i = 0; i < KAL_ADM_PROFILE_AMOUNT; i++) {
963 memcpy(&prev_stats->top_adm_profile[i], &top_adm[i], sizeof(ADM_PROFILE));
964 memcpy(&sys_stats.top_adm_profile[i], &top_adm[i], sizeof(ADM_PROFILE));
965 memcpy(&prev_stats->top_adm_user_profile[i], &top_adm_user[i],
966 sizeof(ADM_PROFILE));
967 memcpy(&sys_stats.top_adm_user_profile[i], &top_adm_user[i],
968 sizeof(ADM_PROFILE));
969 }
970 for (i = 0; i < KAL_ADM_PROFILE_AMOUNT_KICKED_OUT; i++) {
971 prev_stats->kicked_out_smallest_adm_user_size[i] =
972 kicked_out_smallest_adm_user_size[i];
973 sys_stats.kicked_out_smallest_adm_user_size[i] =
974 kicked_out_smallest_adm_user_size[i];
975 }
976 prev_stats->kicked_out_adm_user_number = kicked_out_adm_user_number;
977 sys_stats.kicked_out_adm_user_number = kicked_out_adm_user_number;
978
979 for (i = 0; i < KAL_AFM_PROFILE_AMOUNT; i++) {
980 memcpy(&prev_stats->top_afm_profile[i], &top_afm[i], sizeof(AFM_PROFILE));
981 memcpy(&sys_stats.top_afm_profile[i], &top_afm[i], sizeof(AFM_PROFILE));
982 memcpy(&prev_stats->top_afm_user_profile[i], &top_afm_user[i],
983 sizeof(AFM_PROFILE));
984 memcpy(&sys_stats.top_afm_user_profile[i], &top_afm_user[i],
985 sizeof(AFM_PROFILE));
986 }
987
988#if defined(__HARD_REAL_TIME_CHECK_LOG_LEVEL__)
989
990 for (i = 0; i < HRTQbitFailLogSize && i < HRTQbitProfileSize; i++) {
991 if (prev_stats->NVRAM_HRTQbitFailLog_VPE0_Dur[i] <
992 HRTQbitFailLog_VPE0[i].violationDuration) {
993 prev_stats->NVRAM_HRTQbitFailLog_VPE0_Dur[i] =
994 HRTQbitFailLog_VPE0[i].violationAddress;
995 prev_stats->NVRAM_HRTQbitFailLog_VPE0_Addr[i] =
996 HRTQbitFailLog_VPE0[i].violationDuration;
997 }
998 if (prev_stats->NVRAM_HRTQbitFailLog_VPE1_Dur[i] <
999 HRTQbitFailLog_VPE1[i].violationDuration) {
1000 prev_stats->NVRAM_HRTQbitFailLog_VPE1_Dur[i] =
1001 HRTQbitFailLog_VPE1[i].violationAddress;
1002 prev_stats->NVRAM_HRTQbitFailLog_VPE1_Addr[i] =
1003 HRTQbitFailLog_VPE1[i].violationDuration;
1004 }
1005 if (prev_stats->NVRAM_HRTQbitFailLog_VPE2_Dur[i] <
1006 HRTQbitFailLog_VPE2[i].violationDuration) {
1007 prev_stats->NVRAM_HRTQbitFailLog_VPE2_Dur[i] =
1008 HRTQbitFailLog_VPE2[i].violationAddress;
1009 prev_stats->NVRAM_HRTQbitFailLog_VPE2_Addr[i] =
1010 HRTQbitFailLog_VPE2[i].violationDuration;
1011 }
1012 if (prev_stats->NVRAM_HRTQbitFailLog_VPE3_Dur[i] <
1013 HRTQbitFailLog_VPE3[i].violationDuration) {
1014 prev_stats->NVRAM_HRTQbitFailLog_VPE3_Dur[i] =
1015 HRTQbitFailLog_VPE3[i].violationAddress;
1016 prev_stats->NVRAM_HRTQbitFailLog_VPE3_Addr[i] =
1017 HRTQbitFailLog_VPE3[i].violationDuration;
1018 }
1019 }
1020
1021
1022#endif
1023
1024#endif
1025
1026 if (f_modified == KAL_TRUE) {
1027 prev_stats->stack_stats_status = STACK_STATS_UPDATE;
1028 prev_stats->total_save_count = prev_stats->total_save_count + 1;
1029 }
1030
1031 return f_modified;
1032}
1033
1034/*************************************************************************
1035* FUNCTION
1036* stack_query_stat_info
1037*
1038* DESCRIPTION
1039* This function gets system statistics related informations such as
1040* HISR name.
1041*
1042* PARAMETERS
1043* stat - flag to indicate the querying statsitic
1044* buff - user buffer to store informations
1045* buff_size - user buffer's size
1046*
1047* RETURNS
1048* -1 for failure, other nonzero value for success
1049*
1050*************************************************************************/
1051kal_int32 stack_get_stats_info(kal_uint32 stats, void *buff, kal_uint32 buff_size)
1052{
1053#if !defined(KAL_ON_MERTOS)
1054 kal_int32 ret;
1055 kal_char * chp;
1056 kal_uint32 i, j;
1057
1058
1059 ret = -1;
1060
1061 switch (stats) {
1062 case STACK_STATS_HISR_NAME:
1063 /* check buffer size */
1064 if (buff_size <
1065 (num_hisr_created_g * STACK_STATS_HISR_MAX_NAME * sizeof(kal_char))) {
1066 break;
1067 } else {
1068 ret = num_hisr_created_g * STACK_STATS_HISR_MAX_NAME * sizeof(kal_char);
1069 }
1070
1071 /* copy HISR names into the buffer */
1072 chp = (kal_char *)buff;
1073 for (i = 0; i < KAL_MAX_NUM_HISRS; i++) {
1074 if (kal_hisr_ptrs_g[i] == NULL)
1075 continue;
1076
1077 for (j = 0; j < STACK_STATS_HISR_MAX_NAME; j++, chp++) {
1078#if defined(KAL_ON_OSCAR)
1079 *chp = '0';
1080#endif
1081 }
1082 }
1083
1084 break;
1085
1086 default:
1087 /* unknown statistic type */
1088 break;
1089 }
1090
1091 return ret;
1092#else
1093 return 0;
1094#endif
1095}