1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #include "k_api.h"
6 
7 kstat_t g_sys_stat;
8 uint8_t g_idle_task_spawned[RHINO_CONFIG_CPU_NUM];
9 
10 runqueue_t g_ready_queue;
11 
12 /* schedule lock counter */
13 uint8_t g_sched_lock[RHINO_CONFIG_CPU_NUM];
14 uint8_t g_intrpt_nested_level[RHINO_CONFIG_CPU_NUM];
15 
16 /* highest pri task in ready queue */
17 ktask_t *g_preferred_ready_task[RHINO_CONFIG_CPU_NUM];
18 
19 /* current active task */
20 ktask_t *g_active_task[RHINO_CONFIG_CPU_NUM];
21 
22 /* global task ID */
23 uint32_t g_task_id;
24 
25 /* idle task attribute */
26 ktask_t      g_idle_task[RHINO_CONFIG_CPU_NUM];
27 idle_count_t g_idle_count[RHINO_CONFIG_CPU_NUM];
28 cpu_stack_t  g_idle_task_stack[RHINO_CONFIG_CPU_NUM][RHINO_CONFIG_IDLE_TASK_STACK_SIZE];
29 per_cpu_t    g_per_cpu[RHINO_CONFIG_CPU_NUM];
30 
31 /* tick attribute */
32 tick_t  g_tick_count;
33 klist_t g_tick_head;
34 
35 #if (RHINO_CONFIG_KOBJ_LIST > 0)
36 kobj_list_t g_kobj_list;
37 #endif
38 
39 #if (RHINO_CONFIG_TIMER > 0)
40 klist_t          g_timer_head;
41 tick_t           g_timer_count;
42 ktask_t          g_timer_task;
43 cpu_stack_t      g_timer_task_stack[RHINO_CONFIG_TIMER_TASK_STACK_SIZE];
44 kbuf_queue_t     g_timer_queue;
45 k_timer_queue_cb timer_queue_cb[RHINO_CONFIG_TIMER_MSG_NUM];
46 #endif
47 
48 #if (RHINO_CONFIG_SYS_STATS > 0)
49 hr_timer_t   g_sched_disable_time_start;
50 hr_timer_t   g_sched_disable_max_time;
51 hr_timer_t   g_cur_sched_disable_max_time;
52 uint16_t     g_intrpt_disable_times;
53 hr_timer_t   g_intrpt_disable_time_start;
54 hr_timer_t   g_intrpt_disable_max_time;
55 hr_timer_t   g_cur_intrpt_disable_max_time;
56 ctx_switch_t g_sys_ctx_switch_times;
57 #endif
58 
59 #if (RHINO_CONFIG_HW_COUNT > 0)
60 hr_timer_t g_sys_measure_waste;
61 #endif
62 
63 #if (RHINO_CONFIG_CPU_USAGE_STATS > 0)
64 ktask_t      g_cpu_usage_task;
65 cpu_stack_t  g_cpu_task_stack[RHINO_CONFIG_CPU_USAGE_TASK_STACK];
66 idle_count_t g_idle_count_max;
67 uint32_t     g_cpu_usage;
68 #endif
69 
70 #if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
71 ksem_t      g_res_sem;
72 klist_t     g_res_list;
73 ktask_t     g_dyn_task;
74 cpu_stack_t g_dyn_task_stack[RHINO_CONFIG_K_DYN_TASK_STACK];
75 #endif
76 
77 #if (RHINO_CONFIG_WORKQUEUE > 0)
78 klist_t      g_workqueue_list_head;
79 kmutex_t     g_workqueue_mutex;
80 kworkqueue_t g_workqueue_default;
81 cpu_stack_t  g_workqueue_stack[RHINO_CONFIG_WORKQUEUE_STACK_SIZE];
82 #endif
83 
84 #if (RHINO_CONFIG_MM_TLF > 0)
85 k_mm_head *g_kmm_head;
86 #endif
87 
88 #if (RHINO_CONFIG_CPU_NUM > 1)
89 kspinlock_t       g_sys_lock;
90 klist_t           g_task_del_head;
91 volatile uint64_t g_cpu_flag;
92 #endif
93 
94