Re: [PATCH v2 02/18] gpio: uapi: define uAPI v2
From: Kent Gibson
Date: Wed Aug 05 2020 - 21:03:44 EST
On Wed, Aug 05, 2020 at 07:47:57PM +0200, Bartosz Golaszewski wrote:
> On Wed, Aug 5, 2020 at 7:19 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> >
>
> [snip]
>
> > > >
> > > > +/*
> > > > + * Maximum number of requested lines.
> > > > + *
> > > > + * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
> > > > + */
> > > > +#define GPIOLINES_MAX 64
> > > > +
> > > > +/* The number of __u64 required for a bitmap for GPIOLINES_MAX lines */
> > > > +#define GPIOLINES_BITMAP_SIZE __KERNEL_DIV_ROUND_UP(GPIOLINES_MAX, 64)
> > > > +
> > >
> > > In what circumstances can this be different than 1? It's worth
> > > documenting here I suppose.
> > >
> >
> > In terms of the API definition, GPIOLINES_MAX can be anything you want
> > and the definitions are still valid. In practice in the mainline kernel
> > it would always be 1 for ABI compatibility.
> >
> > Chiselling GPIOLINES_MAX <= 64 into stone could simplify things a bit,
> > as all the bitmaps reduce to a single __u64. Would you prefer that?
> >
>
> I'm not sure I follow. We need to chisel some max value in stone. Up
> to that point it's been 64. We can make it more and the bitmap API
> would handle it alright but if we don't, then this
> __KERNEL_DIV_ROUND_UP() is unnecessary. Limiting it to 64 makes things
> very simple thanks to fitting into a __u64 though. I've personally
> never needed to request even half that so I guess this value's fine?
>
By "chiselling in stone" I mean not supporting > 64 lines - even in
custom kernel builds. The uAPI and definition and implementation would
lock that in. As it stands a custom build could use > 64 and it should
all still work as the bitmaps would be resized.
I satisfied that 64 is more than enough for what this API is intended for,
so I'll change the bitmaps to a single __u64, and remove
GPIOLINES_BITMAP_SIZE.
[ snip]
> > > > + __u64 bits[GPIOLINES_BITMAP_SIZE];
> > > > +};
> > > > +
> > >
> > > We can set values only for a subset of requested lines but AFAICT we
> > > can't read values of only a subset of lines. Would it be difficult to
> > > remove this limitation? While reading values always succeeds - even if
> > > the line is in input mode and has edge detected - I think that someone
> > > may want to request the max number of lines without reading all their
> > > values each time. Maybe consider merging this with struct
> > > gpioline_set_values?
> > >
> >
> > That is correct.
> >
> > I considered that corner case to be unlikely, as a major point of
> > requesting lines together is to be able to perform collective operations
> > on them as atomically as possible. If you only want subsets then
> > request them as separate subsets.
> >
>
> And yet this version implements heterogeneous config and setting edge
> detection and values of subsets of requested lines. :)
>
The corner case I was referring to was only wanting to get a subset of
lines and caring that there may be a slight performance gain if the
kernel filters out the lines you aren't interested in :(.
> > Do you have a case in mind where you would have overlapping subsets?
> >
>
> No, not really but then I also don't have a use-case for setting only
> a certain subset of lines.
>
> > Not difficult to remove the limitation - I just didn't see sufficient
> > benefit.
> >
>
> Using the same structure for setting and getting values is a benefit
> IMO. If it's not a difficult task, then I think it's worth adding it.
>
OK, will add it in.
[ snip]
> > > (maybe even define a special macro to set all bits in mask -
> > > GPIOLINE_CONFIG_ALL_LINES or something) on a first-in-wins basis. I'm
> > > open to other suggestions though.
> > >
> >
> > I think I've addressed this elsewhere, and still think it is worthwhile
> > and very low cost. I thought it was an easy win when I added it, and
> > still do.
> >
> > Happy to change the attrs to first-in-wins though - the validation of
> > the attrs is still my biggest bugbear with this version.
>
> Yes, I read your other reply. Ok, makes sense to have default flags
> with an attribute for overrides. This just needs very explicit
> documentation.
>
I'll add documentation that the attrs associations are on a
first-in-wins basis, and that subsequent associations are ignored.
Cheers,
Kent.