[Toybox] [TOY] lspci

Felix Janda felix.janda at posteo.de
Fri Aug 2 13:35:30 PDT 2013


Isaac wrote:
> On Sat, Jul 27, 2013 at 09:56:53AM +0200, Felix Janda wrote:
[...]
> > Anyway Isaac is doing (or planning to do) a major rewrite enabling lspci
> > to read the pciid database for human readable names of vendors and devices.
> 
> I have a question or two in regards to that.
> 1-mmap or fgets?
> It's a smallish file as data goes (currently~600 kb), and can be searched 
> in very little time if mmap()ed. 
> The alternative is an fgets() based loop, which could involve 
> reading over 11,000 entries, and decent performance would require 
> using a linked list for temporary storage, extracting and sorting the entries
> from the linked list, looping over the sorted entries and storing the text,
> then printing from the linked list (though you can print from the sorted data
> if you don't care about order).
> I'm thinking mmap sounds more practical.

I don't understand your argument. What would be the algorithm using mmap()?

How about the following approach using fgets? Say in a simplified version
we start out with a list of

struct foo {
  struct foo *next;
  struct bar *strs;
  char vendor[4], device[4];
}

, where

struct bar {
  struct foo *ref;
  char *vendor, *device;
}

, filled out from the /sys/ files. The fields strs are initialized to point
to elements (one for each device) of an array of struct bar and the ref fields
of the elements of this array should point back to the corresponding list
element. Then, sort the array of struct bars according to ref->vendor and
ref->device. Next, update ref->strs to point to the right element in the
sorted array. Now we can start reading the (sorted) pci database line by
line and fill out the other elements of the struct bar array. For the
printing we iterate through the list of struct foo.

> 2-is there a way to allow configuring a path in the toybox build system?
> The database can live in several places, so I was thinking to have a 
> customizeable default and allow setting the path in kconfig as well.

Let's wait for Rob.

Felix

 1375475730.0


More information about the Toybox mailing list