linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <jens.axboe@oracle.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Con Kolivas <kernel@kolivas.org>,
	linux-kernel@vger.kernel.org,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Mike Galbraith <efault@gmx.de>
Subject: Re: BFS vs. mainline scheduler benchmarks and measurements
Date: Mon, 7 Sep 2009 22:44:58 +0200	[thread overview]
Message-ID: <20090907204458.GJ18599@kernel.dk> (raw)
In-Reply-To: <20090907173846.GB18599@kernel.dk>

[-- Attachment #1: Type: text/plain, Size: 1454 bytes --]

On Mon, Sep 07 2009, Jens Axboe wrote:
> > And yes, it would be wonderful to get a test-app from you that would 
> > express the kind of pain you are seeing during compile jobs.
> 
> I was hoping this one would, but it's not showing anything. I even added
> support for doing the ping and wakeup over a socket, to see if the pipe
> test was doing well because of the sync wakeup we do there. The net
> latency is a little worse, but still good. So no luck in making that app
> so far.

Here's a version that bounces timestamps between a producer and a number
of consumers (clients). Not really tested much, but perhaps someone can
compare this on a box that boots BFS and see what happens.

To run it, use -cX where X is the number of children that you wait for a
response from. The max delay between this children is logged for each
wakeup. You can invoke it ala:

$ ./latt -c4 'make -j4'

and it'll dump the max/avg/stddev bounce time after make has completed,
or if you just want to play around, start the compile in one xterm and
do:

$ ./latt -c4 'sleep 5'

to just log for a small period of time. Vary the number of clients to
see how that changes the aggregated latency. 1 should be fast, adding
more clients quickly adds up.

Additionally, it has a -f and -t option that controls the window of
sleep time for the parent between each message. The numbers are in
msecs, and it defaults to a minimum of 100msecs and up to 500msecs.

-- 
Jens Axboe


[-- Attachment #2: latt.c --]
[-- Type: text/x-csrc, Size: 5561 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
#include <math.h>


/*
 * In msecs
 */
static unsigned int min_delay = 100;
static unsigned int max_delay = 500;
static unsigned int clients = 1;

#define MAX_CLIENTS		512

struct delays {
	unsigned long nr_delays;
	unsigned long mmap_entries;
	unsigned long max_delay;
	unsigned long delays[0];
};

static struct delays *delays;
static int pipes[MAX_CLIENTS][2];

static unsigned long avg;
static double stddev;

static pid_t app_pid;

#define CLOCKSOURCE		CLOCK_MONOTONIC

#define DEF_ENTRIES		1024

static int parse_options(int argc, char *argv[])
{
	struct option l_opts[] = {
		{ "min-delay", 	1, 	NULL,	'f' },
		{ "max-delay",	1,	NULL,	't' },
		{ "clients",	1,	NULL,	'c' }
	};
	int c, res, index = 0;

	while ((c = getopt_long(argc, argv, "f:t:c:", l_opts, &res)) != -1) {
		index++;
		switch (c) {
			case 'f':
				min_delay = atoi(optarg);
				break;
			case 't':
				max_delay = atoi(optarg);
				break;
			case 'c':
				clients = atoi(optarg);
				if (clients > MAX_CLIENTS)
					clients = MAX_CLIENTS;
				break;
		}
	}

	return index + 1;
}

static pid_t fork_off(const char *app)
{
	pid_t pid;

	pid = fork();
	if (pid)
		return pid;

	exit(system(app));
}

#define entries_to_size(n)	((n) * sizeof(unsigned long) + sizeof(struct delays))

static unsigned long usec_since(struct timespec *start, struct timespec *end)
{
	long secs, nsecs, delay;

	secs = end->tv_sec - start->tv_sec;
	nsecs = end->tv_nsec - start->tv_nsec;

	delay = secs * 1000000L;
	delay += (nsecs / 1000L);

	return delay;
}

static unsigned long usec_since_now(struct timespec *start)
{
	struct timespec e;

	clock_gettime(CLOCKSOURCE, &e);
	return usec_since(start, &e);
}

static void log_delay(unsigned long delay)
{
	if (delays->nr_delays == delays->mmap_entries) {
		unsigned long new_size;

		delays->mmap_entries <<= 1;
		new_size = entries_to_size(delays->mmap_entries);
		delays = realloc(delays, new_size);
	}

	delays->delays[delays->nr_delays++] = delay;

	if (delay > delays->max_delay)
		delays->max_delay = delay;
}

static void run_child(int *pipe)
{
	struct timespec ts;

	do {
		int ret;

		ret = read(pipe[0], &ts, sizeof(ts));
		if (ret <= 0)
			break;

		clock_gettime(CLOCKSOURCE, &ts);

		ret = write(pipe[1], &ts, sizeof(ts));
		if (ret <= 0)
			break;
	} while (1);
}

static void do_rand_sleep(void)
{
	unsigned int msecs;

	msecs = min_delay + ((float) max_delay * (rand() / (RAND_MAX + 1.0)));
	usleep(msecs * 1000);
}

static void kill_connection(void)
{
	int i;

	for (i = 0; i < clients; i++) {
		if (pipes[i][0] != -1) {
			close(pipes[i][0]);
			pipes[i][0] = -1;
		}
		if (pipes[i][1] != -1) {
			close(pipes[i][1]);
			pipes[i][1] = -1;
		}
	}
}

static void run_parent(void)
{
	struct timespec *t1, t2;
	int status, ret, do_exit = 0, i;

	t1 = malloc(sizeof(struct timespec) * clients);

	srand(1234);

	do {
		unsigned long delay, max_delay = 0;

		do_rand_sleep();

		ret = waitpid(app_pid, &status, WNOHANG);
		if (ret < 0) {
			perror("waitpid");
			break;
		} else if (ret == app_pid &&
			   (WIFSIGNALED(status) || WIFEXITED(status))) {
			do_exit = 1;
			kill_connection();
		}
			
		for (i = 0; i < clients; i++) {
			clock_gettime(CLOCKSOURCE, &t1[i]);
			if (write(pipes[i][1], &t1[i], sizeof(t2)) != sizeof(t2)) {
				do_exit = 1;
				break;
			}
		}

		for (i = 0; i < clients; i++) {
			if (read(pipes[i][0], &t2, sizeof(t2)) != sizeof(t2)) {
				do_exit = 1;
				break;
			}
			delay = usec_since(&t1[i], &t2);
			if (delay > max_delay)
				max_delay = delay;
		}

		log_delay(max_delay);
	} while (!do_exit);

	kill_connection();
}

static void parent_setup_connection(void)
{
	int i;

	for (i = 0; i < clients; i++) {
		if (pipe(pipes[i])) {
			perror("pipe");
			return;
		}
	}
}

static void run_test(void)
{
	pid_t cpids[MAX_CLIENTS];
	int i, status;

	parent_setup_connection();

	for (i = 0; i < clients; i++) {
		cpids[i] = fork();
		if (cpids[i])
			continue;

		run_child(pipes[i]);
		exit(0);
	}

	run_parent();

	for (i = 0; i < clients; i++)
		kill(cpids[i], SIGQUIT);
	for (i = 0; i < clients; i++)
		waitpid(cpids[i], &status, 0);
}

static void setup_shared_area(void)
{
	delays = malloc(entries_to_size(DEF_ENTRIES));
	delays->nr_delays = 0;
	delays->mmap_entries = DEF_ENTRIES;
}

static void calc_latencies(void)
{
	unsigned long long sum = 0;
	int i;

	if (!delays->nr_delays)
		return;

	for (i = 0; i < delays->nr_delays; i++)
		sum += delays->delays[i];

	avg = sum / delays->nr_delays;

	if (delays->nr_delays < 2)
		return;

	sum = 0;
	for (i = 0; i < delays->nr_delays; i++) {
		long diff;

		diff = delays->delays[i] - avg;
		sum += (diff * diff);
	}

	stddev = sqrt(sum / (delays->nr_delays - 1));
}

static void handle_sigint(int sig)
{
	kill(app_pid, SIGINT);
}

int main(int argc, char *argv[])
{
	int app_offset, off;
	char app[256];

	setup_shared_area();

	off = 0;
	app_offset = parse_options(argc, argv);
	while (app_offset < argc) {
		if (off) {
			app[off] = ' ';
			off++;
		}
		off += sprintf(app + off, "%s", argv[app_offset]);
		app_offset++;
	}

	signal(SIGINT, handle_sigint);
	app_pid = fork_off(app);
	run_test();

	calc_latencies();

	printf("Entries: %lu (clients=%d)\n", delays->nr_delays, clients);
	printf("\nAverages (in usecs)\n");
	printf("-------------------\n");
	printf("\tMax\t %lu\n", delays->max_delay);
	printf("\tAvg\t %lu\n", avg);
	printf("\tStdev\t %.0f\n", stddev);

	free(delays);
	return 0;
}

  reply	other threads:[~2009-09-07 20:44 UTC|newest]

Thread overview: 224+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-06 20:59 BFS vs. mainline scheduler benchmarks and measurements Ingo Molnar
2009-09-07  2:05 ` Frans Pop
2009-09-07 12:16   ` [quad core results] " Ingo Molnar
2009-09-07 12:36     ` Stefan Richter
2009-09-07 13:41     ` Markus Tornqvist
2009-09-07 13:59       ` Ingo Molnar
2009-09-09  5:54         ` Markus Tornqvist
2009-09-07 14:45       ` Arjan van de Ven
2009-09-07 15:20         ` Frans Pop
2009-09-07 15:36           ` Arjan van de Ven
2009-09-07 15:47             ` Frans Pop
2009-09-07 15:24         ` Xavier Bestel
2009-09-07 15:37           ` Arjan van de Ven
2009-09-07 16:00           ` Diego Calleja
2009-09-07 15:34     ` Nikos Chantziaras
2009-09-07  3:38 ` Nikos Chantziaras
2009-09-07 11:01   ` Frederic Weisbecker
2009-09-08 18:15     ` Nikos Chantziaras
2009-09-10 20:25       ` Frederic Weisbecker
2009-09-07 14:40   ` Arjan van de Ven
2009-09-08  7:19     ` Nikos Chantziaras
2009-09-08  8:31       ` Arjan van de Ven
2009-09-08 20:22         ` Frans Pop
2009-09-08 21:10           ` Michal Schmidt
2009-09-08 21:11           ` Frans Pop
2009-09-08 21:40             ` GeunSik Lim
2009-09-08 22:36               ` Frans Pop
2009-09-09  9:53           ` Benjamin Herrenschmidt
2009-09-09 11:14             ` David Newall
2009-09-09 11:32               ` Benjamin Herrenschmidt
2009-09-09 11:55             ` Frans Pop
2009-09-11  1:36               ` Benjamin Herrenschmidt
2009-09-16 18:27                 ` Frans Pop
2009-09-17  1:29                   ` Benjamin Herrenschmidt
2009-10-01  9:36                     ` Frans Pop
2009-09-08  8:38       ` Arjan van de Ven
2009-09-08 10:13         ` Nikos Chantziaras
2009-09-08 11:32           ` Juergen Beisert
2009-09-08 22:00             ` Nikos Chantziaras
2009-09-08 23:20               ` Jiri Kosina
2009-09-08 23:38                 ` Nikos Chantziaras
2009-09-08 12:03           ` Theodore Tso
2009-09-08 21:28             ` Nikos Chantziaras
2009-09-08 14:20           ` Arjan van de Ven
2009-09-08 22:53             ` Nikos Chantziaras
2009-09-07 23:54   ` Thomas Fjellstrom
2009-09-08 11:30     ` Nikos Chantziaras
2009-09-07  3:50 ` Con Kolivas
2009-09-07 18:20   ` Jerome Glisse
2009-09-07  9:49 ` Jens Axboe
2009-09-07 10:12   ` Nikos Chantziaras
2009-09-07 10:41     ` Jens Axboe
2009-09-07 11:57   ` Jens Axboe
2009-09-07 14:14     ` Ingo Molnar
2009-09-07 17:38       ` Jens Axboe
2009-09-07 20:44         ` Jens Axboe [this message]
2009-09-08  9:13           ` Jens Axboe
2009-09-08 15:23             ` Peter Zijlstra
2009-09-08 20:34               ` Jens Axboe
2009-09-09  6:13                 ` Ingo Molnar
2009-09-09  8:34                   ` Nikos Chantziaras
2009-09-09  8:52                   ` Mike Galbraith
2009-09-09  9:02                     ` Peter Zijlstra
2009-09-09  9:18                       ` Mike Galbraith
2009-09-09  9:05                     ` Nikos Chantziaras
2009-09-09  9:17                       ` Peter Zijlstra
2009-09-09  9:40                         ` Nikos Chantziaras
2009-09-09 10:17                           ` Nikos Chantziaras
2009-09-10 19:45                         ` Martin Steigerwald
2009-09-10 20:06                           ` Ingo Molnar
2009-09-10 20:39                             ` Martin Steigerwald
2009-09-10 20:42                               ` Ingo Molnar
2009-09-10 21:19                                 ` Martin Steigerwald
2009-09-11  9:26                                   ` Mat
2009-09-12 11:26                                     ` Martin Steigerwald
2009-09-09  9:10                     ` Jens Axboe
2009-09-09 11:54                       ` Jens Axboe
2009-09-09 12:20                         ` Jens Axboe
2009-09-09 18:04                           ` Ingo Molnar
2009-09-09 20:12                             ` Nikos Chantziaras
2009-09-09 20:50                               ` Jens Axboe
2009-09-10  1:02                                 ` Con Kolivas
2009-09-10 11:03                                   ` Jens Axboe
2009-09-10  3:15                               ` Mike Galbraith
2009-09-10  6:08                               ` Ingo Molnar
2009-09-10  6:40                                 ` Ingo Molnar
2009-09-10  9:54                                   ` Jens Axboe
2009-09-10 10:03                                     ` Ingo Molnar
2009-09-10 10:11                                       ` Jens Axboe
2009-09-10 10:28                                         ` Jens Axboe
2009-09-10 10:57                                           ` Mike Galbraith
2009-09-10 11:09                                             ` Jens Axboe
2009-09-10 11:21                                               ` Mike Galbraith
2009-09-10 11:24                                                 ` Jens Axboe
2009-09-10 11:28                                                   ` Mike Galbraith
2009-09-10 11:35                                                     ` Jens Axboe
2009-09-10 11:42                                                       ` Mike Galbraith
2009-09-10 16:02                                 ` Bret Towe
2009-09-10 16:05                                   ` Peter Zijlstra
2009-09-10 16:12                                     ` Bret Towe
2009-09-10 16:26                                       ` Ingo Molnar
2009-09-10 16:33                                         ` Bret Towe
2009-09-10 17:03                                           ` Ingo Molnar
2009-09-10 17:53                                 ` Nikos Chantziaras
2009-09-10 18:46                                   ` Ingo Molnar
2009-09-10 18:51                                   ` [tip:sched/core] sched: Disable NEW_FAIR_SLEEPERS for now tip-bot for Ingo Molnar
2009-09-10 18:57                                   ` [tip:sched/core] sched: Fix sched::sched_stat_wait tracepoint field tip-bot for Ingo Molnar
2009-09-10  9:48                             ` BFS vs. mainline scheduler benchmarks and measurements Jens Axboe
2009-09-10  9:59                               ` Ingo Molnar
2009-09-10 10:01                                 ` Jens Axboe
2009-09-10  6:55                           ` Peter Zijlstra
2009-09-10  6:58                             ` Jens Axboe
2009-09-10  7:04                               ` Ingo Molnar
2009-09-10  9:44                                 ` Jens Axboe
2009-09-10  9:45                                   ` Jens Axboe
2009-09-10 13:53                                   ` Steven Rostedt
2009-09-10  7:33                               ` Jens Axboe
2009-09-10  7:49                                 ` Ingo Molnar
2009-09-10  7:53                                   ` Jens Axboe
2009-09-10 10:02                                     ` Ingo Molnar
2009-09-10 10:09                                       ` Jens Axboe
2009-09-10 18:00                                       ` [crash, bisected] Re: clocksource: Resolve cpu hotplug dead lock with TSC unstable Ingo Molnar
2009-09-11  7:37                                         ` Ingo Molnar
2009-09-11  7:48                                           ` Martin Schwidefsky
2009-09-11 13:33                                           ` Martin Schwidefsky
2009-09-11 18:22                                             ` [tip:timers/core] clocksource: Resolve cpu hotplug dead lock with TSC unstable, fix crash tip-bot for Martin Schwidefsky
2009-09-14 15:19                                             ` [crash, bisected] Re: clocksource: Resolve cpu hotplug dead lock with TSC unstable Ingo Molnar
2009-09-14 15:37                                               ` Martin Schwidefsky
2009-09-14 17:59                                               ` Martin Schwidefsky
2009-09-10  6:59                             ` BFS vs. mainline scheduler benchmarks and measurements Ingo Molnar
2009-09-09 12:48                         ` Mike Galbraith
2009-09-09 15:37                     ` [tip:sched/core] sched: Turn off child_runs_first tip-bot for Mike Galbraith
2009-09-09 17:57                       ` Theodore Tso
2009-09-09 18:08                         ` Ingo Molnar
2009-09-09 18:59                           ` Chris Friesen
2009-09-09 19:48                           ` Pavel Machek
2009-09-09 15:37                     ` [tip:sched/core] sched: Re-tune the scheduler latency defaults to decrease worst-case latencies tip-bot for Mike Galbraith
2009-09-12 11:45                       ` Martin Steigerwald
2009-09-09 15:37                     ` [tip:sched/core] sched: Keep kthreads at default priority tip-bot for Mike Galbraith
2009-09-09 16:55                       ` Dmitry Torokhov
2009-09-09 17:06                         ` Peter Zijlstra
2009-09-09 17:34                           ` Mike Galbraith
2009-09-12 11:48                             ` Martin Steigerwald
2009-09-12 12:19                               ` Mike Galbraith
2009-09-09 11:52               ` BFS vs. mainline scheduler benchmarks and measurements Nikos Chantziaras
2009-09-07 18:02   ` Avi Kivity
2009-09-07 18:46     ` Jens Axboe
2009-09-07 20:36       ` Ingo Molnar
2009-09-07 20:46         ` Jens Axboe
2009-09-07 21:03           ` Peter Zijlstra
2009-09-07 21:05             ` Jens Axboe
2009-09-07 22:18               ` Ingo Molnar
2009-09-09  7:38   ` Pavel Machek
2009-09-10 12:19     ` latt location (Was Re: BFS vs. mainline scheduler benchmarks and measurements) Jens Axboe
2009-09-07 15:16 ` BFS vs. mainline scheduler benchmarks and measurements Michael Buesch
2009-09-07 18:26   ` Ingo Molnar
2009-09-07 18:47     ` Daniel Walker
2009-09-07 18:51     ` Michael Buesch
2009-09-07 20:57       ` Ingo Molnar
2009-09-07 23:24         ` Pekka Pietikainen
2009-09-08  8:04           ` Ingo Molnar
2009-09-08  8:13             ` Nikos Chantziaras
2009-09-08 10:12               ` Ingo Molnar
2009-09-08 10:40                 ` Nikos Chantziaras
2009-09-08 11:35                   ` Ingo Molnar
2009-09-08 19:06                     ` Nikos Chantziaras
2009-09-08 12:00                 ` el_es
2009-09-08 15:45         ` Michael Buesch
2009-09-08  7:48     ` Ingo Molnar
2009-09-08  9:50       ` Benjamin Herrenschmidt
2009-09-08 13:09         ` Ralf Baechle
2009-09-09  1:36           ` Felix Fietkau
2009-09-08 13:09         ` Felix Fietkau
2009-09-09  0:28           ` Benjamin Herrenschmidt
2009-09-09  0:37             ` David Miller
2009-09-08 14:45       ` Michael Buesch
2009-09-18 11:24         ` Ingo Molnar
2009-09-18 14:46           ` Felix Fietkau
2009-09-19 18:01             ` Ingo Molnar
2009-09-19 18:43               ` Felix Fietkau
2009-09-19 19:39                 ` Ingo Molnar
2009-09-19 20:15                   ` Felix Fietkau
2009-09-19 20:22                     ` Ingo Molnar
2009-09-19 20:33                       ` Felix Fietkau
2009-09-20 18:10                         ` Ingo Molnar
2009-09-08 12:57 ` Epic regression in throughput since v2.6.23 Serge Belyshev
2009-09-08 17:47   ` Jesse Brandeburg
2009-09-08 18:20     ` Nikos Chantziaras
2009-09-08 19:00     ` Jeff Garzik
2009-09-08 19:20       ` Serge Belyshev
2009-09-08 19:26         ` Jeff Garzik
2009-09-08 18:37   ` Nikos Chantziaras
2009-09-08 22:15   ` Serge Belyshev
2009-09-09 15:52     ` Ingo Molnar
2009-09-09 20:49       ` Serge Belyshev
2009-09-09 21:23         ` Cory Fields
2009-09-10  6:53         ` Ingo Molnar
2009-09-10 23:23           ` Serge Belyshev
2009-09-11  6:10             ` Ingo Molnar
2009-09-11  8:55               ` Serge Belyshev
2009-09-13 15:27               ` Serge Belyshev
2009-09-13 15:47                 ` Ingo Molnar
2009-09-13 19:17                   ` Mike Galbraith
2009-09-14  6:15                     ` Mike Galbraith
2009-09-16 19:45                 ` Ingo Molnar
2009-09-16 23:18                   ` Serge Belyshev
2009-09-17  4:55                     ` [patchlet] " Mike Galbraith
2009-09-17  5:06                       ` Mike Galbraith
2009-09-17  7:21                         ` Ingo Molnar
2009-09-10  7:43 ` [updated] BFS vs. mainline scheduler benchmarks and measurements Ingo Molnar
2009-09-14  9:46 ` Phoronix CFS vs BFS bencharks Nikos Chantziaras
2009-09-14 11:35   ` Mike Galbraith
     [not found]     ` <f42384a10909140727k463ff460q3859892dcb79bcc5@mail.gmail.com>
2009-09-14 15:32       ` Mike Galbraith
2009-09-14 19:14         ` Marcin Letyns
2009-09-14 20:49           ` Willy Tarreau
2009-09-15  8:37             ` Mike Galbraith
  -- strict thread matches above, loose matches on Subject: below --
2009-09-10 21:17 BFS vs. mainline scheduler benchmarks and measurements Martin Steigerwald
2009-09-11 10:10 Mat
2009-09-11 18:33 Volker Armin Hemmann
2009-09-12  7:37 ` Nikos Chantziaras
2009-09-12  7:51   ` Arjan van de Ven
2009-09-12  8:27   ` Volker Armin Hemmann
2009-09-12  9:03     ` Nikos Chantziaras
2009-09-12  9:34       ` Volker Armin Hemmann

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=20090907204458.GJ18599@kernel.dk \
    --to=jens.axboe@oracle.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=efault@gmx.de \
    --cc=kernel@kolivas.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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;
as well as URLs for NNTP newsgroup(s).