t/io_uring: Fix the parameters calculation for multiple threads scenario
[fio.git] / zbd.h
CommitLineData
bfbdd35b
BVA
1/*
2 * Copyright (C) 2018 Western Digital Corporation or its affiliates.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef FIO_ZBD_H
8#define FIO_ZBD_H
9
b7694961
DLM
10#include "io_u.h"
11#include "ioengines.h"
12#include "oslib/blkzoned.h"
13#include "zbd_types.h"
bfbdd35b
BVA
14
15struct fio_file;
16
bfbdd35b
BVA
17enum io_u_action {
18 io_u_accept = 0,
19 io_u_eof = 1,
e3be810b 20 io_u_completed = 2,
bfbdd35b
BVA
21};
22
23/**
24 * struct fio_zone_info - information about a single ZBD zone
2c477f4f
DLM
25 * @start: zone start location (bytes)
26 * @wp: zone write pointer location (bytes)
236d23a8 27 * @capacity: maximum size usable from the start of a zone (bytes)
bfbdd35b
BVA
28 * @verify_block: number of blocks that have been verified for this zone
29 * @mutex: protects the modifiable members in this structure
30 * @type: zone type (BLK_ZONE_TYPE_*)
31 * @cond: zone state (BLK_ZONE_COND_*)
be7a6bae 32 * @has_wp: whether or not this zone can have a valid write pointer
bfbdd35b
BVA
33 * @open: whether or not this zone is currently open. Only relevant if
34 * max_open_zones > 0.
35 * @reset_zone: whether or not this zone should be reset before writing to it
36 */
37struct fio_zone_info {
bfbdd35b
BVA
38 pthread_mutex_t mutex;
39 uint64_t start;
40 uint64_t wp;
236d23a8 41 uint64_t capacity;
bfbdd35b 42 uint32_t verify_block;
b7694961
DLM
43 enum zbd_zone_type type:2;
44 enum zbd_zone_cond cond:4;
be7a6bae 45 unsigned int has_wp:1;
bfbdd35b
BVA
46 unsigned int open:1;
47 unsigned int reset_zone:1;
bfbdd35b
BVA
48};
49
50/**
51 * zoned_block_device_info - zoned block device characteristics
52 * @model: Device model.
219c662d 53 * @max_open_zones: global limit on the number of simultaneously opened
b346af90
NC
54 * sequential write zones. A zero value means unlimited open zones,
55 * and that open zones will not be tracked in the open_zones array.
59b07544
BVA
56 * @mutex: Protects the modifiable members in this structure (refcount and
57 * num_open_zones).
d87d9c6c 58 * @zone_size: size of a single zone in bytes.
a7c2b6fc 59 * @sectors_with_data: total size of data in all zones in units of 512 bytes
403ea795
SK
60 * @wp_sectors_with_data: total size of data in zones with write pointers in
61 * units of 512 bytes
bfbdd35b
BVA
62 * @zone_size_log2: log2 of the zone size in bytes if it is a power of 2 or 0
63 * if the zone size is not a power of 2.
64 * @nr_zones: number of zones
65 * @refcount: number of fio files that share this structure
59b07544 66 * @num_open_zones: number of open zones
a7c2b6fc
BVA
67 * @write_cnt: Number of writes since the latest zone reset triggered by
68 * the zone_reset_frequency fio job parameter.
59b07544 69 * @open_zones: zone numbers of open zones
bfbdd35b
BVA
70 * @zone_info: description of the individual zones
71 *
72 * Only devices for which all zones have the same size are supported.
73 * Note: if the capacity is not a multiple of the zone size then the last zone
74 * will be smaller than 'zone_size'.
75 */
76struct zoned_block_device_info {
b7694961 77 enum zbd_zoned_model model;
219c662d 78 uint32_t max_open_zones;
bfbdd35b
BVA
79 pthread_mutex_t mutex;
80 uint64_t zone_size;
a7c2b6fc 81 uint64_t sectors_with_data;
403ea795 82 uint64_t wp_sectors_with_data;
bfbdd35b
BVA
83 uint32_t zone_size_log2;
84 uint32_t nr_zones;
85 uint32_t refcount;
59b07544 86 uint32_t num_open_zones;
a7c2b6fc 87 uint32_t write_cnt;
b7694961 88 uint32_t open_zones[ZBD_MAX_OPEN_ZONES];
bfbdd35b
BVA
89 struct fio_zone_info zone_info[0];
90};
91
8f39afa7
AD
92int zbd_init_files(struct thread_data *td);
93void zbd_recalc_options_with_zone_granularity(struct thread_data *td);
3c1dc34c 94int zbd_setup_files(struct thread_data *td);
bfbdd35b 95void zbd_free_zone_info(struct fio_file *f);
bfbdd35b
BVA
96void zbd_file_reset(struct thread_data *td, struct fio_file *f);
97bool zbd_unaligned_write(int error_code);
4d37720a 98void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u);
c65057f9
SK
99enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u,
100 enum fio_ddir ddir);
bfbdd35b 101enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u);
fd5d733f 102char *zbd_write_status(const struct thread_stat *ts);
e3be810b 103int zbd_do_io_u_trim(const struct thread_data *td, struct io_u *io_u);
d9ed3e63 104
3c1dc34c
DLM
105static inline void zbd_close_file(struct fio_file *f)
106{
107 if (f->zbd_info)
108 zbd_free_zone_info(f);
109}
110
b2da58c4
SK
111static inline void zbd_queue_io_u(struct thread_data *td, struct io_u *io_u,
112 enum fio_q_status status)
d9ed3e63
DLM
113{
114 if (io_u->zbd_queue_io) {
b2da58c4 115 io_u->zbd_queue_io(td, io_u, status, io_u->error == 0);
d9ed3e63
DLM
116 io_u->zbd_queue_io = NULL;
117 }
118}
119
b2da58c4 120static inline void zbd_put_io_u(struct thread_data *td, struct io_u *io_u)
d9ed3e63
DLM
121{
122 if (io_u->zbd_put_io) {
b2da58c4 123 io_u->zbd_put_io(td, io_u);
d9ed3e63
DLM
124 io_u->zbd_queue_io = NULL;
125 io_u->zbd_put_io = NULL;
126 }
127}
128
bfbdd35b 129#endif /* FIO_ZBD_H */