Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched: Provide idle_rq() helper

A fix for the dl_server 'requires' idle_cpu() usage, which made me
note that it and available_idle_cpu() are extern function calls.

And while idle_cpu() is used outside of kernel/sched/,
available_idle_cpu() is not.

This makes it hard to make idle_cpu() an inline helper, so provide
idle_rq() and implement idle_cpu() and available_idle_cpu() using
that.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

+23 -30
-1
include/linux/sched.h
··· 1874 1874 extern int can_nice(const struct task_struct *p, const int nice); 1875 1875 extern int task_curr(const struct task_struct *p); 1876 1876 extern int idle_cpu(int cpu); 1877 - extern int available_idle_cpu(int cpu); 1878 1877 extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *); 1879 1878 extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *); 1880 1879 extern void sched_set_fifo(struct task_struct *p);
+22
kernel/sched/sched.h
··· 1364 1364 #define cpu_curr(cpu) (cpu_rq(cpu)->curr) 1365 1365 #define raw_rq() raw_cpu_ptr(&runqueues) 1366 1366 1367 + static inline bool idle_rq(struct rq *rq) 1368 + { 1369 + return rq->curr == rq->idle && !rq->nr_running && !rq->ttwu_pending; 1370 + } 1371 + 1372 + /** 1373 + * available_idle_cpu - is a given CPU idle for enqueuing work. 1374 + * @cpu: the CPU in question. 1375 + * 1376 + * Return: 1 if the CPU is currently idle. 0 otherwise. 1377 + */ 1378 + static inline bool available_idle_cpu(int cpu) 1379 + { 1380 + if (!idle_rq(cpu_rq(cpu))) 1381 + return 0; 1382 + 1383 + if (vcpu_is_preempted(cpu)) 1384 + return 0; 1385 + 1386 + return 1; 1387 + } 1388 + 1367 1389 #ifdef CONFIG_SCHED_PROXY_EXEC 1368 1390 static inline void rq_set_donor(struct rq *rq, struct task_struct *t) 1369 1391 {
+1 -29
kernel/sched/syscalls.c
··· 180 180 */ 181 181 int idle_cpu(int cpu) 182 182 { 183 - struct rq *rq = cpu_rq(cpu); 184 - 185 - if (rq->curr != rq->idle) 186 - return 0; 187 - 188 - if (rq->nr_running) 189 - return 0; 190 - 191 - if (rq->ttwu_pending) 192 - return 0; 193 - 194 - return 1; 195 - } 196 - 197 - /** 198 - * available_idle_cpu - is a given CPU idle for enqueuing work. 199 - * @cpu: the CPU in question. 200 - * 201 - * Return: 1 if the CPU is currently idle. 0 otherwise. 202 - */ 203 - int available_idle_cpu(int cpu) 204 - { 205 - if (!idle_cpu(cpu)) 206 - return 0; 207 - 208 - if (vcpu_is_preempted(cpu)) 209 - return 0; 210 - 211 - return 1; 183 + return idle_rq(cpu_rq(cpu)); 212 184 } 213 185 214 186 /**