From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH libdrm 08/11] tests: modetest: Accept connector names
Date: Mon, 26 Jan 2015 12:24:24 +0200 [thread overview]
Message-ID: <2285050.rcOyItG2FY@avalon> (raw)
In-Reply-To: <20150126101430.GB3508@ulmo>
Hi Thierry,
On Monday 26 January 2015 11:14:32 Thierry Reding wrote:
> On Sun, Jan 25, 2015 at 01:56:51AM +0200, Laurent Pinchart wrote:
> > On Friday 23 January 2015 17:08:21 Thierry Reding wrote:
> >> From: Thierry Reding <treding@nvidia.com>
> >>
> >> Allow connector names to be used in the specification of the -s option.
> >> This requires storing the string passed on the command-line so that it
> >> can later be resolved to a connector ID (after the DRM device has been
> >> opened).
> >>
> >> Signed-off-by: Thierry Reding <treding@nvidia.com>
> >> ---
> >>
> >> tests/modetest/modetest.c | 134 +++++++++++++++++++++++++++++++++++----
> >> 1 file changed, 123 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
> >> index d5fd99ebe1fd..a7cc94f8938c 100644
> >> --- a/tests/modetest/modetest.c
> >> +++ b/tests/modetest/modetest.c
> >
> > [snip]
> >
> >> @@ -327,7 +328,7 @@ static void dump_connectors(struct device *dev)
> >>
> >> int i, j;
> >>
> >> printf("Connectors:\n");
> >>
> >> - printf("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\tencoders\n");
> >> + printf("id\tencoder\tstatus\t\tname\t\tsize
> >> (mm)\tmodes\tencoders\n");
> >>
> >> for (i = 0; i < dev->resources->res->count_connectors; i++) {
> >>
> >> struct connector *_connector = &dev->resources->connectors[i];
> >> drmModeConnector *connector = _connector->connector;
> >>
> >> @@ -338,7 +339,7 @@ static void dump_connectors(struct device *dev)
> >>
> >> connector->connector_id,
> >> connector->encoder_id,
> >> util_lookup_connector_status_name(connector->connection),
> >>
> >> - util_lookup_connector_type_name(connector->
> >> connector_type),
> >> + _connector->name,
> >>
> >> connector->mmWidth, connector->mmHeight,
> >> connector->count_modes);
> >
> > As this is a low-level test tool I believe it would be useful to print
> > both the name and the ID. Maybe something like "name (id)" ?
>
> The ID is already printed in the very first column.
My bad.
> >> @@ -511,6 +516,47 @@ static void free_resources(struct resources *res)
> >> free(res);
> >> }
> >>
> >> +static unsigned int get_connector_index(struct resources *res, uint32_t
> >> type)
> >> +{
> >> + unsigned int index = 0;
> >> + int i;
> >> +
> >> + for (i = 0; i < res->res->count_connectors; i++)
> >> + if (res->connectors[i].connector->connector_type == type)
> >> + index++;
> >> +
> >> + return index - 1;
> >> +}
> >> +
> >> +static unsigned int get_order(unsigned int value)
> >> +{
> >> + unsigned int order = 0;
> >> +
> >> + do {
> >> + value /= 10;
> >> + order++;
> >> + } while (value > 0);
> >> +
> >> + return order - 1;
> >> +}
> >> +
> >> +static void connector_set_name(struct connector *connector,
> >> + struct resources *res)
> >> +{
> >> + uint32_t type = connector->connector->connector_type;
> >> + const char *type_name;
> >> + unsigned int index;
> >> + int len;
> >> +
> >> + type_name = util_lookup_connector_type_name(type);
> >> + index = get_connector_index(res, type);
> >
> > The kernel's connector name is created using connector_type_id, not the
> > connector index. Shouldn't we do the same here ?
>
> The idea was to mirror what X was doing so that people familiar with the
> xrandr tool would feel right at home. Note that the index here is by
> type, not global. So you'd end up with something like this:
>
> HDMI-A-1
> HDMI-A-2
> LVDS-1
>
> I think that's what most people would find to be the least surprising.
> Using the connector_type_id would again introduce the potential to get
> no-deterministic names (dependent on driver probe ordering in case of
> multiple cards).
Isn't the index dependent on probe ordering as well ?
> That said I now realize that this actually starts numbering connectors
> at 0, so get_connector_index() should probably return index rather than
> index - 1 to be consistent with what X does.
Yes, I think that's a good idea.
> >> + len = strlen(type_name) + get_order(index) + 2;
> >
> > This looks like an over-optimization to me, can't you just add 9 to
> > account for the largest possible index ? Or, even better, use asprintf ?
> > The function is a GNU extension but is available on BSD according to its
> > manpage.
>
> Always using 9 characters would be wasting 8 bytes per connector for
> something like 99% of the systems.
We're talking about 8 bytes per connector for a test tool. With no more than a
dozen of connectors. Right ? :-)
> I had thought about using asprintf but decided not to use it because it
> isn't always available and it is pretty simple to compute the actual length.
--
Regards,
Laurent Pinchart
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-01-26 10:23 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
2015-01-24 23:19 ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
2015-01-24 23:19 ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
2015-01-24 23:20 ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
2015-01-24 23:24 ` Laurent Pinchart
2015-01-29 15:27 ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
2015-01-29 15:27 ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
2015-01-24 23:24 ` Laurent Pinchart
2015-01-29 15:28 ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
2015-01-24 23:26 ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
2015-01-24 23:40 ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
2015-01-24 23:56 ` Laurent Pinchart
2015-01-26 10:14 ` Thierry Reding
2015-01-26 10:24 ` Laurent Pinchart [this message]
2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
2015-01-29 15:30 ` [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test Thierry Reding
2015-01-29 15:30 ` [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
2015-01-29 15:31 ` [PATCH 11.1/11] SQUASH: kms-universal-planes: link against cairo Emil Velikov
2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov
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=2285050.rcOyItG2FY@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=thierry.reding@gmail.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