更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
sched.c 文件参考

浏览源代码.

函数

int sched_get_priority_min (int policy)
 
int sched_get_priority_max (int policy)
 
int sched_setaffinity (pid_t pid, size_t set_size, const cpu_set_t *set)
 
int sched_getaffinity (pid_t pid, size_t set_size, cpu_set_t *set)
 
int __sched_cpucount (size_t set_size, const cpu_set_t *set)
 
int sched_yield ()
 任务让出CPU 更多...
 

函数说明

◆ __sched_cpucount()

int __sched_cpucount ( size_t  set_size,
const cpu_set_t *  set 
)

在文件 sched.c126 行定义.

127{
128 INT32 count = 0;
129 UINT32 i;
130
131 if ((set_size != sizeof(cpu_set_t)) || (set == NULL)) {
132 return 0;
133 }
134
135 for (i = 0; i < set_size / sizeof(__CPU_BITTYPE); i++) {
136 count += __builtin_popcountl(set->__bits[i]);
137 }
138
139 return count;
140}
signed int INT32
Definition: los_typedef.h:60
unsigned int UINT32
Definition: los_typedef.h:57

◆ sched_get_priority_max()

int sched_get_priority_max ( int  policy)

在文件 sched.c49 行定义.

50{
51 if (policy != SCHED_RR) {
52 errno = EINVAL;
53 return -1;
54 }
55
56 return OS_TASK_PRIORITY_LOWEST;
57}

◆ sched_get_priority_min()

int sched_get_priority_min ( int  policy)

在文件 sched.c39 行定义.

40{
41 if (policy != SCHED_RR) {
42 errno = EINVAL;
43 return -1;
44 }
45
46 return OS_TASK_PRIORITY_HIGHEST;
47}

◆ sched_getaffinity()

int sched_getaffinity ( pid_t  pid,
size_t  set_size,
cpu_set_t *  set 
)

在文件 sched.c95 行定义.

96{
97#ifdef LOSCFG_KERNEL_SMP
98 UINT32 taskID = (UINT32)pid;
99 UINT16 cpuAffiMask;
100
101 if ((set == NULL) || (set_size != sizeof(cpu_set_t))) {
102 errno = EINVAL;
103 return -1;
104 }
105
106 if (taskID == 0) {
107 taskID = LOS_CurTaskIDGet();
108 if (taskID == LOS_ERRNO_TSK_ID_INVALID) {
109 errno = EINVAL;
110 return -1;
111 }
112 }
113
114 cpuAffiMask = LOS_TaskCpuAffiGet(taskID);
115 if (cpuAffiMask == 0) {
116 errno = EINVAL;
117 return -1;
118 }
119
120 set->__bits[0] = cpuAffiMask;
121#endif
122
123 return 0;
124}
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
Obtain current running task ID.
Definition: los_task.c:331
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
查询任务被绑在哪个CPU上
Definition: los_task.c:1263
unsigned short UINT16
Definition: los_typedef.h:56
函数调用图:
这是这个函数的调用关系图:

◆ sched_setaffinity()

int sched_setaffinity ( pid_t  pid,
size_t  set_size,
const cpu_set_t *  set 
)

在文件 sched.c63 行定义.

64{
65#ifdef LOSCFG_KERNEL_SMP
66 UINT32 taskID = (UINT32)pid;
67 UINT32 ret;
68
69 if ((set == NULL) || (set_size != sizeof(cpu_set_t)) || (set->__bits[0] > LOSCFG_KERNEL_CPU_MASK)) {
70 errno = EINVAL;
71 return -1;
72 }
73
74 if (taskID == 0) {
75 taskID = LOS_CurTaskIDGet();
76 if (taskID == LOS_ERRNO_TSK_ID_INVALID) {
77 errno = EINVAL;
78 return -1;
79 }
80 }
81
82 ret = LOS_TaskCpuAffiSet(taskID, (UINT16)set->__bits[0]);
83 if (ret != LOS_OK) {
84 errno = map_errno(ret);
85 return -1;
86 }
87#endif
88
89 return 0;
90}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask)
Set the affinity mask of the task scheduling cpu.
Definition: los_task.c:1231
int map_errno(UINT32 err)
Definition: map_error.c:38
函数调用图:
这是这个函数的调用关系图:

◆ sched_yield()

int sched_yield ( )

任务让出CPU

在文件 sched.c142 行定义.

143{
145 return 0;
146}
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
Change the scheduling sequence of tasks with the same priority.
Definition: los_task.c:1115
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图: