From: Jens Axboe Date: Fri, 21 Oct 2005 14:23:57 +0000 (+0200) Subject: [PATCH] fio: Add [global] job number to set default options for threads. X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=47d4520380ae13ac709fad6a270ed4e4bda2a57c;p=disktools.git [PATCH] fio: Add [global] job number to set default options for threads. --- diff --git a/README.fio b/README.fio index 7c5e430..8880ed7 100644 --- a/README.fio +++ b/README.fio @@ -93,5 +93,10 @@ And fio would be invoked as: $ fio -o0 -s -b4096 -f file_with_above +'global' is a reserved keyword. When used as the filename, it sets the +default options for the threads following that section. It is possible +to have more than one global section in the file, as it only affects +subsequent jobs. Also see the examples/ dir for sample job files. + diff --git a/examples/aio-read b/examples/aio-read index 9862166..556e450 100644 --- a/examples/aio-read +++ b/examples/aio-read @@ -1,29 +1,18 @@ ; Read 4 files with aio at different depths - -[/data1/file1] +[global] aio +random rw=0 bs=128 + +[/data1/file1] aio_depth=4 -random [/data1/file2] -aio -rw=0 -bs=128 aio_depth=32 -random [/data1/file3] -;aio -rw=0 -bs=128 -aio_depth=4 -random +aio_depth=8 [/data1/file4] -aio -rw=0 -bs=128 -aio_depth=8 -random +aio_depth=16 diff --git a/fio.c b/fio.c index 4498f73..c60353a 100644 --- a/fio.c +++ b/fio.c @@ -94,12 +94,8 @@ enum { #define ALIGN(buf) (char *) (((unsigned long) (buf) + MASK) & ~(MASK)) -static int sequential = DEF_SEQUENTIAL; static int write_stat = DEF_WRITESTAT; static int repeatable = DEF_RAND_REPEAT; -static int timeout = DEF_TIMEOUT; -static int odirect = DEF_ODIRECT; -static int global_bs = DEF_BS; static int rate_quit = 1; static int thread_number; @@ -107,8 +103,6 @@ static char *ini_file; static int shm_id; -static cpu_set_t def_cpumask; - enum { DDIR_READ = 0, DDIR_WRITE, @@ -143,6 +137,7 @@ struct thread_data { unsigned int delay_sleep; unsigned int fsync_blocks; unsigned int start_delay; + unsigned int timeout; unsigned int use_aio; cpu_set_t cpumask; @@ -181,6 +176,7 @@ struct thread_data { }; static struct thread_data *threads; +static struct thread_data def_thread; static sem_t startup_sem; @@ -814,10 +810,12 @@ static int setup_rate(struct thread_data *td) return 0; } -static struct thread_data *get_new_job(void) +static struct thread_data *get_new_job(int global) { struct thread_data *td; + if (global) + return &def_thread; if (thread_number >= MAX_JOBS) return NULL; @@ -825,18 +823,12 @@ static struct thread_data *get_new_job(void) memset(td, 0, sizeof(*td)); td->thread_number = thread_number; - td->ddir = DDIR_READ; - td->bs = global_bs; - td->odirect = 1; - td->delay_sleep = 0; - td->rate = 0; - td->ratecycle = DEF_RATE_CYCLE; - td->sequential = sequential; - td->ioprio = 0; - td->use_aio = 0; - td->aio_depth = 0; - td->aio_cur_depth = 0; - memcpy(&td->cpumask, &def_cpumask, sizeof(td->cpumask)); + td->ddir = def_thread.ddir; + td->bs = def_thread.bs; + td->odirect = def_thread.odirect; + td->ratecycle = def_thread.ratecycle; + td->sequential = def_thread.sequential; + memcpy(&td->cpumask, &def_thread.cpumask, sizeof(td->cpumask)); return td; } @@ -850,6 +842,9 @@ static void put_job(struct thread_data *td) static int add_job(struct thread_data *td, const char *filename, int prioclass, int prio) { + if (td == &def_thread) + return 0; + strcpy(td->file_name, filename); td->stat_fd = -1; sem_init(&td->mutex, 1, 0); @@ -918,7 +913,7 @@ static void parse_jobs_cmd(int argc, char *argv[], int index) filename[0] = 0; - td = get_new_job(); + td = get_new_job(0); if (!td) break; @@ -1065,9 +1060,9 @@ static int is_empty_or_comment(char *line) unsigned int i; for (i = 0; i < strlen(line); i++) { - if (!isspace(line[i]) && !iscntrl(line[i])) - return 0; if (line[i] == ';') + return 1; + if (!isspace(line[i]) && !iscntrl(line[i])) return 0; } @@ -1076,7 +1071,7 @@ static int is_empty_or_comment(char *line) static int parse_jobs_ini(char *file) { - unsigned int prioclass, prio, cpu; + unsigned int prioclass, prio, cpu, global; struct thread_data *td; char *string, *name; fpos_t off; @@ -1098,9 +1093,11 @@ static int parse_jobs_ini(char *file) if (sscanf(p, "[%s]", name) != 1) continue; + global = !strncmp(name, "global", 6); + name[strlen(name) - 1] = '\0'; - td = get_new_job(); + td = get_new_job(global); if (!td) break; @@ -1211,20 +1208,20 @@ static int parse_options(int argc, char *argv[]) switch (*parm) { case 's': parm++; - sequential = !!atoi(parm); + def_thread.sequential = !!atoi(parm); break; case 'b': parm++; - global_bs = atoi(parm); - global_bs <<= 10; - if (!global_bs) { + def_thread.bs = atoi(parm); + def_thread.bs <<= 10; + if (!def_thread.bs) { printf("bad block size\n"); - global_bs = DEF_BS; + def_thread.bs = DEF_BS; } break; case 't': parm++; - timeout = atoi(parm); + def_thread.timeout = atoi(parm); break; case 'w': parm++; @@ -1240,7 +1237,7 @@ static int parse_options(int argc, char *argv[]) break; case 'o': parm++; - odirect = !!atoi(parm); + def_thread.odirect = !!atoi(parm); break; case 'f': if (i + 1 >= argc) { @@ -1298,9 +1295,9 @@ static void run_threads(char *argv[]) signal(SIGINT, sig_handler); - if (timeout) { + if (def_thread.timeout) { signal(SIGALRM, sig_handler); - alarm(timeout); + alarm(def_thread.timeout); } todo = thread_number; @@ -1393,11 +1390,21 @@ int main(int argc, char *argv[]) atexit(free_shm); - if (sched_getaffinity(getpid(), sizeof(def_cpumask), &def_cpumask) == -1) { + if (sched_getaffinity(getpid(), sizeof(cpu_set_t), &def_thread.cpumask) == -1) { perror("sched_getaffinity"); return 1; } + /* + * fill globals + */ + def_thread.ddir = DDIR_READ; + def_thread.bs = DEF_BS; + def_thread.odirect = 1; + def_thread.ratecycle = DEF_RATE_CYCLE; + def_thread.sequential = 1; + def_thread.timeout = DEF_TIMEOUT; + i = parse_options(argc, argv); if (ini_file) { @@ -1411,7 +1418,7 @@ int main(int argc, char *argv[]) return 1; } - printf("%s: %s, bs=%uKiB, timeo=%u, write_stat=%u, odirect=%d\n", argv[0], sequential ? "sequential" : "random", global_bs >> 10, timeout, write_stat, odirect); + printf("%s: %s, bs=%uKiB, timeo=%u, write_stat=%u, odirect=%d\n", argv[0], def_thread.sequential ? "sequential" : "random", def_thread.bs >> 10, def_thread.timeout, write_stat, def_thread.odirect); run_threads(argv);