2 * Note: This is similar to a very basic setup
5 * Specify fdp=1 (With char devices /dev/ng0n1)
16 #include "dataplacement.h"
18 static int fdp_ruh_info(struct thread_data *td, struct fio_file *f,
19 struct fio_ruhs_info *ruhs)
24 log_err("fio: no ops set in fdp init?!\n");
28 if (td->io_ops->fdp_fetch_ruhs) {
29 ret = td->io_ops->fdp_fetch_ruhs(td, f, ruhs);
31 td_verror(td, errno, "fdp fetch ruhs failed");
32 log_err("%s: fdp fetch ruhs failed (%d)\n",
36 log_err("%s: engine (%s) lacks fetch ruhs\n",
37 f->file_name, td->io_ops->name);
43 static int init_ruh_info(struct thread_data *td, struct fio_file *f)
45 struct fio_ruhs_info *ruhs, *tmp;
49 /* set up the data structure used for FDP to work with the supplied stream IDs */
50 if (td->o.dp_type == FIO_DP_STREAMS) {
51 if (!td->o.dp_nr_ids) {
52 log_err("fio: stream IDs must be provided for dataplacement=streams\n");
55 ruhs = scalloc(1, sizeof(*ruhs) + td->o.dp_nr_ids * sizeof(*ruhs->plis));
59 ruhs->nr_ruhs = td->o.dp_nr_ids;
60 for (int i = 0; i < ruhs->nr_ruhs; i++)
61 ruhs->plis[i] = td->o.dp_ids[i];
68 * Since we don't know the actual number of ruhs. Only fetch the header.
69 * We will reallocate this buffer and then fetch all the ruhs again.
71 ruhs = calloc(1, sizeof(*ruhs));
72 ret = fdp_ruh_info(td, f, ruhs);
74 log_err("fio: ruh info failed for %s (%d)\n",
79 nr_ruhs = ruhs->nr_ruhs;
80 ruhs = realloc(ruhs, sizeof(*ruhs) + nr_ruhs * sizeof(*ruhs->plis));
82 log_err("fio: ruhs buffer realloc failed for %s\n",
88 ruhs->nr_ruhs = nr_ruhs;
89 ret = fdp_ruh_info(td, f, ruhs);
91 log_err("fio: ruh info failed for %s (%d)\n",
96 if (td->o.dp_nr_ids == 0) {
97 if (ruhs->nr_ruhs > FIO_MAX_DP_IDS)
98 ruhs->nr_ruhs = FIO_MAX_DP_IDS;
100 for (i = 0; i < td->o.dp_nr_ids; i++) {
101 if (td->o.dp_ids[i] >= ruhs->nr_ruhs) {
102 log_err("fio: for %s PID index %d must be smaller than %d\n",
103 f->file_name, td->o.dp_ids[i],
109 ruhs->nr_ruhs = td->o.dp_nr_ids;
112 tmp = scalloc(1, sizeof(*tmp) + ruhs->nr_ruhs * sizeof(*tmp->plis));
118 if (td->o.dp_nr_ids == 0) {
119 for (i = 0; i < ruhs->nr_ruhs; i++)
120 tmp->plis[i] = ruhs->plis[i];
122 tmp->nr_ruhs = ruhs->nr_ruhs;
129 tmp->nr_ruhs = td->o.dp_nr_ids;
130 for (i = 0; i < td->o.dp_nr_ids; i++)
131 tmp->plis[i] = ruhs->plis[td->o.dp_ids[i]];
138 static int init_ruh_scheme(struct thread_data *td, struct fio_file *f)
140 struct fio_ruhs_scheme *ruh_scheme;
142 unsigned long long start, end;
146 if (td->o.dp_id_select != FIO_DP_SCHEME)
149 /* Get the scheme from the file */
150 scheme_fp = fopen(td->o.dp_scheme_file, "r");
153 log_err("fio: ruh scheme failed to open scheme file %s\n",
154 td->o.dp_scheme_file);
159 ruh_scheme = scalloc(1, sizeof(*ruh_scheme));
162 goto out_with_close_fp;
166 i < DP_MAX_SCHEME_ENTRIES && fscanf(scheme_fp, "%llu,%llu,%hu\n", &start, &end, &pli) == 3;
169 ruh_scheme->scheme_entries[i].start_offset = start;
170 ruh_scheme->scheme_entries[i].end_offset = end;
171 ruh_scheme->scheme_entries[i].pli = pli;
172 ruh_scheme->nr_schemes++;
175 if (fscanf(scheme_fp, "%llu,%llu,%hu\n", &start, &end, &pli) == 3)
176 log_info("fio: too many scheme entries in %s. Only the first %d scheme entries are applied\n",
177 td->o.dp_scheme_file,
178 DP_MAX_SCHEME_ENTRIES);
180 f->ruhs_scheme = ruh_scheme;
188 int dp_init(struct thread_data *td)
193 for_each_file(td, f, i) {
194 ret = init_ruh_info(td, f);
198 ret = init_ruh_scheme(td, f);
205 void fdp_free_ruhs_info(struct fio_file *f)
214 sfree(f->ruhs_scheme);
215 f->ruhs_scheme = NULL;
218 void dp_fill_dspec_data(struct thread_data *td, struct io_u *io_u)
220 struct fio_file *f = io_u->file;
221 struct fio_ruhs_info *ruhs = f->ruhs_info;
224 if (!ruhs || io_u->ddir != DDIR_WRITE) {
230 if (td->o.dp_id_select == FIO_DP_RR) {
231 if (ruhs->pli_loc >= ruhs->nr_ruhs)
234 dspec = ruhs->plis[ruhs->pli_loc++];
235 } else if (td->o.dp_id_select == FIO_DP_SCHEME) {
236 struct fio_ruhs_scheme *ruhs_scheme = f->ruhs_scheme;
237 unsigned long long offset = io_u->offset;
240 for (i = 0; i < ruhs_scheme->nr_schemes; i++) {
241 if (offset >= ruhs_scheme->scheme_entries[i].start_offset &&
242 offset < ruhs_scheme->scheme_entries[i].end_offset) {
243 dspec = ruhs_scheme->scheme_entries[i].pli;
249 * If the write offset is not affected by any scheme entry,
250 * 0(default RUH) will be assigned to dspec
252 if (i == ruhs_scheme->nr_schemes)
255 ruhs->pli_loc = rand_between(&td->fdp_state, 0, ruhs->nr_ruhs - 1);
256 dspec = ruhs->plis[ruhs->pli_loc];
259 io_u->dtype = td->o.dp_type == FIO_DP_FDP ? FDP_DIR_DTYPE : STREAMS_DIR_DTYPE;
261 dprint(FD_IO, "dtype set to 0x%x, dspec set to 0x%x\n", io_u->dtype, io_u->dspec);