All of lore.kernel.org
 help / color / mirror / Atom feed
From: Louis Chauvet <louis.chauvet@bootlin.com>
To: Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	igt-dev@lists.freedesktop.org,
	Petri Latvala <adrinael@adrinael.net>,
	Arkadiusz Hiler <arek@hiler.eu>,
	Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>,
	Bhanuprakash Modem <bhanuprakash.modem@intel.com>,
	Ashutosh Dixit <ashutosh.dixit@intel.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	nicolejadeyee@google.com, seanpaul@google.com,
	jeremie.dautheribes@bootlin.com, markyacoub@google.com
Subject: Re: [PATCH i-g-t v2 4/5] lib/igt_kms: Add helper to obtain a connector by its name or MST path
Date: Fri, 8 Nov 2024 16:23:37 +0100	[thread overview]
Message-ID: <Zy4s-WgVEx4fJ3qN@fedora> (raw)
In-Reply-To: <20241106142456.ts3ukhf5aviqc2yn@kamilkon-desk.igk.intel.com>

On 06/11/24 - 15:24, Kamil Konieczny wrote:
> Hi Louis,
> On 2024-10-22 at 12:28:38 +0200, Louis Chauvet wrote:
> > Introduce the functions igt_get_connector_from_name() and
> > igt_get_connector_id_from_mst_path(). These functions serve to retrieve
> > the connector object using a connector name and a connector ID from its
> > MST path, respectively.
> > 
> > Given that the connector id may not be consistent, especially with MST
> > connectors, these functions are essential to recognize each connector even
> > after system reboots and plug/unplug events.
> > 
> > The function igt_get_connector_id_from_name() is a convenient wrapper for
> > igt_get_connector_from_name() to streamline its usage when the caller only
> > requires the connector id.
> > 
> > Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> > ---
> >  lib/igt_kms.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  lib/igt_kms.h |  3 ++
> >  2 files changed, 100 insertions(+)
> > 
> > diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> > index 44b546ae52dc..fce5666cefc6 100644
> > --- a/lib/igt_kms.c
> > +++ b/lib/igt_kms.c
> > @@ -7235,3 +7235,100 @@ int igt_get_connected_connectors(int drm_fd, uint32_t **connector_ids)
> >  	return
> >  	    connected_count;
> >  }
> > +
> > +drmModeConnectorPtr igt_get_connector_from_name(int drm_fd, const char *port_name)
> > +{
> > +	drmModeResPtr res = drmModeGetResources(drm_fd);
> > +	struct timespec start, end;
> > +	int i;
> > +
> > +	if (!res)
> > +		return 0;
> > +
> > +	for (i = 0; i < res->count_connectors; i++) {
> > +		char name[50];
> 
> Add define for this '50' or later on use ARRAY_SIZE()

I will use ARRAY_SIZE(), thanks
 
> > +
> > +		drmModeConnectorPtr connector = drmModeGetConnector(drm_fd, res->connectors[i]);
> > +		/*
> > +		 * This time is required as sometimes some id in the connector list are not totally
> > +		 * ready or can disappear
> > +		 */
> > +		clock_gettime(CLOCK_MONOTONIC, &start);
> > +		clock_gettime(CLOCK_MONOTONIC, &end);

(Same change as before, end = start)

> > +		while (!connector &&
> > +		       igt_time_elapsed(&start, &end) < igt_default_detect_timeout()) {
> > +			connector = drmModeGetConnector(drm_fd, res->connectors[i]);
> > +			clock_gettime(CLOCK_MONOTONIC, &end);
> > +		}
> 
> Could connectors appear/get connected out-of-order?
> Some get connected and some others never get it?

There are two issues:
- One connector can be present when calling drmModeGetResources, and 
disapear before drmModeGetConnector
- The MST connectors are not immediatly available, even modetest is 
crashing, so I have to call again drmModeGetConnector in some case(if I 
remember correctly, `watch -n0 modetest -c` can show you segfaults)

It will not cache new connectors after the call to drmModeGetResources, 
but at least it will not crash with a segfault because connector is not 
available yet/anymore.

> Regards,
> Kamil
> 
> > +
> > +		if (igt_time_elapsed(&start, &end) < igt_default_detect_timeout()) {
> > +			igt_assert(connector);
> > +
> > +			/* We have to generate the connector name on our own */
> > +			snprintf(name, 50, "%s-%u",
> > +				 kmstest_connector_type_str(connector->connector_type),
> > +				 connector->connector_type_id);
> > +
> > +			if (strcmp(port_name, name) == 0) {
> > +				drmModeFreeResources(res);
> > +				return connector;
> > +			}
> > +			drmModeFreeConnector(connector);
> > +		}
> > +	}
> > +	drmModeFreeResources(res);
> > +	return NULL;
> > +}
> > +
> > +/**
> > + * igt_get_connector_id_from_name - Get a connector ID from a connector name
> > + * @drm_fd: DRM file descriptor
> > + * @port_name: Port name to find in the connector
> > + *
> > + * Returns 0 when no connector is found with the correct name
> > + */
> > +uint32_t igt_get_connector_id_from_name(int drm_fd, const char *port_name)
> > +{
> > +	drmModeConnectorPtr connector = igt_get_connector_from_name(drm_fd, port_name);
> > +
> > +	if (connector) {
> > +		int connector_id = connector->connector_id;
> > +
> > +		drmModeFreeConnector(connector);
> > +		return connector_id;
> > +	}
> > +	return 0;
> > +}
> > +
> > +/**
> > + * igt_get_connector_id_from_mst_path - Get a connector ID from a mst path
> > + * @drm_fd: DRM file descriptor
> > + * @mst_path: MST path to find in the connector
> > + *
> > + * Returns 0 when no connector is found with the correct mst path
> > + */
> > +uint32_t igt_get_connector_id_from_mst_path(int drm_fd, const void *mst_path)
> > +{
> > +	drmModeResPtr res = drmModeGetResources(drm_fd);
> > +	int i;
> > +
> > +	if (!res)
> > +		return 0;
> > +
> > +	for (i = 0; i < res->count_connectors; i++) {
> > +		uint32_t connector_id = res->connectors[i];
> > +
> > +		drmModePropertyBlobPtr path_blob = kmstest_get_path_blob(drm_fd, connector_id);
> > +
> > +		if (path_blob) {
> > +			if (strcmp(path_blob->data, mst_path) == 0) {
> > +				drmModeFreePropertyBlob(path_blob);
> > +				drmModeFreeResources(res);
> > +				return connector_id;
> > +			}
> > +			drmModeFreePropertyBlob(path_blob);
> > +		}
> > +	}
> > +	drmModeFreeResources(res);
> > +	return 0;
> > +}
> > diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> > index 4674b271638a..e9732c247dea 100644
> > --- a/lib/igt_kms.h
> > +++ b/lib/igt_kms.h
> > @@ -1266,5 +1266,8 @@ float igt_default_detect_timeout(void);
> >  bool igt_wait_for_connector_status(int drm_fd, unsigned int connector_id, double timeout,
> >  				   int drm_mode);
> >  int igt_get_connected_connectors(int drm_fd, uint32_t **connector_ids);
> > +drmModeConnectorPtr igt_get_connector_from_name(int drm_fd, const char *port_name);
> > +uint32_t igt_get_connector_id_from_name(int drm_fd, const char *port_name);
> > +uint32_t igt_get_connector_id_from_mst_path(int drm_fd, const void *mst_path);
> >  
> >  #endif /* __IGT_KMS_H__ */
> > 
> > -- 
> > 2.46.2
> > 

  reply	other threads:[~2024-11-08 15:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-22 10:28 [PATCH i-g-t v2 0/5] lib/igt_kms: Helpers for connector managment Louis Chauvet
2024-10-22 10:28 ` [PATCH i-g-t v2 1/5] lib/igt_kms: Add a detect timeout value Louis Chauvet
2024-11-06 14:12   ` Kamil Konieczny
2024-11-08 15:23     ` Louis Chauvet
2024-10-22 10:28 ` [PATCH i-g-t v2 2/5] lib/igt_kms: Add helper to wait for a specific status on a connector Louis Chauvet
2024-11-06 14:17   ` Kamil Konieczny
2024-11-08 15:23     ` Louis Chauvet
2024-10-22 10:28 ` [PATCH i-g-t v2 3/5] lib/igt_kms: Add function to list connected connectors Louis Chauvet
2024-11-06 14:20   ` Kamil Konieczny
2024-11-08 15:23     ` Louis Chauvet
2024-10-22 10:28 ` [PATCH i-g-t v2 4/5] lib/igt_kms: Add helper to obtain a connector by its name or MST path Louis Chauvet
2024-11-06 14:24   ` Kamil Konieczny
2024-11-08 15:23     ` Louis Chauvet [this message]
2024-10-22 10:28 ` [PATCH i-g-t v2 5/5] lib/igt_kms: Add function to get valid pipe for specific output Louis Chauvet
2024-11-06 14:28   ` Kamil Konieczny
2024-11-08 15:23     ` Louis Chauvet
2024-10-22 15:45 ` ✓ CI.xeBAT: success for lib/igt_kms: Helpers for connector managment (rev2) Patchwork
2024-10-22 15:47 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-10-22 17:57 ` ✗ CI.xeFULL: " 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=Zy4s-WgVEx4fJ3qN@fedora \
    --to=louis.chauvet@bootlin.com \
    --cc=adrinael@adrinael.net \
    --cc=arek@hiler.eu \
    --cc=ashutosh.dixit@intel.com \
    --cc=bhanuprakash.modem@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jeremie.dautheribes@bootlin.com \
    --cc=juhapekka.heikkila@gmail.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=markyacoub@google.com \
    --cc=nicolejadeyee@google.com \
    --cc=seanpaul@google.com \
    --cc=thomas.petazzoni@bootlin.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.