1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
16 #include <linux/param.h>
18 typedef void *(*fpi_t)(void);
19 typedef void (*fpt_t)(int, void *);
20 typedef void (*fpd_t)(void *);
29 static void d_readdir(void *);
30 static void *i_readdir(void);
31 static void t_readdir(int, void *);
32 static void crfiles(char **, int, char *);
33 static void d_chown(void *);
34 static void d_create(void *);
35 static void d_linkun(void *);
36 static void d_open(void *);
37 static void d_rename(void *);
38 static void d_stat(void *);
39 static void delflist(char **);
40 static void dotest(tdesc_t *);
41 static void *i_chown(void);
42 static void *i_create(void);
43 static void *i_linkun(void);
44 static void *i_open(void);
45 static void *i_rename(void);
46 static void *i_stat(void);
47 static char **mkflist(int, int, char);
48 static double now(void);
49 static void prtime(char *, int, double);
50 static void rmfiles(char **);
51 static void t_chown(int, void *);
52 static void t_create(int, void *);
53 static void t_crunlink(int, void *);
54 static void t_linkun(int, void *);
55 static void t_open(int, void *);
56 static void t_rename(int, void *);
57 static void t_stat(int, void *);
58 static void usage(void);
61 { "chown", i_chown, t_chown, d_chown },
62 { "create", i_create, t_create, d_create },
63 { "crunlink", (fpi_t)0, t_crunlink, (fpd_t)0 },
64 { "readdir", i_readdir, t_readdir, d_readdir },
65 { "linkun", i_linkun, t_linkun, d_linkun },
66 { "open", i_open, t_open, d_open },
67 { "rename", i_rename, t_rename, d_rename },
68 { "stat", i_stat, t_stat, d_stat },
88 main(int argc, char **argv)
94 testdir = getenv("TMPDIR");
97 while ((c = getopt(argc, argv, "cd:i:l:L:n:N:s:t:v")) != -1) {
106 iters = atoi(optarg);
109 fnlen_op = atoi(optarg);
112 fnlen_bg = atoi(optarg);
115 files_op = atoi(optarg);
118 files_bg = atoi(optarg);
121 fsize = atoi(optarg);
124 totsec = atoi(optarg);
130 fprintf(stderr, "bad option\n");
134 if (!iters && !totsec)
136 if (chdir(testdir) < 0) {
140 if (mkdir("metaperf", 0777) < 0 || chdir("metaperf") < 0) {
144 for (; optind < argc; optind++) {
145 for (tp = tests; tp->name; tp++) {
146 if (strcmp(argv[optind], tp->name) == 0) {
158 crfiles(char **flist, int fsize, char *buf)
163 for (fnp = flist; *fnp; fnp++) {
164 fd = creat(*fnp, 0666);
166 write(fd, buf, fsize);
211 delflist((char **)v);
222 delflist(char **flist)
226 for (fnp = flist; *fnp; fnp++)
239 flist_bg = mkflist(files_bg, fnlen_bg, 'b');
240 flist_op = mkflist(files_op, fnlen_op, 'o');
242 buffer = calloc(fsize, 1);
245 crfiles(flist_bg, 0, (char *)0);
246 n = iters ? iters : 1;
258 gotsec = time_end - time_start;
259 if (!totsec || gotsec >= 0.9 * totsec)
262 prtime(tp->name, n, gotsec);
264 gotsec = 1.0 / (2 * HZ);
265 if (gotsec < 0.001 * totsec)
266 dn = n * (0.01 * totsec / gotsec);
267 else if (gotsec < 0.01 * totsec)
268 dn = n * (0.1 * totsec / gotsec);
270 dn = n * (totsec / gotsec);
276 prtime(tp->name, n, gotsec);
289 crfiles(flist_op, 0, (char *)0);
290 for (fnp = flist_op; *fnp; fnp++)
298 crfiles(flist_op, fsize, buffer);
305 crfiles(flist_op, 0, (char *)0);
312 close(creat("a", 0666));
319 crfiles(flist_op, 0, (char *)0);
326 crfiles(flist_op, 0, (char *)0);
327 return (void *)mkflist(files_op, fnlen_op, 'r');
333 crfiles(flist_op, 0, (char *)0);
338 mkflist(int files, int fnlen, char start)
343 rval = calloc(files + 1, sizeof(char *));
344 for (i = 0; i < files; i++) {
345 rval[i] = malloc(fnlen + 1);
346 sprintf(rval[i], "%0*d%c", fnlen - 1, i, start);
356 gettimeofday(&t, (void *)0);
357 return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
361 prtime(char *name, int n, double t)
366 ops_per_sec = (double)n * (double)files_op / t;
367 usec_per_op = t * 1.0e6 / ((double)n * (double)files_op);
369 printf("%s %d %d %d %d %d %d %f %f %f\n",
370 name, n, files_op, fnlen_op, fsize, files_bg, fnlen_bg,
371 t, ops_per_sec, usec_per_op);
373 printf("%s: %d times, %d file(s) namelen %d",
374 name, n, files_op, fnlen_op);
376 printf(" size %d", fsize);
378 printf(", bg %d file(s) namelen %d",
380 printf(", time = %f sec, ops/sec=%f, usec/op = %f\n",
381 t, ops_per_sec, usec_per_op);
386 rmfiles(char **flist)
390 for (fnp = flist; *fnp; fnp++)
396 t_chown(int n, void *v)
401 for (i = 0; i < n; i++) {
402 for (fnp = flist_op; *fnp; fnp++) {
413 t_create(int n, void *v)
417 for (i = 0; i < n; i++)
418 crfiles(flist_op, fsize, buffer);
423 t_crunlink(int n, void *v)
427 for (i = 0; i < n; i++) {
428 crfiles(flist_op, fsize, buffer);
434 t_readdir(int n, void *v)
439 for (dir = (DIR *)v, i = 0; i < n; i++) {
441 while ((readdir(dir)) != NULL);
447 t_linkun(int n, void *v)
452 for (i = 0; i < n; i++) {
453 for (fnp = flist_op; *fnp; fnp++)
461 t_open(int n, void *v)
466 for (i = 0; i < n; i++) {
467 for (fnp = flist_op; *fnp; fnp++)
468 close(open(*fnp, O_RDWR));
473 t_rename(int n, void *v)
480 for (rflist = (char **)v, i = 0; i < n; i++) {
481 for (fnp = flist_op, rfp = rflist; *fnp; fnp++, rfp++) {
492 t_stat(int n, void *v)
498 for (i = 0; i < n; i++) {
499 for (fnp = flist_op; *fnp; fnp++)
508 "Usage: metaperf [-d dname] [-i iters|-t seconds] [-s fsize]\n"
509 "\t[-l opfnamelen] [-L bgfnamelen]\n"
510 "\t[-n opfcount] [-N bgfcount] test...\n");
512 "Tests: chown create crunlink linkun open rename stat readdir\n");