Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1562258
  • 博文数量: 77
  • 博客积分: 1205
  • 博客等级: 少尉
  • 技术积分: 4476
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-22 21:48
文章分类
文章存档

2018年(1)

2017年(1)

2015年(1)

2014年(18)

2013年(12)

2012年(44)

分类: LINUX

2013-03-15 14:39:54

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.
阅读(2760) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~