[glib/wip/linux: 1/6] rec-mutex testcase: add a performance test
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/linux: 1/6] rec-mutex testcase: add a performance test
- Date: Sun, 2 Oct 2011 16:58:15 +0000 (UTC)
commit 4059b92bc377bb4c617db7109dd49643b87d9a31
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Oct 2 12:08:56 2011 -0400
rec-mutex testcase: add a performance test
Add a reasonable performance test for uncontended and contended cases at
different levels of recursion depth.
glib/tests/rec-mutex.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/rec-mutex.c b/glib/tests/rec-mutex.c
index 9ade360..67b6cff 100644
--- a/glib/tests/rec-mutex.c
+++ b/glib/tests/rec-mutex.c
@@ -22,6 +22,8 @@
#include <glib.h>
+#include <stdio.h>
+
static void
test_rec_mutex1 (void)
{
@@ -152,6 +154,71 @@ test_rec_mutex4 (void)
g_assert (owners[i] == NULL);
}
+#define COUNT_TO 100000000
+
+static gint depth;
+
+static gboolean
+do_addition (gint *value)
+{
+ static GRecMutex lock;
+ gboolean more;
+ gint i;
+
+ /* test performance of "good" cases (ie: short critical sections) */
+ for (i = 0; i < depth; i++)
+ g_rec_mutex_lock (&lock);
+
+ if ((more = *value != COUNT_TO))
+ if (*value != -1)
+ (*value)++;
+
+ for (i = 0; i < depth; i++)
+ g_rec_mutex_unlock (&lock);
+
+ return more;
+}
+
+static gpointer
+addition_thread (gpointer value)
+{
+ while (do_addition (value));
+
+ return NULL;
+}
+
+static void
+test_mutex_perf (gconstpointer data)
+{
+ gint c = GPOINTER_TO_INT (data);
+ GThread *threads[THREADS];
+ gint64 start_time;
+ gint n_threads;
+ gdouble rate;
+ gint x = -1;
+ gint i;
+
+ n_threads = c / 256;
+ depth = c % 256;
+
+ for (i = 0; i < n_threads - 1; i++)
+ threads[i] = g_thread_create (addition_thread, &x, TRUE, NULL);
+
+ /* avoid measuring thread setup/teardown time */
+ start_time = g_get_monotonic_time ();
+ g_atomic_int_set (&x, 0);
+ addition_thread (&x);
+ g_assert_cmpint (g_atomic_int_get (&x), ==, COUNT_TO);
+ rate = g_get_monotonic_time () - start_time;
+ rate = x / rate;
+
+ for (i = 0; i < n_threads - 1; i++)
+ g_thread_join (threads[i]);
+
+ g_test_maximized_result (rate, "%f mips", rate);
+}
+
+
int
main (int argc, char *argv[])
{
@@ -162,5 +229,26 @@ main (int argc, char *argv[])
g_test_add_func ("/thread/rec-mutex3", test_rec_mutex3);
g_test_add_func ("/thread/rec-mutex4", test_rec_mutex4);
+ if (g_test_perf ())
+ {
+ gint i, j;
+
+ for (i = 0; i < 5; i++)
+ for (j = 1; j <= 5; j++)
+ {
+ gchar name[80];
+ guint c;
+
+ c = i * 256 + j;
+
+ if (i)
+ sprintf (name, "/thread/rec-mutex/perf/contended%d/depth%d", i, j);
+ else
+ sprintf (name, "/thread/rec-mutex/perf/uncontended/depth%d", j);
+
+ g_test_add_data_func (name, GINT_TO_POINTER (c), test_mutex_perf);
+ }
+ }
+
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]