/* * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 * The President and Fellows of Harvard College. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * parallelvm.c: highly parallelized VM stress test. * * This test probably won't run with only 512k of physical memory * (unless maybe if you have a *really* gonzo VM system) because each * of its processes needs to allocate a kernel stack, and those add up * quickly. */ #include #include #include #include #include #include #include #include #define NJOBS 24 #define DIM 35 #define NMATS 11 #define JOBSIZE ((NMATS+1)*DIM*DIM*sizeof(int)) static const int right_answers[NJOBS] = { -1337312809, 356204544, -537881911, -65406976, 1952063315, -843894784, 1597000869, -993925120, 838840559, -1616928768, -182386335, -364554240, 251084843, -61403136, 295326333, 1488013312, 1901440647, 0, -1901440647, -1488013312, -295326333, 61403136, -251084843, 364554240, }; //////////////////////////////////////////////////////////// struct matrix { int m_data[DIM][DIM]; }; //////////////////////////////////////////////////////////// /* * Use this instead of just calling printf so we know each printout * is atomic; this prevents the lines from getting intermingled. */ static void say(const char *fmt, ...) { char buf[256]; va_list ap; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); write(STDOUT_FILENO, buf, strlen(buf)); } //////////////////////////////////////////////////////////// static void multiply(struct matrix *res, const struct matrix *m1, const struct matrix *m2) { int i, j, k; for (i=0; im_data[i][k]*m2->m_data[k][j]; } res->m_data[i][j] = val; } } } static void addeq(struct matrix *m1, const struct matrix *m2) { int i, j; for (i=0; im_data[i][j] += m2->m_data[i][j]; } } } static int trace(const struct matrix *m1) { int i, t=0; for (i=0; im_data[i][i]; } return t; } //////////////////////////////////////////////////////////// static struct matrix mats[NMATS]; static void populate_initial_matrixes(int mynum) { int i,j; struct matrix *m = &mats[0]; for (i=0; im_data[i][j] = mynum+i-2*j; } } multiply(&mats[1], &mats[0], &mats[0]); } static void compute(int n) { struct matrix tmp; int i, j; for (i=0,j=n-1; i0) { printf("%d subprocesses failed\n", failcount); exit(1); } printf("Test complete\n"); } int main() { makeprocs(); return 0; }