1 /**************************************************************************
3 * Copyright 2007-2008 VMware, Inc.
4 * Copyright 2015 Advanced Micro Devices, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
32 #include "pb_buffer.h"
33 #include "util/list.h"
34 #include "os/os_thread.h"
37 * Statically inserted into the driver-specific buffer structure.
41 struct list_head head
;
42 struct pb_buffer
*buffer
; /**< Pointer to the structure this is part of. */
44 int64_t start
, end
; /**< Caching time interval */
45 unsigned bucket_index
;
50 /* The cache is divided into buckets for minimizing cache misses.
51 * The driver controls which buffer goes into which bucket.
53 struct list_head
*buckets
;
57 uint64_t max_cache_size
;
61 unsigned bypass_usage
;
64 void (*destroy_buffer
)(struct pb_buffer
*buf
);
65 bool (*can_reclaim
)(struct pb_buffer
*buf
);
68 void pb_cache_add_buffer(struct pb_cache_entry
*entry
);
69 struct pb_buffer
*pb_cache_reclaim_buffer(struct pb_cache
*mgr
, pb_size size
,
70 unsigned alignment
, unsigned usage
,
71 unsigned bucket_index
);
72 void pb_cache_release_all_buffers(struct pb_cache
*mgr
);
73 void pb_cache_init_entry(struct pb_cache
*mgr
, struct pb_cache_entry
*entry
,
74 struct pb_buffer
*buf
, unsigned bucket_index
);
75 void pb_cache_init(struct pb_cache
*mgr
, uint num_heaps
,
76 uint usecs
, float size_factor
,
77 unsigned bypass_usage
, uint64_t maximum_cache_size
,
78 void (*destroy_buffer
)(struct pb_buffer
*buf
),
79 bool (*can_reclaim
)(struct pb_buffer
*buf
));
80 void pb_cache_deinit(struct pb_cache
*mgr
);