linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: buffer: Coalesce adjacent demux table entries
Date: Sun, 20 Jul 2014 16:14:41 +0100	[thread overview]
Message-ID: <53CBDCE1.6020403@kernel.org> (raw)
In-Reply-To: <1405612789-27964-4-git-send-email-lars@metafoo.de>

On 17/07/14 16:59, Lars-Peter Clausen wrote:
> When copying multiple multiple samples that are adjacent in both the source as
> well as the destination buffer, instead of creating a new demux table entry for
> each sample just increase the length of the previous entry by the size of the
> new sample. This makes the demuxing process slightly more efficient.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Nice.  Will hold these last two until the first one is in and we have decided
what to do about the second one.

J
> ---
>   drivers/iio/industrialio-buffer.c | 47 +++++++++++++++++++++++----------------
>   1 file changed, 28 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 5063703..779e5b3 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -942,13 +942,34 @@ int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)
>   }
>   EXPORT_SYMBOL_GPL(iio_push_to_buffers);
>
> +static int iio_buffer_add_demux(struct iio_buffer *buffer,
> +	struct iio_demux_table **p, unsigned int in_loc, unsigned int out_loc,
> +	unsigned int length)
> +{
> +
> +	if (*p && (*p)->from + (*p)->length == in_loc &&
> +		(*p)->to + (*p)->length == out_loc) {
> +		(*p)->length += length;
> +	} else {
> +		*p = kmalloc(sizeof(*p), GFP_KERNEL);
> +		if (*p == NULL)
> +			return -ENOMEM;
> +		(*p)->from = in_loc;
> +		(*p)->to = out_loc;
> +		(*p)->length = length;
> +		list_add_tail(&(*p)->l, &buffer->demux_list);
> +	}
> +
> +	return 0;
> +}
> +
>   static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>   				   struct iio_buffer *buffer)
>   {
>   	const struct iio_chan_spec *ch;
>   	int ret, in_ind = -1, out_ind, length;
>   	unsigned in_loc = 0, out_loc = 0;
> -	struct iio_demux_table *p;
> +	struct iio_demux_table *p = NULL;
>
>   	/* Clear out any old demux */
>   	iio_buffer_demux_free(buffer);
> @@ -981,11 +1002,6 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>   			/* Make sure we are aligned */
>   			in_loc = roundup(in_loc, length) + length;
>   		}
> -		p = kmalloc(sizeof(*p), GFP_KERNEL);
> -		if (p == NULL) {
> -			ret = -ENOMEM;
> -			goto error_clear_mux_table;
> -		}
>   		ch = iio_find_channel_from_si(indio_dev, in_ind);
>   		if (ch->scan_type.repeat > 1)
>   			length = ch->scan_type.storagebits / 8 *
> @@ -994,20 +1010,14 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>   			length = ch->scan_type.storagebits / 8;
>   		out_loc = roundup(out_loc, length);
>   		in_loc = roundup(in_loc, length);
> -		p->from = in_loc;
> -		p->to = out_loc;
> -		p->length = length;
> -		list_add_tail(&p->l, &buffer->demux_list);
> +		ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
> +		if (ret)
> +			goto error_clear_mux_table;
>   		out_loc += length;
>   		in_loc += length;
>   	}
>   	/* Relies on scan_timestamp being last */
>   	if (buffer->scan_timestamp) {
> -		p = kmalloc(sizeof(*p), GFP_KERNEL);
> -		if (p == NULL) {
> -			ret = -ENOMEM;
> -			goto error_clear_mux_table;
> -		}
>   		ch = iio_find_channel_from_si(indio_dev,
>   			indio_dev->scan_index_timestamp);
>   		if (ch->scan_type.repeat > 1)
> @@ -1017,10 +1027,9 @@ static int iio_buffer_update_demux(struct iio_dev *indio_dev,
>   			length = ch->scan_type.storagebits / 8;
>   		out_loc = roundup(out_loc, length);
>   		in_loc = roundup(in_loc, length);
> -		p->from = in_loc;
> -		p->to = out_loc;
> -		p->length = length;
> -		list_add_tail(&p->l, &buffer->demux_list);
> +		ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
> +		if (ret)
> +			goto error_clear_mux_table;
>   		out_loc += length;
>   		in_loc += length;
>   	}
>


  reply	other threads:[~2014-07-20 15:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 15:59 [PATCH 1/4] iio: buffer: Fix demux table creation Lars-Peter Clausen
2014-07-17 15:59 ` [PATCH 2/4] iio: buffer: Use roundup() instead of ALIGN() Lars-Peter Clausen
2014-07-20 15:08   ` Jonathan Cameron
2014-07-21  8:46     ` Lars-Peter Clausen
2014-07-27 16:45       ` Jonathan Cameron
2014-07-17 15:59 ` [PATCH 3/4] iio: buffer: Use roundup() instead of open-coding it Lars-Peter Clausen
2014-07-27 18:13   ` Jonathan Cameron
2014-07-17 15:59 ` [PATCH 4/4] iio: buffer: Coalesce adjacent demux table entries Lars-Peter Clausen
2014-07-20 15:14   ` Jonathan Cameron [this message]
2014-08-01 17:28     ` Jonathan Cameron
2014-07-20 14:57 ` [PATCH 1/4] iio: buffer: Fix demux table creation 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=53CBDCE1.6020403@kernel.org \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@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 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).