Exemple #1
0
void dbg_console_thread(void* param)
{
	for (;;)
	{
		switch(console_getc(_dbg_console))
		{
		case 'h':
			printf("dbg console help\n\r");
			printf("h - this text\n\r");
#if (KERNEL_PROFILING)
			printf("m - memory usage statistics\n\r");
			printf("p - process list\n\r");
			printf("s - system stack usage\n\r");
#endif //KERNEL_PROFILING
			break;
#if (KERNEL_PROFILING)
		case 'm':
			mem_stat();
			break;
		case 'p':
			thread_stat();
			break;
		case 's':
			stack_stat();
			break;
#endif //KERNEL_PROFILING
		}
	}
}
Exemple #2
0
static void create_debug_thread(void)
{
    static pthread_t test_tid;
    char buf[80];
    char * newstack;

    errno = 0;
    if ((newstack = sbrk(1024)) == (void *)-1) {
        puts("Failed to create a stack\n");
        return;
    }

    pthread_attr_t attr = {
        .tpriority  = 0,
        .stackAddr  = newstack,
        .stackSize  = 1024
    };

    errno = 0;
    if (pthread_create(&test_tid, &attr, test_thread, 0)) {
        puts("Thread creation failed\n");
        return;
    }
    ksprintf(buf, sizeof(buf), "Thread created with id: %u\n", test_tid);
    puts(buf);
}

static void * test_thread(void * arg)
{
    while(1) {
        sleep(1);
        thread_stat();
    }
}

static void thread_stat(void)
{
    /* Print thread id & cpu mode */
    char buf[80];
    uint32_t mode, sp;
    pthread_t id = pthread_self();

    __asm__ volatile (
        "mrs     %0, cpsr\n\t"
        "mov     %1, sp"
        : "=r" (mode), "=r" (sp));
    ksprintf(buf, sizeof(buf), "My id: %u, sp: %u, my mode: %x\n", id, sp, mode);
    puts(buf);
}