From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio@vger.kernel.org, stefani@seibold.net, ggao@invensense.com
Subject: Re: [PATCH] iio:kfifo_buf Take advantage of the fixed record size used in IIO
Date: Tue, 22 May 2012 07:56:55 +0200 [thread overview]
Message-ID: <4FBB2AA7.2020009@metafoo.de> (raw)
In-Reply-To: <1337426045-6890-1-git-send-email-jic23@kernel.org>
On 05/19/2012 01:14 PM, Jonathan Cameron wrote:
> By bypassing the standard macros for setting up the kfifo we can
> take advantage of the fixed record size implementation without
> having to have a type to pass in (from which the size of an element
> is normally established).
>
> In IIO we have variable 'scans' as our records in which any element
> can be present or not. They do not however vary when we are
> actually filling or reading from the buffer. Thus we have a fixed
> record size whenever we are actually running. As setup and tear
> down are not in the fast path we can take the overhead of reinitializing
> the kfifo every time.
>
> This is an RFC as
>
> a) I'm far from sure I got it right.
> b) There is probably a better way of doing it!
>
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
> Note this is against current staging-next.
>
>
> drivers/iio/kfifo_buf.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
> index 6bf9d05..74b1cb8 100644
> --- a/drivers/iio/kfifo_buf.c
> +++ b/drivers/iio/kfifo_buf.c
> @@ -22,7 +22,8 @@ static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,
> return -EINVAL;
>
> __iio_update_buffer(&buf->buffer, bytes_per_datum, length);
> - return kfifo_alloc(&buf->kf, bytes_per_datum*length, GFP_KERNEL);
> + return __kfifo_alloc((struct __kfifo *)&buf->kf, length,
> + bytes_per_datum, GFP_KERNEL);
> }
>
> static int iio_request_update_kfifo(struct iio_buffer *r)
> @@ -94,7 +95,7 @@ static int iio_store_to_kfifo(struct iio_buffer *r,
> {
> int ret;
> struct iio_kfifo *kf = iio_to_kfifo(r);
> - ret = kfifo_in(&kf->kf, data, r->bytes_per_datum);
> + ret = __kfifo_in((struct __kfifo *)&kf->kf, data, r->bytes_per_datum);
The last parameter has to be 1 now, since we want to store one record. And I
think we can still use kfifo_in(...), the macro magic take care of doing the
right thing.
> if (ret != r->bytes_per_datum)
> return -EBUSY;
> return 0;
> @@ -110,7 +111,7 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
> return -EINVAL;
>
> n = rounddown(n, r->bytes_per_datum);
> - ret = kfifo_to_user(&kf->kf, buf, n, &copied);
Same here. n needs to be n / r->bytes_per_datum
> + ret = __kfifo_to_user((struct __kfifo *)&kf->kf, buf, n, &copied);
>
> return copied;
> }
next prev parent reply other threads:[~2012-05-22 5:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-19 11:14 [PATCH] iio:kfifo_buf Take advantage of the fixed record size used in IIO Jonathan Cameron
2012-05-19 11:15 ` Jonathan Cameron
2012-05-22 5:56 ` Lars-Peter Clausen [this message]
2012-05-26 10:10 ` Jonathan Cameron
2012-05-28 21:06 ` Jonathan Cameron
-- strict thread matches above, loose matches on Subject: below --
2012-05-28 21:12 Jonathan Cameron
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=4FBB2AA7.2020009@metafoo.de \
--to=lars@metafoo.de \
--cc=ggao@invensense.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=stefani@seibold.net \
/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).