public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Kory Maincent <kory.maincent@bootlin.com>
To: Louis Chauvet <louis.chauvet@bootlin.com>
Cc: igt-dev@lists.freedesktop.org, thomas.petazzoni@bootlin.com,
	luca.ceresoli@bootlin.com, markyacoub@google.com,
	khaled.almahallawy@intel.com
Subject: Re: [PATCH i-g-t v7 05/48] lib/igt_kms: Add helper to wait for new connectors
Date: Mon, 23 Feb 2026 15:00:14 +0100	[thread overview]
Message-ID: <20260223150014.2eb4eef7@kmaincent-XPS-13-7390> (raw)
In-Reply-To: <20260223-unigraf-integration-v7-5-73dc9143c8c1@bootlin.com>

On Mon, 23 Feb 2026 13:09:12 +0100
Louis Chauvet <louis.chauvet@bootlin.com> wrote:

> Add list comparison utilities and a new function to wait for new
> connectors to appear on the system.
> 
> Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
> Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
> ---
>  lib/igt_kms.c | 96
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h |
> 6 ++++ 2 files changed, 102 insertions(+)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 8876ee8a11f7..514d905fe1fe 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -8170,3 +8170,99 @@ uint32_t igt_get_connector_id_from_mst_path(int
> drm_fd, const void *mst_path) 
>  	return 0;
>  }
> +
> +/**
> + * list_contains() - Search an element in the list
> + *
> + * @list: Pointer to the list to search into
> + * @list_len: Length of the list
> + * @value: Value to search in the list
> + *
> + * Returns true if @list contains @value
> + */
> +static bool list_contains(const uint32_t *list, int list_len, uint32_t value)
> +{
> +	igt_assert((!list && list_len == 0) || list);

You could simply do this here: igt_assert(list_len == 0 || list);


> +	for (int i = 0; i < list_len; i++) {
> +		if (list[i] == value)
> +			return true;
> +	}

You can remove the for loop bracket for a cleaner code.

> +	return false;
> +}
> +
> +/**
> + * get_list_diff() - Compute and return the set difference between two lists
> + *
> + * @list_a: Pointer to the first list to compare
> + * @list_a_len: Length of the first list
> + * @list_b: Pointer to the second list to compare
> + * @list_b_len: Length of the second list
> + * @diff: Out pointer returning a list of items in list_a but not
> + *        in list_b. Can be NULL to only count the elements.
> + *
> + * Returns the number of element which are in @list_a but not in @list_b.
> + */
> +int
> +get_list_diff(const uint32_t *list_a, int list_a_len, const uint32_t
> *list_b, int list_b_len,
> +	      uint32_t **diff)
> +{
> +	int diff_len = 0;
> +
> +	igt_assert((!list_a && list_a_len == 0) || list_a);
> +	igt_assert((!list_b && list_b_len == 0) || list_b);

Same here.

> +
> +	if (diff)
> +		*diff = malloc(sizeof(**diff));
> +
> +	for (int i = 0; i < list_a_len; i++) {
> +		if (!list_contains(list_b, list_b_len, list_a[i])) {
> +			if (diff) {
> +				*diff = reallocarray(*diff, diff_len + 1,
> sizeof(**diff));
> +				igt_assert(*diff);
> +				(*diff)[diff_len] = list_a[i];
> +			}
> +
> +			diff_len++;
> +		}
> +	}
> +
> +	return diff_len;
> +}
> +
> +/**
> + * kms_wait_for_new_connectors() - Wait for new connector to appear
> + *
> + * @newly_connected: Out pointer returning the list of connectors currently
> + *                   found connected
> + * @already_connected: Input pointer to list of connectors previously
> + *                     connected
> + * @already_connected_count: Length of @already_connected
> + * @drm_fd: DRM file descriptor
> + *
> + * Returns the number of connectors not in @already_connected and currently
> + * found connected.
> + */
> +int kms_wait_for_new_connectors(uint32_t **newly_connected,
> +				const uint32_t *already_connected,
> +				int already_connected_count, int drm_fd)
> +{
> +	int newly_connected_count;
> +	struct timespec start, end;
> +
> +	igt_assert(newly_connected);
> +	igt_assert(drm_fd);
> +
> +	clock_gettime(CLOCK_MONOTONIC, &start);
> +	clock_gettime(CLOCK_MONOTONIC, &end);
> +	do {
> +		if (*newly_connected)
> +			free(*newly_connected);
> +		newly_connected_count = igt_get_connected_connectors(drm_fd,
> newly_connected);
> +		clock_gettime(CLOCK_MONOTONIC, &end);
> +	} while (get_list_diff(*newly_connected, newly_connected_count,
> +			       already_connected, already_connected_count,
> +			       NULL) == 0 &&
> +		 igt_time_elapsed(&start, &end) <=
> igt_default_display_detect_timeout());

!get_list_diff(...)

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

  reply	other threads:[~2026-02-23 14:00 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23 12:09 [PATCH i-g-t v7 00/48] Unigraf integration Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 01/48] lib/igt_kms: Add a detect timeout value Louis Chauvet
2026-02-23 13:21   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 02/48] lib/igt_kms: Add helper to wait for a specific status on a connector Louis Chauvet
2026-02-23 13:23   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 03/48] lib/igt_kms: Add function to list connected connectors Louis Chauvet
2026-02-23 13:41   ` Kory Maincent
2026-02-26  8:35     ` Kamil Konieczny
2026-02-23 12:09 ` [PATCH i-g-t v7 04/48] lib/igt_kms: Add helper to obtain a connector by its name or MST path Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 05/48] lib/igt_kms: Add helper to wait for new connectors Louis Chauvet
2026-02-23 14:00   ` Kory Maincent [this message]
2026-02-26 16:17   ` Kamil Konieczny
2026-02-23 12:09 ` [PATCH i-g-t v7 06/48] lib/igt_kms: Add helper to get a pipe from a connector Louis Chauvet
2026-03-03 18:00   ` [i-g-t,v7,06/48] " Joshi, Kunal1
2026-02-23 12:09 ` [PATCH i-g-t v7 07/48] lib/igt_kms: Expose dump_connector_attrs Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 08/48] lib/igt_kms: Expose reset_connectors_at_exit Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 09/48] lib/igt_kms: Expose connector_attr_set and igt_connector_attr_set Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 10/48] lib/igt_debugfs: Move debugfs helpers to the proper location Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 11/48] lib/igt_debugfs: Add const when make sense Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 12/48] lib/igt_amd: " Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 13/48] lib/igt_kms: " Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 14/48] lib/monitor_edids: Add helper functions for using monitor_edid objects Louis Chauvet
2026-02-23 14:07   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 15/48] lib/monitor_edids: Add helper to get an EDID by its name Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 16/48] lib/monitor_edids: Add helper to print all available EDID names Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 17/48] lib/unigraf: Add used defines for TSI_Types Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 18/48] lib/unigraf: Add TSI.h Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 19/48] lib/unigraf: Initial Unigraf support Louis Chauvet
2026-02-23 14:12   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 20/48] lib/igt_kms: Automatically connect unigraf on display require Louis Chauvet
2026-02-23 14:13   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 21/48] lib/unigraf: Introduce device configuration Louis Chauvet
2026-02-23 14:22   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 22/48] lib/unigraf: Introduce role configuration Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 23/48] lib/unigraf: Introduce input configuration Louis Chauvet
2026-02-23 14:26   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 24/48] lib/unigraf: Add reset function Louis Chauvet
2026-02-23 14:26   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 25/48] lib/unigraf: Add unigraf assert and deassert helpers Louis Chauvet
2026-02-23 14:31   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 26/48] lib/unigraf: Add plug/unplug helpers Louis Chauvet
2026-03-03 18:16   ` [i-g-t,v7,26/48] " Joshi, Kunal1
2026-02-23 12:09 ` [PATCH i-g-t v7 27/48] lib/unigraf: Allows sst/mst configuration Louis Chauvet
2026-02-23 14:34   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 28/48] lib/unigraf: Add helpers to read and write edid Louis Chauvet
2026-02-23 14:37   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 29/48] lib/unigraf: Add connector and EDID configuration Louis Chauvet
2026-02-23 15:03   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 30/48] tests/unigraf: Add basic unigraf tests Louis Chauvet
2026-02-23 15:11   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 31/48] lib/unigraf: Add unigraf CRC capture Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 32/48] lib/unigraf: Add configuration for CRC usage Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 33/48] lib/unigraf: add unigraf_get_connector_by_stream Louis Chauvet
2026-02-23 15:13   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 34/48] lib/unigraf: Add helper to check timings received by unigraf Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 35/48] lib/igt_pipe_crc: Add unigraf crc calculation Louis Chauvet
2026-02-23 15:16   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 36/48] lib/i915/dp: Move DP-related function for i915 to proper folder Louis Chauvet
2026-02-23 15:43   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 37/48] lib/i915/dp: Rename functions to avoid confusion Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 38/48] lib/i915/dp: Add helper to get maximum supported rate Louis Chauvet
2026-02-23 15:45   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 39/48] lib/i915/dp: Properly check sscanf results Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 40/48] lib/i915/dp: Use igt_output_name instead of private field Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 41/48] lib/igt_dp: Create generic helpers for DP information Louis Chauvet
2026-02-23 15:56   ` Kory Maincent
2026-02-25 10:00     ` Louis Chauvet
2026-02-25 10:20       ` Kory Maincent
2026-02-26 15:56   ` Kamil Konieczny
2026-02-23 12:09 ` [PATCH i-g-t v7 42/48] lib/igt_kms: Add asserts to avoid null pointer dereference Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 43/48] lib/igt_kms: Add helper to get a CRTC from an output Louis Chauvet
2026-02-23 16:09   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 44/48] lib/unigraf: Add lane count configuration Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 45/48] docs/unigraf: Add unigraf documentation Louis Chauvet
2026-02-23 16:11   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 46/48] lib/unigraf: Add helpers to set maximum link rate Louis Chauvet
2026-02-23 16:14   ` Kory Maincent
2026-02-23 12:09 ` [PATCH i-g-t v7 47/48] lib/unigraf: Add helpers to get the current LT status Louis Chauvet
2026-02-23 12:09 ` [PATCH i-g-t v7 48/48] tests/unigraf/unigraf_lt: Add test for link training Louis Chauvet
2026-02-23 13:30 ` ✓ Xe.CI.BAT: success for Unigraf integration (rev6) Patchwork
2026-02-23 13:44 ` ✗ i915.CI.BAT: failure " Patchwork
2026-02-24  6:15 ` ✗ Xe.CI.FULL: " 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=20260223150014.2eb4eef7@kmaincent-XPS-13-7390 \
    --to=kory.maincent@bootlin.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=khaled.almahallawy@intel.com \
    --cc=louis.chauvet@bootlin.com \
    --cc=luca.ceresoli@bootlin.com \
    --cc=markyacoub@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox