From: Jens Axboe Date: Mon, 23 Nov 2015 22:04:56 +0000 (-0700) Subject: A few min/max cleanups X-Git-Tag: fio-2.2.12~1 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=4b157ac6446364e5eecdcdbf75fc1a814489a343;ds=sidebyside A few min/max cleanups Signed-off-by: Jens Axboe --- diff --git a/backend.c b/backend.c index aa94acf2..15607496 100644 --- a/backend.c +++ b/backend.c @@ -448,7 +448,7 @@ static int wait_for_completions(struct thread_data *td, struct timeval *time) * if the queue is full, we MUST reap at least 1 event */ min_evts = min(td->o.iodepth_batch_complete_min, td->cur_depth); - if ((full && !min_evts) || !td->o.iodepth_batch_complete_min) + if ((full && !min_evts) || !td->o.iodepth_batch_complete_min) min_evts = 1; if (time && (__should_check_rate(td, DDIR_READ) || diff --git a/io_u.c b/io_u.c index b1aa4141..dd4502f1 100644 --- a/io_u.c +++ b/io_u.c @@ -13,6 +13,7 @@ #include "lib/axmap.h" #include "err.h" #include "lib/pow2.h" +#include "minmax.h" struct io_completion_data { int nr; /* input */ @@ -1927,9 +1928,8 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write, min_write = min(min_write, left); if (perc) { - this_write = min(min_write, td->o.compress_chunk); - if (!this_write) - this_write = min_write; + this_write = min_not_zero(min_write, + td->o.compress_chunk); fill_random_buf_percentage(rs, buf, perc, this_write, this_write, diff --git a/log.c b/log.c index 8d511b54..d5082676 100644 --- a/log.c +++ b/log.c @@ -59,9 +59,8 @@ size_t __log_buf(struct buf_output *buf, const char *format, ...) va_start(args, format); len = vsnprintf(buffer, sizeof(buffer), format, args); va_end(args); - len = min(len, sizeof(buffer) - 1); - return buf_output_add(buf, buffer, len); + return buf_output_add(buf, buffer, min(len, sizeof(buffer) - 1)); } int log_info_flush(void) diff --git a/minmax.h b/minmax.h index 97957c88..afc78f02 100644 --- a/minmax.h +++ b/minmax.h @@ -17,4 +17,9 @@ _x > _y ? _x : _y; }) #endif +#define min_not_zero(x, y) ({ \ + typeof(x) __x = (x); \ + typeof(y) __y = (y); \ + __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) + #endif