2 * Copyright (c) 2003-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 * Test scaling of multiple processes opening/reading
34 * a number of small files simultaneously.
36 * - fork <n> processes
37 * - wait for all processes ready
38 * - start all proceses at the same time
39 * - each processes opens , read, closes each file
40 * - option to resync each process at each file
42 * test [-c cpus] [-b bytes] [-f files] [-v] [-s] [-S]
44 * test -i [-b bytes] [-f files]
50 #include <sys/types.h>
58 void do_initfiles(void);
61 #define VPRINT(x...) do { if(verbose) fprintf(x);} while(0)
62 #define perrorx(s) do {perror(s); exit(1);} while (0)
76 volatile long rdy[512];
85 #ifdef sys_sched_setaffinity
86 unsigned long mask[8];
88 if (cpu < 0 || cpu >= 512)
90 memset(mask, 0, sizeof(mask));
91 mask[cpu/64] |= 1UL<<(cpu&63);
93 if (syscall(sys_sched_setaffinity, 0, sizeof(mask), mask))
105 val = strtol(p, &pe, 0);
106 if (*pe == 'K' || *pe == 'k')
108 else if (*pe == 'M' || *pe == 'm')
110 else if (*pe == 'G' || *pe == 'g')
111 val *= 1024L*1024L*1024L;
112 else if (*pe == 'p' || *pe == 'P')
113 val *= getpagesize();
119 main(int argc, char** argv) {
121 static char optstr[] = "c:b:f:sSivH";
122 int notdone, stat, i, j, c, er=0;
125 while ((c = getopt(argc, argv, optstr)) != EOF)
131 bytes = scaled_atol(optarg);
134 files = atoi(optarg);
153 printf("usage: %s %s\n", argv[0], optstr);
158 if ((shmid = shmget(IPC_PRIVATE, sizeof (share_t), IPC_CREAT|SHM_R|SHM_W)) == -1)
159 perrorx("shmget failed");
160 sharep = (share_t*)shmat(shmid, (void*)0, SHM_R|SHM_W);
161 memset(sharep, -1, sizeof (share_t));
167 for (i=0; i<cpus; i++) {
172 for (i=0; i<files; i++) {
173 VPRINT(stderr, "%d:", i);
176 for (j=0; j<cpus; j++) {
177 if (sharep->rdy[j] == i) {
179 VPRINT(stderr, " %d", j);
184 VPRINT(stderr, "\n");
189 VPRINT(stderr, "\n");
191 while (wait(&stat)> 0)
193 VPRINT(stderr, "\n");
202 char *buf, filename[32];
205 buf = malloc(blksize);
207 for (i=0; i<files; i++) {
208 if (!i || syncstep) {
210 while(sharep->go != i);
212 sprintf(filename, "/tmp/tst.%d", (strided ? ((i + id) % files) : i));
213 if ((fd = open (filename, O_RDONLY)) < 0) {
217 for (byte=0; byte<bytes; byte+=blksize) {
218 if (read (fd, buf, blksize) != blksize)
219 perrorx("read of file failed");
230 char *buf, filename[32];
232 buf = malloc(blksize);
235 for (i=0; i<files; i++) {
236 sprintf(filename, "/tmp/tst.%d", i);
238 if ((fd = open (filename, O_RDWR|O_CREAT, 0644)) < 0)
241 for (byte=0; byte<bytes; byte+=blksize) {
242 if (write (fd, buf, blksize) != blksize)
243 perrorx("write of file failed");