All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Linus Walleij <linus.walleij@linaro.org>,
	Jack Winch <sunt.un.morcov@gmail.com>,
	Helmut Grohne <helmut.grohne@intenta.de>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][PATCH 4/4] bindings: cxx: implement C++ bindings for libgpiod v2.0
Date: Mon, 28 Jun 2021 22:25:05 +0800	[thread overview]
Message-ID: <20210628142505.GA37053@sol> (raw)
In-Reply-To: <CAHp75Vd+5wVa6-B+5kj-0N-wyxr8iT_tSs-A36Pn30p3Z=THQQ@mail.gmail.com>

On Mon, Jun 28, 2021 at 02:53:40PM +0300, Andy Shevchenko wrote:
> On Mon, Jun 28, 2021 at 2:35 PM Kent Gibson <warthog618@gmail.com> wrote:
> > On Mon, Jun 28, 2021 at 02:30:05PM +0300, Andy Shevchenko wrote:
> > > On Sun, Jun 27, 2021 at 04:47:57PM +0800, Kent Gibson wrote:
> 
> ...
> 
> > > Kent, do I understand correctly that Go bindings use C library?
> >
> > No, the Go library is pure Go - it makes the ioctl calls itself.
> 
> Hmm... Interesting. Why is it so? Performance wise? Other points?
> 
> (It means you are basically replicating what libgpiod does, right?)
> 

Yeah, I ended up replicating libgpiod in Go.  Which actually came in
quite handy when it came to developing and testing the v2 uAPI - the
first support and test cases for that were written in Go.

A bit of history...
Initially I wrote a Go GPIO library for the Raspberry Pi for a
project that required better performance than was available via sysfs.
This pre-dated cdev/libgpiod availability on the Raspberry Pi.
That library manipulated the hardware directly via mapped memory, which
at the time was the only alternative to sysfs.  It is hideous and
horrible, but it works, and if you can live with the downsides it is also
quite performant.

Once cdev started being supported in Pi kernels I wanted to port the
library to that.  I did consider porting to libgpiod, but that had a few
downsides:

My original library was pure Go, which is trivial to cross-compile
for the Raspberry Pi (just call 'GOARCH=arm GOARM=6 go build' on my PC
and I have an executable that I can run on a Pi).
If you do call C libraries from Go and want to cross-compile then you
get sucked back into requiring the whole C cross-compilation toolchain.
Plus ease of deployment takes a hit - you now have to consider
the dependent libraries, not just the executable.
At that point you might as well just write in C.
Ease of cross-compilation and deployment was important to me (I'm
lazy), so this was a major factor.

Also, I had less trouble getting my head around the kernel uAPI than
I did the libgpiod API.  The uAPI was a smaller and simpler target,
and was accessible from Go, so I went directly to that.
(I think the libgpiod v2 API is much more approachable than v1, btw.)
Anyway, neither API at the time could implement my existing Go GPIO API,
so I ended up writing a new library instead - the one that replicates
the core functionality of libgpiod.
Ironically, I probably could implement that old API using the v2 uAPI...

So, in short, cos it was easier.

Cheers,
Kent.


  reply	other threads:[~2021-06-28 14:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 19:18 [libgpiod][PATCH 0/4] libgpiod v2: C++ bindings Bartosz Golaszewski
2021-06-21 19:18 ` [libgpiod][PATCH 1/4] events: hide the *_read_fd() symbols from the API header Bartosz Golaszewski
2021-06-21 19:18 ` [libgpiod][PATCH 2/4] API: drop "peek" functions Bartosz Golaszewski
2021-06-21 19:18 ` [libgpiod][PATCH 3/4] API: add an AS_IS value for bias setting Bartosz Golaszewski
2021-06-21 19:18 ` [libgpiod][PATCH 4/4] bindings: cxx: implement C++ bindings for libgpiod v2.0 Bartosz Golaszewski
2021-06-27  8:47   ` Kent Gibson
2021-06-28 11:30     ` Andy Shevchenko
2021-06-28 11:34       ` Kent Gibson
2021-06-28 11:53         ` Andy Shevchenko
2021-06-28 14:25           ` Kent Gibson [this message]
2021-07-02  8:50     ` Bartosz Golaszewski
2021-07-02 11:38       ` Kent Gibson

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=20210628142505.GA37053@sol \
    --to=warthog618@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=helmut.grohne@intenta.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sunt.un.morcov@gmail.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 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.