Skip to content

Commit

Permalink
sched: Add function single_task_running to let a task check if it is …
Browse files Browse the repository at this point in the history
…the only task running on a cpu

This function will help an async task processing batched jobs from
workqueue decide if it wants to keep processing on more chunks of batched
work that can be delayed, or to accumulate more work for more efficient
batched processing later.

If no other tasks are running on the cpu, the batching process can take
advantgae of the available cpu cycles to a make decision to continue
processing the existing accumulated work to minimize delay,
otherwise it will yield.

Signed-off-by: Tim Chen <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
pdxChen authored and herbertx committed Aug 25, 2014
1 parent bbb9a7d commit 2ee507c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ extern int nr_threads;
DECLARE_PER_CPU(unsigned long, process_counts);
extern int nr_processes(void);
extern unsigned long nr_running(void);
extern bool single_task_running(void);
extern unsigned long nr_iowait(void);
extern unsigned long nr_iowait_cpu(int cpu);
extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load);
Expand Down
12 changes: 12 additions & 0 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,18 @@ unsigned long nr_running(void)
return sum;
}

/*
* Check if only the current task is running on the cpu.
*/
bool single_task_running(void)
{
if (cpu_rq(smp_processor_id())->nr_running == 1)
return true;
else
return false;
}
EXPORT_SYMBOL(single_task_running);

unsigned long long nr_context_switches(void)
{
int i;
Expand Down

0 comments on commit 2ee507c

Please sign in to comment.