After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 590059 - GnomeRR: Use hwdb for pnp.ids
GnomeRR: Use hwdb for pnp.ids
Status: RESOLVED FIXED
Product: gnome-desktop
Classification: Core
Component: libgnome-desktop
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Desktop Maintainers
Desktop Maintainers
: 688848 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-07-28 19:56 UTC by Vincent Untz
Modified: 2016-06-25 11:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
pnp-ids: Use an mmap'ed file instead of a HashTable (5.65 KB, patch)
2012-06-20 17:09 UTC, Bastien Nocera
rejected Details | Review
pnp-ids: Use udev's hwdb to query PNP IDs (69.71 KB, patch)
2015-05-20 11:12 UTC, Bastien Nocera
none Details | Review
pnp-ids: Use udev's hwdb to query PNP IDs (70.51 KB, patch)
2016-06-25 11:19 UTC, Bastien Nocera
none Details | Review
pnp-ids: Use udev's hwdb to query PNP IDs (70.51 KB, patch)
2016-06-25 11:30 UTC, Bastien Nocera
committed Details | Review

Description Vincent Untz 2009-07-28 19:56:46 UTC
pnp.ids is 50kB, so that's roughly what is needed to keep that in memory all the time (at least for gnome-settings-daemon). Not sure it's worth the effort to try to fix this...
Comment 1 Adam Jackson 2009-07-28 21:43:01 UTC
Is it worth making this a hash table?  It's small enough (and rarely-used enough) that a straight linear search would probably be just fine, which opens the door for read-only mmap.
Comment 2 Vincent Untz 2009-07-28 22:03:20 UTC
Fine with me too ;-)
Comment 3 Bastien Nocera 2012-06-20 17:09:48 UTC
Created attachment 216854 [details] [review]
pnp-ids: Use an mmap'ed file instead of a HashTable

Which means we don't need the object to be a singleton, and
saves us about 50kB of data most of the time we don't look at it.
Comment 4 Bastien Nocera 2012-06-20 17:12:05 UTC
Something like that? You can test it with test-pnp-ids in the same directory.

It's much slower than the hash table version (as expected), 500k searches take nearly 3 minutes instead of 0.1 second. Not sure that's awfully problematic though.
Comment 5 Matthias Clasen 2012-07-16 14:52:45 UTC
Do we actually have multiple consumers of this data ? Otherwise, the mmap won't actually help us much, right ?

Could use either gperf or gvdb to get the best of both worlds (mmap + O(1) lookup), I guess ? Or make the fields fixed-width, sort the list and use bsearch.

But all of that can be done later, if this approach turns out to be a problem.
Comment 6 Matthias Clasen 2012-07-16 14:58:46 UTC
Review of attachment 216854 [details] [review]:

Looks fine to me.

::: libgnome-desktop/gnome-pnp-ids.c
@@ +204,1 @@
         /* parse into lines */

This comment is now slightly misleading.
Comment 7 Bastien Nocera 2012-07-16 15:30:45 UTC
(In reply to comment #5)
> Do we actually have multiple consumers of this data ? Otherwise, the mmap won't
> actually help us much, right ?

All users of gnome-desktop in gnome-settings-daemon, and the color plugin.

Might worth checking whether it affects http://git.gnome.org/browse/gnome-settings-daemon/commit/gnome-settings-daemon/gnome-settings-manager.c?id=d8c158e74caea048dea5a38232bd87c1c7a78a70 adversely or not.

> Could use either gperf or gvdb to get the best of both worlds (mmap + O(1)
> lookup), I guess ? Or make the fields fixed-width, sort the list and use
> bsearch.

I don't know whether the tear-down and build-up is the expensive part we're trying to avoid. I can't think that the lookup is something we'd do extensively enough that it would make a difference.

> But all of that can be done later, if this approach turns out to be a problem.
Comment 8 Federico Mena Quintero 2012-07-16 16:55:56 UTC
(In reply to comment #7)
> All users of gnome-desktop in gnome-settings-daemon, and the color plugin.
> 
> Might worth checking whether it affects
> http://git.gnome.org/browse/gnome-settings-daemon/commit/gnome-settings-daemon/gnome-settings-manager.c?id=d8c158e74caea048dea5a38232bd87c1c7a78a70
> adversely or not.

That commit mentions saving 400ms at startup, which is totally worthwhile.  It would be interesting to see why that process is so slow (even if it's done three times, that's 133 msec per iteration - plenty enough to seek, read, and parse a small file, unless it's doing something really dumb).

Can someone grep through the code and make a list of the places where the PNP ids are used?  Then we can see how much time we can spend in each place, and whether we can just allocate memory for the table temporarily or whether it's better to keep it around in memory for a while.
Comment 9 Bastien Nocera 2013-02-21 11:08:49 UTC
Putting on NEEDINFO so people do real benchmarking of the effects of this patch on startup time.
Comment 10 Bastien Nocera 2014-07-03 13:32:33 UTC
We should use udev's hwdb, but we'll need to wait for it being split out before that happens.
Comment 11 Bastien Nocera 2014-10-21 09:19:12 UTC
*** Bug 688848 has been marked as a duplicate of this bug. ***
Comment 12 Bastien Nocera 2015-05-20 11:12:43 UTC
Created attachment 303652 [details] [review]
pnp-ids: Use udev's hwdb to query PNP IDs

hwdb has its own database which it compiles to binary, so that:
1) initialisation is practically free
See https://git.gnome.org/browse/gnome-settings-daemon/commit/gnome-settings-daemon/gnome-settings-manager.c?id=d8c158e74caea048dea5a38232bd87c1c7a78a70
2) lookups are also quick, as they use a binary DB
3) we don't have to maintain our own copy of the database

The only problem being that non-Linux OSes will need reimplement this
section of the code. This will be on top of the usual downstream patches
they ship for a number of components.
Comment 13 Richard Hughes 2015-05-20 11:19:20 UTC
Last time I spoke to Kay he was against this; probably worth asking him his views now.
Comment 14 Bastien Nocera 2015-05-20 11:44:21 UTC
(In reply to Richard Hughes from comment #13)
> Last time I spoke to Kay he was against this; probably worth asking him his
> views now.

"this" being making hwdb available on non-Linux? I'm hoping that this will be another patch that non-Linux OSes can ship.

Antoine?
Comment 15 Antoine Jacoutot 2015-05-20 12:50:29 UTC
(In reply to Bastien Nocera from comment #14)
> (In reply to Richard Hughes from comment #13)
> > Last time I spoke to Kay he was against this; probably worth asking him his
> > views now.
> 
> "this" being making hwdb available on non-Linux? I'm hoping that this will
> be another patch that non-Linux OSes can ship.
> 
> Antoine?

Hi Bastien. Thanks for putting me into the loop.

If it's just a matter of reverting the commit; then sure.
If we need a new code implementation, I'll have to have a look at the actual code which I cannot do right now. I must admit I don't even know what it is used by...
Comment 16 Bastien Nocera 2015-05-20 12:59:13 UTC
(In reply to Antoine Jacoutot from comment #15)
> (In reply to Bastien Nocera from comment #14)
> > (In reply to Richard Hughes from comment #13)
> > > Last time I spoke to Kay he was against this; probably worth asking him his
> > > views now.
> > 
> > "this" being making hwdb available on non-Linux? I'm hoping that this will
> > be another patch that non-Linux OSes can ship.
> > 
> > Antoine?
> 
> Hi Bastien. Thanks for putting me into the loop.
> 
> If it's just a matter of reverting the commit; then sure.

OK.

> If we need a new code implementation, I'll have to have a look at the actual
> code which I cannot do right now. I must admit I don't even know what it is
> used by...

It's used by gnome-settings-daemon, and gnome-control-center, to get a vendor name from the EDID.
Comment 17 Richard Hughes 2015-05-20 13:05:44 UTC
(In reply to Bastien Nocera from comment #14)
> "this" being making hwdb available on non-Linux? I'm hoping that this will
> be another patch that non-Linux OSes can ship.

Sorry, no, "this" as in using the hwdb like this. I'll ping Kay.
Comment 18 Lennart Poettering 2015-05-20 15:55:04 UTC
Sorry, nothing changed from out side, we have no interest in maintaining systemd or any of its components for other kernels. The hwdb stuff is pretty much Linux-focussed, as the matches are basically just kmod "modalias" matches. This is not going to change, sorry.

If GNOME wants to support other kernels it needs to make support for this functionality optional, remove support for it, or maintain its own ported copy of it...
Comment 19 Bastien Nocera 2015-05-20 16:03:50 UTC
(In reply to Lennart Poettering from comment #18)
> Sorry, nothing changed from out side, we have no interest in maintaining
> systemd or any of its components for other kernels. The hwdb stuff is pretty
> much Linux-focussed, as the matches are basically just kmod "modalias"
> matches. This is not going to change, sorry.
> 
> If GNOME wants to support other kernels it needs to make support for this
> functionality optional, remove support for it, or maintain its own ported
> copy of it...

That's not the question that was asked...
Comment 20 Bastien Nocera 2016-05-27 15:48:25 UTC
(In reply to Lennart Poettering from comment #18)
> Sorry, nothing changed from out side, we have no interest in maintaining
> systemd or any of its components for other kernels. The hwdb stuff is pretty
> much Linux-focussed, as the matches are basically just kmod "modalias"
> matches. This is not going to change, sorry.
> 
> If GNOME wants to support other kernels it needs to make support for this
> functionality optional, remove support for it, or maintain its own ported
> copy of it...

I'll ask again. We want to know if it's ok to use hwdb as we did in the patch, not whether you want to port it to non-Linux.
Comment 21 Lennart Poettering 2016-06-24 16:35:50 UTC
Sorry for not reviewing this more timely.

Using the hwdb for this certainly makes sense. It's a weirdly named of course for this purpose, given that a display isn't an ACPI device, but the EISA, EDID, ACPI, ISAPNP and UEFI ids all use the same namespace, hence reusing this here makes sense.

The hwdb lookup in the patch doesn't look right however. The key you look up should be generated as "acpi:" + $PNPID + ":" (that means: do not include an asterisk in the string, as you currently do). And use the full $PNPID you got from the display, unmodified and not truncated.

Then, iterate through the list you get back and look for the ID_VENDOR_FROM_DATABASE property to acquire the friendly vendor string. You may also use ID_MODEL_FROM_DATABASE if you like, to acquire a friendly model string for the device. But note that currently the acpi database doesn't actually set that for any device. (It sets it for USB and PCI though, and hence if somebody contributes model strings for the PNP ids, too it would show up under that property.)

you can test the lookup btw with this:

  udevadm hwdb -t acpi:LNXCPU:

It will output you the database entries it finds. (of course, use your display's PNPID here, instead of "LNXCPU", to make this a better example)
Comment 22 Bastien Nocera 2016-06-25 11:19:34 UTC
I added the following lines /usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb:
acpi:DEL4085:
 ID_VENDOR_FROM_DATABASE=Dell Inc.
 ID_MODEL_FROM_DATABASE=Dell S2340T

(that's my monitor)

And ran:
sudo udevadm hwdb --update

I ran, to test the database:
$ udevadm hwdb -t acpi:DEL4085:
ID_VENDOR_FROM_DATABASE=Dell Inc.
ID_MODEL_FROM_DATABASE=Dell S2340T

You can use those changes to test the changes I made to the patch.
Comment 23 Bastien Nocera 2016-06-25 11:19:57 UTC
Created attachment 330352 [details] [review]
pnp-ids: Use udev's hwdb to query PNP IDs

hwdb has its own database which it compiles to binary, so that:
1) initialisation is practically free
See https://git.gnome.org/browse/gnome-settings-daemon/commit/gnome-settings-daemon/gnome-settings-manager.c?id=d8c158e74caea048dea5a38232bd87c1c7a78a70
2) lookups are also quick, as they use a binary DB
3) we don't have to maintain our own copy of the database
4) allows model lookup rather than simply vendor lookup, when the
   database contains that information

The only problem being that non-Linux OSes will need reimplement this
section of the code. This will be on top of the usual downstream patches
they ship for a number of components.
Comment 24 Bastien Nocera 2016-06-25 11:30:41 UTC
Created attachment 330353 [details] [review]
pnp-ids: Use udev's hwdb to query PNP IDs

hwdb has its own database which it compiles to binary, so that:
1) initialisation is practically free
See https://git.gnome.org/browse/gnome-settings-daemon/commit/gnome-settings-daemon/gnome-settings-manager.c?id=d8c158e74caea048dea5a38232bd87c1c7a78a70
2) lookups are also quick, as they use a binary DB
3) we don't have to maintain our own copy of the database
4) allows model lookup rather than simply vendor lookup, when the
   database contains that information

The only problem being that non-Linux OSes will need reimplement this
section of the code. This will be on top of the usual downstream patches
they ship for a number of components.
Comment 25 Bastien Nocera 2016-06-25 11:31:13 UTC
Attachment 330353 [details] pushed as b8cbfbe - pnp-ids: Use udev's hwdb to query PNP IDs