线程调用系统调用时的上下文切换 [英] Context switching when a thread invokes a system call

查看:45
本文介绍了线程调用系统调用时的上下文切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程进程.如果我的一个线程调用像 gettimeofday() 这样的系统调用,内核是只切换上下文之外的线程来为系统调用提供服务,还是切换整个进程(和所有其他线程)断章取义?

I have a process with multiple threads. If one of my threads invokes a system call like gettimeofday(), does the kernel only switch that thread out of context to service the system call, or does it switch the entire process (and all other threads) out of context?

推荐答案

大多数系统调用可能涉及上下文切换(如果其他任务可运行)并将处理器的状态切换到内核模式.

Most system calls may involve a context switch (if other tasks are runnable) and switch the processor's state to kernel mode.

但是 gettimeofday(和例如 getpid())是不寻常的.对于最近的内核,他们使用 VDSO 来避免它(甚至避免 syscallsysenter 指令切换到内核模式).

But gettimeofday (and e.g. getpid()) are unusual. with recent kernels they use VDSO to avoid it (and even to avoid the syscall or sysenter instruction to switch to kernel mode).

这篇关于线程调用系统调用时的上下文切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆