1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #include <stdio.h> 6 #include "k_api.h" 7 8 #if (RHINO_CONFIG_CPU_USAGE_STATS > 0) idle_count_set(idle_count_t value)9void idle_count_set(idle_count_t value) 10 { 11 CPSR_ALLOC(); 12 13 RHINO_CPU_INTRPT_DISABLE(); 14 15 g_idle_count[cpu_cur_get()] = value; 16 17 RHINO_CPU_INTRPT_ENABLE(); 18 } 19 idle_count_get(void)20idle_count_t idle_count_get(void) 21 { 22 CPSR_ALLOC(); 23 idle_count_t idle_count; 24 25 RHINO_CPU_INTRPT_DISABLE(); 26 27 idle_count = g_idle_count[cpu_cur_get()]; 28 29 RHINO_CPU_INTRPT_ENABLE(); 30 31 return idle_count; 32 } 33 #endif 34 idle_task(void * arg)35void idle_task(void *arg) 36 { 37 uint8_t cpu_num; 38 #if (RHINO_CONFIG_CPU_NUM > 1) 39 CPSR_ALLOC(); 40 klist_t *head; 41 ktask_t *task_del; 42 head = &g_task_del_head; 43 #endif 44 45 /* avoid warning */ 46 (void)arg; 47 cpu_num = cpu_cur_get(); 48 49 #if (RHINO_CONFIG_USER_HOOK > 0) 50 krhino_idle_pre_hook(); 51 #endif 52 53 while (RHINO_TRUE) { 54 #if (RHINO_CONFIG_CPU_NUM > 1) 55 RHINO_CPU_INTRPT_DISABLE(); 56 if (head->next != head) { 57 task_del = krhino_list_entry(head->next, ktask_t, task_del_item); 58 if (task_del->cur_exc == 0) { 59 klist_rm(&task_del->task_del_item); 60 if (task_del->mm_alloc_flag == K_OBJ_DYN_ALLOC) { 61 krhino_task_dyn_del(task_del); 62 } else { 63 krhino_task_del(task_del); 64 } 65 } 66 } 67 RHINO_CPU_INTRPT_ENABLE(); 68 #endif 69 /* type conversion is used to avoid compiler optimization */ 70 *(volatile idle_count_t *)(&g_idle_count[cpu_num]) = g_idle_count[cpu_num] + 1; 71 72 #if (RHINO_CONFIG_USER_HOOK > 0) 73 krhino_idle_hook(); 74 #endif 75 76 #if (RHINO_CONFIG_PWRMGMT > 0) 77 cpu_pwr_down(); 78 #endif 79 } 80 } 81 82