Skip to content

Commit

Permalink
Merge branch 'thinkcycles-parameter' of https://github.com/cloehle/fio
Browse files Browse the repository at this point in the history
* 'thinkcycles-parameter' of https://github.com/cloehle/fio:
  fio: Introduce new constant thinkcycles option
  • Loading branch information
vincentkfu committed Nov 3, 2023
2 parents 48cf0c6 + 0d8cc75 commit 2c0b784
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 2 deletions.
8 changes: 8 additions & 0 deletions HOWTO.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3209,6 +3209,14 @@ I/O depth
I/O rate
~~~~~~~~

.. option:: thinkcycles=int

Stall the job for the specified number of cycles after an I/O has completed before
issuing the next. May be used to simulate processing being done by an application.
This is not taken into account for the time to be waited on for :option:`thinktime`.
Might not have any effect on some platforms, this can be checked by trying a setting
a high enough amount of thinkcycles.

.. option:: thinktime=time

Stall the job for the specified period of time after an I/O has completed before issuing the
Expand Down
4 changes: 4 additions & 0 deletions backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "helper_thread.h"
#include "pshared.h"
#include "zone-dist.h"
#include "fio_time.h"

static struct fio_sem *startup_sem;
static struct flist_head *cgroup_list;
Expand Down Expand Up @@ -1133,6 +1134,9 @@ static void do_io(struct thread_data *td, uint64_t *bytes_done)
if (ret < 0)
break;

if (ddir_rw(ddir) && td->o.thinkcycles)
cycles_spin(td->o.thinkcycles);

if (ddir_rw(ddir) && td->o.thinktime)
handle_thinktime(td, ddir, &comp_time);

Expand Down
2 changes: 2 additions & 0 deletions cconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ int convert_thread_options_to_cpu(struct thread_options *o,
o->random_generator = le32_to_cpu(top->random_generator);
o->hugepage_size = le32_to_cpu(top->hugepage_size);
o->rw_min_bs = le64_to_cpu(top->rw_min_bs);
o->thinkcycles = le32_to_cpu(top->thinkcycles);
o->thinktime = le32_to_cpu(top->thinktime);
o->thinktime_spin = le32_to_cpu(top->thinktime_spin);
o->thinktime_blocks = le32_to_cpu(top->thinktime_blocks);
Expand Down Expand Up @@ -472,6 +473,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
top->random_generator = cpu_to_le32(o->random_generator);
top->hugepage_size = cpu_to_le32(o->hugepage_size);
top->rw_min_bs = __cpu_to_le64(o->rw_min_bs);
top->thinkcycles = cpu_to_le32(o->thinkcycles);
top->thinktime = cpu_to_le32(o->thinktime);
top->thinktime_spin = cpu_to_le32(o->thinktime_spin);
top->thinktime_blocks = cpu_to_le32(o->thinktime_blocks);
Expand Down
7 changes: 7 additions & 0 deletions fio.1
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,13 @@ reporting if I/O gets backed up on the device side (the coordinated omission
problem). Note that this option cannot reliably be used with async IO engines.
.SS "I/O rate"
.TP
.BI thinkcycles \fR=\fPint
Stall the job for the specified number of cycles after an I/O has completed before
issuing the next. May be used to simulate processing being done by an application.
This is not taken into account for the time to be waited on for \fBthinktime\fR.
Might not have any effect on some platforms, this can be checked by trying a setting
a high enough amount of thinkcycles.
.TP
.BI thinktime \fR=\fPtime
Stall the job for the specified period of time after an I/O has completed before issuing the
next. May be used to simulate processing being done by an application.
Expand Down
1 change: 1 addition & 0 deletions fio_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern uint64_t time_since_now(const struct timespec *);
extern uint64_t time_since_genesis(void);
extern uint64_t mtime_since_genesis(void);
extern uint64_t utime_since_genesis(void);
extern void cycles_spin(unsigned int);
extern uint64_t usec_spin(unsigned int);
extern uint64_t usec_sleep(struct thread_data *, unsigned long);
extern void fill_start_time(struct timespec *);
Expand Down
12 changes: 12 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3875,6 +3875,18 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
.category = FIO_OPT_C_IO,
.group = FIO_OPT_G_THINKTIME,
},
{
.name = "thinkcycles",
.lname = "Think cycles",
.type = FIO_OPT_INT,
.off1 = offsetof(struct thread_options, thinkcycles),
.help = "Spin for a constant amount of cycles between requests",
.def = "0",
.parent = "thinktime",
.hide = 1,
.category = FIO_OPT_C_IO,
.group = FIO_OPT_G_THINKTIME,
},
{
.name = "thinktime_blocks",
.lname = "Thinktime blocks",
Expand Down
8 changes: 6 additions & 2 deletions thread_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ struct thread_options {
char *exec_prerun;
char *exec_postrun;

unsigned int thinkcycles;

unsigned int thinktime;
unsigned int thinktime_spin;
unsigned int thinktime_blocks;
Expand Down Expand Up @@ -355,8 +357,8 @@ struct thread_options {

unsigned long long latency_target;
unsigned long long latency_window;
fio_fp64_t latency_percentile;
uint32_t latency_run;
fio_fp64_t latency_percentile;

/*
* flow support
Expand Down Expand Up @@ -626,6 +628,8 @@ struct thread_options_pack {
uint8_t exec_prerun[FIO_TOP_STR_MAX];
uint8_t exec_postrun[FIO_TOP_STR_MAX];

uint32_t thinkcycles;

uint32_t thinktime;
uint32_t thinktime_spin;
uint32_t thinktime_blocks;
Expand Down Expand Up @@ -671,8 +675,8 @@ struct thread_options_pack {
uint64_t latency_target;
uint64_t latency_window;
uint64_t max_latency[DDIR_RWDIR_CNT];
fio_fp64_t latency_percentile;
uint32_t latency_run;
fio_fp64_t latency_percentile;

/*
* flow support
Expand Down
11 changes: 11 additions & 0 deletions time.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ uint64_t usec_spin(unsigned int usec)
return t;
}

/*
* busy loop for a fixed amount of cycles
*/
void cycles_spin(unsigned int n)
{
unsigned long i;

for (i=0; i < n; i++)
nop;
}

uint64_t usec_sleep(struct thread_data *td, unsigned long usec)
{
struct timespec req;
Expand Down

0 comments on commit 2c0b784

Please sign in to comment.