-
Notifications
You must be signed in to change notification settings - Fork 4
/
timer.c
244 lines (218 loc) · 6.43 KB
/
timer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* $Id: timer.c,v 1.16.2.1 2009/01/21 00:53:26 yardleyb Exp $
* Disktest
* Copyright (c) International Business Machines Corp., 2001
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Please send e-mail to [email protected] if you have
* questions or comments.
*
* Project Website: TBD
*
* $Id: timer.c,v 1.16.2.1 2009/01/21 00:53:26 yardleyb Exp $
*
*/
#include <stdio.h>
#ifdef WINDOWS
#include <windows.h>
#include <winioctl.h>
#include <io.h>
#include <process.h>
#include <sys/stat.h>
#include "getopt.h"
#else
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include "defs.h"
#include "globals.h"
#include "threading.h"
#include "sfunc.h"
#include "stats.h"
#include "signals.h"
/*
* The main purpose of this thread is track time during the test. Along with
* keeping track of read/write time. And check that each interval, that the
* IO threads are making progress. The timer thread is started before any IO
* threads and will complete either after all IO threads exit, the test fails,
* or if a timed run, the run time is exceeded.
*/
#ifdef WINDOWS
DWORD WINAPI ChildTimer(test_ll_t *test)
#else
void *ChildTimer(void *vtest)
#endif
{
#ifndef WINDOWS
test_ll_t *test = (test_ll_t *)vtest;
#endif
time_t ioTimeoutCount = 0;
time_t total_time = 0;
OFF_T cur_total_io_count = 0;
OFF_T last_total_io_count = 0;
OFF_T tmp_io_count = 0;
time_t run_time = 0;
lvl_t msg_level = WARN;
child_args_t *args = test->args;
test_env_t *env = test->env;
extern int signal_action;
extern unsigned long glb_run;
extern unsigned long glb_flags;
#ifdef _DEBUG
PDBG3(DBUG, args, "In timer %lu, %d\n", time(NULL), env->bContinue);
#endif
do {
Sleep(1000);
run_time++;
#ifdef _DEBUG
PDBG3(DBUG, args, "Continue timing %lu, %lu, %d\n", time(NULL), run_time, env->bContinue);
#endif
if(args->flags & CLD_FLG_W) {
if((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
if(TST_OPER(args->test_state) == WRITER) {
env->hbeat_stats.wtime++;
}
} else {
env->hbeat_stats.wtime++;
}
}
if(args->flags & CLD_FLG_R) {
if((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
if(TST_OPER(args->test_state) == READER) {
env->hbeat_stats.rtime++;
}
} else {
env->hbeat_stats.rtime++;
}
}
/*
* Check to see if we have made any IO progress in the last interval,
* if not incremment the ioTimeout timer, otherwise, clear it
*/
cur_total_io_count = env->global_stats.wcount \
+ env->cycle_stats.wcount \
+ env->hbeat_stats.wcount \
+ env->global_stats.rcount \
+ env->cycle_stats.rcount \
+ env->hbeat_stats.rcount;
if(cur_total_io_count == 0) {
tmp_io_count = 1;
} else {
tmp_io_count = cur_total_io_count;
}
total_time = (time_t) (env->global_stats.rtime \
+ env->cycle_stats.rtime \
+ env->hbeat_stats.rtime \
+ env->global_stats.wtime \
+ env->cycle_stats.wtime \
+ env->hbeat_stats.wtime);
#ifdef _DEBUG
PDBG3(DBUG, args, "average number of seconds per IO: %0.8lf\n", ((double)(total_time)/(double)(tmp_io_count)));
#endif
if(cur_total_io_count == last_total_io_count) { /* no IOs completed in interval */
if(0 == (++ioTimeoutCount % args->ioTimeout)) { /* no progress after modulo ioTimeout interval */
if(args->flags & CLD_FLG_TMO_ERROR) {
args->test_state = SET_STS_FAIL(args->test_state);
glb_flags |= GLB_FLG_FAILED;
env->bContinue = FALSE;
msg_level = ERR;
}
pMsg(msg_level, args, "Possible IO hang condition, IO timeout reached, %lu seconds\n", args->ioTimeout);
}
#ifdef _DEBUG
PDBG3(DBUG, args, "io timeout count: %lu\n", ioTimeoutCount);
#endif
} else {
ioTimeoutCount = 0;
last_total_io_count = cur_total_io_count;
#ifdef _DEBUG
PDBG3(DBUG, args, "io timeout reset\n");
#endif
}
if(((args->hbeat > 0) && ((run_time % args->hbeat) == 0)) || (signal_action & SIGNAL_STAT)) {
print_stats(args, env, HBEAT);
update_cyc_stats(args, env);
clear_stat_signal();
}
if(glb_run == 0) { break; } /* global run flag cleared */
if(signal_action & SIGNAL_STOP) { break; } /* user request to stop */
if(args->flags & CLD_FLG_TMD) { /* if timing */
if(env->kids <= 1) { /* and the timer is the only child, something must have happened */
break;
}
if(run_time >= args->run_time) { /* and run time exceeded */
break;
}
} else { /* if not timing */
if(env->kids <= 1) { /* and the timer is the only child */
break;
}
}
} while(TRUE);
#ifdef _DEBUG
PDBG3(DBUG, args, "Out of timer %lu, %lu, %d, %d\n", time(NULL), run_time, env->bContinue, env->kids);
#endif
if(args->flags & CLD_FLG_TMD) { /* timed test, timer exit needs to stop io threads */
#ifdef _DEBUG
PDBG3(DBUG, args, "Setting bContinue to FALSE, timed test & timer exit\n");
#endif
env->bContinue = FALSE;
}
TEXIT(GETLASTERROR());
}
#ifdef _DEBUG
#ifdef WINDOWS
DWORD startTime;
DWORD endTime;
void setStartTime(void) {
startTime = GetTickCount();
}
void setEndTime(void) {
endTime = GetTickCount();
}
unsigned long getTimeDiff(void) {
if((endTime - startTime) < 0) return (0);
else return((endTime - startTime) * 1000); /* since we report in usecs, and windows is msec, multiply by 1000 */
}
#else
struct timeval tv_start; struct timeval tv_end;
void setStartTime(void) {
gettimeofday(&tv_start, NULL);
}
void setEndTime(void) {
gettimeofday(&tv_end, NULL);
}
unsigned long getTimeDiff(void) {
if((tv_end.tv_usec - tv_start.tv_usec) < 0) {
printf("%lu, %lu\n", tv_end.tv_usec, tv_start.tv_usec);
printf("Here");
exit(1);
}
if((tv_end.tv_usec - tv_start.tv_usec) < 0) return (0);
return(tv_end.tv_usec - tv_start.tv_usec);
}
#endif
#endif