From: Bhupinder Thakur <bhupinder.thakur@linaro.org>
To: Dave Martin <Dave.Martin@arm.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Julien Grall <julien.grall@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Andre Przywara <andre.przywara@arm.com>
Subject: Re: [PATCH 27/27 v10] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt
Date: Wed, 11 Oct 2017 13:28:44 +0530 [thread overview]
Message-ID: <CACtJ1JSaViDzgAgmWzr8bX3AfDL2aEAZ6PMKEFX3=ccOFPBp_w@mail.gmail.com> (raw)
In-Reply-To: <20170926143816.GB17434@e103592.cambridge.arm.com>
Hi Dave,
On 26 September 2017 at 20:08, Dave Martin <Dave.Martin@arm.com> wrote:
> On Fri, Sep 22, 2017 at 01:53:26PM +0530, Bhupinder Thakur wrote:
>> This patch fixes the issue observed when pl011 patches were tested on
>> the junos hardware by Andre/Julien. It was observed that when large output is
>> generated such as on running 'find /', output was getting truncated intermittently
>> due to OUT ring buffer getting full.
>>
>> This issue was due to the fact that the SBSA UART driver expects that when
>> a TX interrupt is asserted then the FIFO queue should be atleast half empty and
>> that it can write N bytes in the FIFO, where N is half the FIFO queue size, without
>> the bytes getting dropped due to FIFO getting full.
>>
>> The SBSA UART emulation logic was asserting the TX interrupt as soon as
>> any space became available in the FIFO and the SBSA UART driver tried to write
>> more data (upto 16 bytes) in the FIFO expecting that there is enough space
>> available leading to dropped bytes.
>>
>> The SBSA spec [1] does not specify when the TX interrupt should be asserted
>> or de-asserted. Due to lack of clarity on the expected behavior, it is
>> assumed for now that TX interrupt should be asserted only when the FIFO goes
>> half empty.
>>
>> TBD: Once the SBSA spec is updated with the expected behavior, the implementation
>> will be modified to align with the spec requirement.
>>
>> [1] http://infocenter.arm.com/help/topic/com.arm.doc.ddi0183f/DDI0183.pdf
>>
>> Signed-off-by: Bhupinder Thakur <bhupinder.thakur@linaro.org>
>> ---
>> CC: Julien Grall <julien.grall@arm.com>
>> CC: Andre Przywara <andre.przywara@arm.com>
>> CC: Stefano Stabellini <sstabellini@kernel.org>
>
> (Taking a quick look at this because I remember fighthing with FIFO
> behaviour issues when hacking the Linux driver -- but beware, I'm not a
> Xen guy...)
>
>
> Should this patch be flattened into the patches is fixes? Keeping
> known-wrong code in the series does not help reviewers (but maybe it's
> the Xen way).
>
>> Changes since v8:
>> - Used variables fifo_level/fifo_threshold for more clarity
>> - Added a new macro SBSA_UART_FIFO_SIZE instead of using a magic number
>
> What's sizeof(intf->in), sizeof(intf->out)?
>
> For correct operation, you assume that the total ring buffer size is >=
> SBSA_UART_FIFO_SIZE, but nothing enforces this. If the xencons ring
> buffer size is set elsewhere and can't be chosen by a driver, you may at
> least add a build-time assert to check that it's big enough.
>
I will add an assert to check this condition.
> [...]
>
>> @@ -144,28 +148,41 @@ static void vpl011_write_data(struct domain *d, uint8_t data)
>
> [...]
>
>> + * Clear the TXI bit if the fifo level exceeds fifo_size/2 mark which
>> + * is the trigger level for asserting/de-assterting the TX interrupt.
>> */
>> - vpl011->uartfr |= BUSY;
>> + fifo_threshold = sizeof (intf->out) - SBSA_UART_FIFO_SIZE/2;
>> +
>> + if ( fifo_level <= fifo_threshold )
>> + vpl011->uartris |= TXI;
>> + else
>> + vpl011->uartris &= ~TXI;
>> }
>> + else
>> + gprintk(XENLOG_ERR, "vpl011: Unexpected OUT ring buffer full\n");
>>
>> vpl011->uartfr &= ~TXFE;
>>
>
> [...]
>
>> @@ -353,37 +370,51 @@ static void vpl011_data_avail(struct domain *d)
>>
>> smp_rmb();
>>
>> - in_ring_qsize = xencons_queued(in_prod,
>> + in_fifo_level = xencons_queued(in_prod,
>> in_cons,
>> sizeof(intf->in));
>>
>> - out_ring_qsize = xencons_queued(out_prod,
>> + out_fifo_level = xencons_queued(out_prod,
>> out_cons,
>> sizeof(intf->out));
>>
>> /* Update the uart rx state if the buffer is not empty. */
>> - if ( in_ring_qsize != 0 )
>> + if ( in_fifo_level != 0 )
>> {
>> vpl011->uartfr &= ~RXFE;
>> - if ( in_ring_qsize == sizeof(intf->in) )
>> +
>> + if ( in_fifo_level == sizeof(intf->in) )
>> vpl011->uartfr |= RXFF;
>> +
>> vpl011->uartris |= RXI;
>> }
>>
>> /* Update the uart tx state if the buffer is not full. */
>> - if ( out_ring_qsize != sizeof(intf->out) )
>> + if ( out_fifo_level != sizeof(intf->out) )
>> {
>> + unsigned int out_fifo_threshold;
>> +
>> vpl011->uartfr &= ~TXFF;
>> - vpl011->uartris |= TXI;
>>
>> /*
>> - * Clear the BUSY bit as soon as space becomes available
>> + * Clear the BUSY bit as soon as space becomes avaliable
>> * so that the SBSA UART driver can start writing more data
>> * without any further delay.
>> */
>> vpl011->uartfr &= ~BUSY;
>>
>> - if ( out_ring_qsize == 0 )
>> + /*
>> + * Set the TXI bit only when there is space for fifo_size/2 bytes which
>> + * is the trigger level for asserting/de-assterting the TX interrupt.
>> + */
>> + out_fifo_threshold = sizeof(intf->out) - SBSA_UART_FIFO_SIZE/2;
>> +
>> + if ( out_fifo_level <= out_fifo_threshold )
>> + vpl011->uartris |= TXI;
>> + else
>> + vpl011->uartris &= ~TXI;
>
> Should this logic be factored out? You do the same thing in
> _write_data().
I will add a common function to set the TXI bit.
>
> Also, is there a reason why you implement the trigger threshold logic on
> the TX side only? It looks inconsistent now.
I did try with RX FIFO threshold also but it seems the current pl011
driver does not
poll on the RX FIFO and just waits for the RX interrupt trigger to
start processing the RX data.
This makes RX very slow and if the RX FIFO is not filled sufficiently,
it does not read data further.
>
> I think a real PL011 implements the trigger logic in exactly the same
> way for RX and TX (except for swapping >= for <= in the threshold
> comparison).
>
>
> It doesn't look like the Linux pl011 driver relies on a correctly
> implemented RX trigger level today, but it may have done in the past --
> I did some hacking in this area at some point, but can't remember the
> details now.
>
The current pl011 driver
> Asserting RXI whenever the RX FIFO is nonempty would result in excessive
> interrupts if you are streaming the data from a slow source (such as a
> real UART) and pushing the chars one by one to the emulated UART: the
> guest would take an IRQ on each char rather than waiting until the RX
> FIFO is half-full.
>
I agree it is an overhead. This may be an issue with the driver which
is solely depending on the RX
interrupt. I think it should switch to polling if there are no
interrupts received recently.
Regards,
Bhupinder
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-10-11 7:58 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-22 8:22 [PATCH 00/27 v10] SBSA UART emulation support in Xen Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 01/27 v10] xen/arm: vpl011: Define common ring buffer helper functions in console.h Bhupinder Thakur
2017-09-22 22:44 ` Stefano Stabellini
2017-09-23 13:25 ` Julien Grall
2017-09-23 15:09 ` Bhupinder Thakur
2017-09-25 7:51 ` Jan Beulich
2017-09-25 7:49 ` Jan Beulich
2017-09-25 23:08 ` Bhupinder Thakur
2017-09-26 7:15 ` Jan Beulich
2017-09-26 8:16 ` Bhupinder Thakur
2017-09-26 11:41 ` Jan Beulich
2017-09-22 8:23 ` [PATCH 02/27 v10] xen/arm: vpl011: Add SBSA UART emulation in Xen Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 03/27 v10] xen/arm: vpl011: Allocate a new GFN in the toolstack for vuart Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 04/27 v10] xen/arm: vpl011: Add support for vuart in libxl Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 05/27 v10] xen/arm: vpl011: Rearrange xen header includes in alphabetical order in domctl.c Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 06/27 v10] xen/arm: vpl011: Add a new domctl API to initialize vpl011 Bhupinder Thakur
2017-09-22 8:28 ` Jan Beulich
2017-09-22 21:46 ` Stefano Stabellini
2017-09-25 8:38 ` Wei Liu
2017-09-22 8:23 ` [PATCH 07/27 v10] xen/arm: vpl011: Add a new vuart node in the xenstore Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 08/27 v10] xen/arm: vpl011: Modify xenconsole to define and use a new console structure Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 09/27 v10] xen/arm: vpl011: Rename the console structure field conspath to xspath Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 10/27 v10] xen/arm: vpl011: Modify xenconsole functions to take console structure as input Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 11/27 v10] xen/arm: vpl011: Add a new console_init function in xenconsole Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 12/27 v10] xen/arm: vpl011: Add a new buffer_available " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 13/27 v10] xen/arm: vpl011: Add a new maybe_add_console_evtchn_fd " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 14/27 v10] xen/arm: vpl011: Add a new maybe_add_console_tty_fd " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 15/27 v10] xen/arm: vpl011: Add a new console_evtchn_unmask " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 16/27 v10] xen/arm: vpl011: Add a new handle_console_ring " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 17/27 v10] xen/arm: vpl011: Add a new handle_console_tty " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 18/27 v10] xen/arm: vpl011: Add a new console_cleanup " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 19/27 v10] xen/arm: vpl011: Add a new console_open_log " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 20/27 v10] xen/arm: vpl011: Add a new console_close_evtchn " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 21/27 v10] xen/arm: vpl011: Add support for multiple consoles " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 22/27 v10] xen/arm: vpl011: Add support for vuart console " Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 23/27 v10] xen/arm: vpl011: Add a new vuart console type to xenconsole client Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 24/27 v10] xen/arm: vpl011: Add a pl011 uart DT node in the guest device tree Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 25/27 v10] xen/arm: vpl011: Update documentation for vuart console support Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 26/27 v10] xen/arm: vpl011: Fix the slow early console SBSA UART output Bhupinder Thakur
2017-09-22 8:23 ` [PATCH 27/27 v10] xen/arm: vpl011: Correct the logic for asserting/de-asserting SBSA UART TX interrupt Bhupinder Thakur
2017-09-26 14:38 ` Dave Martin
2017-09-26 15:50 ` Julien Grall
2017-09-26 16:09 ` Dave Martin
2017-10-11 7:58 ` Bhupinder Thakur [this message]
2017-10-11 10:08 ` Dave Martin
2017-10-11 13:51 ` Bhupinder Thakur
2017-10-11 19:18 ` Dave Martin
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='CACtJ1JSaViDzgAgmWzr8bX3AfDL2aEAZ6PMKEFX3=ccOFPBp_w@mail.gmail.com' \
--to=bhupinder.thakur@linaro.org \
--cc=Dave.Martin@arm.com \
--cc=andre.przywara@arm.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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).