[PATCH i-g-t v1 5/5] tests/kms_flip: Add CPU busy thread simulation using Cairo rendering

Naladala Ramanaidu ramanaidu.naladala at intel.com
Thu Aug 7 07:31:49 UTC 2025


Introduced a new test flag to simulate CPU load during flip tests.
Threads are launched to generate continuous rendering activity, and
properly managed across test execution and cleanup. Enhances stress
testing under CPU contention.

Signed-off-by: Naladala Ramanaidu <ramanaidu.naladala at intel.com>
---
 tests/kms_flip.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index a4860e9cc..1c4df9dc8 100755
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -263,6 +263,7 @@
 #define TEST_DEGAMMA		(1 << 17)
 #define TEST_GAMMA		(1 << 25)
 #define TEST_CTM		(1 << 27)
+#define TEST_CPU_BUSY		(1 << 2)
 
 #define EVENT_FLIP		(1 << 0)
 #define EVENT_VBLANK		(1 << 1)
@@ -274,6 +275,8 @@
 #define DRM_CAP_TIMESTAMP_MONOTONIC 6
 #endif
 
+#define CPU_BUSY_THREADS 9
+
 static bool all_pipes = false;
 
 drmModeRes *resources;
@@ -849,6 +852,47 @@ static bool is_wedged(int fd)
 	return errno == EIO;
 }
 
+static inline double rand_double(unsigned int *seed)
+{
+	return rand_r(seed) / (double)RAND_MAX;
+}
+
+static void *cpu_busy_thread(void *arg)
+{
+	int width = 500;
+	int height = 500;
+	cairo_surface_t *surface;
+	cairo_t *cr;
+	unsigned int seed;
+
+	surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+					     width, height);
+	cr = cairo_create(surface);
+	cairo_set_source_rgb(cr, 1, 1, 1);
+	cairo_paint(cr);
+
+	seed = time(NULL) ^ pthread_self();
+
+	while (1) {
+		double x = rand() % width;
+		double y = rand() % height;
+		double radius = 5 + rand() % 20;
+		double r = rand_double(&seed);
+		double g = rand_double(&seed);
+		double b = rand_double(&seed);
+		double alpha = 0.05 + rand_double(&seed) * 0.2;
+
+		cairo_set_source_rgba(cr, r, g, b, alpha);
+		cairo_arc(cr, x, y, radius, 0, 2 * M_PI);
+		cairo_fill(cr);
+		pthread_testcancel();
+	}
+
+	cairo_destroy(cr);
+	cairo_surface_destroy(surface);
+	return NULL;
+}
+
 static int set_mode(struct test_output *o, uint32_t fb, int x, int y)
 {
 	int n, ret;
@@ -1593,6 +1637,7 @@ static void __run_test_on_crtc_set(struct test_output *o, int *crtc_idxs,
 	data_t data = {};
 	gamma_lut_t *degamma_lut, *gamma_full;
 	igt_pipe_t *pipe;
+	pthread_t threads[CPU_BUSY_THREADS];
 
 restart:
 	last_connector = o->kconnector[0];
@@ -1669,6 +1714,11 @@ restart:
 		}
 	}
 
+	if (o->flags & TEST_CPU_BUSY) {
+		for (i = 0; i < CPU_BUSY_THREADS; ++i)
+			igt_assert(pthread_create(&threads[i], NULL, cpu_busy_thread, NULL) == 0);
+	}
+
 	paint_flip_mode(&o->fb_info[0], false);
 	if (!(o->flags & TEST_BO_TOOBIG))
 		paint_flip_mode(&o->fb_info[1], true);
@@ -1810,6 +1860,18 @@ retry:
 			}
 
 			igt_display_commit(&display);
+
+			if (o->flags & TEST_CPU_BUSY) {
+				for (i = 0; i < CPU_BUSY_THREADS; ++i) {
+					if (pthread_cancel(threads[i]) != 0)
+						perror("Failed to cancel thread");
+					else
+						printf("Thread %d canceled.\n", i);
+				}
+
+				for (i = 0; i < CPU_BUSY_THREADS; ++i)
+					pthread_join(threads[i], NULL);
+			}
 		}
 
 		igt_assert(!retried);
@@ -1849,6 +1911,17 @@ out:
 
 	igt_display_commit(&display);
 
+	if (o->flags & TEST_CPU_BUSY) {
+		for (i = 0; i < CPU_BUSY_THREADS; ++i) {
+			if (pthread_cancel(threads[i]) != 0)
+				perror("Failed to cancel thread");
+			else
+				printf("Thread %d canceled.\n", i);
+		}
+		for (i = 0; i < CPU_BUSY_THREADS; ++i)
+			pthread_join(threads[i], NULL);
+	}
+
 	last_connector = NULL;
 
 	free_test_output(o);
@@ -2211,8 +2284,8 @@ igt_main_args("e", NULL, help_str, opt_handler, NULL)
 		{ 10, TEST_MODESET | TEST_VBLANK_RACE | TEST_CHECK_TS, "modeset-vs-vblank-race" },
 		{ 0, TEST_BO_TOOBIG | TEST_NO_2X_OUTPUT, "bo-too-big" },
 		{ 10, TEST_FLIP | TEST_SUSPEND, "flip-vs-suspend" },
-		{ 30, TEST_DEGAMMA | TEST_GAMMA | TEST_CTM | TEST_FLIP | TEST_CHECK_TS,
-			"flip-color-cpu-busy" },
+		{ 30, TEST_DEGAMMA | TEST_GAMMA | TEST_CTM | TEST_CPU_BUSY | TEST_FLIP |
+			TEST_CHECK_TS, "flip-color-cpu-busy" },
 	};
 	int i;
 
-- 
2.43.0



More information about the Intel-gfx-trybot mailing list