本文介绍了ARM 中的 Linux 进程上下文和 SVC 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据一些 Linux 书籍

As per some Linux books

为用户应用程序发出的系统调用提供服务的内核代码代表相应的应用进程运行,据说在进程上下文中执行.中断处理程序在中断中运行上下文.

现在 svc 和 irq 是两个例外.

Now svc and irq are two exceptions.

因此,当 linux 处理 svc 时,它处于进程上下文中,而处理 irq 时它处于中断上下文中.是这样映射的吗?

So when linux is handling svc it is in process context and while it is handling irq it is in interrupt context. Is that how it is mapped ?

只需对此进行一次修改

书中还提到,tasklets/softirqs 在中断上下文中运行,而工作队列在 Process 上下文中运行.那么这是否意味着 tasklet 将在 CPSR.mode = IRQ 中运行?

It is also mentioned in books that tasklets / softirqs run in interrupt context while workqueues run in Process context. So does it mean that tasklet would run in CPSR.mode = IRQ ?

推荐答案

如果我以正确的方式理解您的困惑:

If I understand your confusion in the right way:

由于 Linux 是一个功能强大的、抢占式的、复杂的操作系统,与裸机硬件相比,它可以更好地处理中断或服务软件陷阱等概念.

Since Linux is a capable, preemptive, complex operating system it has much finer handling of concepts such as handling of interrupts or serving software traps compared to bare metal hardware.

例如,当主管调用 (svc) 发生时,硬件切换到 SVC 模式,然后 Linux 处理这就像准备一些数据结构以进一步处理它,然后退出 SVC 模式,因此核心可以继续在用户模式下服务,从而使其成为可能遇到更多异常模式而不是阻止它们.

For example when a supervisor call (svc) happens hardware switches to SVC mode then Linux handles this as simple as preparing some data structures for handling it further then quits from SVC mode so core can continue serving in user mode thus making it possible to run into many more exception modes instead of blocking them.

IRQ 模式也是如此,Linux 在 IRQ 模式下处理最少.它准备数据结构,如发生 IRQ、应调用哪个处理程序等,然后立即退出 IRQ 模式以允许在该核心上发生更多.稍后一些其他内部内核线程可能会进一步处理该中断.由于硬件虽然相对简单,但运行速度非常快,因此中断处理与许多进程并行运行.

It is same for IRQ mode, Linux handles bare minimum in IRQ mode. It prepares data structures as which IRQ happened, which handler should be invoked etc then exits from IRQ mode immediately to allow more to happen on that core. Later on some other internal kernel thread may process that interrupt further. Since hardware while being relatively simple runs really fast thus handling of interrupt runs in parallel with many processes.

这种高级方法的缺点是它不能保证响应时间要求,或者它的开销在 MCU 等速度较慢的硬件上变得可见.

Downside of this advanced approach is it gives no guarantees on response time requirements or overhead of it becomes visible on slower hardware like MCUs.

所以 ARM 的异常模式为 Linux 提供了两件事:消息类型和优先级,并由硬件支持.

So ARM's exception modes provides two things for Linux: message type and priority backed with hardware support.

  • 消息类型是关于异常模式的,如果它是 SVC、IRQ、FIQ、DATA ABORT、UNDEFINED INSTRUCTION 等.所以当硬件运行到异常模式时,Linux 隐式地知道它正在处理什么.
  • 优先考虑提供功能强大且响应迅速的硬件,例如系统应该能够在处理一些不太重要的主管调用的同时确认中断.
  • 硬件支持是为了更轻松、更快捷地处理以上两种情况.例如,某些寄存器被存储,或者有一个额外的系统模式可以更轻松地处理可重入 IRQ.

这篇关于ARM 中的 Linux 进程上下文和 SVC 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:40