-1

Is there another solution for non canonical serial mode to poll each char?

Related kernel source code: https://elixir.bootlin.com/linux/latest/C/ident/n_tty_read VTIME processing

I think I need a kernel patch to get a VTIME from tty termios API lower than 100ms, in order to decrease gap inter char. Microsoft Windows Serial API is able to configure until 1ms but not Linux... ReadIntervalTimeout : https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_timeouts

Is there someone to advise me? I only have to use non-canonical mode (without framing protocol, no ascii, no break). And VMIN is still null because message length are ramdom.

VTIME Timeout in deciseconds for noncanonical read (TIME). https://man7.org/linux/man-pages/man3/termios.3.html

A Linux kernel patch is necessary...

K. PANIK
  • 15
  • 1
  • 6
  • You can set MIN=1, VTIME=0 and simulate any timeout with poll() (millisecond resolution) or with epoll_wait() (up to nanosecond theoretical resolution). Or use it together with timer fd with nanosecond theoretical resolution. – dimich Aug 25 '23 at 20:28
  • Does this answer your question: [How to set Inter-Byte Delay Timeout to milliseconds?](https://stackoverflow.com/questions/58898980/how-to-set-inter-byte-delay-timeout-to-milliseconds) – sawdust Aug 25 '23 at 21:54
  • Are you asking an XY question, and the real issue is: [Parsing time-delimited UART data](https://stackoverflow.com/questions/27152926/parsing-time-delimited-uart-data)? – sawdust Aug 25 '23 at 23:18
  • Is it better to divide HZ with a greater value ? Or to set global HZ to a smaller value ? – K. PANIK Aug 26 '23 at 07:53
  • Dimich, if I poll one char each time with userspace software and annoying context switch, when do I consider end of frame? After a couple of empty poll? EOF shall be trigger with a gap inter byte paramater VTIME. Termios have to implement a smaller VTIME, review the resolution. – K. PANIK Aug 27 '23 at 08:13
  • Sawdust, thanks but I use a preempt rt Linux with bottom-half of the UART driver and the kworker threads for termios with high priority and low latency. The trouble is a termios limitation from kernel source code to wakeup userspace, schedule_timeout() shall be smaller than 100ms. Moreover, with non-canonical protocol only raw data are transmitted. There is not additionnal frame protocole to trigger end of frame. – K. PANIK Aug 27 '23 at 09:19
  • Sawdust, have a look to my answer, follow the link unix : https://unix.stackexchange.com/questions/754975/how-to-patch-kernel-to-reduce-vtime-gap-for-uart-termios-api/755035#755035 – K. PANIK Aug 27 '23 at 11:05
  • @K.PANIK For example, poll() will wait until tty fd became readable or timeout occured. If fd became readable - read available bytes, append them to a buffer. If timeout occured - it's your EOF. – dimich Aug 27 '23 at 12:27
  • Yes but at EOF, the only way to get aware is timeout, then fd is ready. And so, in this case, VTIME timeout is too long. In fact, polling each char is too heavy for system because userspace doesn't know how many char to read for a full message. Why polling each char while driver DMA is applied. There is a waste somewhere. – K. PANIK Aug 27 '23 at 13:11
  • @K.PANIK No, poll()/epoll_wait() will return as soon as at least one character is available. While data is available, no timeout occures. – dimich Aug 27 '23 at 13:15
  • I can use poll or I can use VMIN=1 too... – K. PANIK Aug 27 '23 at 13:18
  • In my proposed solution you have to use poll() AND VMIN=1. Simplified pseudocode: `timeout = -1; while (1) { if (poll(fd, timeout) == 1) { read(fd); apped_to_buffer(); timeout = interchar_timeout; } else { /* timeout */ timeout = -1; handle_eof(); } }` – dimich Aug 27 '23 at 13:25
  • I can use poll or I can use VMIN=1 too... I can't imagine a solution for dozen uart processing by polling from userspace. Processus will consume so much CPU for wasting polling time and context switches... Windows is doing better ! I am embarassed. – K. PANIK Aug 27 '23 at 13:26
  • @K.PANIK poll() is not a busy loop polling. It doesn't consume CPU while waiting for event. – dimich Aug 27 '23 at 13:28
  • Of course, no consomption while waiting. – K. PANIK Aug 27 '23 at 13:43
  • Please read [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/q/285551/354577). Instead, format code as a [code block]. The easiest way to do this is to paste the code as text directly into your question, then select it and click the code block button. – ChrisGPT was on strike Aug 27 '23 at 16:05
  • Sorry but unable to copy paste source code from elixir bootlin with Chrome on Android. User interface always keeps blocked. – K. PANIK Aug 27 '23 at 18:58
  • @dimich, to sum It up, It needs one poll syscall for each char to pull a full message and then a systematic final inter gap timeout (with a task preemption) to detect EOF. At this time, I am convinced that is a poor and uncommon solution to process simple uart without latency. How will you explain that to student ? – K. PANIK Aug 27 '23 at 19:08
  • @K.PANIK What exact problem are you trying to solve? Have you measured performance? Have you compared it to windows? Is this a bottle neck in your application? – dimich Aug 27 '23 at 20:29
  • Thank you dimich. I will compare tracing and performance your solution to a VTIME patch. – K. PANIK Aug 27 '23 at 22:07

0 Answers0