linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Dick Hollenbeck <dick@softplc.com>
Cc: linux-rt-users <linux-rt-users@vger.kernel.org>,
	Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: Re: 8250: set_ier(), clear_ier() and the concept of atomic console writes
Date: Fri, 20 Dec 2019 09:04:32 +0100	[thread overview]
Message-ID: <87woarjucv.fsf@linutronix.de> (raw)
In-Reply-To: <6e0f459a-d3dc-73cb-679f-6e86008048e1@softplc.com> (Dick Hollenbeck's message of "Thu, 19 Dec 2019 11:47:19 -0600")

(added printk maintainers CC)

Hi Dick,

On 2019-12-19, Dick Hollenbeck <dick@softplc.com> wrote:
> Let's talk serially:
>
> When using serial port debug printing, I have always dedicated a
> serial port for that.  In contrast, I have never tried to dovetail
> debug messages with actual other use of the serial port.  I don't
> understand the use case for changing to polled mode on the fly and
> then changing back.  I could not disconnect the normal use (interrupt
> driven) serial cable and then rapidly attach another serial cable
> intended for capturing debug messages in time to see a polled debug
> message interleaved with normal port usage.  So I think the use case
> contemplated by the current code is rare if non-existent.  And the
> result is that the code is super ugly.

In Linux there are consoles, which I dare say is a common use case for
UARTs (i.e debug messages interleaved with normal port usage is not rare
and definitely exists).

> In fact the serial port code is getting uglier by the month. Its
> gotten too complex and bulkier for weird apparent requirements.  When
> those corner case requirements are met such that concurrent use is
> mandated, the solution is always more complex than if requirements can
> be considered mutually exclusive.  (e.g. Who prints debug statements
> onto a serial cable that is already in use for a MODBUS driver?  How
> would you see those print statements easily?)
>
> But for now, I drill down to a specific complaint.
>
> I am looking at branch linux-5.2.y-rt-rebase, file:
>   drivers/tty/serial/8250/8250_core.c
>   commit 82dfc28946eacceae by John Ogness.
>
>
> Here is a belated partial patch review, and would be some of the
> reasons I could not accept this patch if I was in charge of mainline:

Thanks. I've been waiting nearly a year for feedback on these patches.

> 1) The mutual exclusion used in set_eir() clear_ier() feels like the
> big kernel lock all over again.  All ports using the same lock....

Yes, this is a problem. Only consoles should be using the cpu-lock. I
will address this.

> 2) Those functions are in an 8250 specific area but do not have 8250
> specific names, and they are public.

So you would like to see them renamed to:

   serial8250_set_ier()
   serial8250_clear_ier()
   serial8250_restore_ier()

> 3) The lock used in set_eir() & clear_eir() puts the CPU into atomic
> mode and then calls serial_port_out().  This assumes that we know
> everything there will ever be to know about serial_port_out(), even
> though it is an abstraction, with multiple implementations now and
> more in the future.

Mainline serial8250_console_write() calls serial_port_out() in atomic
context as well. So this is already a requirement of serial_port_out(),
at least for consoles. And if the cpu-lock is only taken for consoles
(see my response to #1), then this should not introduce any new issues.

> In fact, the future is now.  I have expanded serial_port_out() to use
> a spinlock because my UART is in an FPGA, along with other peripherals
> which share a common FPGA interface.  The spinlock gets remapped to
> rt_mutex.  When there is a collision on that mutex somebody must get
> suspended, and then I see the kernel report of:
>
> BUG: scheduling while atomic: irq/56-ttyS5/592/0x00000002

If your FPGA-UART should be a console, then it is a bug in your
implementation (for mainline as well). I don't know if non-consoles also
have atomic requirements.

> fpga_write() is where the rt_mutex is, aka spinlock in true source
> representation.  I can run a couple million bytes through that
> function for UARTs and other peripherals, but you know RT, if can go
> wrong it will, and it eventually does.
>
> The atomic mode was entered in the common (shared_by_all_ports) serial
> lock in console_atomic_lock().  This is because the author was trying
> to provide mutual exclusion between debug messages and actual normal
> serial port use.  I think that is fool's gold.  I have no problem with
> serial port debug messages, but I don't share a port when I am using
> them.

You don't use your debug serial port as a console. That is a wise
choice that unfortunately most people will not make.

> So the next question is, do I go to a raw spin lock in my
> fpga_write(), or do I try and fix the usage of console_atomic_lock()
> in set_eir() and clear_eir()?

- I will change the functions to only take the cpu-lock if the 8250 is a
  console.

- I will rename the functions to serial8250_*.

I believe that will address your main points. However, if you want to
use your FPGA-UART as a console, you will need to change to a raw spin
lock (even for mainline).

Thanks for the feedback.

John Ogness

  reply	other threads:[~2019-12-20  8:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-19 17:47 8250: set_ier(), clear_ier() and the concept of atomic console writes Dick Hollenbeck
2019-12-20  8:04 ` John Ogness [this message]
2019-12-20 13:53   ` Dick Hollenbeck
2020-01-09 12:29     ` John Ogness
2020-01-10 14:43       ` Dick Hollenbeck

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=87woarjucv.fsf@linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=dick@softplc.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).