]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/ocf/src/utils/utils_cleaner.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / ocf / src / utils / utils_cleaner.h
CommitLineData
9f95a23c
TL
1/*
2 * Copyright(c) 2012-2018 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause-Clear
4 */
5
6#ifndef UTILS_CLEANER_H_
7#define UTILS_CLEANER_H_
8
9#include "../ocf_request.h"
10
11/**
12 * @brief Getter for next cache line to be cleaned
13 *
14 * @param cache[in] Cache instance
15 * @param getter_context[in] Context for cleaner caller
16 * @param item[in] Current iteration item when collection cache lines
17 * @param line[out] line to be cleaned
18 * @retval 0 When caller return zero it means take this cache line to clean
19 * @retval Non-zero Means skip this cache line and do not clean it
20 */
21typedef int (*ocf_cleaner_get_item)(struct ocf_cache *cache,
22 void *getter_context, uint32_t item, ocf_cache_line_t *line);
23
24/**
25 * @brief Cleaning attributes for clean request
26 */
27struct ocf_cleaner_attribs {
28 uint8_t cache_line_lock : 1; /*!< Clean under cache line lock */
29
30 uint8_t do_sort : 1; /*!< Sort cache lines which will be cleaned */
31
32 uint32_t count; /*!< max number of cache lines to be cleaned */
33
34 void *cmpl_context; /*!< Completion context of cleaning requester */
35 void (*cmpl_fn)(void *priv, int error); /*!< Completion function of requester */
36
37 ocf_cleaner_get_item getter;
38 /*!< Getter for collecting cache lines which will be cleaned */
39 void *getter_context;
40 /*!< Context for getting cache lines */
41 uint32_t getter_item;
42 /*!< Additional variable that can be used by cleaner caller
43 * to iterate over items
44 */
45
46 ocf_queue_t io_queue;
47};
48
49/**
50 * @brief Flush table entry structure
51 */
52struct flush_data {
53 uint64_t core_line;
54 uint32_t cache_line;
55 ocf_core_id_t core_id;
56};
57
58typedef void (*ocf_flush_containter_coplete_t)(void *ctx);
59
60/**
61 * @brief Flush table container
62 */
63struct flush_container {
64 ocf_core_id_t core_id;
65 struct flush_data *flush_data;
66 uint32_t count;
67 uint32_t iter;
68
69 struct ocf_cleaner_attribs attribs;
70 ocf_cache_t cache;
71
72 struct ocf_request *req;
73
74 uint64_t flush_portion;
75 uint64_t ticks1;
76 uint64_t ticks2;
77
78 ocf_flush_containter_coplete_t end;
79 struct ocf_mngt_cache_flush_context *context;
80};
81
f67539c2
TL
82typedef void (*ocf_cleaner_refcnt_zero_cb_t)(void *priv);
83
84/**
85 * @brief Context for ocf_cleaner_refcnt_register_zero_cb
86 */
87struct ocf_cleaner_wait_context
88{
89 env_atomic waiting;
90 ocf_cleaner_refcnt_zero_cb_t cb;
91 void *priv;
92};
93
9f95a23c
TL
94/**
95 * @brief Run cleaning procedure
96 *
97 * @param cache - Cache instance
98 * @param attribs - Cleaning attributes
99 */
100void ocf_cleaner_fire(struct ocf_cache *cache,
101 const struct ocf_cleaner_attribs *attribs);
102
103/**
104 * @brief Perform cleaning procedure for specified flush data. Only dirty
105 * cache lines will be cleaned.
106 *
107 * @param cache - Cache instance
108 * @param flush - flush data to be cleaned
109 * @param count - Count of cache lines to be cleaned
110 * @param attribs - Cleaning attributes
111 * @return - Cleaning result. 0 - no errors, non zero errors occurred
112 */
113int ocf_cleaner_do_flush_data_async(struct ocf_cache *cache,
114 struct flush_data *flush, uint32_t count,
115 struct ocf_cleaner_attribs *attribs);
116
117/**
118 * @brief Sort flush data by core sector
119 *
120 * @param tbl Flush data to sort
121 * @param num Number of entries in tbl
122 */
123void ocf_cleaner_sort_sectors(struct flush_data *tbl, uint32_t num);
124
125/**
126 * @brief Sort flush data in all flush containters
127 *
128 * @param tbl Flush containers to sort
129 * @param num Number of entries in fctbl
130 */
131void ocf_cleaner_sort_flush_containers(struct flush_container *fctbl,
132 uint32_t num);
133
f67539c2
TL
134/**
135 * @brief Disable incrementing of cleaner reference counters
136 *
137 * @param cache - Cache instance
138 */
139void ocf_cleaner_refcnt_freeze(ocf_cache_t cache);
140
141/**
142 * @brief Enable incrementing of cleaner reference counters
143 *
144 * @param cache - Cache instance
145 */
146void ocf_cleaner_refcnt_unfreeze(ocf_cache_t cache);
147
148/**
149 * @brief Register callback for cleaner reference counters dropping to 0
150 *
151 * @param cache - Cache instance
152 * @param ctx - Routine private context, allocated by caller to avoid ENOMEM
153 * @param cb - Caller callback
154 * @param priv - Caller callback private data
155 */
156void ocf_cleaner_refcnt_register_zero_cb(ocf_cache_t cache,
157 struct ocf_cleaner_wait_context *ctx,
158 ocf_cleaner_refcnt_zero_cb_t cb, void *priv);
159
9f95a23c 160#endif /* UTILS_CLEANER_H_ */