From 36d80bc7c7f7fbc2612941b7dd7ceaf645798c7f Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 30 Nov 2012 21:46:06 +0100 Subject: [PATCH] Wire up SIGUSR2 to kill blocking threads Get rid of io engine ops SIGTERM flag, it didn't really work. Signed-off-by: Jens Axboe --- backend.c | 2 +- engines/net.c | 13 ++++++++++--- fio.h | 2 +- ioengine.h | 10 +++++----- libfio.c | 8 ++++---- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/backend.c b/backend.c index f901503a..faa861cf 100644 --- a/backend.c +++ b/backend.c @@ -1385,7 +1385,7 @@ static void reap_threads(unsigned int *nr_running, unsigned int *t_rate, if (WIFSIGNALED(status)) { int sig = WTERMSIG(status); - if (sig != SIGTERM) + if (sig != SIGTERM && sig != SIGUSR2) log_err("fio: pid=%d, got signal=%d\n", (int) td->pid, sig); td->sig = sig; diff --git a/engines/net.c b/engines/net.c index 89575455..81e173cc 100644 --- a/engines/net.c +++ b/engines/net.c @@ -881,6 +881,11 @@ static int fio_netio_setup(struct thread_data *td) return 0; } +static void fio_netio_terminate(struct thread_data *td) +{ + kill(td->pid, SIGUSR2); +} + #ifdef FIO_HAVE_SPLICE static int fio_netio_setup_splice(struct thread_data *td) { @@ -909,11 +914,12 @@ static struct ioengine_ops ioengine_splice = { .init = fio_netio_init, .cleanup = fio_netio_cleanup, .open_file = fio_netio_open_file, - .close_file = generic_close_file, + .close_file = fio_netio_close_file, + .terminate = fio_netio_terminate, .options = options, .option_struct_size = sizeof(struct netio_options), .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | - FIO_SIGTERM | FIO_PIPEIO, + FIO_PIPEIO, }; #endif @@ -927,10 +933,11 @@ static struct ioengine_ops ioengine_rw = { .cleanup = fio_netio_cleanup, .open_file = fio_netio_open_file, .close_file = fio_netio_close_file, + .terminate = fio_netio_terminate, .options = options, .option_struct_size = sizeof(struct netio_options), .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | - FIO_SIGTERM | FIO_PIPEIO, + FIO_PIPEIO, }; static int str_hostname_cb(void *data, const char *input) diff --git a/fio.h b/fio.h index d7cb4ab8..58364aaf 100644 --- a/fio.h +++ b/fio.h @@ -694,8 +694,8 @@ enum { TD_NOT_CREATED = 0, TD_CREATED, TD_INITIALIZED, - TD_SETTING_UP, TD_RAMP, + TD_SETTING_UP, TD_RUNNING, TD_PRE_READING, TD_VERIFYING, diff --git a/ioengine.h b/ioengine.h index e27dab1c..997f90af 100644 --- a/ioengine.h +++ b/ioengine.h @@ -1,7 +1,7 @@ #ifndef FIO_IOENGINE_H #define FIO_IOENGINE_H -#define FIO_IOOPS_VERSION 13 +#define FIO_IOOPS_VERSION 14 enum { IO_U_F_FREE = 1 << 0, @@ -120,6 +120,7 @@ struct ioengine_ops { int (*open_file)(struct thread_data *, struct fio_file *); int (*close_file)(struct thread_data *, struct fio_file *); int (*get_file_size)(struct thread_data *, struct fio_file *); + void (*terminate)(struct thread_data *); int option_struct_size; struct fio_option *options; void *data; @@ -134,10 +135,9 @@ enum fio_ioengine_flags { FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ - FIO_SIGTERM = 1 << 7, /* needs SIGTERM to exit */ - FIO_PIPEIO = 1 << 8, /* input/output no seekable */ - FIO_BARRIER = 1 << 9, /* engine supports barriers */ - FIO_MEMALIGN = 1 << 10, /* engine wants aligned memory */ + FIO_PIPEIO = 1 << 7, /* input/output no seekable */ + FIO_BARRIER = 1 << 8, /* engine supports barriers */ + FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */ }; /* diff --git a/libfio.c b/libfio.c index ee5a0ead..96ae8146 100644 --- a/libfio.c +++ b/libfio.c @@ -177,15 +177,15 @@ void fio_terminate_threads(int group_id) /* * if the thread is running, just let it exit */ - if (!td->pid) + if (!td->pid || pid == td->pid) continue; else if (td->runstate < TD_RAMP) kill(td->pid, SIGTERM); - else if (pid != td->pid) { + else { struct ioengine_ops *ops = td->io_ops; - if (ops && (ops->flags & FIO_SIGTERM)) - kill(td->pid, SIGTERM); + if (ops && ops->terminate) + ops->terminate(td); } } } -- 2.25.1