sched_taffinity如何在Linux内核中工作

更新时间:2023-06-14 03:51:33 阅读: 评论:0

sched_taffinity如何在Linux内核中⼯作为开头的成语接龙
Abstract
质量整改通知单
Sometimes, we may want to migrate one process/thread to one specific CPU for some specific purpo. In the Unix/ , you may choo sched_taffinity to finish this job. This article will help you to understand how sched_taffinity (or other APIs like pthread_taffinity_np in ur-) works internal Linux kernel.
抽象
有时,出于某些特定⽬的,我们可能希望将⼀个进程/线程迁移到⼀个特定的CPU。 在Unix / ,您可以选择sched_taffinity完成此⼯作。 本⽂将帮助您了解sched_taffinity(或⽤户其他API,如pthread_taffinity_np)如何在内部Linux内核中⼯作。
Details
细节相声词
SYSCALL_DEFINE3(sched_taffinity, pid_t, pid, unsigned int, len, unsigned long __ur *, ur_mask_ptr)
-- sched_taffinity(pid_t pid, const struct cpumask *in_mask)
--- __t_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask, bool check)
---- stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
----- migration_cpu_stop(void *data)
------ __migrate_task(struct rq *rq, struct task_struct *p, int dest_cpu)
------- move_queued_task(struct rq *rq, struct task_struct *p, int new_cpu)
-------- enqueue_task(struct rq *rq, struct task_struct *p, int flags)
--------- returns the new run queue of destination CPU
Above character steps give a workflow of how sched_taffinity works (how it migrates one process/thread from the run queue of source CPU to the run queue of destination CPU). Let’s analyze them in details (Note that this article is discussing about how sched_taffinity works inside the Linux Kernel 4.7.4 and other versions may have a little differences).
上⾯的字符步骤提供了sched_taffinity如何⼯作的⼯作流程(它如何将⼀个进程/线程从源CPU的运⾏队列迁移到⽬标CPU的运⾏队列)。 让我们对其进⾏详细分析(请注意,本⽂正在讨论sched_taffinity在Linux Kernel 4.7.4内的⼯作⽅式,其他版本可能会有⼀些不同)。
Obviously, we can find that sched_taffinity is a system call in Linux System. Sched_taffinity gets the process ID we
want to migrate and the destination CPU mask bits we want to migrate to. Then, it calls __t_cpus_allowed_ptr to do some checking works before migration. In __t_cpus_allowed_ptr, it changes the affinity of the process/thread and then calls the most important function "stop_one_cpu" to do the migration. However, before this, it checks whether the process/thread is running (or is going to run, TASK_WAKING). If true, the stop_one_cpu triggers. If not true, check whether the
process/thread is on the run queue of source CPU, if true, the CPU which executes sched_taffinity just migrates the process/thread from the run queue of source CPU to the run queue of destination CPU directly.
显然,我们可以发现sched_taffinity是Linux系统中的系统调⽤。 Sched_taffinity获取我们要迁移的进程ID和我们要迁移到的⽬标CPU掩码位。 然后,它在迁移之前调⽤__t_cpus_allowed_ptr进⾏
空气能10大品牌⼀些检查。 在__t_cpus_allowed_ptr ,它更改进程/线程的亲和⼒,然后调⽤最重要的函数“ stop_one_cpu”进⾏迁移。 但是,在此之前,它将检查进程/线程是否正在运⾏(或将要运
qq红包怎么发
⾏,TASK_WAKING)。 如果为true,则stop_one_cpu触发。 如果不是,则检查进程/线程是否在源CPU的运⾏队列中;如果为true,则执⾏sched_taffinity的CPU会将进程/线程从源CPU的运⾏队列直接迁移到⽬标CPU的运⾏队列。
In stop_one_cpu, it invokes migration_cpu_stop on the CPU of the process/thread we want to migrate with high priority. In migration_cpu_stop, it calls __migrate_task to test whether the affinity of the process/thread has been changed correctly previously and then, it calls move_queued_task to move the process/thread from the old run queue. At last, in
职工养老保险查询
move_queued_task function, it calls enqueue_task to move the process/thread to the new CPU’s run queue. Up to here, stop_one_cpu function returns and the migration is done.
在stop_one_cpu中,它在我们要⾼优先级迁移的进程/线程的CPU上调⽤migration_cpu_stop。 在migration_cpu_stop中,它调
⽤__migrate_task来测试进程/线程的亲和性先前是否已正确更改,然后,它调⽤move_queued_task
将进程/线程从旧的运⾏队列中移出。最后,在move_queued_task函数中,它调⽤enqueue_task将进程/线程移⾄新CPU的运⾏队列。 到此为⽌,stop_one_cpu函数将返回并完成迁移。
Conclusion
云南财经大学排名In a word, the sched_taffinity does following jobs internal Linux Kernel.
向死而生英文
1, Check the status of migrated process.
2, If it is in the running/task_waking status, let the source CPU of this process/thread to do migration.
3, If it is in the run queue of source CPU, let the CPU (executes sched_taffinity system call) to do migration. 4, If it is in the waiting queue, only change the affinity of the source CPU.
5, The migration is to move the process/thread from old run queue to the new run queue of destionation CPU.
结论
简⽽⾔之,sched_taffinity会执⾏以下内部Linux内核作业。
1,检查迁移过程的状态。
2,如果它处于运⾏中/任务唤醒状态,则让该进程/线程的源CPU进⾏迁移。
3,如果它在源CPU的运⾏队列中,请让CPU(执⾏sched_taffinity系统调⽤)进⾏迁移。
4,如果它在等待队列中,则仅更改源CPU的亲和⼒。
5,迁移是将进程/线程从⽬标CPU的旧运⾏队列移动到新运⾏队列。

本文发布于:2023-06-14 03:51:33,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/949677.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:进程   线程   迁移   队列   检查   是否   完成
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图