2 * Copyright © 2018 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "anv_private.h"
28 int main(int argc
, char **argv
)
30 struct anv_instance instance
;
31 struct anv_device device
= {
32 .instance
= &instance
,
34 struct anv_state_pool state_pool
;
36 anv_state_pool_init(&state_pool
, &device
, 4096, 4096, EXEC_OBJECT_PINNED
);
38 /* Get the size of the underlying block_pool */
39 struct anv_block_pool
*bp
= &state_pool
.block_pool
;
40 uint64_t pool_size
= bp
->size
;
42 /* Grab one so the pool has some initial usage */
43 anv_state_pool_alloc(&state_pool
, 16, 16);
45 /* Grab a state that is the size of the initial allocation */
46 struct anv_state state
= anv_state_pool_alloc(&state_pool
, pool_size
, 16);
48 /* The pool must have grown */
49 assert(bp
->size
> pool_size
);
51 /* And the state must have been allocated at the end of the original size */
52 assert(state
.offset
== pool_size
);
54 /* A new allocation that fits into the returned empty space should have an
55 * offset within the original pool size
57 state
= anv_state_pool_alloc(&state_pool
, 4096, 16);
58 assert(state
.offset
+ state
.alloc_size
<= pool_size
);
60 /* We should be able to allocate pool->block_size'd chunks in the returned area
62 int left_chunks
= pool_size
/ 4096 - 2;
63 for (int i
= 0; i
< left_chunks
; i
++) {
64 state
= anv_state_pool_alloc(&state_pool
, 4096, 16);
65 assert(state
.offset
+ state
.alloc_size
<= pool_size
);
68 /* Now the next chunk to be allocated should make the pool grow again */
70 state
= anv_state_pool_alloc(&state_pool
, 4096, 16);
71 assert(bp
->size
> pool_size
);
72 assert(state
.offset
== pool_size
);
74 anv_state_pool_finish(&state_pool
);