All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Garzik <jeff@garzik.org>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-ide@vger.kernel.org
Subject: Re: [RFC PATCH] libata: PIO via bounce buffer
Date: Fri, 29 Feb 2008 19:26:40 -0500	[thread overview]
Message-ID: <47C8A2C0.7070005@garzik.org> (raw)
In-Reply-To: <20080229135106.4fcf19e3@core>

Alan Cox wrote:
> First cut at the problem. Given the lack of certainty about worst case
> buffer size (1 page I suspect) this uses kmalloc. We could hang a buffer
> off the device (or I think in fact the port as we never do overlapped PIO)

> +static void ata_bounce_pio_xfer(struct ata_device *dev, struct page *page, 
> +				  unsigned int offset, int count, int do_write)
> +{
> +	struct ata_port *ap = dev->link->ap;
> +	unsigned long flags;
> +	unsigned char *zebedee;
> +	unsigned char *buf;
> +
> +	BUG_ON(offset + count > PAGE_SIZE);
> +
> +	zebedee = kmalloc(count, GFP_ATOMIC);
> +	if (likely(zebedee)) {
> +		if (do_write) {
> +			local_irq_save(flags);
> +			buf = kmap_atomic(page, KM_IRQ0);
> +			memcpy(zebedee, buf + offset, count);
> +			kunmap_atomic(buf, KM_IRQ0);
> +			local_irq_restore(flags);
> +		}
> +		/* do the actual data transfer */
> +		ap->ops->data_xfer(dev, zebedee, count, do_write);
> +		if (!do_write) {
> +			/* Read so bounce  data upwards */
> +			local_irq_save(flags);
> +			buf = kmap_atomic(page, KM_IRQ0);
> +			memcpy(buf + offset, zebedee, count);
> +			kunmap_atomic(buf, KM_IRQ0);
> +			local_irq_restore(flags);
> +		}
> +		kfree(zebedee);
> +	} else {
> +		/* Only used when we are out of buffer memory
> +		   as a last last resort */
> +		local_irq_save(flags);
> +		buf = kmap_atomic(page, KM_IRQ0);
> +		/* do the actual data transfer */
> +		ap->ops->data_xfer(dev, buf + offset, count, do_write);
> +		kunmap_atomic(buf, KM_IRQ0);
> +		local_irq_restore(flags);
> +	}


Pretty good first cut, though I think you can dramatically reduce the 
allocations:

Create a per-cpu var during libata module init, a pointer to a kmalloc'd 
structure:

	struct ata_bb {
		unsigned long len;
		u8 buffer[0];
	};

Initialize to an 8K buffer (or other size, or NULL, if you prefer).

Inside ata_bounce_pio_xfer(), get the buffer for your CPU.  If NULL or 
too small, allocate new buffer, otherwise re-use existing buffer.

This method makes the common case _not_ allocate anything, which should 
be obviously more efficient.

	Jeff



  reply	other threads:[~2008-03-01  0:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-29 13:51 [RFC PATCH] libata: PIO via bounce buffer Alan Cox
2008-03-01  0:26 ` Jeff Garzik [this message]
2008-03-01 16:38   ` Alan Cox

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=47C8A2C0.7070005@garzik.org \
    --to=jeff@garzik.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-ide@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.