From the kernel source code:
static void __sched notrace __schedule(bool preempt)
{
struct task_struct *prev, *next;
unsigned long *switch_count;
struct rq_flags rf;
struct rq *rq;
int cpu;
cpu = smp_processor_id();
rq = cpu_rq(cpu);
prev = rq->curr; // <=================(1)
.....
What is the difference between current and prev at the line (1) above?
Adding a printk() after that line:
static void __sched notrace __schedule(bool preempt)
{
struct task_struct *prev, *next;
unsigned long *switch_count;
struct rq_flags rf;
struct rq *rq;
int cpu;
cpu = smp_processor_id();
rq = cpu_rq(cpu);
prev = rq->curr;
//if(prev->pid != current->pid)
printk("the prev->pid =%d, The current = %d \n", prev->pid, current->pid); // <===========(2)
schedule_debug(prev);
if (sched_feat(HRTICK))
hrtick_clear(rq);
The resulting logs from (2) are:
[ 4184.164038] the prev->pid =0, The current = 0
[ 4184.165365] the prev->pid =12, The current = 12
[ 4186.008068] the prev->pid =0, The current = 0
[ 4186.009396] the prev->pid =30, The current = 30
[ 4188.008046] the prev->pid =0, The current = 0
[ 4188.009334] the prev->pid =30, The current = 30
[ 4188.164041] the prev->pid =0, The current = 0
[ 4188.165315] the prev->pid =12, The current = 12
[ 4190.008047] the prev->pid =0, The current = 0
[ 4190.009431] the prev->pid =30, The current = 30
The displays show that the result is the same.
- why not use
currentinstead of
cpu = smp_processor_id();
rq = cpu_rq(cpu);
prev = rq->curr;