LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Theodore Tso <tytso@mit.edu>
To: Willy Tarreau <w@1wt.eu>
Cc: Joe Barr <joe@pjprimer.com>,
Linux Kernel mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Serial port blues
Date: Sun, 21 Jan 2007 00:54:56 -0500 [thread overview]
Message-ID: <20070121055456.GC27422@thunk.org> (raw)
In-Reply-To: <20070120173644.GY24090@1wt.eu>
On Sat, Jan 20, 2007 at 06:36:44PM +0100, Willy Tarreau wrote:
> On Fri, Jan 19, 2007 at 03:37:34PM -0600, Joe Barr wrote:
> >
> > I'm forwarding this post by the author of a great little program for
> > digital amateur radio on Linux, because I'm curious whether or not the
> > problem he is seeing can be resolved outside the kernel.
>
> At least, I see one wrong claim and one unexplored track in his report.
> The wrong claim : the serial port can only be controled by the kernel.
> It is totally wrong for true serial ports. If he does not want to use
> ioctl(), then he can directly program the I/O port.
There's more wrong with his claim than just that. Another wrong claim
is that it's caused by the Linux kernel not treating ioctl requests
with high priority. Of course that's nonsense. It might be the case
if we were using brain-damaged messaging-passing approach like what
Andrew Tenenbaum is proposing with Minix 3.1, but in Linux, the serial
port DTR/CTS lines are toggled as soon as the userspace executes the
ioctl.
The real issue is when does the userspace program get a chance to run.
He's using the select() system call, which only guarantees accuracy up
to the granularity of the system clock. Given that he's reporting a
jitter of between 0 and 4ms, I'm guessing that he's running with a
system clock tick of 250HZ (since 1/250 == 4ms ).
So if he wants accuracy greater than that, there are a couple of
things he can do. One is to recompile his kernel with HZ=1000. That
will give him accuracy up to 1ms or so. If he needs better than 1ms
granularity, there are two options. One is use sched_setscheduler()
to enable posix soft-realtime, and then calibrate a busy loop. This
will of course burn power and completely busy out one CPU, so if he
needs to run CW continuously this probably isn't a great solution. On
an SMP system it might work, although it is obviously a huge kludge.
The other choice would be to install Ingo's -rt patches (see
http://rt.wiki.kernel.org for more information), and then use the
Posix high-resolution timer API's (i.e., timer_create, et. al). Make
sure you enable CONFIG_HIGH_RES_TIMERS after you apply the patch. It
would also be a good idea to set a real-time scheduling priority for
the application, to make sure that when the timer goes off, the
process doesn't get preempted by some background cron job.
> Now he must be careful about avoiding busy loops in the rest of the
> program, or he will have to use the reset button.
An easy way of dealing with this is to have an sshd running
an alternative port running at a nice high priority (say, prio 95 or
so). That way, if you screw up, you can always login remotely and
kill the offending program.
There is also a RT Watchdog program which can be found on
rt.wiki.kernel.org which can be used to recover from runaway real-time
processes without needing to hit the reset button.
Finally, please feel free to direct your amateur radio friend to the
linux-rt-users@vger.kernel.org. There are plenty of folks there who
would be very happy to help him out.
73 de Ted, N1ZSU
next prev parent reply other threads:[~2007-01-21 6:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-19 21:37 Joe Barr
2007-01-20 17:36 ` Willy Tarreau
2007-01-21 5:54 ` Theodore Tso [this message]
2007-01-21 7:05 ` Willy Tarreau
2007-01-21 14:04 ` Johannes Stezenbach
[not found] ` <2f4958ff0701210650w4fa0138di6a5026de8a0823dc@mail.gmail.com>
2007-01-21 14:58 ` Willy Tarreau
[not found] ` <2f4958ff0701210710r743c1821n9af23a050c847a7@mail.gmail.com>
2007-01-21 18:52 ` Theodore Tso
[not found] ` <2f4958ff0701211105p4f7e3e86x8aaf14566112bc51@mail.gmail.com>
2007-01-21 19:30 ` Theodore Tso
2007-01-21 18:55 ` Theodore Tso
2007-01-21 5:09 ` Stuart MacDonald
2007-01-21 7:07 ` H. Peter Anvin
2007-01-21 7:08 ` H. Peter Anvin
2007-01-21 20:44 ` H. Peter Anvin
2007-01-22 11:37 ` Alan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070121055456.GC27422@thunk.org \
--to=tytso@mit.edu \
--cc=joe@pjprimer.com \
--cc=linux-kernel@vger.kernel.org \
--cc=w@1wt.eu \
--subject='Re: Serial port blues' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).