Skip to content

Commit 1e0a2ba

Browse files
author
Peter Zijlstra
committed
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>
1 parent 64e6fa7 commit 1e0a2ba

3 files changed

Lines changed: 23 additions & 30 deletions

File tree

include/linux/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,6 @@ static inline int task_nice(const struct task_struct *p)
18741874
extern int can_nice(const struct task_struct *p, const int nice);
18751875
extern int task_curr(const struct task_struct *p);
18761876
extern int idle_cpu(int cpu);
1877-
extern int available_idle_cpu(int cpu);
18781877
extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *);
18791878
extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *);
18801879
extern void sched_set_fifo(struct task_struct *p);

kernel/sched/sched.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,28 @@ static inline u32 sched_rng(void)
13641364
#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
13651365
#define raw_rq() raw_cpu_ptr(&runqueues)
13661366

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+
13671389
#ifdef CONFIG_SCHED_PROXY_EXEC
13681390
static inline void rq_set_donor(struct rq *rq, struct task_struct *t)
13691391
{

kernel/sched/syscalls.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,35 +180,7 @@ int task_prio(const struct task_struct *p)
180180
*/
181181
int idle_cpu(int cpu)
182182
{
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));
212184
}
213185

214186
/**

0 commit comments

Comments
 (0)