nice() error handling
[fio.git] / backend.c
CommitLineData
2e1df07d
JA
1/*
2 * fio - the flexible io tester
3 *
4 * Copyright (C) 2005 Jens Axboe <axboe@suse.de>
5 * Copyright (C) 2006-2012 Jens Axboe <axboe@kernel.dk>
6 *
7 * The license below covers all files distributed with fio unless otherwise
8 * noted in the file itself.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24#include <unistd.h>
25#include <fcntl.h>
26#include <string.h>
27#include <limits.h>
28#include <signal.h>
29#include <time.h>
30#include <locale.h>
31#include <assert.h>
32#include <time.h>
33#include <sys/stat.h>
34#include <sys/wait.h>
35#include <sys/ipc.h>
36#include <sys/shm.h>
37#include <sys/mman.h>
38
39#include "fio.h"
40#include "hash.h"
41#include "smalloc.h"
42#include "verify.h"
43#include "trim.h"
44#include "diskutil.h"
45#include "cgroup.h"
46#include "profile.h"
47#include "lib/rand.h"
48#include "memalign.h"
49#include "server.h"
50
51static pthread_t disk_util_thread;
52static struct fio_mutex *startup_mutex;
53static struct fio_mutex *writeout_mutex;
54static struct flist_head *cgroup_list;
55static char *cgroup_mnt;
56static int exit_value;
57static volatile int fio_abort;
58
59struct io_log *agg_io_log[2];
60
a3efc919
JA
61int groupid = 0;
62unsigned int thread_number = 0;
63unsigned int nr_process = 0;
64unsigned int nr_thread = 0;
65int shm_id = 0;
66int temp_stall_ts;
67unsigned long done_secs = 0;
68
2e1df07d
JA
69#define PAGE_ALIGN(buf) \
70 (char *) (((unsigned long) (buf) + page_mask) & ~page_mask)
71
72#define JOB_START_TIMEOUT (5 * 1000)
73
74static void sig_int(int sig)
75{
76 if (threads) {
77 if (is_backend)
78 fio_server_got_signal(sig);
79 else {
80 log_info("\nfio: terminating on signal %d\n", sig);
81 fflush(stdout);
82 exit_value = 128;
83 }
84
85 fio_terminate_threads(TERMINATE_ALL);
86 }
87}
88
89static void set_sig_handlers(void)
90{
91 struct sigaction act;
92
93 memset(&act, 0, sizeof(act));
94 act.sa_handler = sig_int;
95 act.sa_flags = SA_RESTART;
96 sigaction(SIGINT, &act, NULL);
97
98 memset(&act, 0, sizeof(act));
99 act.sa_handler = sig_int;
100 act.sa_flags = SA_RESTART;
101 sigaction(SIGTERM, &act, NULL);
102
103 if (is_backend) {
104 memset(&act, 0, sizeof(act));
105 act.sa_handler = sig_int;
106 act.sa_flags = SA_RESTART;
107 sigaction(SIGPIPE, &act, NULL);
108 }
109}
110
111/*
112 * Check if we are above the minimum rate given.
113 */
114static int __check_min_rate(struct thread_data *td, struct timeval *now,
115 enum fio_ddir ddir)
116{
117 unsigned long long bytes = 0;
118 unsigned long iops = 0;
119 unsigned long spent;
120 unsigned long rate;
121 unsigned int ratemin = 0;
122 unsigned int rate_iops = 0;
123 unsigned int rate_iops_min = 0;
124
125 assert(ddir_rw(ddir));
126
127 if (!td->o.ratemin[ddir] && !td->o.rate_iops_min[ddir])
128 return 0;
129
130 /*
131 * allow a 2 second settle period in the beginning
132 */
133 if (mtime_since(&td->start, now) < 2000)
134 return 0;
135
136 iops += td->this_io_blocks[ddir];
137 bytes += td->this_io_bytes[ddir];
138 ratemin += td->o.ratemin[ddir];
139 rate_iops += td->o.rate_iops[ddir];
140 rate_iops_min += td->o.rate_iops_min[ddir];
141
142 /*
143 * if rate blocks is set, sample is running
144 */
145 if (td->rate_bytes[ddir] || td->rate_blocks[ddir]) {
146 spent = mtime_since(&td->lastrate[ddir], now);
147 if (spent < td->o.ratecycle)
148 return 0;
149
150 if (td->o.rate[ddir]) {
151 /*
152 * check bandwidth specified rate
153 */
154 if (bytes < td->rate_bytes[ddir]) {
155 log_err("%s: min rate %u not met\n", td->o.name,
156 ratemin);
157 return 1;
158 } else {
159 rate = ((bytes - td->rate_bytes[ddir]) * 1000) / spent;
160 if (rate < ratemin ||
161 bytes < td->rate_bytes[ddir]) {
162 log_err("%s: min rate %u not met, got"
163 " %luKB/sec\n", td->o.name,
164 ratemin, rate);
165 return 1;
166 }
167 }
168 } else {
169 /*
170 * checks iops specified rate
171 */
172 if (iops < rate_iops) {
173 log_err("%s: min iops rate %u not met\n",
174 td->o.name, rate_iops);
175 return 1;
176 } else {
177 rate = ((iops - td->rate_blocks[ddir]) * 1000) / spent;
178 if (rate < rate_iops_min ||
179 iops < td->rate_blocks[ddir]) {
180 log_err("%s: min iops rate %u not met,"
181 " got %lu\n", td->o.name,
182 rate_iops_min, rate);
183 }
184 }
185 }
186 }
187
188 td->rate_bytes[ddir] = bytes;
189 td->rate_blocks[ddir] = iops;
190 memcpy(&td->lastrate[ddir], now, sizeof(*now));
191 return 0;
192}
193
194static int check_min_rate(struct thread_data *td, struct timeval *now,
195 unsigned long *bytes_done)
196{
197 int ret = 0;
198
199 if (bytes_done[0])
200 ret |= __check_min_rate(td, now, 0);
201 if (bytes_done[1])
202 ret |= __check_min_rate(td, now, 1);
203
204 return ret;
205}
206
207/*
208 * When job exits, we can cancel the in-flight IO if we are using async
209 * io. Attempt to do so.
210 */
211static void cleanup_pending_aio(struct thread_data *td)
212{
213 struct flist_head *entry, *n;
214 struct io_u *io_u;
215 int r;
216
217 /*
218 * get immediately available events, if any
219 */
220 r = io_u_queued_complete(td, 0, NULL);
221 if (r < 0)
222 return;
223
224 /*
225 * now cancel remaining active events
226 */
227 if (td->io_ops->cancel) {
228 flist_for_each_safe(entry, n, &td->io_u_busylist) {
229 io_u = flist_entry(entry, struct io_u, list);
230
231 /*
232 * if the io_u isn't in flight, then that generally
233 * means someone leaked an io_u. complain but fix
234 * it up, so we don't stall here.
235 */
236 if ((io_u->flags & IO_U_F_FLIGHT) == 0) {
237 log_err("fio: non-busy IO on busy list\n");
238 put_io_u(td, io_u);
239 } else {
240 r = td->io_ops->cancel(td, io_u);
241 if (!r)
242 put_io_u(td, io_u);
243 }
244 }
245 }
246
247 if (td->cur_depth)
248 r = io_u_queued_complete(td, td->cur_depth, NULL);
249}
250
251/*
252 * Helper to handle the final sync of a file. Works just like the normal
253 * io path, just does everything sync.
254 */
255static int fio_io_sync(struct thread_data *td, struct fio_file *f)
256{
257 struct io_u *io_u = __get_io_u(td);
258 int ret;
259
260 if (!io_u)
261 return 1;
262
263 io_u->ddir = DDIR_SYNC;
264 io_u->file = f;
265
266 if (td_io_prep(td, io_u)) {
267 put_io_u(td, io_u);
268 return 1;
269 }
270
271requeue:
272 ret = td_io_queue(td, io_u);
273 if (ret < 0) {
274 td_verror(td, io_u->error, "td_io_queue");
275 put_io_u(td, io_u);
276 return 1;
277 } else if (ret == FIO_Q_QUEUED) {
278 if (io_u_queued_complete(td, 1, NULL) < 0)
279 return 1;
280 } else if (ret == FIO_Q_COMPLETED) {
281 if (io_u->error) {
282 td_verror(td, io_u->error, "td_io_queue");
283 return 1;
284 }
285
286 if (io_u_sync_complete(td, io_u, NULL) < 0)
287 return 1;
288 } else if (ret == FIO_Q_BUSY) {
289 if (td_io_commit(td))
290 return 1;
291 goto requeue;
292 }
293
294 return 0;
295}
a3efc919 296
2e1df07d
JA
297static inline void __update_tv_cache(struct thread_data *td)
298{
299 fio_gettime(&td->tv_cache, NULL);
300}
301
302static inline void update_tv_cache(struct thread_data *td)
303{
304 if ((++td->tv_cache_nr & td->tv_cache_mask) == td->tv_cache_mask)
305 __update_tv_cache(td);
306}
307
308static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
309{
310 if (in_ramp_time(td))
311 return 0;
312 if (!td->o.timeout)
313 return 0;
314 if (mtime_since(&td->epoch, t) >= td->o.timeout * 1000)
315 return 1;
316
317 return 0;
318}
319
320static int break_on_this_error(struct thread_data *td, enum fio_ddir ddir,
321 int *retptr)
322{
323 int ret = *retptr;
324
325 if (ret < 0 || td->error) {
326 int err;
327
328 if (ret < 0)
329 err = -ret;
330 else
331 err = td->error;
332
333 if (!(td->o.continue_on_error & td_error_type(ddir, err)))
334 return 1;
335
336 if (td_non_fatal_error(err)) {
337 /*
338 * Continue with the I/Os in case of
339 * a non fatal error.
340 */
341 update_error_count(td, err);
342 td_clear_error(td);
343 *retptr = 0;
344 return 0;
345 } else if (td->o.fill_device && err == ENOSPC) {
346 /*
347 * We expect to hit this error if
348 * fill_device option is set.
349 */
350 td_clear_error(td);
351 td->terminate = 1;
352 return 1;
353 } else {
354 /*
355 * Stop the I/O in case of a fatal
356 * error.
357 */
358 update_error_count(td, err);
359 return 1;
360 }
361 }
362
363 return 0;
364}
365
2e1df07d
JA
366/*
367 * The main verify engine. Runs over the writes we previously submitted,
368 * reads the blocks back in, and checks the crc/md5 of the data.
369 */
370static void do_verify(struct thread_data *td)
371{
372 struct fio_file *f;
373 struct io_u *io_u;
374 int ret, min_events;
375 unsigned int i;
376
377 dprint(FD_VERIFY, "starting loop\n");
378
379 /*
380 * sync io first and invalidate cache, to make sure we really
381 * read from disk.
382 */
383 for_each_file(td, f, i) {
384 if (!fio_file_open(f))
385 continue;
386 if (fio_io_sync(td, f))
387 break;
388 if (file_invalidate_cache(td, f))
389 break;
390 }
391
392 if (td->error)
393 return;
394
395 td_set_runstate(td, TD_VERIFYING);
396
397 io_u = NULL;
398 while (!td->terminate) {
399 int ret2, full;
400
401 update_tv_cache(td);
402
403 if (runtime_exceeded(td, &td->tv_cache)) {
404 __update_tv_cache(td);
405 if (runtime_exceeded(td, &td->tv_cache)) {
406 td->terminate = 1;
407 break;
408 }
409 }
410
411 io_u = __get_io_u(td);
412 if (!io_u)
413 break;
414
415 if (get_next_verify(td, io_u)) {
416 put_io_u(td, io_u);
417 break;
418 }
419
420 if (td_io_prep(td, io_u)) {
421 put_io_u(td, io_u);
422 break;
423 }
424
425 if (td->o.verify_async)
426 io_u->end_io = verify_io_u_async;
427 else
428 io_u->end_io = verify_io_u;
429
430 ret = td_io_queue(td, io_u);
431 switch (ret) {
432 case FIO_Q_COMPLETED:
433 if (io_u->error) {
434 ret = -io_u->error;
435 clear_io_u(td, io_u);
436 } else if (io_u->resid) {
437 int bytes = io_u->xfer_buflen - io_u->resid;
438
439 /*
440 * zero read, fail
441 */
442 if (!bytes) {
443 td_verror(td, EIO, "full resid");
444 put_io_u(td, io_u);
445 break;
446 }
447
448 io_u->xfer_buflen = io_u->resid;
449 io_u->xfer_buf += bytes;
450 io_u->offset += bytes;
451
452 if (ddir_rw(io_u->ddir))
453 td->ts.short_io_u[io_u->ddir]++;
454
455 f = io_u->file;
456 if (io_u->offset == f->real_file_size)
457 goto sync_done;
458
459 requeue_io_u(td, &io_u);
460 } else {
461sync_done:
462 ret = io_u_sync_complete(td, io_u, NULL);
463 if (ret < 0)
464 break;
465 }
466 continue;
467 case FIO_Q_QUEUED:
468 break;
469 case FIO_Q_BUSY:
470 requeue_io_u(td, &io_u);
471 ret2 = td_io_commit(td);
472 if (ret2 < 0)
473 ret = ret2;
474 break;
475 default:
476 assert(ret < 0);
477 td_verror(td, -ret, "td_io_queue");
478 break;
479 }
480
481 if (break_on_this_error(td, io_u->ddir, &ret))
482 break;
483
484 /*
485 * if we can queue more, do so. but check if there are
486 * completed io_u's first. Note that we can get BUSY even
487 * without IO queued, if the system is resource starved.
488 */
489 full = queue_full(td) || (ret == FIO_Q_BUSY && td->cur_depth);
490 if (full || !td->o.iodepth_batch_complete) {
491 min_events = min(td->o.iodepth_batch_complete,
492 td->cur_depth);
493 if (full && !min_events && td->o.iodepth_batch_complete != 0)
494 min_events = 1;
495
496 do {
497 /*
498 * Reap required number of io units, if any,
499 * and do the verification on them through
500 * the callback handler
501 */
502 if (io_u_queued_complete(td, min_events, NULL) < 0) {
503 ret = -1;
504 break;
505 }
506 } while (full && (td->cur_depth > td->o.iodepth_low));
507 }
508 if (ret < 0)
509 break;
510 }
511
512 if (!td->error) {
513 min_events = td->cur_depth;
514
515 if (min_events)
516 ret = io_u_queued_complete(td, min_events, NULL);
517 } else
518 cleanup_pending_aio(td);
519
520 td_set_runstate(td, TD_RUNNING);
521
522 dprint(FD_VERIFY, "exiting loop\n");
523}
524
525/*
526 * Main IO worker function. It retrieves io_u's to process and queues
527 * and reaps them, checking for rate and errors along the way.
528 */
529static void do_io(struct thread_data *td)
530{
531 unsigned int i;
532 int ret = 0;
533
534 if (in_ramp_time(td))
535 td_set_runstate(td, TD_RAMP);
536 else
537 td_set_runstate(td, TD_RUNNING);
538
539 while ( (td->o.read_iolog_file && !flist_empty(&td->io_log_list)) ||
540 (!flist_empty(&td->trim_list)) ||
541 ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->o.size) ) {
542 struct timeval comp_time;
543 unsigned long bytes_done[2] = { 0, 0 };
544 int min_evts = 0;
545 struct io_u *io_u;
546 int ret2, full;
547 enum fio_ddir ddir;
548
549 if (td->terminate)
550 break;
551
552 update_tv_cache(td);
553
554 if (runtime_exceeded(td, &td->tv_cache)) {
555 __update_tv_cache(td);
556 if (runtime_exceeded(td, &td->tv_cache)) {
557 td->terminate = 1;
558 break;
559 }
560 }
561
562 io_u = get_io_u(td);
563 if (!io_u)
564 break;
565
566 ddir = io_u->ddir;
567
568 /*
569 * Add verification end_io handler, if asked to verify
570 * a previously written file.
571 */
572 if (td->o.verify != VERIFY_NONE && io_u->ddir == DDIR_READ &&
573 !td_rw(td)) {
574 if (td->o.verify_async)
575 io_u->end_io = verify_io_u_async;
576 else
577 io_u->end_io = verify_io_u;
578 td_set_runstate(td, TD_VERIFYING);
579 } else if (in_ramp_time(td))
580 td_set_runstate(td, TD_RAMP);
581 else
582 td_set_runstate(td, TD_RUNNING);
583
584 ret = td_io_queue(td, io_u);
585 switch (ret) {
586 case FIO_Q_COMPLETED:
587 if (io_u->error) {
588 ret = -io_u->error;
589 clear_io_u(td, io_u);
590 } else if (io_u->resid) {
591 int bytes = io_u->xfer_buflen - io_u->resid;
592 struct fio_file *f = io_u->file;
593
594 /*
595 * zero read, fail
596 */
597 if (!bytes) {
598 td_verror(td, EIO, "full resid");
599 put_io_u(td, io_u);
600 break;
601 }
602
603 io_u->xfer_buflen = io_u->resid;
604 io_u->xfer_buf += bytes;
605 io_u->offset += bytes;
606
607 if (ddir_rw(io_u->ddir))
608 td->ts.short_io_u[io_u->ddir]++;
609
610 if (io_u->offset == f->real_file_size)
611 goto sync_done;
612
613 requeue_io_u(td, &io_u);
614 } else {
615sync_done:
616 if (__should_check_rate(td, 0) ||
617 __should_check_rate(td, 1))
618 fio_gettime(&comp_time, NULL);
619
620 ret = io_u_sync_complete(td, io_u, bytes_done);
621 if (ret < 0)
622 break;
623 }
624 break;
625 case FIO_Q_QUEUED:
626 /*
627 * if the engine doesn't have a commit hook,
628 * the io_u is really queued. if it does have such
629 * a hook, it has to call io_u_queued() itself.
630 */
631 if (td->io_ops->commit == NULL)
632 io_u_queued(td, io_u);
633 break;
634 case FIO_Q_BUSY:
635 requeue_io_u(td, &io_u);
636 ret2 = td_io_commit(td);
637 if (ret2 < 0)
638 ret = ret2;
639 break;
640 default:
641 assert(ret < 0);
642 put_io_u(td, io_u);
643 break;
644 }
645
646 if (break_on_this_error(td, ddir, &ret))
647 break;
648
649 /*
650 * See if we need to complete some commands. Note that we
651 * can get BUSY even without IO queued, if the system is
652 * resource starved.
653 */
654 full = queue_full(td) || (ret == FIO_Q_BUSY && td->cur_depth);
655 if (full || !td->o.iodepth_batch_complete) {
656 min_evts = min(td->o.iodepth_batch_complete,
657 td->cur_depth);
658 if (full && !min_evts && td->o.iodepth_batch_complete != 0)
659 min_evts = 1;
660
661 if (__should_check_rate(td, 0) ||
662 __should_check_rate(td, 1))
663 fio_gettime(&comp_time, NULL);
664
665 do {
666 ret = io_u_queued_complete(td, min_evts, bytes_done);
667 if (ret < 0)
668 break;
669
670 } while (full && (td->cur_depth > td->o.iodepth_low));
671 }
672
673 if (ret < 0)
674 break;
675 if (!(bytes_done[0] + bytes_done[1]))
676 continue;
677
678 if (!in_ramp_time(td) && should_check_rate(td, bytes_done)) {
679 if (check_min_rate(td, &comp_time, bytes_done)) {
680 if (exitall_on_terminate)
681 fio_terminate_threads(td->groupid);
682 td_verror(td, EIO, "check_min_rate");
683 break;
684 }
685 }
686
687 if (td->o.thinktime) {
688 unsigned long long b;
689
690 b = td->io_blocks[0] + td->io_blocks[1];
691 if (!(b % td->o.thinktime_blocks)) {
692 int left;
693
694 if (td->o.thinktime_spin)
695 usec_spin(td->o.thinktime_spin);
696
697 left = td->o.thinktime - td->o.thinktime_spin;
698 if (left)
699 usec_sleep(td, left);
700 }
701 }
702 }
703
704 if (td->trim_entries)
705 log_err("fio: %d trim entries leaked?\n", td->trim_entries);
706
707 if (td->o.fill_device && td->error == ENOSPC) {
708 td->error = 0;
709 td->terminate = 1;
710 }
711 if (!td->error) {
712 struct fio_file *f;
713
714 i = td->cur_depth;
715 if (i) {
716 ret = io_u_queued_complete(td, i, NULL);
717 if (td->o.fill_device && td->error == ENOSPC)
718 td->error = 0;
719 }
720
721 if (should_fsync(td) && td->o.end_fsync) {
722 td_set_runstate(td, TD_FSYNCING);
723
724 for_each_file(td, f, i) {
725 if (!fio_file_open(f))
726 continue;
727 fio_io_sync(td, f);
728 }
729 }
730 } else
731 cleanup_pending_aio(td);
732
733 /*
734 * stop job if we failed doing any IO
735 */
736 if ((td->this_io_bytes[0] + td->this_io_bytes[1]) == 0)
737 td->done = 1;
738}
739
740static void cleanup_io_u(struct thread_data *td)
741{
742 struct flist_head *entry, *n;
743 struct io_u *io_u;
744
745 flist_for_each_safe(entry, n, &td->io_u_freelist) {
746 io_u = flist_entry(entry, struct io_u, list);
747
748 flist_del(&io_u->list);
749 fio_memfree(io_u, sizeof(*io_u));
750 }
751
752 free_io_mem(td);
753}
754
755static int init_io_u(struct thread_data *td)
756{
757 struct io_u *io_u;
758 unsigned int max_bs;
759 int cl_align, i, max_units;
760 char *p;
761
762 max_units = td->o.iodepth;
763 max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
764 td->orig_buffer_size = (unsigned long long) max_bs
765 * (unsigned long long) max_units;
766
767 if (td->o.mem_type == MEM_SHMHUGE || td->o.mem_type == MEM_MMAPHUGE) {
768 unsigned long bs;
769
770 bs = td->orig_buffer_size + td->o.hugepage_size - 1;
771 td->orig_buffer_size = bs & ~(td->o.hugepage_size - 1);
772 }
773
774 if (td->orig_buffer_size != (size_t) td->orig_buffer_size) {
775 log_err("fio: IO memory too large. Reduce max_bs or iodepth\n");
776 return 1;
777 }
778
779 if (allocate_io_mem(td))
780 return 1;
781
782 if (td->o.odirect || td->o.mem_align ||
783 (td->io_ops->flags & FIO_RAWIO))
784 p = PAGE_ALIGN(td->orig_buffer) + td->o.mem_align;
785 else
786 p = td->orig_buffer;
787
788 cl_align = os_cache_line_size();
789
790 for (i = 0; i < max_units; i++) {
791 void *ptr;
792
793 if (td->terminate)
794 return 1;
795
796 ptr = fio_memalign(cl_align, sizeof(*io_u));
797 if (!ptr) {
798 log_err("fio: unable to allocate aligned memory\n");
799 break;
800 }
801
802 io_u = ptr;
803 memset(io_u, 0, sizeof(*io_u));
804 INIT_FLIST_HEAD(&io_u->list);
805 dprint(FD_MEM, "io_u alloc %p, index %u\n", io_u, i);
806
807 if (!(td->io_ops->flags & FIO_NOIO)) {
808 io_u->buf = p;
809 dprint(FD_MEM, "io_u %p, mem %p\n", io_u, io_u->buf);
810
811 if (td_write(td))
812 io_u_fill_buffer(td, io_u, max_bs);
813 if (td_write(td) && td->o.verify_pattern_bytes) {
814 /*
815 * Fill the buffer with the pattern if we are
816 * going to be doing writes.
817 */
818 fill_pattern(td, io_u->buf, max_bs, io_u, 0, 0);
819 }
820 }
821
822 io_u->index = i;
823 io_u->flags = IO_U_F_FREE;
824 flist_add(&io_u->list, &td->io_u_freelist);
825 p += max_bs;
826 }
827
828 return 0;
829}
830
831static int switch_ioscheduler(struct thread_data *td)
832{
833 char tmp[256], tmp2[128];
834 FILE *f;
835 int ret;
836
837 if (td->io_ops->flags & FIO_DISKLESSIO)
838 return 0;
839
840 sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
841
842 f = fopen(tmp, "r+");
843 if (!f) {
844 if (errno == ENOENT) {
845 log_err("fio: os or kernel doesn't support IO scheduler"
846 " switching\n");
847 return 0;
848 }
849 td_verror(td, errno, "fopen iosched");
850 return 1;
851 }
852
853 /*
854 * Set io scheduler.
855 */
856 ret = fwrite(td->o.ioscheduler, strlen(td->o.ioscheduler), 1, f);
857 if (ferror(f) || ret != 1) {
858 td_verror(td, errno, "fwrite");
859 fclose(f);
860 return 1;
861 }
862
863 rewind(f);
864
865 /*
866 * Read back and check that the selected scheduler is now the default.
867 */
868 ret = fread(tmp, 1, sizeof(tmp), f);
869 if (ferror(f) || ret < 0) {
870 td_verror(td, errno, "fread");
871 fclose(f);
872 return 1;
873 }
874
875 sprintf(tmp2, "[%s]", td->o.ioscheduler);
876 if (!strstr(tmp, tmp2)) {
877 log_err("fio: io scheduler %s not found\n", td->o.ioscheduler);
878 td_verror(td, EINVAL, "iosched_switch");
879 fclose(f);
880 return 1;
881 }
882
883 fclose(f);
884 return 0;
885}
886
887static int keep_running(struct thread_data *td)
888{
889 unsigned long long io_done;
890
891 if (td->done)
892 return 0;
893 if (td->o.time_based)
894 return 1;
895 if (td->o.loops) {
896 td->o.loops--;
897 return 1;
898 }
899
900 io_done = td->io_bytes[DDIR_READ] + td->io_bytes[DDIR_WRITE]
901 + td->io_skip_bytes;
902 if (io_done < td->o.size)
903 return 1;
904
905 return 0;
906}
907
908static int exec_string(const char *string)
909{
910 int ret, newlen = strlen(string) + 1 + 8;
911 char *str;
912
913 str = malloc(newlen);
914 sprintf(str, "sh -c %s", string);
915
916 ret = system(str);
917 if (ret == -1)
918 log_err("fio: exec of cmd <%s> failed\n", str);
919
920 free(str);
921 return ret;
922}
923
924/*
925 * Entry point for the thread based jobs. The process based jobs end up
926 * here as well, after a little setup.
927 */
928static void *thread_main(void *data)
929{
930 unsigned long long elapsed;
931 struct thread_data *td = data;
932 pthread_condattr_t attr;
933 int clear_state;
934
935 if (!td->o.use_thread) {
936 setsid();
937 td->pid = getpid();
938 } else
939 td->pid = gettid();
940
941 dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
942
943 INIT_FLIST_HEAD(&td->io_u_freelist);
944 INIT_FLIST_HEAD(&td->io_u_busylist);
945 INIT_FLIST_HEAD(&td->io_u_requeues);
946 INIT_FLIST_HEAD(&td->io_log_list);
947 INIT_FLIST_HEAD(&td->io_hist_list);
948 INIT_FLIST_HEAD(&td->verify_list);
949 INIT_FLIST_HEAD(&td->trim_list);
950 pthread_mutex_init(&td->io_u_lock, NULL);
951 td->io_hist_tree = RB_ROOT;
952
953 pthread_condattr_init(&attr);
954 pthread_cond_init(&td->verify_cond, &attr);
955 pthread_cond_init(&td->free_cond, &attr);
956
957 td_set_runstate(td, TD_INITIALIZED);
958 dprint(FD_MUTEX, "up startup_mutex\n");
959 fio_mutex_up(startup_mutex);
960 dprint(FD_MUTEX, "wait on td->mutex\n");
961 fio_mutex_down(td->mutex);
962 dprint(FD_MUTEX, "done waiting on td->mutex\n");
963
964 /*
965 * the ->mutex mutex is now no longer used, close it to avoid
966 * eating a file descriptor
967 */
968 fio_mutex_remove(td->mutex);
969
970 /*
971 * A new gid requires privilege, so we need to do this before setting
972 * the uid.
973 */
974 if (td->o.gid != -1U && setgid(td->o.gid)) {
975 td_verror(td, errno, "setgid");
976 goto err;
977 }
978 if (td->o.uid != -1U && setuid(td->o.uid)) {
979 td_verror(td, errno, "setuid");
980 goto err;
981 }
982
983 /*
984 * If we have a gettimeofday() thread, make sure we exclude that
985 * thread from this job
986 */
987 if (td->o.gtod_cpu)
988 fio_cpu_clear(&td->o.cpumask, td->o.gtod_cpu);
989
990 /*
991 * Set affinity first, in case it has an impact on the memory
992 * allocations.
993 */
994 if (td->o.cpumask_set && fio_setaffinity(td->pid, td->o.cpumask) == -1) {
995 td_verror(td, errno, "cpu_set_affinity");
996 goto err;
997 }
998
999 /*
1000 * May alter parameters that init_io_u() will use, so we need to
1001 * do this first.
1002 */
1003 if (init_iolog(td))
1004 goto err;
1005
1006 if (init_io_u(td))
1007 goto err;
1008
1009 if (td->o.verify_async && verify_async_init(td))
1010 goto err;
1011
1012 if (td->ioprio_set) {
1013 if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
1014 td_verror(td, errno, "ioprio_set");
1015 goto err;
1016 }
1017 }
1018
1019 if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
1020 goto err;
1021
649c10c5
BC
1022 errno = 0;
1023 if (nice(td->o.nice) == -1 && errno != 0) {
2e1df07d
JA
1024 td_verror(td, errno, "nice");
1025 goto err;
1026 }
1027
1028 if (td->o.ioscheduler && switch_ioscheduler(td))
1029 goto err;
1030
1031 if (!td->o.create_serialize && setup_files(td))
1032 goto err;
1033
1034 if (td_io_init(td))
1035 goto err;
1036
1037 if (init_random_map(td))
1038 goto err;
1039
1040 if (td->o.exec_prerun) {
1041 if (exec_string(td->o.exec_prerun))
1042 goto err;
1043 }
1044
1045 if (td->o.pre_read) {
1046 if (pre_read_files(td) < 0)
1047 goto err;
1048 }
1049
1050 fio_gettime(&td->epoch, NULL);
1051 getrusage(RUSAGE_SELF, &td->ru_start);
1052
1053 clear_state = 0;
1054 while (keep_running(td)) {
1055 fio_gettime(&td->start, NULL);
1056 memcpy(&td->bw_sample_time, &td->start, sizeof(td->start));
1057 memcpy(&td->iops_sample_time, &td->start, sizeof(td->start));
1058 memcpy(&td->tv_cache, &td->start, sizeof(td->start));
1059
1060 if (td->o.ratemin[0] || td->o.ratemin[1]) {
1061 memcpy(&td->lastrate[0], &td->bw_sample_time,
1062 sizeof(td->bw_sample_time));
1063 memcpy(&td->lastrate[1], &td->bw_sample_time,
1064 sizeof(td->bw_sample_time));
1065 }
1066
1067 if (clear_state)
1068 clear_io_state(td);
1069
1070 prune_io_piece_log(td);
1071
1072 do_io(td);
1073
1074 clear_state = 1;
1075
1076 if (td_read(td) && td->io_bytes[DDIR_READ]) {
1077 elapsed = utime_since_now(&td->start);
1078 td->ts.runtime[DDIR_READ] += elapsed;
1079 }
1080 if (td_write(td) && td->io_bytes[DDIR_WRITE]) {
1081 elapsed = utime_since_now(&td->start);
1082 td->ts.runtime[DDIR_WRITE] += elapsed;
1083 }
1084
1085 if (td->error || td->terminate)
1086 break;
1087
1088 if (!td->o.do_verify ||
1089 td->o.verify == VERIFY_NONE ||
1090 (td->io_ops->flags & FIO_UNIDIR))
1091 continue;
1092
1093 clear_io_state(td);
1094
1095 fio_gettime(&td->start, NULL);
1096
1097 do_verify(td);
1098
1099 td->ts.runtime[DDIR_READ] += utime_since_now(&td->start);
1100
1101 if (td->error || td->terminate)
1102 break;
1103 }
1104
1105 update_rusage_stat(td);
1106 td->ts.runtime[0] = (td->ts.runtime[0] + 999) / 1000;
1107 td->ts.runtime[1] = (td->ts.runtime[1] + 999) / 1000;
1108 td->ts.total_run_time = mtime_since_now(&td->epoch);
1109 td->ts.io_bytes[0] = td->io_bytes[0];
1110 td->ts.io_bytes[1] = td->io_bytes[1];
1111
1112 fio_mutex_down(writeout_mutex);
1113 if (td->bw_log) {
1114 if (td->o.bw_log_file) {
1115 finish_log_named(td, td->bw_log,
1116 td->o.bw_log_file, "bw");
1117 } else
1118 finish_log(td, td->bw_log, "bw");
1119 }
1120 if (td->lat_log) {
1121 if (td->o.lat_log_file) {
1122 finish_log_named(td, td->lat_log,
1123 td->o.lat_log_file, "lat");
1124 } else
1125 finish_log(td, td->lat_log, "lat");
1126 }
1127 if (td->slat_log) {
1128 if (td->o.lat_log_file) {
1129 finish_log_named(td, td->slat_log,
1130 td->o.lat_log_file, "slat");
1131 } else
1132 finish_log(td, td->slat_log, "slat");
1133 }
1134 if (td->clat_log) {
1135 if (td->o.lat_log_file) {
1136 finish_log_named(td, td->clat_log,
1137 td->o.lat_log_file, "clat");
1138 } else
1139 finish_log(td, td->clat_log, "clat");
1140 }
1141 if (td->iops_log) {
1142 if (td->o.iops_log_file) {
1143 finish_log_named(td, td->iops_log,
1144 td->o.iops_log_file, "iops");
1145 } else
1146 finish_log(td, td->iops_log, "iops");
1147 }
1148
1149 fio_mutex_up(writeout_mutex);
1150 if (td->o.exec_postrun)
1151 exec_string(td->o.exec_postrun);
1152
1153 if (exitall_on_terminate)
1154 fio_terminate_threads(td->groupid);
1155
1156err:
1157 if (td->error)
1158 log_info("fio: pid=%d, err=%d/%s\n", (int) td->pid, td->error,
1159 td->verror);
1160
1161 if (td->o.verify_async)
1162 verify_async_exit(td);
1163
1164 close_and_free_files(td);
1165 close_ioengine(td);
1166 cleanup_io_u(td);
1167 cgroup_shutdown(td, &cgroup_mnt);
1168
1169 if (td->o.cpumask_set) {
1170 int ret = fio_cpuset_exit(&td->o.cpumask);
1171
1172 td_verror(td, ret, "fio_cpuset_exit");
1173 }
1174
1175 /*
1176 * do this very late, it will log file closing as well
1177 */
1178 if (td->o.write_iolog_file)
1179 write_iolog_close(td);
1180
1181 td_set_runstate(td, TD_EXITED);
1182 return (void *) (unsigned long) td->error;
1183}
1184
1185
1186/*
1187 * We cannot pass the td data into a forked process, so attach the td and
1188 * pass it to the thread worker.
1189 */
1190static int fork_main(int shmid, int offset)
1191{
1192 struct thread_data *td;
1193 void *data, *ret;
1194
1195#ifndef __hpux
1196 data = shmat(shmid, NULL, 0);
1197 if (data == (void *) -1) {
1198 int __err = errno;
1199
1200 perror("shmat");
1201 return __err;
1202 }
1203#else
1204 /*
1205 * HP-UX inherits shm mappings?
1206 */
1207 data = threads;
1208#endif
1209
1210 td = data + offset * sizeof(struct thread_data);
1211 ret = thread_main(td);
1212 shmdt(data);
1213 return (int) (unsigned long) ret;
1214}
1215
1216/*
1217 * Run over the job map and reap the threads that have exited, if any.
1218 */
1219static void reap_threads(unsigned int *nr_running, unsigned int *t_rate,
1220 unsigned int *m_rate)
1221{
1222 struct thread_data *td;
1223 unsigned int cputhreads, realthreads, pending;
1224 int i, status, ret;
1225
1226 /*
1227 * reap exited threads (TD_EXITED -> TD_REAPED)
1228 */
1229 realthreads = pending = cputhreads = 0;
1230 for_each_td(td, i) {
1231 int flags = 0;
1232
1233 /*
1234 * ->io_ops is NULL for a thread that has closed its
1235 * io engine
1236 */
1237 if (td->io_ops && !strcmp(td->io_ops->name, "cpuio"))
1238 cputhreads++;
1239 else
1240 realthreads++;
1241
1242 if (!td->pid) {
1243 pending++;
1244 continue;
1245 }
1246 if (td->runstate == TD_REAPED)
1247 continue;
1248 if (td->o.use_thread) {
1249 if (td->runstate == TD_EXITED) {
1250 td_set_runstate(td, TD_REAPED);
1251 goto reaped;
1252 }
1253 continue;
1254 }
1255
1256 flags = WNOHANG;
1257 if (td->runstate == TD_EXITED)
1258 flags = 0;
1259
1260 /*
1261 * check if someone quit or got killed in an unusual way
1262 */
1263 ret = waitpid(td->pid, &status, flags);
1264 if (ret < 0) {
1265 if (errno == ECHILD) {
1266 log_err("fio: pid=%d disappeared %d\n",
1267 (int) td->pid, td->runstate);
1268 td_set_runstate(td, TD_REAPED);
1269 goto reaped;
1270 }
1271 perror("waitpid");
1272 } else if (ret == td->pid) {
1273 if (WIFSIGNALED(status)) {
1274 int sig = WTERMSIG(status);
1275
1276 if (sig != SIGTERM)
1277 log_err("fio: pid=%d, got signal=%d\n",
1278 (int) td->pid, sig);
1279 td_set_runstate(td, TD_REAPED);
1280 goto reaped;
1281 }
1282 if (WIFEXITED(status)) {
1283 if (WEXITSTATUS(status) && !td->error)
1284 td->error = WEXITSTATUS(status);
1285
1286 td_set_runstate(td, TD_REAPED);
1287 goto reaped;
1288 }
1289 }
1290
1291 /*
1292 * thread is not dead, continue
1293 */
1294 pending++;
1295 continue;
1296reaped:
1297 (*nr_running)--;
1298 (*m_rate) -= (td->o.ratemin[0] + td->o.ratemin[1]);
1299 (*t_rate) -= (td->o.rate[0] + td->o.rate[1]);
1300 if (!td->pid)
1301 pending--;
1302
1303 if (td->error)
1304 exit_value++;
1305
1306 done_secs += mtime_since_now(&td->epoch) / 1000;
1307 }
1308
1309 if (*nr_running == cputhreads && !pending && realthreads)
1310 fio_terminate_threads(TERMINATE_ALL);
1311}
1312
2e1df07d
JA
1313/*
1314 * Main function for kicking off and reaping jobs, as needed.
1315 */
1316static void run_threads(void)
1317{
1318 struct thread_data *td;
1319 unsigned long spent;
1320 unsigned int i, todo, nr_running, m_rate, t_rate, nr_started;
1321
1322 if (fio_pin_memory())
1323 return;
1324
1325 if (fio_gtod_offload && fio_start_gtod_thread())
1326 return;
1327
1328 set_sig_handlers();
1329
1330 if (!terse_output) {
1331 log_info("Starting ");
1332 if (nr_thread)
1333 log_info("%d thread%s", nr_thread,
1334 nr_thread > 1 ? "s" : "");
1335 if (nr_process) {
1336 if (nr_thread)
1337 log_info(" and ");
1338 log_info("%d process%s", nr_process,
1339 nr_process > 1 ? "es" : "");
1340 }
1341 log_info("\n");
1342 fflush(stdout);
1343 }
1344
1345 todo = thread_number;
1346 nr_running = 0;
1347 nr_started = 0;
1348 m_rate = t_rate = 0;
1349
1350 for_each_td(td, i) {
1351 print_status_init(td->thread_number - 1);
1352
1353 if (!td->o.create_serialize)
1354 continue;
1355
1356 /*
1357 * do file setup here so it happens sequentially,
1358 * we don't want X number of threads getting their
1359 * client data interspersed on disk
1360 */
1361 if (setup_files(td)) {
1362 exit_value++;
1363 if (td->error)
1364 log_err("fio: pid=%d, err=%d/%s\n",
1365 (int) td->pid, td->error, td->verror);
1366 td_set_runstate(td, TD_REAPED);
1367 todo--;
1368 } else {
1369 struct fio_file *f;
1370 unsigned int j;
1371
1372 /*
1373 * for sharing to work, each job must always open
1374 * its own files. so close them, if we opened them
1375 * for creation
1376 */
1377 for_each_file(td, f, j) {
1378 if (fio_file_open(f))
1379 td_io_close_file(td, f);
1380 }
1381 }
1382 }
1383
1384 set_genesis_time();
1385
1386 while (todo) {
1387 struct thread_data *map[REAL_MAX_JOBS];
1388 struct timeval this_start;
1389 int this_jobs = 0, left;
1390
1391 /*
1392 * create threads (TD_NOT_CREATED -> TD_CREATED)
1393 */
1394 for_each_td(td, i) {
1395 if (td->runstate != TD_NOT_CREATED)
1396 continue;
1397
1398 /*
1399 * never got a chance to start, killed by other
1400 * thread for some reason
1401 */
1402 if (td->terminate) {
1403 todo--;
1404 continue;
1405 }
1406
1407 if (td->o.start_delay) {
1408 spent = mtime_since_genesis();
1409
1410 if (td->o.start_delay * 1000 > spent)
1411 continue;
1412 }
1413
1414 if (td->o.stonewall && (nr_started || nr_running)) {
1415 dprint(FD_PROCESS, "%s: stonewall wait\n",
1416 td->o.name);
1417 break;
1418 }
1419
1420 init_disk_util(td);
1421
1422 /*
1423 * Set state to created. Thread will transition
1424 * to TD_INITIALIZED when it's done setting up.
1425 */
1426 td_set_runstate(td, TD_CREATED);
1427 map[this_jobs++] = td;
1428 nr_started++;
1429
1430 if (td->o.use_thread) {
1431 int ret;
1432
1433 dprint(FD_PROCESS, "will pthread_create\n");
1434 ret = pthread_create(&td->thread, NULL,
1435 thread_main, td);
1436 if (ret) {
1437 log_err("pthread_create: %s\n",
1438 strerror(ret));
1439 nr_started--;
1440 break;
1441 }
1442 ret = pthread_detach(td->thread);
1443 if (ret)
1444 log_err("pthread_detach: %s",
1445 strerror(ret));
1446 } else {
1447 pid_t pid;
1448 dprint(FD_PROCESS, "will fork\n");
1449 pid = fork();
1450 if (!pid) {
1451 int ret = fork_main(shm_id, i);
1452
1453 _exit(ret);
1454 } else if (i == fio_debug_jobno)
1455 *fio_debug_jobp = pid;
1456 }
1457 dprint(FD_MUTEX, "wait on startup_mutex\n");
1458 if (fio_mutex_down_timeout(startup_mutex, 10)) {
1459 log_err("fio: job startup hung? exiting.\n");
1460 fio_terminate_threads(TERMINATE_ALL);
1461 fio_abort = 1;
1462 nr_started--;
1463 break;
1464 }
1465 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
1466 }
1467
1468 /*
1469 * Wait for the started threads to transition to
1470 * TD_INITIALIZED.
1471 */
1472 fio_gettime(&this_start, NULL);
1473 left = this_jobs;
1474 while (left && !fio_abort) {
1475 if (mtime_since_now(&this_start) > JOB_START_TIMEOUT)
1476 break;
1477
1478 usleep(100000);
1479
1480 for (i = 0; i < this_jobs; i++) {
1481 td = map[i];
1482 if (!td)
1483 continue;
1484 if (td->runstate == TD_INITIALIZED) {
1485 map[i] = NULL;
1486 left--;
1487 } else if (td->runstate >= TD_EXITED) {
1488 map[i] = NULL;
1489 left--;
1490 todo--;
1491 nr_running++; /* work-around... */
1492 }
1493 }
1494 }
1495
1496 if (left) {
4e87c37a
JA
1497 log_err("fio: %d job%s failed to start\n", left,
1498 left > 1 ? "s" : "");
2e1df07d
JA
1499 for (i = 0; i < this_jobs; i++) {
1500 td = map[i];
1501 if (!td)
1502 continue;
1503 kill(td->pid, SIGTERM);
1504 }
1505 break;
1506 }
1507
1508 /*
1509 * start created threads (TD_INITIALIZED -> TD_RUNNING).
1510 */
1511 for_each_td(td, i) {
1512 if (td->runstate != TD_INITIALIZED)
1513 continue;
1514
1515 if (in_ramp_time(td))
1516 td_set_runstate(td, TD_RAMP);
1517 else
1518 td_set_runstate(td, TD_RUNNING);
1519 nr_running++;
1520 nr_started--;
1521 m_rate += td->o.ratemin[0] + td->o.ratemin[1];
1522 t_rate += td->o.rate[0] + td->o.rate[1];
1523 todo--;
1524 fio_mutex_up(td->mutex);
1525 }
1526
1527 reap_threads(&nr_running, &t_rate, &m_rate);
1528
1529 if (todo) {
1530 if (is_backend)
1531 fio_server_idle_loop();
1532 else
1533 usleep(100000);
1534 }
1535 }
1536
1537 while (nr_running) {
1538 reap_threads(&nr_running, &t_rate, &m_rate);
1539
1540 if (is_backend)
1541 fio_server_idle_loop();
1542 else
1543 usleep(10000);
1544 }
1545
1546 update_io_ticks();
1547 fio_unpin_memory();
1548}
1549
1550static void *disk_thread_main(void *data)
1551{
1552 fio_mutex_up(startup_mutex);
1553
1554 while (threads) {
1555 usleep(DISK_UTIL_MSEC * 1000);
1556 if (!threads)
1557 break;
1558 update_io_ticks();
1559
1560 if (!is_backend)
1561 print_thread_status();
1562 }
1563
1564 return NULL;
1565}
1566
1567static int create_disk_util_thread(void)
1568{
1569 int ret;
1570
1571 ret = pthread_create(&disk_util_thread, NULL, disk_thread_main, NULL);
1572 if (ret) {
1573 log_err("Can't create disk util thread: %s\n", strerror(ret));
1574 return 1;
1575 }
1576
1577 ret = pthread_detach(disk_util_thread);
1578 if (ret) {
1579 log_err("Can't detatch disk util thread: %s\n", strerror(ret));
1580 return 1;
1581 }
1582
1583 dprint(FD_MUTEX, "wait on startup_mutex\n");
1584 fio_mutex_down(startup_mutex);
1585 dprint(FD_MUTEX, "done waiting on startup_mutex\n");
1586 return 0;
1587}
1588
2e1df07d
JA
1589int fio_backend(void)
1590{
1591 struct thread_data *td;
1592 int i;
1593
1594 if (exec_profile) {
1595 if (load_profile(exec_profile))
1596 return 1;
1597 free(exec_profile);
1598 exec_profile = NULL;
1599 }
1600 if (!thread_number)
1601 return 0;
1602
1603 if (write_bw_log) {
1604 setup_log(&agg_io_log[DDIR_READ], 0);
1605 setup_log(&agg_io_log[DDIR_WRITE], 0);
1606 }
1607
1608 startup_mutex = fio_mutex_init(0);
1609 if (startup_mutex == NULL)
1610 return 1;
1611 writeout_mutex = fio_mutex_init(1);
1612 if (writeout_mutex == NULL)
1613 return 1;
1614
1615 set_genesis_time();
1616 create_disk_util_thread();
1617
1618 cgroup_list = smalloc(sizeof(*cgroup_list));
1619 INIT_FLIST_HEAD(cgroup_list);
1620
1621 run_threads();
1622
1623 if (!fio_abort) {
1624 show_run_stats();
1625 if (write_bw_log) {
1626 __finish_log(agg_io_log[DDIR_READ], "agg-read_bw.log");
1627 __finish_log(agg_io_log[DDIR_WRITE],
1628 "agg-write_bw.log");
1629 }
1630 }
1631
1632 for_each_td(td, i)
1633 fio_options_free(td);
1634
1635 cgroup_kill(cgroup_list);
1636 sfree(cgroup_list);
1637 sfree(cgroup_mnt);
1638
1639 fio_mutex_remove(startup_mutex);
1640 fio_mutex_remove(writeout_mutex);
1641 return exit_value;
1642}