All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: Re: [libgpiod][PATCH] core: Basic port to uAPI v2
Date: Wed, 14 Oct 2020 11:17:21 +0800	[thread overview]
Message-ID: <20201014031721.GA12685@sol> (raw)
In-Reply-To: <CAMRc=Md51g2-3PvQV_BA-qFJ=iDHqQELyMLx18yLR2LDQOCNHw@mail.gmail.com>

On Tue, Oct 13, 2020 at 09:08:44AM +0200, Bartosz Golaszewski wrote:
> On Fri, Oct 2, 2020 at 8:32 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > Port existing implementation from GPIO uAPI v1 to v2.
> > The libgpiod external interface remains unchanged, only the internal
> > implementation switches from uAPI v1 to v2.
> >
> > This is a minimal port - uAPI v2 features are only used where it
> > simplifies the implementation, specifically multiple events on a bulk can
> > now be handled directly by the kernel in a single v2 line request rather
> > than being emulated by multiple v1 event requests.
> >
> > Signed-off-by: Kent Gibson <warthog618@gmail.com>
> > ---
> 
> Hi Kent!
> 
> I just noticed that this broke the tests in Python and C++ bindings.
> Something to do with the RISING and FALLING edge values and how
> they're translated in the bindings, it seems. Let me know if you'd
> have time to take a look at it and see if it's something obvious.
> Otherwise I'll investigate that tomorrow.
> 

Lots of problems here, so where to start...

Firstly, I foolishly assumed that the coverage of the CXX and Python
tests was aimed at testing the binding, and that wouldn't provide
additional coverage to the core API to that tested by the C tests.
Not the case :(.

Most of the problems are due to the switch from an event request per
line to a single line request.  This breaks tests that assume an fd per
line and test the fds using poll.  As they are now the same, all line fds
in the bulk become ready to read at once, where previously it was only one.
These are only present in CXX and Python test cases :(.

I also misunderstood the use case for gpiod_line_event_wait_bulk(),
and used the event from the fd to determine the line (incorrectly as it
turns out).  As a consequence tests that then read the event from the
line fd find the subsequent event, or the wrong number of events.
Again, these are only present in CXX and Python tests :(.

And I misunderstood the offset passed in gpiod_line_bulk_get_line(),
using the chip offset not the bulk offset (there are too many damn
offsets here), so that only happened to work in the C tests as ALL lines
on the test chip were requested so the chip and bulk offsets match.
Changing the test to mismatch those offsets makes the C tests fail as
well :).
To fix that we'd need to peek into the file to get the event
offset without actually removing the event from the file, and be able to
find the line in a bulk based on chip offset.

Oh, and gpiod_line_bulk_get_line() doesn't do range checking, so will
happily return garbage if offset >= bulk.num_lines.  It happened to
return NULL in my testing, resulting an exception when trying to add the
line to the bulk.  But if it had returned something else...

So, in short, the switch to using one line request for all events in the
bulk is problematic with the exposing of the line fd, and the
current implementation of gpiod_line_event_wait_bulk() is broken.

Where to go from here depends on where you want to go with the API.
As mentioned yesterday, my preference would be for
gpiod_line_event_wait_bulk() to return the next event that occured on the
bulk rather than a bulk of lines with events.

And it needs to be made clear that the fd returned by
line.event_get_fd() applies to the bulk - assuming we switch to the one
request per bulk.

Cheers,
Kent.

  parent reply	other threads:[~2020-10-14  9:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02  6:31 [libgpiod][PATCH] core: Basic port to uAPI v2 Kent Gibson
2020-10-02 13:48 ` Andy Shevchenko
2020-10-02 16:06   ` Kent Gibson
2020-10-05 10:27     ` Bartosz Golaszewski
2020-10-12 10:37 ` Bartosz Golaszewski
2020-10-13  7:08 ` Bartosz Golaszewski
2020-10-13  8:30   ` Kent Gibson
2020-10-14  3:17   ` Kent Gibson [this message]
2020-10-14  7:37     ` Bartosz Golaszewski
2020-10-14  8:51       ` Kent Gibson
2020-10-14  8:52         ` Bartosz Golaszewski

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=20201014031721.GA12685@sol \
    --to=warthog618@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@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.