czw., 19 gru 2019 o 19:17 Andy Shevchenko <andy.shevchenko@xxxxxxxxx> napisał(a): > > On Thu, Dec 19, 2019 at 7:17 PM Bartosz Golaszewski <brgl@xxxxxxxx> wrote: > > > > From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx> > > > > Currently there is no way for user-space to be informed about changes > > in status of GPIO lines e.g. when someone else requests the line or its > > config changes. We can only periodically re-read the line-info. This > > is fine for simple one-off user-space tools, but any daemon that provides > > a centralized access to GPIO chips would benefit hugely from an event > > driven line info synchronization. > > > > This patch adds a new ioctl() that allows user-space processes to reuse > > the file descriptor associated with the character device for watching > > any changes in line properties. Every such event contains the updated > > line information. > > > > Currently the events are generated on three types of status changes: when > > a line is requested, when it's released and when its config is changed. > > The first two are self-explanatory. For the third one: this will only > > happen when another user-space process calls the new SET_CONFIG ioctl() > > as any changes that can happen from within the kernel (i.e. > > set_transitory() or set_debounce()) are of no interest to user-space. > > > - } else if (cmd == GPIO_GET_LINEINFO_IOCTL) { > > + } else if (cmd == GPIO_GET_LINEINFO_IOCTL || > > + cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) { > > Wouldn't be better for maintenance to have them separated from the day 1? > Sure. Will fix in v4. > ... > > > + if (test_bit(desc_to_gpio(desc), priv->watched_lines)) { > > if (!test_bit(...)) > return NOTIFY_DONE; > > ? > > > + pr_debug_ratelimited( > > + "%s: lineinfo event FIFO is full - event dropped\n", > > > + __func__); > > This is in 99.9% cases redundant in *_dbg() calls. > > > + ret = NOTIFY_OK; > > + } > > + > > + return ret; > > return NOTIFY_OK; Yeah, makes sense. > ? > > > +} > > ... > > > @@ -3111,6 +3285,7 @@ static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc) > > if (ret != -ENOTSUPP) > > return ret; > > } > > + > > return 0; > > } > > > > This hunk doesn't belong to this patch. > Ha! Of course it doesn't. :) > ... > > > +/** > > + * struct gpioline_info_changed - Information about a change in status > > + * of a GPIO line > > + * @info: updated line information > > + * @timestamp: estimate of time of status change occurrence, in nanoseconds > > + * and GPIOLINE_CHANGED_CONFIG > > + * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED > > + */ > > +struct gpioline_info_changed { > > > + struct gpioline_info info; > > Is this guaranteed to be always 8 byte aligned? > I'm expecting to see some comments there and / or here about it. > struct gpioline_info alone is 32-bit aligned but its size is 72 bytes which works for 64-bit alignment. This new structure's biggest element in 64-bit, so it's 64-bit aligned on 64-bit arch. We have 72 bytes of gpioline_info, 8 bytes of timestamp, 32 bytes of event type and 5 * 32 bytes of padding. Should be fine, but I'll add comments to the header. Bart > > + __u64 timestamp; > > + __u32 event_type; > > + __u32 padding[5]; /* for future use */ > > +}; > > -- > With Best Regards, > Andy Shevchenko