Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>,
	Petri Latvala <petri.latvala@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t] lib: Use a bsearch to find the module name
Date: Mon, 03 Sep 2018 13:34:53 +0300	[thread overview]
Message-ID: <87zhwy3m42.fsf@intel.com> (raw)
In-Reply-To: <153596785954.17211.2727933623977298340@skylake-alporthouse-com>

On Mon, 03 Sep 2018, Chris Wilson <chris@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@chris-wilson.co.uk>
>> > Cc: Katarzyna Dec <katarzyna.dec@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'


diff --git a/lib/drmtest.c b/lib/drmtest.c
index adff1a81fffb..3a050211146e 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -209,11 +209,19 @@ static const struct module {
 	{}
 };
 
+static int module_compare(const void *_m1, const void *_m2)
+{
+	const struct module *m1 = _m1, *m2 = _m2;
+
+	return strcmp(m1->module, m2->module);
+}
+
 static int open_device(const char *name, unsigned int chipset)
 {
 	char dev_name[16] = "";
 	int chip = DRIVER_ANY;
 	int fd;
+	struct module key, *res;
 
 	fd = open(name, O_RDWR);
 	if (fd == -1)
@@ -222,18 +230,11 @@ 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 (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) {
-			start = mid + 1;
-		} else if (ret > 0) {
-			end = mid;
-		} else {
-			chip = modules[mid].bit;
-			break;
-		}
-	}
+	key.module = dev_name;
+	res = bsearch(&key, modules, ARRAY_SIZE(modules) - 1,
+		      sizeof(modules[0]), module_compare);
+	if (res)
+		chip = res->bit;
 	if (chipset & chip)
 		return fd;
 

-- 
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2018-09-03 10:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-01 18:09 [igt-dev] [PATCH i-g-t] lib: Use a bsearch to find the module name Chris Wilson
2018-09-01 18:46 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-09-01 19:35 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-09-03  7:02 ` [igt-dev] [PATCH i-g-t] " Katarzyna Dec
2018-09-03  9:39 ` Petri Latvala
2018-09-03  9:44   ` Chris Wilson
2018-09-03 10:34     ` Jani Nikula [this message]
2018-09-03 10:39       ` Chris Wilson
2018-09-03 11:01 ` [igt-dev] ✓ Fi.CI.BAT: success for lib: Use a bsearch to find the module name (rev2) Patchwork
2018-09-03 14:43 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=87zhwy3m42.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox