2 * Copyright (c) 2003-2004 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Test scaling of multiple processes opening/reading
20 * a number of small files simultaneously.
22 * - fork <n> processes
23 * - wait for all processes ready
24 * - start all proceses at the same time
25 * - each processes opens , read, closes each file
26 * - option to resync each process at each file
28 * test [-c cpus] [-b bytes] [-f files] [-v] [-s] [-S]
30 * test -i [-b bytes] [-f files]
36 #include <sys/types.h>
44 void do_initfiles(void);
47 #define VPRINT(x...) do { if(verbose) fprintf(x);} while(0)
48 #define perrorx(s) do {perror(s); exit(1);} while (0)
62 volatile long rdy[512];
71 #ifdef sys_sched_setaffinity
72 unsigned long mask[8];
74 if (cpu < 0 || cpu >= 512)
76 memset(mask, 0, sizeof(mask));
77 mask[cpu/64] |= 1UL<<(cpu&63);
79 if (syscall(sys_sched_setaffinity, 0, sizeof(mask), mask))
91 val = strtol(p, &pe, 0);
92 if (*pe == 'K' || *pe == 'k')
94 else if (*pe == 'M' || *pe == 'm')
96 else if (*pe == 'G' || *pe == 'g')
97 val *= 1024L*1024L*1024L;
98 else if (*pe == 'p' || *pe == 'P')
105 main(int argc, char** argv) {
107 static char optstr[] = "c:b:f:sSivH";
108 int notdone, stat, i, j, c, er=0;
111 while ((c = getopt(argc, argv, optstr)) != EOF)
117 bytes = scaled_atol(optarg);
120 files = atoi(optarg);
139 printf("usage: %s %s\n", argv[0], optstr);
144 if ((shmid = shmget(IPC_PRIVATE, sizeof (share_t), IPC_CREAT|SHM_R|SHM_W)) == -1)
145 perrorx("shmget failed");
146 sharep = (share_t*)shmat(shmid, (void*)0, SHM_R|SHM_W);
147 memset(sharep, -1, sizeof (share_t));
153 for (i=0; i<cpus; i++) {
158 for (i=0; i<files; i++) {
159 VPRINT(stderr, "%d:", i);
162 for (j=0; j<cpus; j++) {
163 if (sharep->rdy[j] == i) {
165 VPRINT(stderr, " %d", j);
170 VPRINT(stderr, "\n");
175 VPRINT(stderr, "\n");
177 while (wait(&stat)> 0)
179 VPRINT(stderr, "\n");
188 char *buf, filename[32];
191 buf = malloc(blksize);
193 for (i=0; i<files; i++) {
194 if (!i || syncstep) {
196 while(sharep->go != i);
198 sprintf(filename, "/tmp/tst.%d", (strided ? ((i + id) % files) : i));
199 if ((fd = open (filename, O_RDONLY)) < 0) {
203 for (byte=0; byte<bytes; byte+=blksize) {
204 if (read (fd, buf, blksize) != blksize)
205 perrorx("read of file failed");
216 char *buf, filename[32];
218 buf = malloc(blksize);
221 for (i=0; i<files; i++) {
222 sprintf(filename, "/tmp/tst.%d", i);
224 if ((fd = open (filename, O_RDWR|O_CREAT, 0644)) < 0)
227 for (byte=0; byte<bytes; byte+=blksize) {
228 if (write (fd, buf, blksize) != blksize)
229 perrorx("write of file failed");