From: Gregor Boirie <gregor.boirie@parrot.com>
To: Jonathan Cameron <jic23@kernel.org>, <linux-iio@vger.kernel.org>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Denis Ciocca <denis.ciocca@st.com>,
Linus Walleij <linus.walleij@linaro.org>,
Giuseppe Barba <giuseppe.barba@st.com>
Subject: Re: [RFC PATCH v1 4/9] iio:st_sensors: align on storagebits boundaries
Date: Mon, 2 May 2016 10:19:55 +0200 [thread overview]
Message-ID: <57270DAB.40401@parrot.com> (raw)
In-Reply-To: <974d01ea-326b-9a18-3a12-131eefcfbbf8@kernel.org>
On 05/01/2016 09:27 PM, Jonathan Cameron wrote:
> On 24/04/16 10:35, Jonathan Cameron wrote:
>> On 19/04/16 10:18, Gregor Boirie wrote:
>>> Triggered buffering memory accesses are not aligned on per channel
>>> storagebits boundaries. Fix this by reading each channel individually to
>>> ensure proper alignment.
>>> Note that this patch drops the earlier optimisation that packs multiple
>>> channels reading into a single data block transaction when their
>>> respective I2C register addresses are contiguous.
>> I wonder how much effect this change has on the read out rate and whether
>> repacking in software would be significantly quicker than the multiple
>> transfers...
> Thinking more on this I'm really not happy with this solution - may well
> kill data rates on some chips, to deal with this one unaligned case.
> Gregor, can you give repacking in software a go?
> Won't be that hard I think... Be cynical and just memove the data a byte if
> you hit a 24bit channel.
I'll give it a try, maybe next week as I'm quite busy right now.
>
> We could do this in the core demux but then we'd have to do something a bit
> clever with the reported buffer element type so it looked different to the driver
> and the buffer.
>
> Lars, IIRC you've messed with that corner of the code more recently than me.
> Do you think doing unaligned data smashing in the demux would be sensible?
>
> Can see we'd have to:
> * expand the 'does the demux have to do anything' case to catch
> this one (not too hard).
> * make the demux table builder force size constraints to power of two.
> * either work out the shift to export to userspace (nasty) or make sure we packed
> the data right depending on endianness so there wasn't any change to the shift.
> All this stuff occurs in the slow patch (table build) - it would look no worse
> than normal demux (some memcpys) in the fast path.
>
> Good idea or not? What do people think.
>
> I'm might mock this up in iio_dummy if I get bored and find out how bad it really is...
>
> Jonathan
>
>>> Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
>>> ---
>>> drivers/iio/common/st_sensors/st_sensors_buffer.c | 38 ++++++++++-------------
>>> drivers/iio/common/st_sensors/st_sensors_core.c | 2 +-
>>> 2 files changed, 18 insertions(+), 22 deletions(-)
>>>
>>> diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
>>> index c558985..a7f1ced 100644
>>> --- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
>>> +++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
>>> @@ -21,33 +21,29 @@
>>>
>>> #include <linux/iio/common/st_sensors.h>
>>>
>>> -
>>> int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
>>> {
>>> - int i, len;
>>> - int total = 0;
>>> + unsigned int cid;
>>> struct st_sensor_data *sdata = iio_priv(indio_dev);
>>> - unsigned int num_data_channels = sdata->num_data_channels;
>>> -
>>> - for (i = 0; i < num_data_channels; i++) {
>>> - unsigned int bytes_to_read;
>>> -
>>> - if (test_bit(i, indio_dev->active_scan_mask)) {
>>> - bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3;
>>> - len = sdata->tf->read_multiple_byte(&sdata->tb,
>>> - sdata->dev, indio_dev->channels[i].address,
>>> - bytes_to_read,
>>> - buf + total, sdata->multiread_bit);
>>> -
>>> - if (len < bytes_to_read)
>>> - return -EIO;
>>>
>>> - /* Advance the buffer pointer */
>>> - total += len;
>>> - }
>>> + for_each_set_bit(cid, indio_dev->active_scan_mask,
>>> + sdata->num_data_channels) {
>>> + const struct iio_chan_spec *chan = &indio_dev->channels[cid];
>>> + int sb = chan->scan_type.storagebits / 8;
>>> + int rb = chan->scan_type.realbits / 8;
>>> + int err;
>>> +
>>> + buf = PTR_ALIGN(buf, sb);
>>> + err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
>>> + chan->address, rb, buf,
>>> + sdata->multiread_bit);
>>> + if (err != rb)
>>> + return (err < 0) ? err : -EIO;
>>> +
>>> + buf += sb;
>>> }
>>>
>>> - return total;
>>> + return 0;
>>> }
>>> EXPORT_SYMBOL(st_sensors_get_buffer_element);
>>>
>>> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
>>> index dffe006..6901c7f 100644
>>> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
>>> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
>>> @@ -463,7 +463,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
>>> int err;
>>> u8 *outdata;
>>> struct st_sensor_data *sdata = iio_priv(indio_dev);
>>> - unsigned int byte_for_channel = ch->scan_type.storagebits >> 3;
>>> + unsigned int byte_for_channel = ch->scan_type.realbits >> 3;
>>>
>>> outdata = kmalloc(byte_for_channel, GFP_KERNEL);
>>> if (!outdata)
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
next prev parent reply other threads:[~2016-05-02 8:18 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-19 9:18 [RFC PATCH v1 0/9] iio:st_sensors: fixes and lps22hb pressure sensor Gregor Boirie
2016-04-19 9:18 ` [RFC PATCH v1 1/9] iio:st_pressure:initial lps22hb sensor support Gregor Boirie
2016-04-24 9:29 ` Jonathan Cameron
2016-05-01 19:28 ` Jonathan Cameron
2016-05-29 14:14 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 2/9] iio:st_pressure: fix sampling gains Gregor Boirie
2016-05-29 15:14 ` Jonathan Cameron
2016-05-30 8:17 ` Linus Walleij
2016-05-30 12:23 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 3/9] iio:st_pressure: lps22hb temperature support Gregor Boirie
2016-05-29 14:53 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 4/9] iio:st_sensors: align on storagebits boundaries Gregor Boirie
2016-04-24 9:35 ` Jonathan Cameron
2016-05-01 19:27 ` Jonathan Cameron
2016-05-02 8:19 ` Gregor Boirie [this message]
2016-05-14 17:54 ` Jonathan Cameron
2016-05-03 16:20 ` Crestez Dan Leonard
2016-04-19 9:18 ` [RFC PATCH v1 5/9] iio:st_pressure: align storagebits on power of 2 Gregor Boirie
2016-04-19 9:18 ` [RFC PATCH v1 6/9] iio:st_pressure: temperature triggered buffering Gregor Boirie
2016-04-24 10:58 ` Jonathan Cameron
2016-05-29 14:57 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 7/9] iio:st_sensors: unexport st_sensors_get_buffer_element Gregor Boirie
2016-05-29 14:59 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 8/9] iio:st_sensors: emulate SMBus block read if needed Gregor Boirie
2016-05-29 15:06 ` Jonathan Cameron
2016-04-19 9:18 ` [RFC PATCH v1 9/9] iio:st_sensors: fix power regulator usage Gregor Boirie
2016-04-24 11:01 ` Jonathan Cameron
2016-04-24 11:02 ` Jonathan Cameron
2016-05-29 15:10 ` Jonathan Cameron
2016-04-27 11:26 ` [RFC PATCH v1 0/9] iio:st_sensors: fixes and lps22hb pressure sensor Linus Walleij
2016-04-27 12:02 ` Linus Walleij
2016-04-27 13:08 ` Gregor Boirie
2016-04-28 7:47 ` Linus Walleij
2016-04-28 14:57 ` Gregor Boirie
2016-04-28 15:02 ` Gregor Boirie
2016-06-11 17:36 ` Jonathan Cameron
2016-06-15 10:58 ` Gregor Boirie
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=57270DAB.40401@parrot.com \
--to=gregor.boirie@parrot.com \
--cc=denis.ciocca@st.com \
--cc=giuseppe.barba@st.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.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).