Chinaunix首页 | 论坛 | 博客
  • 博客访问: 998307
  • 博文数量: 442
  • 博客积分: 1146
  • 博客等级: 少尉
  • 技术积分: 1604
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-04 12:52
个人简介

123

文章分类

全部博文(442)

文章存档

2017年(3)

2016年(15)

2015年(132)

2014年(52)

2013年(101)

2012年(110)

2011年(29)

分类: LINUX

2015-05-28 15:07:37

Question:

If we have a pointer to a task structure, ie, struct task_struct *p, how to know if p is running on a cpu or not (suppose we're talking about the SMP system)?

Answer from the kernel (lot's of useful infomation in this good knowledge base -- kernel source code) --

The 1st function:
static inline unsigned int task_cpu(const struct task_struct *p)
{
    return task_thread_info(p)->cpu;
}

We can guess if a process (eg, the p above) has been scheduled to a cpu, then task_thread_info(p)->cpu will be the record that on which cpu the task (p) is running, so if a task is running on a cpu, we can know the index of cpu that the task is running by "task_thread_info(p)->cpu",  OK, we got the cpu number to which the task p is bound. Now we can check the cpu running task queue using cpu_curr(cpu), cpu_curr(cpu) will get the running queue belong to the cpu specified by the parameter. As a followed step, current running queue (q for short) will provide the clue what the current running task via q->curr, so :

if p = cpu_curr(task_cpu(p), then p is the current running task on the cpu.
阅读(1114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~