2 * IO priority handling declarations and helper functions common to the
3 * libaio and io_uring engines.
12 unsigned int percentage[DDIR_RWDIR_CNT];
13 unsigned int class[DDIR_RWDIR_CNT];
14 unsigned int level[DDIR_RWDIR_CNT];
15 unsigned int bssplit_nr[DDIR_RWDIR_CNT];
16 struct bssplit *bssplit[DDIR_RWDIR_CNT];
19 static int fio_cmdprio_bssplit_ddir(struct thread_options *to, void *cb_arg,
20 enum fio_ddir ddir, char *str, bool data)
22 struct cmdprio *cmdprio = cb_arg;
26 if (ddir == DDIR_TRIM)
29 memset(&split, 0, sizeof(split));
31 if (split_parse_ddir(to, &split, str, data, BSSPLIT_MAX))
36 cmdprio->bssplit_nr[ddir] = split.nr;
37 cmdprio->bssplit[ddir] = malloc(split.nr * sizeof(struct bssplit));
38 if (!cmdprio->bssplit[ddir])
41 for (i = 0; i < split.nr; i++) {
42 cmdprio->bssplit[ddir][i].bs = split.val1[i];
43 if (split.val2[i] == -1U) {
44 cmdprio->bssplit[ddir][i].perc = 0;
46 if (split.val2[i] > 100)
47 cmdprio->bssplit[ddir][i].perc = 100;
49 cmdprio->bssplit[ddir][i].perc = split.val2[i];
56 static int fio_cmdprio_bssplit_parse(struct thread_data *td, const char *input,
57 struct cmdprio *cmdprio)
62 p = str = strdup(input);
64 strip_blank_front(&str);
67 ret = str_split_parse(td, str, fio_cmdprio_bssplit_ddir, cmdprio, false);
70 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
71 free(cmdprio->bssplit[i]);
72 cmdprio->bssplit[i] = NULL;
73 cmdprio->bssplit_nr[i] = 0;
81 static inline int fio_cmdprio_percentage(struct cmdprio *cmdprio,
84 enum fio_ddir ddir = io_u->ddir;
85 unsigned int p = cmdprio->percentage[ddir];
89 * If cmdprio_percentage option was specified, then use that
90 * percentage. Otherwise, use cmdprio_bssplit percentages depending
96 for (i = 0; i < cmdprio->bssplit_nr[ddir]; i++) {
97 if (cmdprio->bssplit[ddir][i].bs == io_u->buflen)
98 return cmdprio->bssplit[ddir][i].perc;
104 static int fio_cmdprio_init(struct thread_data *td, struct cmdprio *cmdprio,
107 struct thread_options *to = &td->o;
108 bool has_cmdprio_percentage = false;
109 bool has_cmdprio_bssplit = false;
113 * If cmdprio_percentage/cmdprio_bssplit is set and cmdprio_class
114 * is not set, default to RT priority class.
116 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
117 if (cmdprio->percentage[i]) {
118 if (!cmdprio->class[i])
119 cmdprio->class[i] = IOPRIO_CLASS_RT;
120 has_cmdprio_percentage = true;
122 if (cmdprio->bssplit_nr[i]) {
123 if (!cmdprio->class[i])
124 cmdprio->class[i] = IOPRIO_CLASS_RT;
125 has_cmdprio_bssplit = true;
130 * Check for option conflicts
132 if (has_cmdprio_percentage && has_cmdprio_bssplit) {
133 log_err("%s: cmdprio_percentage and cmdprio_bssplit options "
134 "are mutually exclusive\n",
139 *has_cmdprio = has_cmdprio_percentage || has_cmdprio_bssplit;