From: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
To: Alexandre Courbot <gnurou@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Arnd Bergmann <arnd@arndb.de>,
Santosh Shilimkar <santosh.shilimkar@ti.com>,
Kevin Hilman <khilman@linaro.org>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
linux-omap@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 0/5] add gpio_chip_ops to hold GPIO operations
Date: Thu, 10 Apr 2014 11:34:41 +0200 [thread overview]
Message-ID: <534665B1.9090207@collabora.co.uk> (raw)
In-Reply-To: <CAAVeFu+XV_wy9JzewGs0bcSA-ivQg-kzygMh_kt434rsYRQwHQ@mail.gmail.com>
Hello Alexandre,
Thanks a lot for your feedback.
On 04/10/2014 09:36 AM, Alexandre Courbot wrote:
> On Wed, Apr 9, 2014 at 3:20 AM, Javier Martinez Canillas
> <javier.martinez@collabora.co.uk> wrote:
>> In the kernel there are basically two patterns to implement object
>> oriented code in C. You can either embedded a set of function pointers
>
> s/embedded/embed
>
>> in a struct along with other members or have a separate virtual function
>> table (vtable) structure that hold all the functions and only store a
>> pointer to that vtable on our particular object.
>>
>> The struct gpio_chip uses the former approach, but I don't know if that
>> is a design decision or is just that this code predates the fact that
>> the separate structure pattern is now so popular. Since the having a
>> the operations on a different structure has a number of benefits:
>
> "Since having the operations" maybe?
>
Yes, since I'm not a native english speaker I sometimes miss some obvious
grammatical errors. I'll fix those when posting the final version with all the
drivers converted.
>>
>> - A clean separation between state (fields) and operations (functions).
>> - Size reduction of struct gpio_chip since will only hold one pointer.
>> - These functions are not supposed to change at runtime so the const
>> qualifier can be used to prevent pointers modification during execution.
>> - Similar drivers for a chip family can reuse their function vtable.
>>
>> There is a drawback though which is that now two memory accesses are
>> needed to execute a GPIO operation since an additional level of
>> indirection is introduced but that should be minimized due temporal and
>> spatial memory locality.
>
> I think I really do like this. Having ops in a separate structure is a
> very common pattern in the kernel and makes things a lot cleaner. On
> top of the advantages you listed, it also only requires a single
> assignment in the driver's init function vs. a lot more today.
>
> If no one complains about the additional memory access, I'd like to go
> forward with this. I did much worse performance-hurting changes when
> introducing gpiod, so I suppose it will be fine.
>
>>
>> So this is an RFC patch-set to add a virtual table to be used by
>> GPIO chip controllers and consist of the following patches:
>>
>> Javier Martinez Canillas (5):
>> gpio: add a vtable to abstract GPIO controller operations
>> gpiolib: set gpio_chip operations on add using a gpio_chip_ops
>> gpio: omap: convert driver to use gpio_chip_ops
>> gpio: twl4030: convert driver to use gpio_chip_ops
>> gpio: switch to use struct struct gpio_chip_ops
>>
>> drivers/gpio/gpio-omap.c | 19 ++++++++-----
>> drivers/gpio/gpio-twl4030.c | 10 +++++--
>> drivers/gpio/gpiolib.c | 64 ++++++++++++++++++++---------------------
>> include/linux/gpio/driver.h | 69 +++++++++++++++++++++++++++------------------
>> 4 files changed, 93 insertions(+), 69 deletions(-)
>>
>> The patch-set is not a complete one though since only the GPIO OMAP
>> and GPIO TWL4030 drivers have been converted so I could test it on
>> my platform (DM3730 OMAP IGEPv2 board).
>>
>> But I preferred to send an early RFC than changing every single driver
>> before discussing if doing the split is worth it or not.
>>
>> To not break git bisect-ability, I added some patches that are
>> transitional changes. If you have a better suggestion on how to
>> handle that please let me know.
>
> We will probably need that transition phase. We will also need to
> switch every single driver to your new scheme, so please wait until we
> hear from Linus before proceeding. :)
>
I'm glad you agree with the idea, let's see what Linus thinks about it.
> Thanks,
> Alex.
>
Best regards,
Javier
next prev parent reply other threads:[~2014-04-10 9:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-08 18:20 [RFC PATCH 0/5] add gpio_chip_ops to hold GPIO operations Javier Martinez Canillas
2014-04-08 18:20 ` [RFC PATCH 1/5] gpio: add a vtable to abstract GPIO controller operations Javier Martinez Canillas
2014-04-08 18:20 ` [RFC PATCH 2/5] gpiolib: set gpio_chip operations on add using a gpio_chip_ops Javier Martinez Canillas
2014-04-08 18:20 ` [RFC PATCH 3/5] gpio: omap: convert driver to use gpio_chip_ops Javier Martinez Canillas
2014-04-08 18:20 ` [RFC PATCH 4/5] gpio: twl4030: " Javier Martinez Canillas
2014-04-08 18:20 ` [RFC PATCH 5/5] gpio: switch to use struct struct gpio_chip_ops Javier Martinez Canillas
2014-04-10 7:36 ` [RFC PATCH 0/5] add gpio_chip_ops to hold GPIO operations Alexandre Courbot
2014-04-10 9:34 ` Javier Martinez Canillas [this message]
2014-04-10 11:00 ` Andy Shevchenko
2014-04-10 11:46 ` Javier Martinez Canillas
2014-04-22 11:36 ` Linus Walleij
2014-04-22 12:28 ` Javier Martinez Canillas
2014-04-22 14:17 ` Arnd Bergmann
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=534665B1.9090207@collabora.co.uk \
--to=javier.martinez@collabora.co.uk \
--cc=acourbot@nvidia.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=gnurou@gmail.com \
--cc=khilman@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=santosh.shilimkar@ti.com \
/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).