[igt-dev] [PATCH i-g-t] lib: Use a bsearch to find the module name

Chris Wilson chris at chris-wilson.co.uk
Mon Sep 3 10:39:24 UTC 2018


Quoting Jani Nikula (2018-09-03 11:34:53)
> On Mon, 03 Sep 2018, Chris Wilson <chris at chris-wilson.co.uk> wrote:
> > Quoting Petri Latvala (2018-09-03 10:39:31)
> >> On Sat, Sep 01, 2018 at 07:09:11PM +0100, Chris Wilson wrote:
> >> > Even with a small number of known drivers (6), a bsearch will take at
> >> > most 3 steps, whereas the linear search will take 3 steps on average. In
> >> > the future with more known drivers, the logN bsearch will be even more
> >> > advantageous.
> >> > 
> >> > Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> >> > Cc: Katarzyna Dec <katarzyna.dec at intel.com>
> >> > ---
> >> >  lib/drmtest.c | 12 +++++++++---
> >> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >> > 
> >> > diff --git a/lib/drmtest.c b/lib/drmtest.c
> >> > index 93228f900..bfb38f1e9 100644
> >> > --- a/lib/drmtest.c
> >> > +++ b/lib/drmtest.c
> >> > @@ -222,9 +222,15 @@ static int open_device(const char *name, unsigned int chipset)
> >> >       if (__get_drm_device_name(fd, dev_name, sizeof(dev_name) - 1) == -1)
> >> >               goto err;
> >> >  
> >> > -     for (const struct module *m = modules; m->module; m++) {
> >> > -             if (strcmp(m->module, dev_name) == 0) {
> >> > -                     chip = m->bit;
> >> > +     for (int start = 0, end = ARRAY_SIZE(modules) - 1; start < end; ){
> >> > +             int mid = start + (end - start) / 2;
> >> > +             int ret = strcmp(modules[mid].module, dev_name);
> >> > +             if (ret < 0) {
> >> > +                     end = mid;
> >> > +             } else if (ret > 0) {
> >> > +                     start = mid + 1;
> >> 
> >> 
> >> Isn't this the wrong way around?
> >
> > * blinks.
> >
> > Yes. Shame on me for assuming that a run through igt was good enough to
> > flush out the kinks. It just happens that vgem occupies the initial mid,
> > so anything that wanted vgem-only got it; everything else hit the
> > DRIVER_ANY.
> >
> > amdgpu -> skip. Ah. Hmm, that should have been flagged :|
> 
> Just sayin'

The bug was getting m1 and m2 reversed...
Wouldn't have prevented the bug, but if besearch() was a macro generator
then yes I'd be more inclined (or we had real generics).
-Chris


More information about the igt-dev mailing list