4 Copyright (C) Andrew Tridgell 1999-2004
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* This file links against either fileio.c to do operations against a
21 local filesystem (making dbench), or sockio.c to issue SMB-like
22 command packets over a socket (making tbench).
24 So, the pattern of operations and the control structure is the same
25 for both benchmarks, but the operations performed are different.
30 #define ival(s) strtol(s, NULL, 0)
32 static void nb_target_rate(struct child_struct *child, double rate)
36 if (child->rate.last_bytes == 0) {
37 child->rate.last_bytes = child->bytes;
38 child->rate.last_time = timeval_current();
43 tdelay = (child->bytes - child->rate.last_bytes)/(1.0e6*rate) -
44 timeval_elapsed(&child->rate.last_time);
46 tdelay = - timeval_elapsed(&child->rate.last_time);
48 if (tdelay > 0 && rate != 0) {
51 child->max_latency = MAX(child->max_latency, -tdelay);
54 child->rate.last_time = timeval_current();
55 child->rate.last_bytes = child->bytes;
58 static void nb_time_reset(struct child_struct *child)
60 child->starttime = timeval_current();
63 static void nb_time_delay(struct child_struct *child, double targett)
65 double elapsed = timeval_elapsed(&child->starttime);
66 if (targett > elapsed) {
67 msleep(1000*(targett - elapsed));
68 } else if (elapsed - targett > child->max_latency) {
69 child->max_latency = MAX(elapsed - targett, child->max_latency);
77 static void child_op(struct child_struct *child, char **params,
78 const char *fname, const char *fname2, const char *status)
81 printf("op %s in client %d fname=%s fname2=%s\n", params[0], child->id,
84 if (!strcmp(params[0],"NTCreateX")) {
85 nb_createx(child, fname, ival(params[2]), ival(params[3]),
86 ival(params[4]), status);
87 } else if (!strcmp(params[0],"Close")) {
88 nb_close(child, ival(params[1]), status);
89 } else if (!strcmp(params[0],"Rename")) {
90 nb_rename(child, fname, fname2, status);
91 } else if (!strcmp(params[0],"Unlink")) {
92 nb_unlink(child, fname, ival(params[2]), status);
93 } else if (!strcmp(params[0],"Deltree")) {
94 nb_deltree(child, fname);
95 } else if (!strcmp(params[0],"Rmdir")) {
96 nb_rmdir(child, fname, status);
97 } else if (!strcmp(params[0],"Mkdir")) {
98 nb_mkdir(child, fname, status);
99 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
100 nb_qpathinfo(child, fname, ival(params[2]), status);
101 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
102 nb_qfileinfo(child, ival(params[1]), ival(params[2]), status);
103 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
104 nb_qfsinfo(child, ival(params[1]), status);
105 } else if (!strcmp(params[0],"SET_FILE_INFORMATION")) {
106 nb_sfileinfo(child, ival(params[1]), ival(params[2]), status);
107 } else if (!strcmp(params[0],"FIND_FIRST")) {
108 nb_findfirst(child, fname, ival(params[2]),
109 ival(params[3]), ival(params[4]), status);
110 } else if (!strcmp(params[0],"WriteX")) {
111 nb_writex(child, ival(params[1]),
112 ival(params[2]), ival(params[3]), ival(params[4]),
114 } else if (!strcmp(params[0],"LockX")) {
115 nb_lockx(child, ival(params[1]),
116 ival(params[2]), ival(params[3]), status);
117 } else if (!strcmp(params[0],"UnlockX")) {
118 nb_unlockx(child, ival(params[1]),
119 ival(params[2]), ival(params[3]), status);
120 } else if (!strcmp(params[0],"ReadX")) {
121 nb_readx(child, ival(params[1]),
122 ival(params[2]), ival(params[3]), ival(params[4]),
124 } else if (!strcmp(params[0],"Flush")) {
125 nb_flush(child, ival(params[1]), status);
126 } else if (!strcmp(params[0],"Sleep")) {
127 nb_sleep(child, ival(params[1]), status);
129 printf("[%d] Unknown operation %s\n", child->line, params[0]);
134 /* run a test that simulates an approximate netbench client load */
135 void child_run(struct child_struct *child0, const char *loadfile)
139 char **sparams, **params;
142 FILE *f = fopen(loadfile, "r");
143 pid_t parent = getppid();
145 struct child_struct *child;
147 for (child=child0;child<child0+options.clients_per_process;child++) {
149 asprintf(&child->cname,"client%d", child->id);
152 sparams = calloc(20, sizeof(char *));
154 sparams[i] = malloc(100);
158 for (child=child0;child<child0+options.clients_per_process;child++) {
159 nb_time_reset(child);
162 while (fgets(line, sizeof(line)-1, f)) {
165 if (kill(parent, 0) == -1) {
169 for (child=child0;child<child0+options.clients_per_process;child++) {
170 if (child->done) goto done;
175 line[strlen(line)-1] = 0;
177 all_string_sub(line,"\\", "/");
178 all_string_sub(line," /", " ");
182 i<19 && next_token(&p, params[i], " ");
187 if (i < 2 || params[0][0] == '#') continue;
189 if (!strncmp(params[0],"SMB", 3)) {
190 printf("ERROR: You are using a dbench 1 load file\n");
194 if (i > 0 && isdigit(params[0][0])) {
195 targett = strtod(params[0], NULL);
202 if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
203 strncmp(params[i-1], "0x", 2) != 0) {
204 printf("Badly formed status at line %d\n", child->line);
208 status = params[i-1];
210 for (child=child0;child<child0+options.clients_per_process;child++) {
214 if (i>1 && params[1][0] == '/') {
215 asprintf(&fname, "%s%s", child->directory, params[1]);
216 all_string_sub(fname,"client1", child->cname);
218 if (i>2 && params[2][0] == '/') {
219 if (fname2) free(fname2);
220 asprintf(&fname2, "%s%s", child->directory, params[2]);
221 all_string_sub(fname2,"client1", child->cname);
224 if (options.targetrate != 0 || targett == 0.0) {
225 nb_target_rate(child, options.targetrate);
227 nb_time_delay(child, targett);
229 child->lasttime = timeval_current();
231 child_op(child, params, fname, fname2, status);
232 if (fname) free(fname);
233 if (fname2) free(fname2);
242 for (child=child0;child<child0+options.clients_per_process;child++) {