阻塞从 RS232 串行端口接收的线程唤醒所需的最长时间是多少?

What's the longest time that a thread, which is blocking on receiving from an RS232 serial port, can take to wake up?

假设我将进程设置为尽可能高的优先级并且没有交换...

从 RS232 串行端口接收数据时阻塞的线程唤醒所需的最长时间是多少?

我想知道线程是否会在 UART 中断到达内核后的几微秒内被唤醒,或者它是否必须等待 CPU.

上的下一个 100 毫秒时间片

What's the longest time that a thread, which is blocking on receiving from an RS232 serial port, can take to wake up?

根据模式(例如规范),进程可能会永远等待(例如等待 EOL 字符)。


I want to know whether the thread will be woken within microseconds of the UART interrupt hitting the kernel, or

线路上的帧结束(即停止位)是更好(即一致)的参考点。

"UART 中断命中内核" 考虑到可以推迟中断生成和处理,这是一个糟糕的参考点。
UART FIFO 可能不会为每个 character/byte.
生成中断 中断控制器对挂起的中断进行优先级排序,而 UART 很少被分配高优先级。
软件可以禁用关键区域的中断。


whether it will have to wait for the next 100ms timeslice on a CPU.

最高优先级的可运行进程在系统调用完成后获得控制权。
参考:Linux Kernel Development: Preemption and Context Switching:

Consequently, whenever the kernel is preparing to return to user-space, either 
on return from an interrupt or after a system call, the value of need_resched 
is checked. If it is set, the scheduler is invoked to select a new (more fit) 
process to execute.

I'm looking to minimise Linux serial latency between the received stop bit and the start bit of the reply from a high-priority userspace thread.

我怀疑这才是你真正想要的。
串行终端的配置对于最小化此类延迟至关重要,例如研究 ASYNC_LOW_LATENCY 序列标志。
但是 Linux 内核的配置可以进一步 improve/minimize 这种延迟,例如this developer reports 幅度从毫秒减少到只有 ~100 微秒。


I'm only familiar with serial interfaces on ATMEGA and STM32 microcontrollers ...

然后一定要复习Linuxserial drivers.