[Toybox] lspci text output

Isaac idunham at lavabit.com
Sat Aug 3 10:33:00 PDT 2013


On Fri, Aug 02, 2013 at 10:35:30PM +0200, Felix Janda wrote:
> 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()?

With mmap, the time is small enough to search the whole file every time.
But now that I try fgets, I think I overestimated the time it takes:
$ time ./lookup-fgets "C 11" "80  " /usr/share/misc/pci.ids    
0: Signal processing controller : gnal processing controller
    0m0.01s real     0m0.01s user     0m0.00s system

(5400 RPM HDD, Atom N270 locked to 800 MHz)
When "Vendor" is "C **", device is 2 chars long, and I'm not sure what's a good way to handle that.
See attached files for mmap (thanks to "jamesbond" at the Puppy forums) 
and fgets examples.
Usage is 
lookup-fgets <vendor> <device> /usr/share/misc/pci.ids
lookup <vendor> <device>
lookup-fgets can be used with USB devices as well.

> 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.
 
That seems to make more sense than what I was thinking of, 
if it really is needed (see time).


Thanks,
Isaac Dunham


 1375551180.0


More information about the Toybox mailing list