|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH] Hackbench scheduler test inclusion to LTPHi Ingo/Zhang/Arjan/Nathan/Nick,
I would like to include the hackbench testcase, the recent updated one being available at: http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the Linux Test Project (http://ltp.sourceforge.net/). Please review the attached patch which shows the test as well as the integration code for the same. I have included Copyrights in your names and can be released under GPLv2. If you would like to add/remove somebody from the copyright, please let me know. I would request somebody to reply to this mail with a DCO Signoff, if you have no objection donating the same to Linux Test Project. Regards-- Subrata [include_hackbench_in_ltp.patch] diff -uprN ltp-full-20080531.orig/runtest/sched ltp-full-20080531/runtest/sched --- ltp-full-20080531.orig/runtest/sched 2008-06-25 17:15:31.000000000 +0530 +++ ltp-full-20080531/runtest/sched 2008-06-25 17:41:20.000000000 +0530 @@ -6,4 +6,5 @@ pth_str03 pth_str03 time-schedule01 time-schedule trace_sched01 trace_sched -c 1 - +hackbench01 hackbench 150 process 1000 +hackbench02 hackbench 150 thread 1000 diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/hackbench.c ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/hackbench.c --- ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/hackbench.c 1970-01-01 05:30:00.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/hackbench.c 2008-06-25 18:01:09.000000000 +0530 @@ -0,0 +1,348 @@ +/******************************************************************************/ +/* Copyright Zhang, Yanmin, */ +/* Copyright Ingo Molnar, */ +/* Copyright Arjan van de Ven, */ +/* Copyright Nathan Lynch, */ +/* Copyright (c) International Business Machines Corp., 2008 */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ +/* the GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/******************************************************************************/ + + +/******************************************************************************/ +/* */ +/* File: hackbench.c */ +/* */ +/* Description: hackbench tests the Linux scheduler. Test groups of 20 */ +/* processes spraying to 20 receivers */ +/* */ +/* Total Tests: 1 */ +/* */ +/* Test Name: hackbench01 and hackbench02 */ +/* */ +/* Test Assertion: */ +/* */ +/* Author: Ingo Molnar <mingo@...>, */ +/* Arjan van de Ven <arjan@...>, */ +/* "Zhang, Yanmin" <yanmin_zhang@...>, */ +/* Nathan Lynch <ntl@...> */ +/* */ +/* History: Included into LTP */ +/* - June 25 2008 - Subrata Modak<subrata@...>*/ +/* */ +/******************************************************************************/ +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/wait.h> +#include <sys/time.h> +#include <sys/poll.h> + +#define DATASIZE 100 +static unsigned int loops = 100; +/* + * 0 means thread mode and others mean process (default) + */ +static unsigned int process_mode = 1; + +static int use_pipes = 0; + +struct sender_context { + unsigned int num_fds; + int ready_out; + int wakefd; + int out_fds[0]; +}; + +struct receiver_context { + unsigned int num_packets; + int in_fds[2]; + int ready_out; + int wakefd; +}; + + +static void barf(const char *msg) +{ + fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno)); + exit(1); +} + +static void print_usage_exit() +{ + printf("Usage: hackbench [-pipe] <num groups> [process|thread] [loops]\n"); + exit(1); +} + +static void fdpair(int fds[2]) +{ + if (use_pipes) { + if (pipe(fds) == 0) + return; + } else { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0) + return; + } + barf("Creating fdpair"); +} + +/* Block until we're ready to go */ +static void ready(int ready_out, int wakefd) +{ + char dummy; + struct pollfd pollfd = { .fd = wakefd, .events = POLLIN }; + + /* Tell them we're ready. */ + if (write(ready_out, &dummy, 1) != 1) + barf("CLIENT: ready write"); + + /* Wait for "GO" signal */ + if (poll(&pollfd, 1, -1) != 1) + barf("poll"); +} + +/* Sender sprays loops messages down each file descriptor */ +static void *sender(struct sender_context *ctx) +{ + char data[DATASIZE]; + unsigned int i, j; + + ready(ctx->ready_out, ctx->wakefd); + + /* Now pump to every receiver. */ + for (i = 0; i < loops; i++) { + for (j = 0; j < ctx->num_fds; j++) { + int ret, done = 0; + +again: + ret = write(ctx->out_fds[j], data + done, sizeof(data)-done); + if (ret < 0) + barf("SENDER: write"); + done += ret; + if (done < sizeof(data)) + goto again; + } + } + + return NULL; +} + + +/* One receiver per fd */ +static void *receiver(struct receiver_context* ctx) +{ + unsigned int i; + + if (process_mode) + close(ctx->in_fds[1]); + + /* Wait for start... */ + ready(ctx->ready_out, ctx->wakefd); + + /* Receive them all */ + for (i = 0; i < ctx->num_packets; i++) { + char data[DATASIZE]; + int ret, done = 0; + +again: + ret = read(ctx->in_fds[0], data + done, DATASIZE - done); + if (ret < 0) + barf("SERVER: read"); + done += ret; + if (done < DATASIZE) + goto again; + } + + return NULL; +} + +pthread_t create_worker(void *ctx, void *(*func)(void *)) +{ + pthread_attr_t attr; + pthread_t childid; + int err; + + if (process_mode) { + /* process mode */ + /* Fork the receiver. */ + switch (fork()) { + case -1: barf("fork()"); + case 0: + (*func) (ctx); + exit(0); + } + + return (pthread_t) 0; + } + + if (pthread_attr_init(&attr) != 0) + barf("pthread_attr_init:"); + +#ifndef __ia64__ + if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) + barf("pthread_attr_setstacksize"); +#endif + + if ((err=pthread_create(&childid, &attr, func, ctx)) != 0) { + fprintf(stderr, "pthread_create failed: %s (%d)\n", strerror(err), err); + exit(-1); + } + return (childid); +} + +void reap_worker(pthread_t id) +{ + int status; + + if (process_mode) { + /* process mode */ + wait(&status); + if (!WIFEXITED(status)) + exit(1); + } else { + void *status; + + pthread_join(id, &status); + } +} + +/* One group of senders and receivers */ +static unsigned int group(pthread_t *pth, + unsigned int num_fds, + int ready_out, + int wakefd) +{ + unsigned int i; + struct sender_context* snd_ctx = malloc (sizeof(struct sender_context) + +num_fds*sizeof(int)); + + for (i = 0; i < num_fds; i++) { + int fds[2]; + struct receiver_context* ctx = malloc (sizeof(*ctx)); + + if (!ctx) + barf("malloc()"); + + + /* Create the pipe between client and server */ + fdpair(fds); + + ctx->num_packets = num_fds*loops; + ctx->in_fds[0] = fds[0]; + ctx->in_fds[1] = fds[1]; + ctx->ready_out = ready_out; + ctx->wakefd = wakefd; + + pth[i] = create_worker(ctx, (void *)(void *)receiver); + + snd_ctx->out_fds[i] = fds[1]; + if (process_mode) + close(fds[0]); + } + + /* Now we have all the fds, fork the senders */ + for (i = 0; i < num_fds; i++) { + snd_ctx->ready_out = ready_out; + snd_ctx->wakefd = wakefd; + snd_ctx->num_fds = num_fds; + + pth[num_fds+i] = create_worker(snd_ctx, (void *)(void *)sender); + } + + /* Close the fds we have left */ + if (process_mode) + for (i = 0; i < num_fds; i++) + close(snd_ctx->out_fds[i]); + + /* Return number of children to reap */ + return num_fds * 2; +} + +int main(int argc, char *argv[]) +{ + unsigned int i, num_groups = 10, total_children; + struct timeval start, stop, diff; + unsigned int num_fds = 20; + int readyfds[2], wakefds[2]; + char dummy; + pthread_t *pth_tab; + + if (argv[1] && strcmp(argv[1], "-pipe") == 0) { + use_pipes = 1; + argc--; + argv++; + } + + if (argc >= 2 && (num_groups = atoi(argv[1])) == 0) + print_usage_exit(); + + printf("Running with %d*40 (== %d) tasks.\n", + num_groups, num_groups*40); + + fflush(NULL); + + if (argc > 2) { + if ( !strcmp(argv[2], "process") ) + process_mode = 1; + else if ( !strcmp(argv[2], "thread") ) + process_mode = 0; + else + print_usage_exit(); + } + + if (argc > 3) + loops = atoi(argv[3]); + + pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t)); + + if (!pth_tab) + barf("main:malloc()"); + + fdpair(readyfds); + fdpair(wakefds); + + total_children = 0; + for (i = 0; i < num_groups; i++) + total_children += group(pth_tab+total_children, num_fds, readyfds[1], wakefds[0]); + + /* Wait for everyone to be ready */ + for (i = 0; i < total_children; i++) + if (read(readyfds[0], &dummy, 1) != 1) + barf("Reading for readyfds"); + + gettimeofday(&start, NULL); + + /* Kick them off */ + if (write(wakefds[1], &dummy, 1) != 1) + barf("Writing to start them"); + + /* Reap them all */ + for (i = 0; i < total_children; i++) + reap_worker(pth_tab[i]); + + gettimeofday(&stop, NULL); + + /* Print time... */ + timersub(&stop, &start, &diff); + printf("Time: %lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000); + exit(0); +} + diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/Makefile ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/Makefile --- ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/Makefile 1970-01-01 05:30:00.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/Makefile 2008-06-25 17:39:36.000000000 +0530 @@ -0,0 +1,31 @@ +# +# Copyright (c) International Business Machines Corp., 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +CFLAGS += -I../../../../include -Wall +LDLIBS += -L../../../../lib -lltp -lpthread + +SRCS = $(wildcard *.c) +TARGETS = $(patsubst %.c,%,$(SRCS)) + +all: $(TARGETS) + +install: + @set -e; for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done + +clean: + rm -f $(TARGETS) diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/Makefile ltp-full-20080531/testcases/kernel/sched/Makefile --- ltp-full-20080531.orig/testcases/kernel/sched/Makefile 2008-06-25 17:15:50.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/Makefile 2008-06-25 17:45:48.000000000 +0530 @@ -1,4 +1,4 @@ -SUBDIRS = clisrv nptl pthreads process_stress sched_stress tool +SUBDIRS = clisrv nptl pthreads process_stress sched_stress tool cfs-scheduler all: @set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i ; done ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTP* Subrata Modak <subrata@...> wrote: > Hi Ingo/Zhang/Arjan/Nathan/Nick, > > I would like to include the hackbench testcase, the recent updated one > being available at: > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > Linux Test Project (http://ltp.sourceforge.net/). as far as my (very) small additions are concerned, fair enough. I really just put it up for download. Ingo ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPSubrata Modak wrote:
> Hi Ingo/Zhang/Arjan/Nathan/Nick, > > I would like to include the hackbench testcase, the recent updated one > being available at: > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > Linux Test Project (http://ltp.sourceforge.net/). > > Please review the attached patch which shows the test as well as the > integration code for the same. I have included Copyrights in your names > and can be released under GPLv2. If you would like to add/remove > somebody from the copyright, please let me know. I don't think my one-line fix from the other day warrants an author credit or copyright :) ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPOn Wed, 2008-06-25 at 12:42 -0500, Nathan Lynch wrote: > Subrata Modak wrote: > > Hi Ingo/Zhang/Arjan/Nathan/Nick, > > > > I would like to include the hackbench testcase, the recent updated one > > being available at: > > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > > Linux Test Project (http://ltp.sourceforge.net/). > > > > Please review the attached patch which shows the test as well as the > > integration code for the same. I have included Copyrights in your names > > and can be released under GPLv2. If you would like to add/remove > > somebody from the copyright, please let me know. > > I don't think my one-line fix from the other day warrants an author > credit or copyright :) some new parameters. I'll be very happy if you would add my name, but pls. add the original authors firstly. -yanmin ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPOn Thu, 2008-06-26 at 08:42 +0800, Zhang, Yanmin wrote:
> On Wed, 2008-06-25 at 12:42 -0500, Nathan Lynch wrote: > > Subrata Modak wrote: > > > Hi Ingo/Zhang/Arjan/Nathan/Nick, > > > > > > I would like to include the hackbench testcase, the recent updated one > > > being available at: > > > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > > > Linux Test Project (http://ltp.sourceforge.net/). > > > > > > Please review the attached patch which shows the test as well as the > > > integration code for the same. I have included Copyrights in your names > > > and can be released under GPLv2. If you would like to add/remove > > > somebody from the copyright, please let me know. > > > > I don't think my one-line fix from the other day warrants an author > > credit or copyright :) > As not the original authors, I just merged the process and pthread and added > some new parameters. I'll be very happy if you would add my name, but pls. add > the original authors firstly. Zhang, Thanks for writing back. May you please point me to the original author(s) of this test cases, so that i can write to them as well ? Regards-- Subrata > > -yanmin > > ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPOn Thu, 2008-06-26 at 12:04 +0530, Subrata Modak wrote: > On Thu, 2008-06-26 at 08:42 +0800, Zhang, Yanmin wrote: > > On Wed, 2008-06-25 at 12:42 -0500, Nathan Lynch wrote: > > > Subrata Modak wrote: > > > > Hi Ingo/Zhang/Arjan/Nathan/Nick, > > > > > > > > I would like to include the hackbench testcase, the recent updated one > > > > being available at: > > > > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > > > > Linux Test Project (http://ltp.sourceforge.net/). > > > > > > > > Please review the attached patch which shows the test as well as the > > > > integration code for the same. I have included Copyrights in your names > > > > and can be released under GPLv2. If you would like to add/remove > > > > somebody from the copyright, please let me know. > > > > > > I don't think my one-line fix from the other day warrants an author > > > credit or copyright :) > > As not the original authors, I just merged the process and pthread and added > > some new parameters. I'll be very happy if you would add my name, but pls. add > > the original authors firstly. > > Zhang, > > Thanks for writing back. May you please point me to the original > author(s) of this test cases, so that i can write to them as well ? I got the info from http://devresources.linux-foundation.org/craiger/hackbench/. 2) Pierre Peiffer <pierre.peiffer@...>: Used pthread to replace fork from the original hackbench, i.e., implemented thread mode. -yanmin ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPOn Thu, 2008-06-26 at 15:10 +0800, Zhang, Yanmin wrote:
> On Thu, 2008-06-26 at 12:04 +0530, Subrata Modak wrote: > > On Thu, 2008-06-26 at 08:42 +0800, Zhang, Yanmin wrote: > > > On Wed, 2008-06-25 at 12:42 -0500, Nathan Lynch wrote: > > > > Subrata Modak wrote: > > > > > Hi Ingo/Zhang/Arjan/Nathan/Nick, > > > > > > > > > > I would like to include the hackbench testcase, the recent updated one > > > > > being available at: > > > > > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > > > > > Linux Test Project (http://ltp.sourceforge.net/). > > > > > > > > > > Please review the attached patch which shows the test as well as the > > > > > integration code for the same. I have included Copyrights in your names > > > > > and can be released under GPLv2. If you would like to add/remove > > > > > somebody from the copyright, please let me know. > > > > > > > > I don't think my one-line fix from the other day warrants an author > > > > credit or copyright :) > > > As not the original authors, I just merged the process and pthread and added > > > some new parameters. I'll be very happy if you would add my name, but pls. add > > > the original authors firstly. > > > > Zhang, > > > > Thanks for writing back. May you please point me to the original > > author(s) of this test cases, so that i can write to them as well ? > 1) Rusty Russell <rusty@...>: created the initial hackbench. > I got the info from http://devresources.linux-foundation.org/craiger/hackbench/. > 2) Pierre Peiffer <pierre.peiffer@...>: Used pthread to replace fork from > the original hackbench, i.e., implemented thread mode. Thanks Yanmin once again. I would write to these authors immediately with a renewed patch. Regards-- Subrata > > -yanmin > > ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
[PATCH] Hackbench scheduler test inclusion to Linux Test ProjectHi Rusty/Pierre,
I would like to include the hackbench testcase, the recent updated one being available at: http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the Linux Test Project (http://ltp.sourceforge.net/). >From Yanmin i came to know that you were the original author(s) of this test case: On Thu, 2008-06-26 at 15:10 +0800, Zhang, Yanmin wrote: > 1) Rusty Russell <rusty@...>: created the initial > hackbench. > I got the info from > http://devresources.linux-foundation.org/craiger/hackbench/. > 2) Pierre Peiffer <pierre.peiffer@...>: Used pthread to replace > fork from > the original hackbench, i.e., implemented thread mode. Please review the attached patch which shows the test as well as the integration code for the same. I have included Copyrights in your names and can be released under GPLv2. If you would like to add/remove somebody from the copyright, please let me know. I would request you to reply to this mail with a DCO Signoff, if you have no objection donating this valuable test to Linux Test Project. I would also like to know if you have some other test cases in your Kitty, which you can also donate the the LTP. Regards-- Subrata [include_hackbench_in_ltp.patch] diff -uprN ltp-full-20080531.orig/runtest/sched ltp-full-20080531/runtest/sched --- ltp-full-20080531.orig/runtest/sched 2008-06-25 17:15:31.000000000 +0530 +++ ltp-full-20080531/runtest/sched 2008-06-25 17:41:20.000000000 +0530 @@ -6,4 +6,5 @@ pth_str03 pth_str03 time-schedule01 time-schedule trace_sched01 trace_sched -c 1 - +hackbench01 hackbench 150 process 1000 +hackbench02 hackbench 150 thread 1000 diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/hackbench.c ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/hackbench.c --- ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/hackbench.c 1970-01-01 05:30:00.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/hackbench.c 2008-06-25 18:01:09.000000000 +0530 @@ -0,0 +1,348 @@ +/******************************************************************************/ +/* Copyright Rusty Russell, */ +/* Copyright Pierre Peiffer */ +/* Copyright Zhang, Yanmin, */ +/* Copyright Ingo Molnar, */ +/* Copyright Arjan van de Ven, */ +/* Copyright Nathan Lynch, */ +/* Copyright (c) International Business Machines Corp., 2008 */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ +/* the GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* */ +/******************************************************************************/ + + +/******************************************************************************/ +/* */ +/* File: hackbench.c */ +/* */ +/* Description: hackbench tests the Linux scheduler. Test groups of 20 */ +/* processes spraying to 20 receivers */ +/* */ +/* Total Tests: 1 */ +/* */ +/* Test Name: hackbench01 and hackbench02 */ +/* */ +/* Test Assertion: */ +/* */ +/* Author: Rusty Russell <rusty@...>, */ +/* Pierre Peiffer <pierre.peiffer@...>, */ +/* Ingo Molnar <mingo@...>, */ +/* Arjan van de Ven <arjan@...>, */ +/* "Zhang, Yanmin" <yanmin_zhang@...>, */ +/* Nathan Lynch <ntl@...> */ +/* */ +/* History: Included into LTP */ +/* - June 26 2008 - Subrata Modak<subrata@...>*/ +/* */ +/******************************************************************************/ +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/wait.h> +#include <sys/time.h> +#include <sys/poll.h> + +#define DATASIZE 100 +static unsigned int loops = 100; +/* + * 0 means thread mode and others mean process (default) + */ +static unsigned int process_mode = 1; + +static int use_pipes = 0; + +struct sender_context { + unsigned int num_fds; + int ready_out; + int wakefd; + int out_fds[0]; +}; + +struct receiver_context { + unsigned int num_packets; + int in_fds[2]; + int ready_out; + int wakefd; +}; + + +static void barf(const char *msg) +{ + fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno)); + exit(1); +} + +static void print_usage_exit() +{ + printf("Usage: hackbench [-pipe] <num groups> [process|thread] [loops]\n"); + exit(1); +} + +static void fdpair(int fds[2]) +{ + if (use_pipes) { + if (pipe(fds) == 0) + return; + } else { + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0) + return; + } + barf("Creating fdpair"); +} + +/* Block until we're ready to go */ +static void ready(int ready_out, int wakefd) +{ + char dummy; + struct pollfd pollfd = { .fd = wakefd, .events = POLLIN }; + + /* Tell them we're ready. */ + if (write(ready_out, &dummy, 1) != 1) + barf("CLIENT: ready write"); + + /* Wait for "GO" signal */ + if (poll(&pollfd, 1, -1) != 1) + barf("poll"); +} + +/* Sender sprays loops messages down each file descriptor */ +static void *sender(struct sender_context *ctx) +{ + char data[DATASIZE]; + unsigned int i, j; + + ready(ctx->ready_out, ctx->wakefd); + + /* Now pump to every receiver. */ + for (i = 0; i < loops; i++) { + for (j = 0; j < ctx->num_fds; j++) { + int ret, done = 0; + +again: + ret = write(ctx->out_fds[j], data + done, sizeof(data)-done); + if (ret < 0) + barf("SENDER: write"); + done += ret; + if (done < sizeof(data)) + goto again; + } + } + + return NULL; +} + + +/* One receiver per fd */ +static void *receiver(struct receiver_context* ctx) +{ + unsigned int i; + + if (process_mode) + close(ctx->in_fds[1]); + + /* Wait for start... */ + ready(ctx->ready_out, ctx->wakefd); + + /* Receive them all */ + for (i = 0; i < ctx->num_packets; i++) { + char data[DATASIZE]; + int ret, done = 0; + +again: + ret = read(ctx->in_fds[0], data + done, DATASIZE - done); + if (ret < 0) + barf("SERVER: read"); + done += ret; + if (done < DATASIZE) + goto again; + } + + return NULL; +} + +pthread_t create_worker(void *ctx, void *(*func)(void *)) +{ + pthread_attr_t attr; + pthread_t childid; + int err; + + if (process_mode) { + /* process mode */ + /* Fork the receiver. */ + switch (fork()) { + case -1: barf("fork()"); + case 0: + (*func) (ctx); + exit(0); + } + + return (pthread_t) 0; + } + + if (pthread_attr_init(&attr) != 0) + barf("pthread_attr_init:"); + +#ifndef __ia64__ + if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) + barf("pthread_attr_setstacksize"); +#endif + + if ((err=pthread_create(&childid, &attr, func, ctx)) != 0) { + fprintf(stderr, "pthread_create failed: %s (%d)\n", strerror(err), err); + exit(-1); + } + return (childid); +} + +void reap_worker(pthread_t id) +{ + int status; + + if (process_mode) { + /* process mode */ + wait(&status); + if (!WIFEXITED(status)) + exit(1); + } else { + void *status; + + pthread_join(id, &status); + } +} + +/* One group of senders and receivers */ +static unsigned int group(pthread_t *pth, + unsigned int num_fds, + int ready_out, + int wakefd) +{ + unsigned int i; + struct sender_context* snd_ctx = malloc (sizeof(struct sender_context) + +num_fds*sizeof(int)); + + for (i = 0; i < num_fds; i++) { + int fds[2]; + struct receiver_context* ctx = malloc (sizeof(*ctx)); + + if (!ctx) + barf("malloc()"); + + + /* Create the pipe between client and server */ + fdpair(fds); + + ctx->num_packets = num_fds*loops; + ctx->in_fds[0] = fds[0]; + ctx->in_fds[1] = fds[1]; + ctx->ready_out = ready_out; + ctx->wakefd = wakefd; + + pth[i] = create_worker(ctx, (void *)(void *)receiver); + + snd_ctx->out_fds[i] = fds[1]; + if (process_mode) + close(fds[0]); + } + + /* Now we have all the fds, fork the senders */ + for (i = 0; i < num_fds; i++) { + snd_ctx->ready_out = ready_out; + snd_ctx->wakefd = wakefd; + snd_ctx->num_fds = num_fds; + + pth[num_fds+i] = create_worker(snd_ctx, (void *)(void *)sender); + } + + /* Close the fds we have left */ + if (process_mode) + for (i = 0; i < num_fds; i++) + close(snd_ctx->out_fds[i]); + + /* Return number of children to reap */ + return num_fds * 2; +} + +int main(int argc, char *argv[]) +{ + unsigned int i, num_groups = 10, total_children; + struct timeval start, stop, diff; + unsigned int num_fds = 20; + int readyfds[2], wakefds[2]; + char dummy; + pthread_t *pth_tab; + + if (argv[1] && strcmp(argv[1], "-pipe") == 0) { + use_pipes = 1; + argc--; + argv++; + } + + if (argc >= 2 && (num_groups = atoi(argv[1])) == 0) + print_usage_exit(); + + printf("Running with %d*40 (== %d) tasks.\n", + num_groups, num_groups*40); + + fflush(NULL); + + if (argc > 2) { + if ( !strcmp(argv[2], "process") ) + process_mode = 1; + else if ( !strcmp(argv[2], "thread") ) + process_mode = 0; + else + print_usage_exit(); + } + + if (argc > 3) + loops = atoi(argv[3]); + + pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t)); + + if (!pth_tab) + barf("main:malloc()"); + + fdpair(readyfds); + fdpair(wakefds); + + total_children = 0; + for (i = 0; i < num_groups; i++) + total_children += group(pth_tab+total_children, num_fds, readyfds[1], wakefds[0]); + + /* Wait for everyone to be ready */ + for (i = 0; i < total_children; i++) + if (read(readyfds[0], &dummy, 1) != 1) + barf("Reading for readyfds"); + + gettimeofday(&start, NULL); + + /* Kick them off */ + if (write(wakefds[1], &dummy, 1) != 1) + barf("Writing to start them"); + + /* Reap them all */ + for (i = 0; i < total_children; i++) + reap_worker(pth_tab[i]); + + gettimeofday(&stop, NULL); + + /* Print time... */ + timersub(&stop, &start, &diff); + printf("Time: %lu.%03lu\n", diff.tv_sec, diff.tv_usec/1000); + exit(0); +} + diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/Makefile ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/Makefile --- ltp-full-20080531.orig/testcases/kernel/sched/cfs-scheduler/Makefile 1970-01-01 05:30:00.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/cfs-scheduler/Makefile 2008-06-25 17:39:36.000000000 +0530 @@ -0,0 +1,31 @@ +# +# Copyright (c) International Business Machines Corp., 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +CFLAGS += -I../../../../include -Wall +LDLIBS += -L../../../../lib -lltp -lpthread + +SRCS = $(wildcard *.c) +TARGETS = $(patsubst %.c,%,$(SRCS)) + +all: $(TARGETS) + +install: + @set -e; for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done + +clean: + rm -f $(TARGETS) diff -uprN ltp-full-20080531.orig/testcases/kernel/sched/Makefile ltp-full-20080531/testcases/kernel/sched/Makefile --- ltp-full-20080531.orig/testcases/kernel/sched/Makefile 2008-06-25 17:15:50.000000000 +0530 +++ ltp-full-20080531/testcases/kernel/sched/Makefile 2008-06-25 17:45:48.000000000 +0530 @@ -1,4 +1,4 @@ -SUBDIRS = clisrv nptl pthreads process_stress sched_stress tool +SUBDIRS = clisrv nptl pthreads process_stress sched_stress tool cfs-scheduler all: @set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i ; done ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to Linux Test ProjectOn Thursday 26 June 2008 17:48:59 Subrata Modak wrote:
> Hi Rusty/Pierre, > > I would like to include the hackbench testcase, the recent updated one > being available at: > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > Linux Test Project (http://ltp.sourceforge.net/). At a quick glance, it looks reasonable to me. The original license (like all my GPL code) was GPL version 2 or (at your option) any later version. But of course I can't ensure that the later version part is maintained. > I would request you to reply to this mail with a DCO Signoff, if you > have no objection donating this valuable test to Linux Test Project. Signed-off-by: Rusty Russell <rusty@...> Cheers, Rusty. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to Linux Test ProjectOn Fri, 2008-06-27 at 12:54 +1000, Rusty Russell wrote:
> On Thursday 26 June 2008 17:48:59 Subrata Modak wrote: > > Hi Rusty/Pierre, > > > > I would like to include the hackbench testcase, the recent updated one > > being available at: > > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > > Linux Test Project (http://ltp.sourceforge.net/). > > At a quick glance, it looks reasonable to me. > > The original license (like all my GPL code) was GPL version 2 or (at your > option) any later version. But of course I can't ensure that the later > version part is maintained. > > > I would request you to reply to this mail with a DCO Signoff, if you > > have no objection donating this valuable test to Linux Test Project. > > Signed-off-by: Rusty Russell <rusty@...> Thanks Rusty. This will now become part of LTP automated tests. Meanwhile, can you also point us to some work on test cases that you might have done earlier. We would like to incorporate them as well. Regards-- Subrata > > Cheers, > Rusty. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |
|
|
Re: [PATCH] Hackbench scheduler test inclusion to LTPOn Wednesday 25 June 2008 22:48, Subrata Modak wrote:
> Hi Ingo/Zhang/Arjan/Nathan/Nick, > > I would like to include the hackbench testcase, the recent updated one > being available at: > http://people.redhat.com/mingo/cfs-scheduler/tools/hackbench.c, for the > Linux Test Project (http://ltp.sourceforge.net/). > > Please review the attached patch which shows the test as well as the > integration code for the same. I have included Copyrights in your names > and can be released under GPLv2. If you would like to add/remove > somebody from the copyright, please let me know. > > I would request somebody to reply to this mail with a DCO Signoff, if > you have no objection donating the same to Linux Test Project. > I can't remember if I even changed anything, but if I have, then feel free to do whatever you like with my additions. ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ Ltp-list mailing list Ltp-list@... https://lists.sourceforge.net/lists/listinfo/ltp-list |