11#include "irx_imports.h"
15IRX_ID(
"Temporarily_Thread_monitor", 1, 3);
20 volatile int m_start_stop_status;
31 struct thread *m_thread_ptr;
41 unsigned int m_alarm_id;
46static int CreateThmonThread(u32 attr,
void (*
thread)(
void *), u32 priority, u32 stacksize, u32 option);
47static int do_get_thread_count();
49static void ThmonMainThread(
void *arg);
51static const char *g_help_msg[] =
53 "\nsimple thread monitor program =====================================\n",
54 "-- thlist [-v] [-a] [<thid>] -- thread list\n",
55 "-- rdlist [-v] -- ready thread list\n",
56 "-- sllist [-v] -- sleeping thread list\n",
57 "-- dllist [-v] -- delayed thread list\n",
58 "-- rtlist [-v] [<times>] -- thread running time list\n",
59 "-- semlist [-w] [-v] -- semaphore list\n",
60 "-- evlist [-w] [-v] -- eventflag list\n",
61 "-- msglist -- messagebox list\n",
62 "-- vpllist -- Vpool list\n",
63 "-- fpllist -- Fpool list\n",
64 "-- almlist -- Alarm list\n",
65 "-- cpuwatch [-b] [-br] [-v] [<samples>] -- cpu time watching <samples/sec>\n",
66 "-- thwatch [-b] [-br] [-v] <thid> [<samples>] -- thread time watching <samples/sec>\n",
67 "-- freemem -- report free memory size\n",
68 "-- vblank <on/off> -- vblank interrupt on/off\n",
69 "-- / -- repeat last command\n",
72static const char *g_th_status_short =
"000RunRdy333Wat555666777Sus999aaabbbWSudddeeefffDom???";
73static const char *g_th_wait_short =
" SlDlSeEvMbVpFp ";
75static int g_monitorThreadId;
78static char g_progspace1[52];
79static char g_progspace2[52];
81static char g_PreviousCommand[208];
82static char g_CommandBuffer[200];
84int _start(
int ac,
char **av)
90 if (ac >= 2 && !strncmp(av[1],
"-th=", 4)) {
91 margen_val = strtol(av[1] + 4, 0, 10) + 10;
92 printf(
"margen = %d\n", margen_val);
94 g_thcpuwatch_info.m_start_stop_status = 0;
95 g_tty9_fd = open(
"tty9:", 3);
97 main_thread_id = CreateThmonThread(
101 28 * (do_get_thread_count() + margen_val) + 3584,
103 g_monitorThreadId = CreateThmonThread(0x2000000u, (
void (*)(
void *))ThmonMonitorThread, 4u, 0x800u, 0);
104 if (main_thread_id <= 0 || g_monitorThreadId <= 0)
106 StartThread(main_thread_id, 0);
110static int CreateThmonThread(u32 attr,
void (*
thread)(
void *), u32 priority, u32 stacksize, u32 option)
116 thparam.priority = priority;
117 thparam.stacksize = stacksize;
118 thparam.option = option;
119 return CreateThread(&thparam);
122static int do_get_thread_count()
130 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
137static void PrintMessage(
const char *msg)
139 fdprintf(g_tty9_fd,
"%s\n", msg);
142static char *RemoveLeadingWhitespaces(
char *str)
144 for (; *str ==
' ' || *str ==
'\t'; str += 1) {
150static char *GetEndOfString(
char *str)
152 for (; *str && *str !=
' ' && *str !=
'\t'; str += 1)
157static void DisplayHelpMessage()
161 for (i = 0; g_help_msg[i]; i += 1) {
162 fdprintf(g_tty9_fd, g_help_msg[i]);
163 if (i + 1 == 23 * ((i + 1) / 23) && g_help_msg[i + 1]) {
164 fdprintf(g_tty9_fd,
" more ? ");
165 if (fdgetc(g_tty9_fd) !=
'y') {
166 fdprintf(g_tty9_fd,
"\n");
169 fdprintf(g_tty9_fd,
"\r");
174static int do_parse_hex(
char *str)
179 for (; *str && isxdigit(*str); str += 1) {
181 retres += toupper(*str);
182 retres -= isdigit(*str) ?
'0' :
'7';
187static char *get_module_name_from_addr(
unsigned int entry_addr)
191 for (image_info = GetLoadcoreInternalData()->image_info; image_info; image_info = image_info->next) {
192 if (entry_addr >= image_info->text_start && entry_addr < image_info->text_start + image_info->text_size)
193 return image_info->name;
198static void DisplayThreadInformation(
struct thread *threadstruct,
int is_verbose,
int is_brief)
201 fdprintf(g_tty9_fd,
" ");
204 "%3x %07x %08x %07x %.3s ",
205 threadstruct->tag.id,
206 MAKE_HANDLE(threadstruct),
208 threadstruct->option,
209 &g_th_status_short[3 * (
char)threadstruct->status]);
212 "%06x %06x %04x %06x %3d %3d",
214 threadstruct->stack_top,
215 threadstruct->stack_size,
217 (s16)threadstruct->priority,
218 (s16)threadstruct->init_priority);
220 fdprintf(g_tty9_fd,
"\n");
225 g_th_wait_short[2 * (s16)threadstruct->wait_type],
226 g_th_wait_short[2 * (s16)threadstruct->wait_type + 1]);
227 switch ((s16)threadstruct->wait_type) {
229 fdprintf(g_tty9_fd,
"%7s%2x\n",
"", threadstruct->wakeup_count);
232 fdprintf(g_tty9_fd,
"%6x %2x\n", threadstruct->wait_usecs, threadstruct->wakeup_count);
239 MAKE_HANDLE(threadstruct->wait_usecs),
240 threadstruct->wakeup_count);
245 char *module_name_from_addr;
247 module_name_from_addr = get_module_name_from_addr((
unsigned int)threadstruct->entry);
248 if (module_name_from_addr) {
250 fdprintf(g_tty9_fd,
" ");
251 fdprintf(g_tty9_fd,
" Name=%s\n", module_name_from_addr);
254 if (threadstruct->saved_regs && threadstruct->status != 16) {
256 fdprintf(g_tty9_fd,
" ");
259 " PC=%06x RA=%06x SP=%06x Context_addr/mask=%08x/%08x\n",
260 threadstruct->saved_regs->pc,
261 threadstruct->saved_regs->ra,
262 threadstruct->saved_regs->sp,
263 threadstruct->saved_regs,
264 threadstruct->saved_regs->unk);
269 for (i = 0; i < (threadstruct->stack_size / 4); i += 1) {
270 if (((u32 *)threadstruct->stack_top)[i] != 0xFFFFFFFF && ((u32 *)threadstruct->stack_top)[i] != 0x11111111)
274 fdprintf(g_tty9_fd,
" ");
275 fdprintf(g_tty9_fd,
" Free_Stack_Size=%06x", i * 4);
278 " I-preempt/T-preenmpt/release counts=%d,%d,%d\n",
279 threadstruct->irq_preemption_count,
280 threadstruct->thread_preemption_count,
281 threadstruct->release_count);
282 if (is_brief && threadstruct->wait_type == 4) {
283 fdprintf(g_tty9_fd,
" ");
286 " Event bitpattern, mode=0x%08x, 0x%x\n",
287 threadstruct->event_bits,
288 (s16)threadstruct->event_mode);
293static void thlist_cmd_handler(
char *cmdparam)
308 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
309 EndOfString = GetEndOfString(cmdparam_cur);
312 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
314 if (!strcmp(cmdparam_cur,
"-v"))
316 if (!strcmp(cmdparam_cur,
"-a"))
318 if (!strcmp(cmdparam_cur,
"-i"))
320 if (*cmdparam_cur !=
'-')
321 is_hexval = do_parse_hex(cmdparam_cur);
324 if (is_hexval < g_ThbaseInternal->thread_id) {
325 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
326 if (
thread->tag.id == is_hexval) {
331 fdprintf(g_tty9_fd,
"thread #%d not found \n", is_hexval);
334 is_hexval = MAKE_HANDLE(
thread);
336 if (ReferThreadStatus(is_hexval, &thstatus) < 0) {
337 fdprintf(g_tty9_fd,
"thid:%x not found \n", is_hexval);
340 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP WT WID WUC\n");
341 DisplayThreadInformation(
342 (
struct thread *)HANDLE_PTR(is_hexval),
346 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP WT WID WUC\n");
347 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
348 if (ReferThreadStatus(MAKE_HANDLE(
thread), &thstatus) < 0) {
351 "thid = %x not found \n",
355 if ((is_flag_a || thstatus.status != 16) && (is_flag_i ||
thread != g_ThbaseInternal->idle_thread)) {
356 DisplayThreadInformation(
thread, is_flag_v, 0);
362static void do_rtlist_handle_clock(
int is_flag_v_or_c)
365 char *module_name_from_addr;
371 fdprintf(g_tty9_fd,
" THID CLOCK SEC\n");
372 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
373 if (ReferThreadStatus(MAKE_HANDLE(
thread), &thstatus) < 0 || thstatus.status == 16) {
376 "thid = %x not found \n",
377 (
unsigned int)MAKE_HANDLE(
thread));
380 clks.hi =
thread->run_clocks_hi;
381 clks.lo =
thread->run_clocks_lo;
382 SysClock2USec(&clks, &sec_val, &usec_val);
383 if (
thread == g_ThbaseInternal->idle_thread) {
386 " %08x_%08x %5d.%06d",
391 fdprintf(g_tty9_fd,
" System Idle time\n");
395 "%3x %07x %08x_%08x %5d.%06d",
397 (
unsigned int)MAKE_HANDLE(
thread),
402 if (is_flag_v_or_c) {
403 module_name_from_addr = get_module_name_from_addr((
unsigned int)thstatus.entry);
404 if (module_name_from_addr)
405 fdprintf(g_tty9_fd,
" Name=%s", module_name_from_addr);
407 fdprintf(g_tty9_fd,
"\n");
412 " Total thread switch count = %d, comes out of idle count = %d\n",
413 g_ThbaseInternal->thread_switch_count,
414 g_ThbaseInternal->idle_thread->irq_preemption_count);
417static void sys_clock_subtract(
424 diff.lo = pEnd->lo - pStart->lo;
425 diff.hi = pEnd->hi - pStart->hi - (pStart->lo > pEnd->lo);
426 memcpy(pRet, &diff,
sizeof(diff));
429static void do_rtlist_handle_priority(
int is_flag_v_or_c,
int int_value)
433 char *module_name_from_addr;
440 g_rtlist_nondormant = __builtin_alloca(
sizeof(
struct thmon_rtlist_item) * do_get_thread_count());
441 for (; int_value > 0; int_value -= 1) {
445 curelem1 = g_rtlist_nondormant;
446 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
447 curelem1->m_thread_ptr = 0;
448 if (
thread->status != 16) {
449 curelem1->m_thread_ptr =
thread;
450 curelem1->m_thread_id =
thread->tag.id;
451 curelem1->m_old_clocks.hi =
thread->run_clocks_hi;
452 curelem1->m_old_clocks.lo =
thread->run_clocks_lo;
454 curelem1->m_thread_ptr = 0;
457 GetSystemTime(&timebefore);
458 DelayThread(1000000);
459 GetSystemTime(&timeafter);
460 for (curelem2 = g_rtlist_nondormant; curelem2->m_thread_ptr; curelem2 += 1) {
461 if (curelem2->m_thread_id == curelem2->m_thread_ptr->tag.id) {
462 curelem2->m_flags = 0;
463 curelem2->m_new_clocks.hi = curelem2->m_thread_ptr->run_clocks_hi;
464 curelem2->m_new_clocks.lo = curelem2->m_thread_ptr->run_clocks_lo;
466 curelem2->m_flags = -1;
469 sys_clock_subtract(&timeafter, &timebefore, &timeafter);
470 fdprintf(g_tty9_fd,
" THID PRIO USE\n");
471 for (curelem2 = g_rtlist_nondormant; curelem2->m_thread_ptr; curelem2 += 1) {
472 if ((curelem2->m_flags & 0x80000000) != 0) {
475 curptr = curelem2->m_thread_ptr;
476 sys_clock_subtract(&curelem2->m_new_clocks, &curelem2->m_old_clocks, &timeres);
479 SysClock2USec(&timeafter, &sec, &usec);
480 if (curptr != g_ThbaseInternal->idle_thread) {
483 "%3x %07x %3d %3d.%03d %%",
486 (s16)curptr->priority,
489 if (is_flag_v_or_c) {
490 module_name_from_addr = get_module_name_from_addr((
unsigned int)curptr->entry);
491 if (module_name_from_addr)
492 fdprintf(g_tty9_fd,
" Name=%s", module_name_from_addr);
494 fdprintf(g_tty9_fd,
"\n");
499 " %6d/%6d/ %3d.%03d %%",
500 g_ThbaseInternal->thread_switch_count,
501 curptr->irq_preemption_count,
504 fdprintf(g_tty9_fd,
" Total switch / comes out of idle / System Idle time\n");
510static void rtlist_cmd_handler(
char *cmdparam)
519 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
520 EndOfString = GetEndOfString(cmdparam_cur);
523 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
525 if (!strcmp(cmdparam_cur,
"-v"))
526 is_flag_v_or_c |= 1u;
527 if (!strcmp(cmdparam_cur,
"-c"))
528 is_flag_v_or_c |= 2u;
529 if (*cmdparam_cur !=
'-')
530 int_value = strtol(cmdparam_cur, 0, 10);
533 do_rtlist_handle_priority(is_flag_v_or_c, int_value);
535 do_rtlist_handle_clock(is_flag_v_or_c);
538static char *do_output_progress_bar_newline(
int curlen)
542 curlen_div_2000 = curlen / 2000;
543 strncpy(g_progspace1,
"----+----+----+----+----+----+----+----+----+----+", curlen / 2000);
544 g_progspace1[curlen_div_2000] =
'\n';
545 g_progspace1[curlen_div_2000 + 1] =
'\0';
549static char *do_output_progress_bar_carriageret(
int curlen)
553 curlen_div_2000 = curlen / 2000;
554 strncpy(g_progspace2,
"----+----+----+----+----+----+----+----+----+----+", curlen / 2000);
555 strncpy(&g_progspace2[curlen_div_2000],
" ", 50 - curlen_div_2000);
556 strcpy(&g_progspace2[50],
"\r");
564 struct thread *target_thread;
574 struct thread *this_thread;
579 delayval = 1000 * (1000 / usrptr->m_sample_count);
580 usrptr->m_start_stop_status = 1;
581 target_thread = usrptr->m_thread;
582 this_thread = (
struct thread *)HANDLE_PTR(GetThreadId());
583 this_thread_clks_2.lo = 0;
584 this_thread_clks_2.hi = 0;
585 while (usrptr->m_start_stop_status != 2) {
587 target_thread_clks_1.hi = target_thread->run_clocks_hi;
588 target_thread_clks_1.lo = target_thread->run_clocks_lo;
589 DelayThread(delayval);
590 GetSystemTime(&sys_time_clks_1);
595 sys_time_clks_2 = sys_time_clks_1;
596 target_thread_clks_2.hi = target_thread->run_clocks_hi;
597 target_thread_clks_2.lo = target_thread->run_clocks_lo;
598 this_thread_clks_1.hi = this_thread->run_clocks_hi;
599 this_thread_clks_1.lo = this_thread->run_clocks_lo;
603 &this_thread_clks_2);
608 this_thread_clks_2 = this_thread_clks_1;
610 &target_thread_clks_2,
611 &target_thread_clks_1,
615 SysClock2USec(&tmp_time_clks_1, &sec, &usec);
616 switch (usrptr->m_barchart) {
618 Kprintf(
"%3d.%03d %07x", sec, usec, target_thread->saved_regs->pc);
619 if (usrptr->m_verbose) {
622 target_thread->irq_preemption_count,
623 target_thread->thread_preemption_count,
624 target_thread->release_count);
625 Kprintf(
"%c", (chrcnt <= 0) ?
' ' :
'\n');
630 Kprintf(
"%c", (chrcnt < 4) ?
' ' :
'\n');
642 (usrptr->m_barchart == 1) ? do_output_progress_bar_newline(sec * 1000 + usec) : do_output_progress_bar_carriageret(sec * 1000 + usec));
648 target_thread_clks_1.hi = g_ThbaseInternal->idle_thread->run_clocks_hi;
649 target_thread_clks_1.lo = g_ThbaseInternal->idle_thread->run_clocks_lo;
650 GetSystemTime(&sys_time_clks_2);
651 DelayThread(delayval);
652 GetSystemTime(&sys_time_clks_1);
653 target_thread_clks_2.hi = g_ThbaseInternal->idle_thread->run_clocks_hi;
654 target_thread_clks_2.lo = g_ThbaseInternal->idle_thread->run_clocks_lo;
660 &target_thread_clks_2,
661 &target_thread_clks_1,
665 SysClock2USec(&tmp_time_clks_1, &sec, &usec);
666 math_magic_3 = 100000 - (sec * 1000 + usec);
667 switch (usrptr->m_barchart) {
669 Kprintf(
"%3d.%03d", math_magic_3 / 1000, math_magic_3 % 1000);
670 if (usrptr->m_verbose) {
673 g_ThbaseInternal->thread_switch_count,
674 g_ThbaseInternal->idle_thread->irq_preemption_count,
675 (chrcnt < 2) ?
" " :
"\n");
680 Kprintf((chrcnt < 8) ?
" " :
"\n");
692 (usrptr->m_barchart == 1) ? do_output_progress_bar_newline(math_magic_3) : do_output_progress_bar_carriageret(math_magic_3));
699 usrptr->m_start_stop_status = 0;
702static void do_stop_current_thcpuwatch()
704 if (!g_thcpuwatch_info.m_start_stop_status) {
707 g_thcpuwatch_info.m_start_stop_status = 2;
708 while (g_thcpuwatch_info.m_start_stop_status) {
713static void thwatch_cmd_handler(
char *cmdparam)
728 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
729 EndOfString = GetEndOfString(cmdparam_cur);
732 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
734 if (!strcmp(cmdparam_cur,
"-b"))
736 if (!strcmp(cmdparam_cur,
"-br"))
738 if (!strcmp(cmdparam_cur,
"-v"))
740 if (*cmdparam_cur !=
'-') {
742 integer_value = strtol(cmdparam_cur, 0, 10);
744 hex_value = do_parse_hex(cmdparam_cur);
747 do_stop_current_thcpuwatch();
751 if (hex_value < g_ThbaseInternal->thread_id) {
754 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
755 if (
thread->tag.id == hex_value)
759 fdprintf(g_tty9_fd,
"thread #%d not found \n", hex_value);
762 hex_value = MAKE_HANDLE(
thread);
764 g_thcpuwatch_info.m_barchart = is_flag_b_or_br;
765 g_thcpuwatch_info.m_sample_count = integer_value;
766 g_thcpuwatch_info.m_verbose = is_flag_v;
767 if (hex_value <= 0 || ReferThreadStatus(hex_value, &thstatus)) {
768 fdprintf(g_tty9_fd,
"thid:%x not found \n", hex_value);
769 }
else if (integer_value > 0) {
770 g_thcpuwatch_info.m_thread = (
struct thread *)HANDLE_PTR(hex_value);
771 fdprintf(g_tty9_fd,
"Thread %x time watching and print to ITTYK\n", hex_value);
772 StartThread(g_monitorThreadId, &g_thcpuwatch_info);
776static void cpuwatch_cmd_handler(
char *cmdparam)
787 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
788 EndOfString = GetEndOfString(cmdparam_cur);
791 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
793 if (!strcmp(cmdparam_cur,
"-b"))
795 if (!strcmp(cmdparam_cur,
"-br"))
797 if (!strcmp(cmdparam_cur,
"-v"))
799 if (*cmdparam_cur !=
'-')
800 int_value = strtol(cmdparam_cur, 0, 10);
802 do_stop_current_thcpuwatch();
804 g_thcpuwatch_info.m_barchart = is_flag_b_or_br;
805 g_thcpuwatch_info.m_sample_count = int_value;
806 g_thcpuwatch_info.m_verbose = is_flag_v;
807 g_thcpuwatch_info.m_thread = 0;
808 fdprintf(g_tty9_fd,
"CPU time watching and print to ITTYK\n");
809 StartThread(g_monitorThreadId, &g_thcpuwatch_info);
813static void rdlist_cmd_handler(
char *cmdparam)
825 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
826 EndOfString = GetEndOfString(cmdparam_cur);
829 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
831 if (!strcmp(cmdparam_cur,
"-v"))
833 if (!strcmp(cmdparam_cur,
"-i"))
836 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP WT WID WUC\n");
837 for (i = 1; i < (is_flag_i + 127); i += 1) {
838 if (list_empty(&g_ThbaseInternal->ready_queue[i])) {
841 list_for_each (
thread, &g_ThbaseInternal->ready_queue[i], queue) {
842 if (!ReferThreadStatus(MAKE_HANDLE(
thread), &thstatus))
843 DisplayThreadInformation(
thread, is_flag_v, 0);
848static void sllist_cmd_handler(
char *cmdparam)
857 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
858 EndOfString = GetEndOfString(cmdparam_cur);
861 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
863 if (!strcmp(cmdparam_cur,
"-v"))
866 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP WT WID WUC\n");
867 list_for_each (
thread, &g_ThbaseInternal->sleep_queue, queue) {
868 if (ReferThreadStatus(MAKE_HANDLE(
thread), &thstatus) < 0) {
869 fdprintf(g_tty9_fd,
"thid = %x not found \n", MAKE_HANDLE(
thread));
872 if (
thread != g_ThbaseInternal->idle_thread)
873 DisplayThreadInformation(
thread, is_flag_v, 0);
877static void dlist_print_thread_info(
struct thread *threadstruct,
int is_verbose)
881 "%3x %07x %08x %07x %.3s ",
882 threadstruct->tag.id,
883 MAKE_HANDLE(threadstruct),
885 threadstruct->option,
886 &g_th_status_short[3 * (
char)threadstruct->status]);
889 "%06x %06x %04x %06x %3d %3d %d\n",
891 threadstruct->stack_top,
892 threadstruct->stack_size,
894 (s16)threadstruct->priority,
895 (s16)threadstruct->init_priority,
896 threadstruct->wait_usecs);
898 char *module_name_from_addr;
900 module_name_from_addr = get_module_name_from_addr((
unsigned int)threadstruct->entry);
901 if (module_name_from_addr)
902 fdprintf(g_tty9_fd,
" Name=%s\n", module_name_from_addr);
904 if (threadstruct->saved_regs && threadstruct->status != 16)
907 " PC=%06x RA=%06x SP=%06x Context_addr/mask=%08x/%08x\n",
908 threadstruct->saved_regs->pc,
909 threadstruct->saved_regs->ra,
910 threadstruct->saved_regs->sp,
911 threadstruct->saved_regs,
912 threadstruct->saved_regs->unk);
916 for (i = 0; i < (threadstruct->stack_size / 4); i += 1) {
917 if (((u32 *)threadstruct->stack_top)[i] != 0xFFFFFFFF && ((u32 *)threadstruct->stack_top)[i] != 0x11111111)
920 fdprintf(g_tty9_fd,
" Free_Stack_Size=%06x\n", i * 4);
924static void dllist_cmd_handler(
char *cmdparam)
933 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
934 EndOfString = GetEndOfString(cmdparam_cur);
937 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
939 if (!strcmp(cmdparam_cur,
"-v"))
942 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP USEC\n");
943 list_for_each (
thread, &g_ThbaseInternal->delay_queue, queue) {
944 if (ReferThreadStatus(MAKE_HANDLE(
thread), &thstatus) < 0) {
945 fdprintf(g_tty9_fd,
"thid = %x not found \n", MAKE_HANDLE(
thread));
948 if (
thread != g_ThbaseInternal->idle_thread)
949 dlist_print_thread_info(
thread, is_flag_v);
953static void ShowSemList(
char *cmdparam)
966 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
967 EndOfString = GetEndOfString(cmdparam_cur);
970 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
972 if (!strcmp(cmdparam_cur,
"-v"))
974 if (!strcmp(cmdparam_cur,
"-w"))
977 if (list_empty(&g_ThbaseInternal->semaphore)) {
980 fdprintf(g_tty9_fd,
" SEMID ATTR OPTION iCnt cCnt mCnt waitThreads\n");
981 list_for_each (sema, &g_ThbaseInternal->semaphore, sema_list) {
982 if (ReferSemaStatus(MAKE_HANDLE(sema), &semastatus) < 0) {
985 if (semastatus.numWaitThreads > 0 || !is_flag_w_count) {
988 "%3x %07x %08x %08x %05d %5d %5d %5d\n",
996 semastatus.numWaitThreads);
998 if (semastatus.numWaitThreads > 0 && is_flag_w_count) {
999 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP\n");
1000 list_for_each_safe (waiter, &sema->event.waiters, queue) {
1001 ReferThreadStatus(MAKE_HANDLE(waiter), &thstatus);
1002 DisplayThreadInformation(waiter, is_flag_v_count, 1);
1008static void ShowEventFlagList(
char *cmdparam)
1011 int is_flag_v_count;
1012 int is_flag_w_count;
1019 is_flag_v_count = 0;
1020 is_flag_w_count = 0;
1021 for (cmdparam_cur = cmdparam; *cmdparam_cur; cmdparam_cur = EndOfString) {
1022 EndOfString = GetEndOfString(cmdparam_cur);
1025 EndOfString = RemoveLeadingWhitespaces(EndOfString + 1);
1027 if (!strcmp(cmdparam_cur,
"-v"))
1029 if (!strcmp(cmdparam_cur,
"-w"))
1032 if (list_empty(&g_ThbaseInternal->event_flag)) {
1035 fdprintf(g_tty9_fd,
" EVID ATTR OPTION iPattern cPattern waitThreads\n");
1036 list_for_each (evf, &g_ThbaseInternal->event_flag, evf_list) {
1037 if (ReferEventFlagStatus(MAKE_HANDLE(evf), &efstatus) < 0) {
1040 if (efstatus.
numThreads > 0 || !is_flag_w_count) {
1043 "%3x %07x %08x %08x %08x %08x %5d\n",
1052 if (efstatus.
numThreads > 0 && is_flag_w_count) {
1053 fdprintf(g_tty9_fd,
" THID ATTR OPTION STS ENTRY STACK SSIZE GP CP IP\n");
1054 list_for_each_safe (waiter, &evf->event.waiters, queue) {
1055 ReferThreadStatus(MAKE_HANDLE(waiter), &thstatus);
1056 DisplayThreadInformation(waiter, is_flag_v_count, 1);
1062static void ShowMsgbxList()
1067 if (list_empty(&g_ThbaseInternal->mbox)) {
1070 fdprintf(g_tty9_fd,
" MSGID ATTR OPTION waitThreads messages\n");
1071 list_for_each (mbx, &g_ThbaseInternal->mbox, mbox_list) {
1072 ReferMbxStatus(MAKE_HANDLE(mbx), &mbxstatus);
1075 "%3x %07x %08x %08x %5d %5d\n",
1080 mbxstatus.numWaitThreads,
1081 mbxstatus.numMessage);
1085static void ShowVplList()
1090 if (list_empty(&g_ThbaseInternal->vpool)) {
1093 fdprintf(g_tty9_fd,
" VPLID ATTR OPTION Size Free waitThreads\n");
1094 list_for_each (vpl, &g_ThbaseInternal->vpool, vpl_list) {
1095 ReferVplStatus(MAKE_HANDLE(vpl), &vplstatus);
1098 "%3x %07x %08x %08x %06x %06x %5d\n",
1105 vplstatus.numWaitThreads);
1109static void ShowFplList()
1114 if (list_empty(&g_ThbaseInternal->fpool)) {
1117 fdprintf(g_tty9_fd,
" FPLID ATTR OPTION BlkSIze AllBlocks FreeSize waitThreads\n");
1118 list_for_each (fpl, &g_ThbaseInternal->fpool, fpl_list) {
1119 ReferFplStatus(MAKE_HANDLE(fpl), &fplstatus);
1122 "%3x %07x %08x %08x %06x %06x %06x %5d\n",
1127 fplstatus.blockSize,
1128 fplstatus.numBlocks,
1129 fplstatus.freeBlocks,
1130 fplstatus.numWaitThreads);
1134static void DumpReadyQueue()
1140 fdprintf(g_tty9_fd,
"ready queue ----\n");
1141 for (i = 0; i < 127; i += 1) {
1142 if (list_empty(&g_ThbaseInternal->ready_queue[i])) {
1146 fdprintf(g_tty9_fd,
" %3d:%x ", i, &g_ThbaseInternal->ready_queue[i]);
1147 list_for_each (
thread, &g_ThbaseInternal->ready_queue[i], queue)
1148 fdprintf(g_tty9_fd,
" %d(%x) ",
thread->tag.id,
thread);
1149 fdprintf(g_tty9_fd,
"\n");
1152 fdprintf(g_tty9_fd,
"ready map = ");
1153 for (i = 0; i < 4; i += 1) {
1154 fdprintf(g_tty9_fd,
"%08x ", g_ThbaseInternal->queue_map[i]);
1156 fdprintf(g_tty9_fd,
"\n");
1159static void ToggleThswdisp(
const char *cmdparam)
1161 if (!strcmp(cmdparam,
"on"))
1162 g_ThbaseInternal->debug_flags |= 1u;
1163 if (!strcmp(cmdparam,
"off"))
1164 g_ThbaseInternal->debug_flags &= ~1u;
1165 if (isdigit(*cmdparam))
1166 g_ThbaseInternal->debug_flags = strtol(cmdparam, 0, 10);
1169static void ToggleThLED(
const char *cmdparam)
1171 if (!strcmp(cmdparam,
"on"))
1172 g_ThbaseInternal->debug_flags |= 0x20u;
1173 if (!strcmp(cmdparam,
"off"))
1174 g_ThbaseInternal->debug_flags &= ~0x20u;
1175 if (isdigit(*cmdparam))
1176 g_ThbaseInternal->debug_flags = strtol(cmdparam, 0, 10);
1179static void ToggleWarnDisp(
const char *cmdparam)
1181 if (!strcmp(cmdparam,
"on"))
1182 g_ThbaseInternal->debug_flags |= 8u;
1183 if (!strcmp(cmdparam,
"off"))
1184 g_ThbaseInternal->debug_flags &= ~8u;
1185 if (isdigit(*cmdparam))
1186 g_ThbaseInternal->debug_flags = strtol(cmdparam, 0, 10);
1189static void DumpThreads()
1193 fdprintf(g_tty9_fd,
"===============================\n");
1194 fdprintf(g_tty9_fd,
"tcb list ----\n");
1195 list_for_each (
thread, &g_ThbaseInternal->thread_list, thread_list) {
1198 " %d: tcb=%x sts=0x%x pri=%d ",
1203 if ((
char)
thread->status == 4)
1204 fdprintf(g_tty9_fd,
"wType = %x:%x ", (s16)
thread->wait_type,
thread->wait_usecs);
1205 if ((
char)
thread->status != 1)
1206 fdprintf(g_tty9_fd,
"contx=%x sp=%x",
thread->saved_regs,
thread->saved_regs->sp);
1207 fdprintf(g_tty9_fd,
"\n");
1209 fdprintf(g_tty9_fd,
"sleep list ----\n");
1210 if (list_empty(&g_ThbaseInternal->sleep_queue)) {
1213 fdprintf(g_tty9_fd,
" %x: ", &g_ThbaseInternal->sleep_queue);
1214 list_for_each (
thread, &g_ThbaseInternal->sleep_queue, queue) {
1215 fdprintf(g_tty9_fd,
" %d(%x) ",
thread->tag.id,
thread);
1217 fdprintf(g_tty9_fd,
"\n");
1220static void ShowAlarmList()
1231 if (!list_empty(&g_ThbaseInternal->alarm)) {
1232 list_for_each (
alarm, &g_ThbaseInternal->alarm, alarm_list) {
1237 list_for_each (
alarm, &g_ThbaseInternal->alarm, alarm_list) {
1238 alarm_ents[i].m_alarm_id =
alarm->tag.id;
1239 alarm_ents[i].m_target.lo =
alarm->target;
1240 alarm_ents[i].m_target.hi =
alarm->target >> 32;
1241 alarm_ents[i].m_cb =
alarm->cb;
1242 alarm_ents[i].m_userptr =
alarm->userptr;
1247 fdprintf(g_tty9_fd,
" NUM TIME HANDLER COMMON\n");
1248 for (i = 0; i < alarm_cnt; i += 1) {
1251 "%3x %08x_%08x %06x, %08x\n",
1252 alarm_ents[i].m_alarm_id,
1253 alarm_ents[i].m_target.hi,
1254 alarm_ents[i].m_target.lo,
1256 alarm_ents[i].m_userptr);
1260static void freemem_cmd_handler()
1262 u32 TotalFreeMemSize;
1264 TotalFreeMemSize = QueryTotalFreeMemSize();
1267 "IOP system memory 0x%x(%d) byte free, Max free block size 0x%x\n",
1270 QueryMaxFreeMemSize());
1273static void ThmonMainThread(
void *arg)
1282 fdprintf(g_tty9_fd,
"\n\n========= simple thread monitor program =========\n");
1283 fdprintf(g_tty9_fd,
"help command is 'help'\n");
1284 g_PreviousCommand[0] = 0;
1286 fdprintf(g_tty9_fd,
" > ");
1287 if (!fdgets(g_CommandBuffer, g_tty9_fd))
1289 PrintMessage(g_CommandBuffer);
1290 if (!strlen(g_CommandBuffer))
1292 if (!strcmp(g_CommandBuffer,
"/")) {
1293 cmdbufsrc = g_PreviousCommand;
1294 cmdbufdst = g_CommandBuffer;
1296 cmdbufsrc = g_CommandBuffer;
1297 cmdbufdst = g_PreviousCommand;
1299 strcpy(cmdbufdst, cmdbufsrc);
1300 cmdbuf_trim = RemoveLeadingWhitespaces(g_CommandBuffer);
1301 cmdparam = RemoveLeadingWhitespaces(GetEndOfString(cmdbuf_trim));
1302 if (*cmdbuf_trim ==
'#')
1304 if (!strncmp(
"quit", cmdbuf_trim, strlen(cmdbuf_trim)))
1306 else if (!strncmp(
"?", cmdbuf_trim, strlen(cmdbuf_trim)) || !strncmp(
"help", cmdbuf_trim, strlen(cmdbuf_trim)))
1307 DisplayHelpMessage();
1308 else if (!strncmp(
"thlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1309 thlist_cmd_handler(cmdparam);
1310 else if (!strncmp(
"rdlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1311 rdlist_cmd_handler(cmdparam);
1312 else if (!strncmp(
"sllist", cmdbuf_trim, strlen(cmdbuf_trim)))
1313 sllist_cmd_handler(cmdparam);
1314 else if (!strncmp(
"dllist", cmdbuf_trim, strlen(cmdbuf_trim)))
1315 dllist_cmd_handler(cmdparam);
1316 else if (!strncmp(
"rtlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1317 rtlist_cmd_handler(cmdparam);
1318 else if (!strncmp(
"semlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1319 ShowSemList(cmdparam);
1320 else if (!strncmp(
"evlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1321 ShowEventFlagList(cmdparam);
1322 else if (!strncmp(
"msglist", cmdbuf_trim, strlen(cmdbuf_trim)))
1324 else if (!strncmp(
"vpllist", cmdbuf_trim, strlen(cmdbuf_trim)))
1326 else if (!strncmp(
"fpllist", cmdbuf_trim, strlen(cmdbuf_trim)))
1328 else if (!strncmp(
"almlist", cmdbuf_trim, strlen(cmdbuf_trim)))
1330 else if (!strncmp(
"freemem", cmdbuf_trim, strlen(cmdbuf_trim)))
1331 freemem_cmd_handler();
1332 else if (!strncmp(
"cpuwatch", cmdbuf_trim, strlen(cmdbuf_trim)))
1333 cpuwatch_cmd_handler(cmdparam);
1334 else if (!strncmp(
"thwatch", cmdbuf_trim, strlen(cmdbuf_trim)))
1335 thwatch_cmd_handler(cmdparam);
1336 else if (!strncmp(
"thswdisp", cmdbuf_trim, strlen(cmdbuf_trim)))
1337 ToggleThswdisp(cmdparam);
1338 else if (!strncmp(
"thled", cmdbuf_trim, strlen(cmdbuf_trim)))
1339 ToggleThLED(cmdparam);
1340 else if (!strncmp(
"warndisp", cmdbuf_trim, strlen(cmdbuf_trim)))
1341 ToggleWarnDisp(cmdparam);
1342 else if (!strncmp(
"dumpthread", cmdbuf_trim, strlen(cmdbuf_trim)))
1344 else if (!strncmp(
"dumpready", cmdbuf_trim, strlen(cmdbuf_trim)))
1347 fdprintf(g_tty9_fd,
" ?? \n");
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)