linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
To: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-rpi-kernel
	<linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [PATCH 5/6] spi: bcm2835: add polling mode for transfers below 30us
Date: Mon, 30 Mar 2015 21:28:38 -0600	[thread overview]
Message-ID: <551A1466.2020706@wwwdotorg.org> (raw)
In-Reply-To: <808DC596-35BB-4A08-8CF4-DFAB6294636E-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>

On 03/29/2015 08:03 AM, Martin Sperl wrote:
> In cases of short transfer times the CPU is spending lots of time
> in the interrupt handler and scheduler to reschedule the worker thread.
> 
> Measurements show that we have times where it takes 29.32us to between
> the last clock change and the time that the worker-thread is running again
> returning from wait_for_completion_timeout().
> 
> During this time the interrupt-handler is running calling complete()
> and then also the scheduler is rescheduling the worker thread.
> 
> This time can vary depending on how much of the code is still in
> CPU-caches, when there is a burst of spi transfers the subsequent delays
> are in the order of 25us, so the value of 30us seems reasonable.
> 
> With polling the whole transfer of 4 bytes at 10MHz finishes after 6.16us
> (CS down to up) with the real transfer (clock running) taking 3.56us.
> So the efficiency has much improved and also freeing CPU cycles, reducing
> interrupts and context switches.
> 
> Because of the above 30us seems to be a reasonable limit for polling.

> diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c

> @@ -204,6 +207,37 @@ static int bcm2835_spi_transfer_one(struct spi_master *master,

> +	spi_used_hz = (cdiv) ? (clk_hz / cdiv) : (clk_hz / 65536);

"(cdiv)" can be just "cdiv".

> +	/* check if we shall run in polling mode */
> +	xfer_time_us = tfr->len * 9 * 1000000 / spi_used_hz;

Why 9 not 8; presumably thats bits per byte, and IIRC SPI doesn't have
anything like I2C's ack bit per byte?

> +	if (xfer_time_us <= BCM2835_SPI_POLLING_LIMIT_US) {
...
> +			if ((bs->rx_len) && (time_after(jiffies, timeout))) {

There are many extra brackets here too.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-03-31  3:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-29 14:03 [PATCH 5/6] spi: bcm2835: add polling mode for transfers below 30us Martin Sperl
     [not found] ` <808DC596-35BB-4A08-8CF4-DFAB6294636E-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-03-30  4:27   ` Mark Brown
2015-03-31  3:28   ` Stephen Warren [this message]
     [not found]     ` <551A1466.2020706-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-03-31  6:00       ` Martin Sperl
     [not found]         ` <E15DA84C-4EF9-432A-ADA9-81789EAE379F-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-04-01 15:14           ` Stephen Warren

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=551A1466.2020706@wwwdotorg.org \
    --to=swarren-3lzwwm7+weoh9zmkesr00q@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org \
    --cc=lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.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).