| 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 | |
| 10 | #include "io_u.h" |
| 11 | #include "ioengines.h" |
| 12 | #include "oslib/blkzoned.h" |
| 13 | #include "zbd_types.h" |
| 14 | |
| 15 | struct fio_file; |
| 16 | |
| 17 | enum io_u_action { |
| 18 | io_u_accept = 0, |
| 19 | io_u_eof = 1, |
| 20 | io_u_completed = 2, |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * struct fio_zone_info - information about a single ZBD zone |
| 25 | * @start: zone start location (bytes) |
| 26 | * @wp: zone write pointer location (bytes) |
| 27 | * @capacity: maximum size usable from the start of a zone (bytes) |
| 28 | * @mutex: protects the modifiable members in this structure |
| 29 | * @type: zone type (BLK_ZONE_TYPE_*) |
| 30 | * @cond: zone state (BLK_ZONE_COND_*) |
| 31 | * @has_wp: whether or not this zone can have a valid write pointer |
| 32 | * @write: whether or not this zone is the write target at this moment. Only |
| 33 | * relevant if zbd->max_open_zones > 0. |
| 34 | * @reset_zone: whether or not this zone should be reset before writing to it |
| 35 | */ |
| 36 | struct fio_zone_info { |
| 37 | pthread_mutex_t mutex; |
| 38 | uint64_t start; |
| 39 | uint64_t wp; |
| 40 | uint64_t capacity; |
| 41 | enum zbd_zone_type type:2; |
| 42 | enum zbd_zone_cond cond:4; |
| 43 | unsigned int has_wp:1; |
| 44 | unsigned int write:1; |
| 45 | unsigned int reset_zone:1; |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * zoned_block_device_info - zoned block device characteristics |
| 50 | * @model: Device model. |
| 51 | * @max_write_zones: global limit on the number of sequential write zones which |
| 52 | * are simultaneously written. A zero value means unlimited zones of |
| 53 | * simultaneous writes and that write target zones will not be tracked in |
| 54 | * the write_zones array. |
| 55 | * @max_active_zones: device side limit on the number of sequential write zones |
| 56 | * in open or closed conditions. A zero value means unlimited number of |
| 57 | * zones in the conditions. |
| 58 | * @mutex: Protects the modifiable members in this structure (refcount and |
| 59 | * num_open_zones). |
| 60 | * @zone_size: size of a single zone in bytes. |
| 61 | * @wp_valid_data_bytes: total size of data in zones with write pointers |
| 62 | * @write_min_zone: Minimum zone index of all job's write ranges. Inclusive. |
| 63 | * @write_max_zone: Maximum zone index of all job's write ranges. Exclusive. |
| 64 | * @zone_size_log2: log2 of the zone size in bytes if it is a power of 2 or 0 |
| 65 | * if the zone size is not a power of 2. |
| 66 | * @nr_zones: number of zones |
| 67 | * @refcount: number of fio files that share this structure |
| 68 | * @num_write_zones: number of write target zones |
| 69 | * @write_cnt: Number of writes since the latest zone reset triggered by |
| 70 | * the zone_reset_frequency fio job parameter. |
| 71 | * @write_zones: zone numbers of write target zones |
| 72 | * @zone_info: description of the individual zones |
| 73 | * |
| 74 | * Only devices for which all zones have the same size are supported. |
| 75 | * Note: if the capacity is not a multiple of the zone size then the last zone |
| 76 | * will be smaller than 'zone_size'. |
| 77 | */ |
| 78 | struct zoned_block_device_info { |
| 79 | enum zbd_zoned_model model; |
| 80 | uint32_t max_write_zones; |
| 81 | uint32_t max_active_zones; |
| 82 | pthread_mutex_t mutex; |
| 83 | uint64_t zone_size; |
| 84 | uint64_t wp_valid_data_bytes; |
| 85 | uint32_t write_min_zone; |
| 86 | uint32_t write_max_zone; |
| 87 | uint32_t zone_size_log2; |
| 88 | uint32_t nr_zones; |
| 89 | uint32_t refcount; |
| 90 | uint32_t num_write_zones; |
| 91 | uint32_t write_cnt; |
| 92 | uint32_t write_zones[ZBD_MAX_WRITE_ZONES]; |
| 93 | struct fio_zone_info zone_info[0]; |
| 94 | }; |
| 95 | |
| 96 | int zbd_init_files(struct thread_data *td); |
| 97 | void zbd_recalc_options_with_zone_granularity(struct thread_data *td); |
| 98 | int zbd_setup_files(struct thread_data *td); |
| 99 | void zbd_free_zone_info(struct fio_file *f); |
| 100 | void zbd_file_reset(struct thread_data *td, struct fio_file *f); |
| 101 | bool zbd_unaligned_write(int error_code); |
| 102 | void setup_zbd_zone_mode(struct thread_data *td, struct io_u *io_u); |
| 103 | enum fio_ddir zbd_adjust_ddir(struct thread_data *td, struct io_u *io_u, |
| 104 | enum fio_ddir ddir); |
| 105 | enum io_u_action zbd_adjust_block(struct thread_data *td, struct io_u *io_u); |
| 106 | char *zbd_write_status(const struct thread_stat *ts); |
| 107 | int zbd_do_io_u_trim(struct thread_data *td, struct io_u *io_u); |
| 108 | void zbd_log_err(const struct thread_data *td, const struct io_u *io_u); |
| 109 | |
| 110 | static inline void zbd_close_file(struct fio_file *f) |
| 111 | { |
| 112 | if (f->zbd_info) |
| 113 | zbd_free_zone_info(f); |
| 114 | } |
| 115 | |
| 116 | static inline void zbd_queue_io_u(struct thread_data *td, struct io_u *io_u, |
| 117 | enum fio_q_status status) |
| 118 | { |
| 119 | if (io_u->zbd_queue_io) { |
| 120 | io_u->zbd_queue_io(td, io_u, status, io_u->error == 0); |
| 121 | io_u->zbd_queue_io = NULL; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | static inline void zbd_put_io_u(struct thread_data *td, struct io_u *io_u) |
| 126 | { |
| 127 | if (io_u->zbd_put_io) { |
| 128 | io_u->zbd_put_io(td, io_u); |
| 129 | io_u->zbd_queue_io = NULL; |
| 130 | io_u->zbd_put_io = NULL; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | #endif /* FIO_ZBD_H */ |