1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2003-2004 Silicon Graphics, Inc.
7 * Test scaling of multiple processes opening/reading
8 * a number of small files simultaneously.
10 * - fork <n> processes
11 * - wait for all processes ready
12 * - start all proceses at the same time
13 * - each processes opens , read, closes each file
14 * - option to resync each process at each file
16 * test [-c cpus] [-b bytes] [-f files] [-v] [-s] [-S]
18 * test -i [-b bytes] [-f files]
24 #include <sys/types.h>
32 void do_initfiles(void);
35 #define VPRINT(x...) do { if(verbose) fprintf(x);} while(0)
36 #define perrorx(s) do {perror(s); exit(1);} while (0)
50 volatile long rdy[512];
59 #ifdef sys_sched_setaffinity
60 unsigned long mask[8];
62 if (cpu < 0 || cpu >= 512)
64 memset(mask, 0, sizeof(mask));
65 mask[cpu/64] |= 1UL<<(cpu&63);
67 if (syscall(sys_sched_setaffinity, 0, sizeof(mask), mask))
79 val = strtol(p, &pe, 0);
80 if (*pe == 'K' || *pe == 'k')
82 else if (*pe == 'M' || *pe == 'm')
84 else if (*pe == 'G' || *pe == 'g')
85 val *= 1024L*1024L*1024L;
86 else if (*pe == 'p' || *pe == 'P')
93 main(int argc, char** argv) {
95 static char optstr[] = "c:b:f:sSivH";
96 int notdone, stat, i, j, c, er=0;
99 while ((c = getopt(argc, argv, optstr)) != EOF)
105 bytes = scaled_atol(optarg);
108 files = atoi(optarg);
127 printf("usage: %s %s\n", argv[0], optstr);
132 if ((shmid = shmget(IPC_PRIVATE, sizeof (share_t), IPC_CREAT|SHM_R|SHM_W)) == -1)
133 perrorx("shmget failed");
134 sharep = (share_t*)shmat(shmid, (void*)0, SHM_R|SHM_W);
135 memset(sharep, -1, sizeof (share_t));
141 for (i=0; i<cpus; i++) {
146 for (i=0; i<files; i++) {
147 VPRINT(stderr, "%d:", i);
150 for (j=0; j<cpus; j++) {
151 if (sharep->rdy[j] == i) {
153 VPRINT(stderr, " %d", j);
158 VPRINT(stderr, "\n");
163 VPRINT(stderr, "\n");
165 while (wait(&stat)> 0)
167 VPRINT(stderr, "\n");
176 char *buf, filename[32];
179 buf = malloc(blksize);
181 for (i=0; i<files; i++) {
182 if (!i || syncstep) {
184 while(sharep->go != i);
186 sprintf(filename, "/tmp/tst.%d", (strided ? ((i + id) % files) : i));
187 if ((fd = open (filename, O_RDONLY)) < 0) {
191 for (byte=0; byte<bytes; byte+=blksize) {
192 if (read (fd, buf, blksize) != blksize)
193 perrorx("read of file failed");
204 char *buf, filename[32];
206 buf = malloc(blksize);
209 for (i=0; i<files; i++) {
210 sprintf(filename, "/tmp/tst.%d", i);
212 if ((fd = open (filename, O_RDWR|O_CREAT, 0644)) < 0)
215 for (byte=0; byte<bytes; byte+=blksize) {
216 if (write (fd, buf, blksize) != blksize)
217 perrorx("write of file failed");