Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /*------------------------------------------------------------------------- |
14 | | * |
15 | | * Created: H5Cquery.c |
16 | | * |
17 | | * Purpose: Routines which query different components of the generic |
18 | | * cache structure or entries. |
19 | | * |
20 | | *------------------------------------------------------------------------- |
21 | | */ |
22 | | |
23 | | /****************/ |
24 | | /* Module Setup */ |
25 | | /****************/ |
26 | | |
27 | | #include "H5Cmodule.h" /* This source code file is part of the H5C module */ |
28 | | #define H5F_FRIEND /*suppress error about including H5Fpkg */ |
29 | | |
30 | | /***********/ |
31 | | /* Headers */ |
32 | | /***********/ |
33 | | #include "H5private.h" /* Generic Functions */ |
34 | | #include "H5Cpkg.h" /* Cache */ |
35 | | #include "H5Eprivate.h" /* Error handling */ |
36 | | #include "H5Fpkg.h" /* Files */ |
37 | | |
38 | | /****************/ |
39 | | /* Local Macros */ |
40 | | /****************/ |
41 | | |
42 | | /******************/ |
43 | | /* Local Typedefs */ |
44 | | /******************/ |
45 | | |
46 | | /********************/ |
47 | | /* Local Prototypes */ |
48 | | /********************/ |
49 | | |
50 | | /*********************/ |
51 | | /* Package Variables */ |
52 | | /*********************/ |
53 | | |
54 | | /*****************************/ |
55 | | /* Library Private Variables */ |
56 | | /*****************************/ |
57 | | |
58 | | /*******************/ |
59 | | /* Local Variables */ |
60 | | /*******************/ |
61 | | |
62 | | /*------------------------------------------------------------------------- |
63 | | * Function: H5C_get_cache_auto_resize_config |
64 | | * |
65 | | * Purpose: Copy the current configuration of the cache automatic |
66 | | * re-sizing function into the instance of H5C_auto_size_ctl_t |
67 | | * pointed to by config_ptr. |
68 | | * |
69 | | * Return: SUCCEED on success, and FAIL on failure. |
70 | | * |
71 | | *------------------------------------------------------------------------- |
72 | | */ |
73 | | herr_t |
74 | | H5C_get_cache_auto_resize_config(const H5C_t *cache_ptr, H5C_auto_size_ctl_t *config_ptr) |
75 | 0 | { |
76 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
77 | |
|
78 | 0 | FUNC_ENTER_NOAPI(FAIL) |
79 | |
|
80 | 0 | if (cache_ptr == NULL) |
81 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
82 | 0 | if (config_ptr == NULL) |
83 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad config_ptr on entry."); |
84 | | |
85 | 0 | *config_ptr = cache_ptr->resize_ctl; |
86 | |
|
87 | 0 | config_ptr->set_initial_size = false; |
88 | 0 | config_ptr->initial_size = cache_ptr->max_cache_size; |
89 | |
|
90 | 0 | done: |
91 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
92 | 0 | } /* H5C_get_cache_auto_resize_config() */ |
93 | | |
94 | | /*------------------------------------------------------------------------- |
95 | | * Function: H5C_get_cache_size |
96 | | * |
97 | | * Purpose: Return the cache maximum size, the minimum clean size, the |
98 | | * current size, and the current number of entries in |
99 | | * *max_size_ptr, *min_clean_size_ptr, *cur_size_ptr, and |
100 | | * *cur_num_entries_ptr respectively. If any of these |
101 | | * parameters are NULL, skip that value. |
102 | | * |
103 | | * Return: SUCCEED on success, and FAIL on failure. |
104 | | * |
105 | | *------------------------------------------------------------------------- |
106 | | */ |
107 | | herr_t |
108 | | H5C_get_cache_size(const H5C_t *cache_ptr, size_t *max_size_ptr, size_t *min_clean_size_ptr, |
109 | | size_t *cur_size_ptr, uint32_t *cur_num_entries_ptr) |
110 | 0 | { |
111 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
112 | |
|
113 | 0 | FUNC_ENTER_NOAPI(FAIL) |
114 | |
|
115 | 0 | if (cache_ptr == NULL) |
116 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
117 | | |
118 | 0 | if (max_size_ptr != NULL) |
119 | 0 | *max_size_ptr = cache_ptr->max_cache_size; |
120 | |
|
121 | 0 | if (min_clean_size_ptr != NULL) |
122 | 0 | *min_clean_size_ptr = cache_ptr->min_clean_size; |
123 | |
|
124 | 0 | if (cur_size_ptr != NULL) |
125 | 0 | *cur_size_ptr = cache_ptr->index_size; |
126 | |
|
127 | 0 | if (cur_num_entries_ptr != NULL) |
128 | 0 | *cur_num_entries_ptr = cache_ptr->index_len; |
129 | |
|
130 | 0 | done: |
131 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
132 | 0 | } /* H5C_get_cache_size() */ |
133 | | |
134 | | /*------------------------------------------------------------------------- |
135 | | * Function: H5C_get_cache_flush_in_progress |
136 | | * |
137 | | * Purpose: Return flush_in_progress in *flush_in_progress_ptr |
138 | | * If the parameter is NULL, skip that value. |
139 | | * |
140 | | * Return: SUCCEED on success, and FAIL on failure. |
141 | | * |
142 | | *------------------------------------------------------------------------- |
143 | | */ |
144 | | herr_t |
145 | | H5C_get_cache_flush_in_progress(const H5C_t *cache_ptr, bool *flush_in_progress_ptr) |
146 | 0 | { |
147 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
148 | |
|
149 | 0 | FUNC_ENTER_NOAPI(FAIL) |
150 | |
|
151 | 0 | if (cache_ptr == NULL) |
152 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
153 | | |
154 | 0 | if (flush_in_progress_ptr != NULL) |
155 | 0 | *flush_in_progress_ptr = cache_ptr->flush_in_progress; |
156 | |
|
157 | 0 | done: |
158 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
159 | 0 | } /* H5C_get_cache_flush_in_progress() */ |
160 | | |
161 | | /*------------------------------------------------------------------------- |
162 | | * Function: H5C_get_cache_hit_rate |
163 | | * |
164 | | * Purpose: Compute and return the current cache hit rate in |
165 | | * *hit_rate_ptr. If there have been no accesses since the |
166 | | * last time the cache hit rate stats were reset, set |
167 | | * *hit_rate_ptr to 0.0. On error, *hit_rate_ptr is |
168 | | * undefined. |
169 | | * |
170 | | * Return: SUCCEED on success, and FAIL on failure. |
171 | | * |
172 | | *------------------------------------------------------------------------- |
173 | | */ |
174 | | herr_t |
175 | | H5C_get_cache_hit_rate(const H5C_t *cache_ptr, double *hit_rate_ptr) |
176 | 0 | { |
177 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
178 | |
|
179 | 0 | FUNC_ENTER_NOAPI(FAIL) |
180 | |
|
181 | 0 | if (cache_ptr == NULL) |
182 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
183 | 0 | if (hit_rate_ptr == NULL) |
184 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad hit_rate_ptr on entry."); |
185 | | |
186 | 0 | assert(cache_ptr->cache_hits >= 0); |
187 | 0 | assert(cache_ptr->cache_accesses >= cache_ptr->cache_hits); |
188 | |
|
189 | 0 | if (cache_ptr->cache_accesses > 0) |
190 | 0 | *hit_rate_ptr = ((double)(cache_ptr->cache_hits)) / ((double)(cache_ptr->cache_accesses)); |
191 | 0 | else |
192 | 0 | *hit_rate_ptr = 0.0; |
193 | |
|
194 | 0 | done: |
195 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
196 | 0 | } /* H5C_get_cache_hit_rate() */ |
197 | | |
198 | | /*------------------------------------------------------------------------- |
199 | | * Function: H5C_get_entry_status |
200 | | * |
201 | | * Purpose: This function is used to determine whether the cache |
202 | | * contains an entry with the specified base address. If |
203 | | * the entry exists, it also reports some status information |
204 | | * on the entry. |
205 | | * |
206 | | * Status information is reported in the locations pointed |
207 | | * to by the size_ptr, in_cache_ptr, is_dirty_ptr, and |
208 | | * is_protected_ptr. While in_cache_ptr must be defined, |
209 | | * the remaining pointers may be NULL, in which case the |
210 | | * associated data is not reported. |
211 | | * |
212 | | * Return: Non-negative on success/Negative on failure |
213 | | * |
214 | | *------------------------------------------------------------------------- |
215 | | */ |
216 | | herr_t |
217 | | H5C_get_entry_status(const H5F_t *f, haddr_t addr, size_t *size_ptr, bool *in_cache_ptr, bool *is_dirty_ptr, |
218 | | bool *is_protected_ptr, bool *is_pinned_ptr, bool *is_corked_ptr, |
219 | | bool *is_flush_dep_parent_ptr, bool *is_flush_dep_child_ptr, bool *image_up_to_date_ptr) |
220 | 0 | { |
221 | 0 | H5C_t *cache_ptr; |
222 | 0 | H5C_cache_entry_t *entry_ptr = NULL; |
223 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
224 | |
|
225 | 0 | FUNC_ENTER_NOAPI(FAIL) |
226 | | |
227 | | /* Sanity checks */ |
228 | 0 | assert(f); |
229 | 0 | assert(f->shared); |
230 | 0 | cache_ptr = f->shared->cache; |
231 | 0 | assert(cache_ptr != NULL); |
232 | 0 | assert(H5_addr_defined(addr)); |
233 | 0 | assert(in_cache_ptr != NULL); |
234 | |
|
235 | 0 | if (cache_ptr == NULL) |
236 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
237 | | |
238 | 0 | H5C__SEARCH_INDEX(cache_ptr, addr, entry_ptr, FAIL); |
239 | |
|
240 | 0 | if (entry_ptr == NULL) { |
241 | | /* the entry doesn't exist in the cache -- report this |
242 | | * and quit. |
243 | | */ |
244 | 0 | *in_cache_ptr = false; |
245 | 0 | } /* end if */ |
246 | 0 | else { |
247 | 0 | *in_cache_ptr = true; |
248 | 0 | if (size_ptr != NULL) |
249 | 0 | *size_ptr = entry_ptr->size; |
250 | 0 | if (is_dirty_ptr != NULL) |
251 | 0 | *is_dirty_ptr = entry_ptr->is_dirty; |
252 | 0 | if (is_protected_ptr != NULL) |
253 | 0 | *is_protected_ptr = entry_ptr->is_protected; |
254 | 0 | if (is_pinned_ptr != NULL) |
255 | 0 | *is_pinned_ptr = entry_ptr->is_pinned; |
256 | 0 | if (is_corked_ptr != NULL) |
257 | 0 | *is_corked_ptr = entry_ptr->tag_info ? entry_ptr->tag_info->corked : false; |
258 | 0 | if (is_flush_dep_parent_ptr != NULL) |
259 | 0 | *is_flush_dep_parent_ptr = (entry_ptr->flush_dep_nchildren > 0); |
260 | 0 | if (is_flush_dep_child_ptr != NULL) |
261 | 0 | *is_flush_dep_child_ptr = (entry_ptr->flush_dep_nparents > 0); |
262 | 0 | if (image_up_to_date_ptr != NULL) |
263 | 0 | *image_up_to_date_ptr = entry_ptr->image_up_to_date; |
264 | 0 | } /* end else */ |
265 | |
|
266 | 0 | done: |
267 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
268 | 0 | } /* H5C_get_entry_status() */ |
269 | | |
270 | | /*------------------------------------------------------------------------- |
271 | | * Function: H5C_get_evictions_enabled() |
272 | | * |
273 | | * Purpose: Copy the current value of cache_ptr->evictions_enabled into |
274 | | * *evictions_enabled_ptr. |
275 | | * |
276 | | * Return: SUCCEED on success, and FAIL on failure. |
277 | | * |
278 | | *------------------------------------------------------------------------- |
279 | | */ |
280 | | herr_t |
281 | | H5C_get_evictions_enabled(const H5C_t *cache_ptr, bool *evictions_enabled_ptr) |
282 | 0 | { |
283 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
284 | |
|
285 | 0 | FUNC_ENTER_NOAPI(FAIL) |
286 | |
|
287 | 0 | if (cache_ptr == NULL) |
288 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad cache_ptr on entry."); |
289 | | |
290 | 0 | if (evictions_enabled_ptr == NULL) |
291 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_SYSTEM, FAIL, "Bad evictions_enabled_ptr on entry."); |
292 | | |
293 | 0 | *evictions_enabled_ptr = cache_ptr->evictions_enabled; |
294 | |
|
295 | 0 | done: |
296 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
297 | 0 | } /* H5C_get_evictions_enabled() */ |
298 | | |
299 | | /*------------------------------------------------------------------------- |
300 | | * Function: H5C_get_aux_ptr |
301 | | * |
302 | | * Purpose: Get the aux_ptr field from the cache. |
303 | | * |
304 | | * This field will either be NULL (when accessing a file serially) |
305 | | * or contains a pointer to the auxiliary info for parallel I/O. |
306 | | * |
307 | | * Return: NULL/non-NULL (can't fail) |
308 | | * |
309 | | *------------------------------------------------------------------------- |
310 | | */ |
311 | | void * |
312 | | H5C_get_aux_ptr(const H5C_t *cache_ptr) |
313 | 0 | { |
314 | 0 | FUNC_ENTER_NOAPI_NOERR |
315 | | |
316 | | /* Check arguments */ |
317 | 0 | assert(cache_ptr); |
318 | |
|
319 | 0 | FUNC_LEAVE_NOAPI(cache_ptr->aux_ptr) |
320 | 0 | } /* H5C_get_aux_ptr() */ |
321 | | |
322 | | /*------------------------------------------------------------------------- |
323 | | * Function: H5C_get_entry_ring |
324 | | * |
325 | | * Purpose: Given a file address, retrieve the ring for an entry at that |
326 | | * address. |
327 | | * |
328 | | * On error, the value of *ring is not modified. |
329 | | * |
330 | | * Return: Non-negative on success/Negative on failure |
331 | | * |
332 | | *------------------------------------------------------------------------- |
333 | | */ |
334 | | herr_t |
335 | | H5C_get_entry_ring(const H5F_t *f, haddr_t addr, H5C_ring_t *ring) |
336 | 0 | { |
337 | 0 | H5C_t *cache_ptr; /* Pointer to cache */ |
338 | 0 | H5C_cache_entry_t *entry_ptr; /* Pointer to cache entry at address */ |
339 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
340 | |
|
341 | 0 | FUNC_ENTER_NOAPI(FAIL) |
342 | | |
343 | | /* Sanity checks */ |
344 | 0 | assert(f); |
345 | 0 | assert(f->shared); |
346 | 0 | cache_ptr = f->shared->cache; |
347 | 0 | assert(cache_ptr); |
348 | 0 | assert(H5_addr_defined(addr)); |
349 | | |
350 | | /* Locate the entry at the address */ |
351 | 0 | H5C__SEARCH_INDEX(cache_ptr, addr, entry_ptr, FAIL); |
352 | 0 | if (entry_ptr == NULL) |
353 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_NOTFOUND, FAIL, "can't find entry in index"); |
354 | | |
355 | | /* Return the ring value */ |
356 | 0 | *ring = entry_ptr->ring; |
357 | |
|
358 | 0 | done: |
359 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
360 | 0 | } /* H5C_get_entry_ring() */ |
361 | | |
362 | | /*------------------------------------------------------------------------- |
363 | | * Function: H5C_get_mdc_image_info |
364 | | * |
365 | | * Purpose: To retrieve the address and size of the cache image in the file. |
366 | | * |
367 | | * Return: SUCCEED on success, and FAIL on failure. |
368 | | * |
369 | | *------------------------------------------------------------------------- |
370 | | */ |
371 | | herr_t |
372 | | H5C_get_mdc_image_info(const H5C_t *cache_ptr, haddr_t *image_addr, hsize_t *image_len) |
373 | 0 | { |
374 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
375 | |
|
376 | 0 | FUNC_ENTER_NOAPI(FAIL) |
377 | |
|
378 | 0 | if (cache_ptr == NULL) |
379 | 0 | HGOTO_ERROR(H5E_CACHE, H5E_BADVALUE, FAIL, "bad cache_ptr on entry"); |
380 | | |
381 | 0 | if (image_addr) |
382 | 0 | *image_addr = cache_ptr->image_addr; |
383 | 0 | if (image_len) |
384 | 0 | *image_len = cache_ptr->image_len; |
385 | |
|
386 | 0 | done: |
387 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
388 | 0 | } /* H5C_get_mdc_image_info() */ |