Add regression test for recent offload locking bug
[fio.git] / zone-dist.c
CommitLineData
07776127
JA
1#include <stdlib.h>
2#include "fio.h"
3#include "zone-dist.h"
4
5static void __td_zone_gen_index(struct thread_data *td, enum fio_ddir ddir)
6{
7 unsigned int i, j, sprev, aprev;
8 uint64_t sprev_sz;
9
10 td->zone_state_index[ddir] = malloc(sizeof(struct zone_split_index) * 100);
11
12 sprev_sz = sprev = aprev = 0;
13 for (i = 0; i < td->o.zone_split_nr[ddir]; i++) {
14 struct zone_split *zsp = &td->o.zone_split[ddir][i];
15
16 for (j = aprev; j < aprev + zsp->access_perc; j++) {
17 struct zone_split_index *zsi = &td->zone_state_index[ddir][j];
18
19 zsi->size_perc = sprev + zsp->size_perc;
20 zsi->size_perc_prev = sprev;
21
22 zsi->size = sprev_sz + zsp->size;
23 zsi->size_prev = sprev_sz;
24 }
25
26 aprev += zsp->access_perc;
27 sprev += zsp->size_perc;
28 sprev_sz += zsp->size;
29 }
30}
31
32static bool has_zones(struct thread_data *td)
33{
34 int i, zones = 0;
35
36 for (i = 0; i < DDIR_RWDIR_CNT; i++)
37 zones += td->o.zone_split_nr[i];
38
39 return zones != 0;
40}
41
42/*
43 * Generate state table for indexes, so we don't have to do it inline from
44 * the hot IO path
45 */
46void td_zone_gen_index(struct thread_data *td)
47{
48 int i;
49
50 if (!has_zones(td))
51 return;
52
53 td->zone_state_index = malloc(DDIR_RWDIR_CNT *
54 sizeof(struct zone_split_index *));
55
56 for (i = 0; i < DDIR_RWDIR_CNT; i++)
57 __td_zone_gen_index(td, i);
58}
59
60void td_zone_free_index(struct thread_data *td)
61{
62 int i;
63
64 if (!td->zone_state_index)
65 return;
66
67 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
68 free(td->zone_state_index[i]);
69 td->zone_state_index[i] = NULL;
70 }
71
72 free(td->zone_state_index);
73 td->zone_state_index = NULL;
74}