]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/ocf/src/engine/engine_common.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / ocf / src / engine / engine_common.h
CommitLineData
9f95a23c
TL
1/*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6#ifndef ENGINE_COMMON_H_
7#define ENGINE_COMMON_H_
8
9#include "../ocf_request.h"
f67539c2 10#include "../utils/utils_cache_line.h"
9f95a23c
TL
11
12/**
13 * @file engine_common.h
14 * @brief OCF cache engine common module
15 */
16
17/**
18 * @brief Signal and handle OCF request error
19 *
20 * @param req OCF request
21 * @param stop_cache Indicates if OCF cache engine need to be stopped
22 * @param msg Error message to be printed into log
23 */
24void ocf_engine_error(struct ocf_request *req, bool stop_cache,
25 const char *msg);
26
27/**
28 * @brief Check if OCF request is hit
29 *
30 * @param req OCF request
31 *
32 * @retval true HIT
33 * @retval false MISS
34 */
35static inline bool ocf_engine_is_hit(struct ocf_request *req)
36{
37 return req->info.hit_no == req->core_line_count;
38}
39
40/**
41 * @brief Check if OCF request is miss
42 *
43 * @param req OCF request
44 *
45 * @retval true MISS
46 * @retval false HIT
47 */
48#define ocf_engine_is_miss(req) (!ocf_engine_is_hit(req))
49
50/**
51 * @brief Check if all cache lines are mapped fully
52 *
53 * @param req OCF request
54 *
55 * @retval true request is mapped fully
56 * @retval false request is not mapped fully and eviction might be run in
57 * order to complete mapping
58 */
59static inline bool ocf_engine_is_mapped(struct ocf_request *req)
60{
61 return req->info.hit_no + req->info.invalid_no == req->core_line_count;
62}
63
64/**
65 * @brief Check if all cache lines are dirty
66 *
67 * @param req OCF request
68 *
69 * @retval true request is dirty fully
70 * @retval false request is not dirty fully
71 */
72static inline bool ocf_engine_is_dirty_all(struct ocf_request *req)
73{
74 return req->info.dirty_all == req->core_line_count;
75}
76
77/**
78 * @brief Get number of mapped cache lines
79 *
80 * @param req OCF request
81 *
82 * @return Number of mapped cache lines
83 */
84static inline uint32_t ocf_engine_mapped_count(struct ocf_request *req)
85{
86 return req->info.hit_no + req->info.invalid_no;
87}
88
89/**
90 * @brief Get number of unmapped cache lines
91 *
92 * @param req OCF request
93 *
94 * @return Number of unmapped cache lines
95 */
96static inline uint32_t ocf_engine_unmapped_count(struct ocf_request *req)
97{
98 return req->core_line_count - (req->info.hit_no + req->info.invalid_no);
99}
100
101/**
102 * @brief Get number of IOs to perform cache read or write
103 *
104 * @param req OCF request
105 *
106 * @return Count of cache IOs
107 */
108static inline uint32_t ocf_engine_io_count(struct ocf_request *req)
109{
110 return req->info.seq_req ? 1 : req->core_line_count;
111}
112
f67539c2
TL
113static inline
114bool ocf_engine_map_all_sec_dirty(struct ocf_request *req, uint32_t line)
115{
116 uint8_t start = ocf_map_line_start_sector(req, line);
117 uint8_t end = ocf_map_line_end_sector(req, line);
118
119 if (req->map[line].status != LOOKUP_HIT)
120 return false;
121
122 return metadata_test_dirty_all_sec(req->cache, req->map[line].coll_idx,
123 start, end);
124}
125
126static inline
127bool ocf_engine_map_all_sec_clean(struct ocf_request *req, uint32_t line)
128{
129 uint8_t start = ocf_map_line_start_sector(req, line);
130 uint8_t end = ocf_map_line_end_sector(req, line);
131
132 if (req->map[line].status != LOOKUP_HIT)
133 return false;
134
135 if (!metadata_test_valid_sec(req->cache, req->map[line].coll_idx,
136 start, end)) {
137 return false;
138 }
139
140 return !metadata_test_dirty_sec(req->cache, req->map[line].coll_idx,
141 start, end);
142}
143
9f95a23c
TL
144/**
145 * @brief Clean request (flush dirty data to the core device)
146 *
147 * @param req OCF request
148 *
149 * @note After successful cleaning:
150 * - Dirty status bits in request info will be cleared
151 * - Request will be pushed front, <B>IO interface need to be set</B>
152 *
153 * @note In case of failure:
154 * - unlock request
155 * - complete request to the application
156 * - free request
157 */
158void ocf_engine_clean(struct ocf_request *req);
159
160void ocf_engine_lookup_map_entry(struct ocf_cache *cache,
161 struct ocf_map_info *entry, ocf_core_id_t core_id,
162 uint64_t core_line);
163
164/**
f67539c2
TL
165 * @brief Request cacheline lock type
166 */
167enum ocf_engine_lock_type
168{
169 /** No lock */
170 ocf_engine_lock_none = 0,
171 /** Write lock */
172 ocf_engine_lock_write,
173 /** Read lock */
174 ocf_engine_lock_read,
175};
176
177/**
178 * @brief Engine-specific callbacks for common request handling rountine
9f95a23c 179 *
f67539c2
TL
180 * TODO(arutk): expand this structure to fit all engines and all steps
181 */
182struct ocf_engine_callbacks
183{
184 /** Specify locking requirements after request is mapped */
185 enum ocf_engine_lock_type (*get_lock_type)(struct ocf_request *req);
186
187 /** Resume handling after acquiring asynchronous lock */
188 ocf_req_async_lock_cb resume;
189};
190
191/**
192 * @brief Map and lock cachelines
9f95a23c
TL
193 *
194 * @param req OCF request
f67539c2
TL
195 *
196 * @returns eviction status
197 * @retval LOOKUP_MAPPED successfully evicted required number of cachelines
198 * @retval LOOKUP_MISS eviction failure
9f95a23c 199 */
f67539c2
TL
200int ocf_engine_prepare_clines(struct ocf_request *req,
201 const struct ocf_engine_callbacks *engine_cbs);
9f95a23c
TL
202
203/**
204 * @brief Traverse OCF request (lookup cache)
205 *
f67539c2 206 * @note This function does not evict cachelines. Only lookup in metadata is
9f95a23c
TL
207 * performed. Main purpose of this function is to check if there is a HIT.
208 *
209 * @param req OCF request
210 */
211void ocf_engine_traverse(struct ocf_request *req);
212
213/**
214 * @brief Check if OCF request mapping is still valid
215 *
216 * @note If mapping entries is invalid it will be marked
217 *
218 * @param req OCF request
219 *
220 * @retval 0 - OCF request mapping is valid
221 * @return Non zero - OCF request mapping is invalid and need to call re-mapping
222 */
223int ocf_engine_check(struct ocf_request *req);
224
225/**
226 * @brief Update OCF request info
227 *
228 * @param req OCF request
229 */
230void ocf_engine_update_req_info(struct ocf_cache *cache,
231 struct ocf_request *req, uint32_t entry);
232
233/**
234 * @brief Update OCF request block statistics for an exported object
235 *
236 * @param req OCF request
237 */
238void ocf_engine_update_block_stats(struct ocf_request *req);
239
240/**
241 * @brief Update OCF request request statistics for an exported object
242 * (not applicable to write wi and to read wt
243 *
244 * @param req OCF request
245 */
246void ocf_engine_update_request_stats(struct ocf_request *req);
247
248/**
249 * @brief Push front OCF request to the OCF thread worker queue
250 *
251 * @param req OCF request
252 * @param allow_sync caller allows for request from queue to be ran immediately
253 from push function in caller context
254 */
255void ocf_engine_push_req_back(struct ocf_request *req,
256 bool allow_sync);
257
258/**
259 * @brief Push back OCF request to the OCF thread worker queue
260 *
261 * @param req OCF request
262 * @param allow_sync caller allows for request from queue to be ran immediately
263 from push function in caller context
264 */
265void ocf_engine_push_req_front(struct ocf_request *req,
266 bool allow_sync);
267
268/**
269 * @brief Set interface and push from request to the OCF thread worker queue
270 *
271 * @param req OCF request
272 * @param io_if IO interface
273 * @param allow_sync caller allows for request from queue to be ran immediately
274 from push function in caller context
275 */
276void ocf_engine_push_req_front_if(struct ocf_request *req,
277 const struct ocf_io_if *io_if,
278 bool allow_sync);
279
280void inc_fallback_pt_error_counter(ocf_cache_t cache);
281
282void ocf_engine_on_resume(struct ocf_request *req);
283
284#endif /* ENGINE_COMMON_H_ */