From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Chris Mason <chris.mason@oracle.com>
Cc: Frank Rowand <frank.rowand@am.sony.com>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
Mike Galbraith <efault@gmx.de>, Oleg Nesterov <oleg@redhat.com>,
Paul Turner <pjt@google.com>, Jens Axboe <axboe@kernel.dk>,
Yong Zhang <yong.zhang0@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [RFC][PATCH] sembench: add stddev to the burn stats
Date: Mon, 03 Jan 2011 15:36:10 +0100 [thread overview]
Message-ID: <1294065370.2016.79.camel@laptop> (raw)
In-Reply-To: <20101224123743.303699501@chello.nl>
On Fri, 2010-12-24 at 13:23 +0100, Peter Zijlstra wrote:
> As measured using: http://oss.oracle.com/~mason/sembench.c
>
> $ echo 4096 32000 64 128 > /proc/sys/kernel/sem
> $ ./sembench -t 2048 -w 1900 -o 0
>
> unpatched: run time 30 seconds 537953 worker burns per second
> patched: run time 30 seconds 657336 worker burns per second
>
> Still need to sort out all the races marked XXX (non-trivial), and its
> x86 only for the moment.
---
Adds stats to see how stable the sembench results are, it does slow the
burn rate down, I guess because we're now touching the FPU and the
context switch overhead increases dramatically, but it does show its
relatively stable.
New output looks like:
# ./sembench -t 2048 -w 1900 -o 0 -r 30
main loop going
all done
2048 threads, waking 1900 at a time
using ipc sem operations
main thread burns: 2374
worker burn count total 4510600 min 1187 max 2374 avg 2202.441 +- 0.415%
run time 30 seconds 150353 worker burns per second
---
--- sembench.c 2010-04-12 20:45:50.000000000 +0200
+++ sembench3.c 2011-01-03 15:29:42.000000000 +0100
@@ -1,6 +1,6 @@
/*
* copyright Oracle 2007. Licensed under GPLv2
- * To compile: gcc -Wall -o sembench sembench.c -lpthread
+ * To compile: gcc -Wall -o sembench sembench.c -lpthread -lm
*
* usage: sembench -t thread count -w wakenum -r runtime -o op
* op can be: 0 (ipc sem) 1 (nanosleep) 2 (futexes)
@@ -28,8 +28,9 @@
#include <sys/time.h>
#include <sys/syscall.h>
#include <errno.h>
+#include <math.h>
-#define VERSION "0.2"
+#define VERSION "0.3"
/* futexes have been around since 2.5.something, but it still seems I
* need to make my own syscall. Sigh.
@@ -78,10 +79,55 @@
int *semid_lookup = NULL;
+struct stats
+{
+ double n, mean, M2;
+};
+
+static void update_stats(struct stats *stats, long long val)
+{
+ double delta;
+
+ stats->n++;
+ delta = val - stats->mean;
+ stats->mean += delta / stats->n;
+ stats->M2 += delta*(val - stats->mean);
+}
+
+static double avg_stats(struct stats *stats)
+{
+ return stats->mean;
+}
+
+/*
+ * http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
+ *
+ * (\Sum n_i^2) - ((\Sum n_i)^2)/n
+ * s^2 = -------------------------------
+ * n - 1
+ *
+ * http://en.wikipedia.org/wiki/Stddev
+ *
+ * The std dev of the mean is related to the std dev by:
+ *
+ * s
+ * s_mean = -------
+ * sqrt(n)
+ *
+ */
+static double stddev_stats(struct stats *stats)
+{
+ double variance = stats->M2 / (stats->n - 1);
+ double variance_mean = variance / stats->n;
+
+ return sqrt(variance_mean);
+}
+
pthread_mutex_t worklist_mutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned long total_burns = 0;
static unsigned long min_burns = ~0UL;
static unsigned long max_burns = 0;
+static struct stats burn_stats;
static int thread_count = 0;
struct lockinfo *worklist_head = NULL;
struct lockinfo *worklist_tail = NULL;
@@ -385,6 +431,7 @@
min_burns = burn_count;
if (burn_count > max_burns)
max_burns = burn_count;
+ update_stats(&burn_stats, burn_count);
thread_count--;
pthread_mutex_unlock(&worklist_mutex);
return (void *)0;
@@ -508,8 +555,9 @@
printf("%d threads, waking %d at a time\n", num_threads, wake_num);
printf("using %s\n", ops->name);
printf("main thread burns: %d\n", burn_count);
- printf("worker burn count total %lu min %lu max %lu avg %lu\n",
- total_burns, min_burns, max_burns, total_burns / num_threads);
+ printf("worker burn count total %lu min %lu max %lu avg %.3f +- %.3f%%\n",
+ total_burns, min_burns, max_burns, avg_stats(&burn_stats),
+ 100 * stddev_stats(&burn_stats) / avg_stats(&burn_stats));
printf("run time %d seconds %lu worker burns per second\n",
(int)(now.tv_sec - start.tv_sec),
total_burns / (now.tv_sec - start.tv_sec));
next prev parent reply other threads:[~2011-01-03 14:36 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-24 12:23 [RFC][PATCH 00/17] sched: Reduce runqueue lock contention -v3 Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 01/17] sched: Always provide p->on_cpu Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 02/17] mutex: Use p->on_cpu for the adaptive spin Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 03/17] sched: Change the ttwu success details Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 04/17] sched: Clean up ttwu stats Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 05/17] x86: Optimize arch_spin_unlock_wait() Peter Zijlstra
2010-12-24 18:26 ` Linus Torvalds
2011-01-03 11:32 ` Peter Zijlstra
2011-01-04 6:45 ` Nick Piggin
2011-01-05 19:14 ` [RFC][PATCH] spinlock: Kill spin_unlock_wait() Peter Zijlstra
2011-01-05 19:26 ` Oleg Nesterov
2011-01-05 19:43 ` Linus Torvalds
2011-01-06 9:32 ` Peter Zijlstra
2011-01-06 10:38 ` Nick Piggin
2011-01-06 18:26 ` Peter Zijlstra
2011-01-07 21:01 ` Tejun Heo
2011-01-07 21:13 ` Jeff Garzik
2011-01-07 21:13 ` Jeff Garzik
2011-01-07 21:33 ` Tejun Heo
2010-12-24 12:23 ` [RFC][PATCH 06/17] sched: Provide p->on_rq Peter Zijlstra
2010-12-29 14:14 ` Yong Zhang
2010-12-24 12:23 ` [RFC][PATCH 07/17] sched: Serialize p->cpus_allowed and ttwu() using p->pi_lock Peter Zijlstra
2010-12-29 14:20 ` Yong Zhang
2011-01-03 11:12 ` Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 08/17] sched: Drop the rq argument to sched_class::select_task_rq() Peter Zijlstra
2010-12-29 14:31 ` Yong Zhang
2011-01-03 11:16 ` Peter Zijlstra
2011-01-03 14:59 ` Oleg Nesterov
2011-01-03 15:21 ` Peter Zijlstra
2011-01-03 15:49 ` Oleg Nesterov
2011-01-03 16:35 ` Peter Zijlstra
2011-01-03 16:41 ` Peter Zijlstra
2011-01-04 7:27 ` Yong Zhang
2011-01-04 12:34 ` Peter Zijlstra
2011-01-04 5:59 ` Yong Zhang
2011-01-04 13:00 ` Peter Zijlstra
2011-01-03 18:05 ` Oleg Nesterov
2011-01-04 13:01 ` Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 09/17] sched: Remove rq argument to sched_class::task_waking() Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 10/17] sched: Add TASK_WAKING to task_rq_lock Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 11/17] sched: Delay task_contributes_to_load() Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 12/17] sched: Also serialize ttwu_local() with p->pi_lock Peter Zijlstra
2011-01-03 17:32 ` Oleg Nesterov
2011-01-09 23:11 ` Tejun Heo
2010-12-24 12:23 ` [RFC][PATCH 13/17] sched: Remove rq->lock from the first half of ttwu() Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 14/17] sched: Remove rq argument to ttwu_stat() Peter Zijlstra
2010-12-29 14:40 ` Yong Zhang
2011-01-03 11:20 ` Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 15/17] sched: Rename ttwu_post_activation Peter Zijlstra
2010-12-24 12:23 ` [RFC][PATCH 16/17] sched: Move the second half of ttwu() to the remote cpu Peter Zijlstra
2011-01-03 14:36 ` Peter Zijlstra [this message]
2011-01-04 14:28 ` Oleg Nesterov
2011-01-04 14:47 ` Peter Zijlstra
2011-01-04 15:18 ` Oleg Nesterov
2011-01-04 15:43 ` Peter Zijlstra
2011-01-04 16:06 ` Oleg Nesterov
2010-12-24 12:23 ` [RFC][PATCH 17/17] sched: Sort hotplug vs ttwu queueing Peter Zijlstra
2010-12-29 14:51 ` Yong Zhang
2011-01-03 11:21 ` Peter Zijlstra
2010-12-24 13:15 ` [RFC][PATCH 00/17] sched: Reduce runqueue lock contention -v3 Peter Zijlstra
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=1294065370.2016.79.camel@laptop \
--to=a.p.zijlstra@chello.nl \
--cc=axboe@kernel.dk \
--cc=chris.mason@oracle.com \
--cc=efault@gmx.de \
--cc=frank.rowand@am.sony.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=pjt@google.com \
--cc=tglx@linutronix.de \
--cc=yong.zhang0@gmail.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.