-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathocf_cache.c
More file actions
249 lines (206 loc) · 6.4 KB
/
Copy pathocf_cache.c
File metadata and controls
249 lines (206 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright(c) 2012-2021 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include "ocf/ocf.h"
#include "metadata/metadata.h"
#include "engine/cache_engine.h"
#include "utils/utils_cache_line.h"
#include "ocf_request.h"
#include "utils/utils_part.h"
#include "ocf_priv.h"
#include "ocf_cache_priv.h"
#include "ocf_queue_priv.h"
#include "utils/utils_stats.h"
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache)
{
return cache->device ? &cache->device->volume : NULL;
}
int ocf_cache_set_name(ocf_cache_t cache, const char *src, size_t src_size)
{
OCF_CHECK_NULL(cache);
return env_strncpy(cache->conf_meta->name, OCF_CACHE_NAME_SIZE,
src, src_size);
}
bool ocf_cache_is_any_core_rotational(ocf_cache_t cache)
{
ocf_core_t core;
ocf_core_id_t core_id;
uint8_t result = 0;
for_each_core(cache, core, core_id){
result = ocf_core_is_rotational(core);
if (result)
return result;
}
return result;
}
const char *ocf_cache_get_name(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->conf_meta->name;
}
bool ocf_cache_is_incomplete(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return env_bit_test(ocf_cache_state_incomplete, &cache->cache_state);
}
bool ocf_cache_is_running(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return env_bit_test(ocf_cache_state_running, &cache->cache_state);
}
bool ocf_cache_is_device_attached(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return !ocf_refcnt_frozen(&cache->refcnt.metadata);
}
ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->conf_meta->cache_mode;
}
static uint64_t _calc_dirty_for(uint64_t dirty_since)
{
uint64_t current_time = env_ticks_to_secs(env_get_tick_count());
return dirty_since ? (current_time - dirty_since) : 0;
}
int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
{
uint32_t cache_occupancy_total = 0;
uint32_t dirty_blocks_total = 0;
uint32_t initial_dirty_blocks_total = 0;
uint32_t flushed_total = 0;
uint32_t curr_dirty_cnt;
uint64_t dirty_since = 0;
uint32_t init_dirty_cnt;
uint64_t core_dirty_since;
uint32_t dirty_blocks_inactive = 0;
uint32_t cache_occupancy_inactive = 0;
ocf_core_t core;
ocf_core_id_t core_id;
OCF_CHECK_NULL(cache);
if (!info)
return -OCF_ERR_INVAL;
ENV_BUG_ON(env_memset(info, sizeof(*info), 0));
_ocf_stats_zero(&info->inactive);
info->attached = ocf_cache_is_device_attached(cache);
if (info->attached) {
info->volume_type = ocf_ctx_get_volume_type_id(cache->owner,
cache->device->volume.type);
info->size = cache->conf_meta->cachelines;
}
info->core_count = cache->conf_meta->core_count;
info->cache_mode = ocf_cache_get_mode(cache);
/* iterate through all possibly valid core objcts, as list of
* valid objects may be not continuous
*/
for_each_core(cache, core, core_id) {
/* If current dirty blocks exceeds saved initial dirty
* blocks then update the latter
*/
curr_dirty_cnt = env_atomic_read(
&core->runtime_meta->dirty_clines);
init_dirty_cnt = env_atomic_read(
&core->runtime_meta->initial_dirty_clines);
if (init_dirty_cnt && (curr_dirty_cnt > init_dirty_cnt)) {
env_atomic_set(
&core->runtime_meta->initial_dirty_clines,
env_atomic_read(
&core->runtime_meta->dirty_clines));
}
cache_occupancy_total += env_atomic_read(
&core->runtime_meta->cached_clines);
dirty_blocks_total += env_atomic_read(
&core->runtime_meta->dirty_clines);
initial_dirty_blocks_total += env_atomic_read(
&core->runtime_meta->initial_dirty_clines);
if (!core->opened) {
cache_occupancy_inactive += env_atomic_read(
&core->runtime_meta->cached_clines);
dirty_blocks_inactive += env_atomic_read(
&core->runtime_meta->dirty_clines);
}
core_dirty_since = env_atomic64_read(
&core->runtime_meta->dirty_since);
if (core_dirty_since) {
dirty_since = (dirty_since ?
OCF_MIN(dirty_since, core_dirty_since) :
core_dirty_since);
}
flushed_total += env_atomic_read(&core->flushed);
}
info->dirty = dirty_blocks_total;
info->dirty_initial = initial_dirty_blocks_total;
info->occupancy = cache_occupancy_total;
info->dirty_for = _calc_dirty_for(dirty_since);
info->metadata_end_offset = ocf_cache_is_device_attached(cache) ?
cache->device->metadata_offset / PAGE_SIZE : 0;
info->state = cache->cache_state;
if (info->attached) {
_set(&info->inactive.occupancy,
_lines4k(cache_occupancy_inactive, ocf_line_size(cache)),
_lines4k(info->size, ocf_line_size(cache)));
_set(&info->inactive.clean,
_lines4k(cache_occupancy_inactive - dirty_blocks_inactive,
ocf_line_size(cache)),
_lines4k(cache_occupancy_total, ocf_line_size(cache)));
_set(&info->inactive.dirty,
_lines4k(dirty_blocks_inactive, ocf_line_size(cache)),
_lines4k(cache_occupancy_total, ocf_line_size(cache)));
}
info->flushed = (env_atomic_read(&cache->flush_in_progress)) ?
flushed_total : 0;
info->fallback_pt.status = ocf_fallback_pt_is_on(cache);
info->fallback_pt.error_counter =
env_atomic_read(&cache->fallback_pt_error_counter);
info->eviction_policy = cache->conf_meta->eviction_policy_type;
info->cleaning_policy = cache->conf_meta->cleaning_policy_type;
info->promotion_policy = cache->conf_meta->promotion_policy_type;
info->metadata_footprint = ocf_cache_is_device_attached(cache) ?
ocf_metadata_size_of(cache) : 0;
info->cache_line_size = ocf_line_size(cache);
return 0;
}
const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache)
{
if (!ocf_cache_is_device_attached(cache))
return NULL;
return ocf_volume_get_uuid(ocf_cache_get_volume(cache));
}
uint8_t ocf_cache_get_type_id(ocf_cache_t cache)
{
if (!ocf_cache_is_device_attached(cache))
return 0xff;
return ocf_ctx_get_volume_type_id(ocf_cache_get_ctx(cache),
ocf_volume_get_type(ocf_cache_get_volume(cache)));
}
ocf_cache_line_size_t ocf_cache_get_line_size(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return ocf_line_size(cache);
}
uint64_t ocf_cache_bytes_2_lines(ocf_cache_t cache, uint64_t bytes)
{
OCF_CHECK_NULL(cache);
return ocf_bytes_2_lines(cache, bytes);
}
uint32_t ocf_cache_get_core_count(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->conf_meta->core_count;
}
ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->owner;
}
void ocf_cache_set_priv(ocf_cache_t cache, void *priv)
{
OCF_CHECK_NULL(cache);
cache->priv = priv;
}
void *ocf_cache_get_priv(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->priv;
}