[Pixman] [PATCH] test: safeguard the scaling-bench test against COW

Siarhei Siamashka siarhei.siamashka at gmail.com
Wed Sep 4 22:07:52 PDT 2013


On Wed,  4 Sep 2013 03:12:51 +0300
Siarhei Siamashka <siarhei.siamashka at gmail.com> wrote:

> The calloc call from pixman_image_create_bits may still
> rely on http://en.wikipedia.org/wiki/Copy-on-write
> Explicitly initializing the destination image results in
> a more predictable behaviour.

A newer revision of this patch. To make the results of the scaling-bench
test more reliable and easier to analyze.


From ec3c89b1cba40c6a976aed5302dceb6020a6ba91 Mon Sep 17 00:00:00 2001
From: Siarhei Siamashka <siarhei.siamashka at gmail.com>
Date: Wed, 4 Sep 2013 03:04:36 +0300
Subject: [PATCH] test: safeguard the scaling-bench test against COW

The calloc call from pixman_image_create_bits may still
rely on http://en.wikipedia.org/wiki/Copy-on-write
Explicitly initializing the destination image results in
a more predictable behaviour.

V2:
 - allocate 16 bytes aligned buffer with aligned stride instead
   of delegating this to pixman_image_create_bits
 - use memset for the allocated buffer instead of pixman solid fill
 - repeat tests 3 times and select best results in order to filter
   out even more measurement noise
---
 test/scaling-bench.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/test/scaling-bench.c b/test/scaling-bench.c
index b39adef..365e798 100644
--- a/test/scaling-bench.c
+++ b/test/scaling-bench.c
@@ -3,6 +3,7 @@
 
 #define SOURCE_WIDTH 320
 #define SOURCE_HEIGHT 240
+#define TEST_REPEATS 3
 
 static pixman_image_t *
 make_source (void)
@@ -39,30 +40,40 @@ main ()
 	    "time per pixel / ns");
     for (scale = 0.1; scale < 10.005; scale += 0.01)
     {
+	int i;
 	int dest_width = SOURCE_WIDTH * scale + 0.5;
 	int dest_height = SOURCE_HEIGHT * scale + 0.5;
+	int dest_byte_stride = (dest_width * 4 + 15) & ~15;
 	pixman_fixed_t s = (1 / scale) * 65536.0 + 0.5;
 	pixman_transform_t transform;
 	pixman_image_t *dest;
-	double t1, t2;
+	double t1, t2, t = -1;
+	uint32_t *dest_buf = aligned_malloc (16, dest_byte_stride * dest_height);
+	memset (dest_buf, 0, dest_byte_stride * dest_height);
 
 	pixman_transform_init_scale (&transform, s, s);
 	pixman_image_set_transform (src, &transform);
 	
 	dest = pixman_image_create_bits (
-	    PIXMAN_a8r8g8b8, dest_width, dest_height, NULL, -1);
+	    PIXMAN_a8r8g8b8, dest_width, dest_height, dest_buf, dest_byte_stride);
+
+	for (i = 0; i < TEST_REPEATS; i++)
+	{
+	    t1 = gettime();
+	    pixman_image_composite (
+		PIXMAN_OP_OVER, src, NULL, dest,
+		scale, scale, 0, 0, 0, 0, dest_width, dest_height);
+	    t2 = gettime();
+	    if (t < 0 || t2 - t1 < t)
+		t = t2 - t1;
+	}
 
-	t1 = gettime();
-	pixman_image_composite (
-	    PIXMAN_OP_OVER, src, NULL, dest,
-	    scale, scale, 0, 0, 0, 0, dest_width, dest_height);
-	t2 = gettime();
-	
 	printf ("%6.2f : %4dx%-4d => %4dx%-4d : %12.4f : %12.4f\n",
 		scale, SOURCE_WIDTH, SOURCE_HEIGHT, dest_width, dest_height,
-		(t2 - t1) * 1000, ((t2 - t1) / (dest_width * dest_height)) * 1000000000);
+		t * 1000, (t / (dest_width * dest_height)) * 1000000000);
 
 	pixman_image_unref (dest);
+	free (dest_buf);
     }
 
     return 0;
-- 
1.8.1.5


-- 
Best regards,
Siarhei Siamashka


More information about the Pixman mailing list