Lines Matching +full:track +full:- +full:count
4 * SPDX-License-Identifier: Apache-2.0
23 k_spinlock_key_t key = k_spin_lock(&mem_block->lock); in alloc_blocks()
27 r = sys_bitarray_alloc(mem_block->bitmap, num_blocks, &offset); in alloc_blocks()
30 k_spin_unlock(&mem_block->lock, key); in alloc_blocks()
37 mem_block->info.used_blocks += (uint32_t)num_blocks; in alloc_blocks()
39 if (mem_block->info.max_used_blocks < mem_block->info.used_blocks) { in alloc_blocks()
40 mem_block->info.max_used_blocks = mem_block->info.used_blocks; in alloc_blocks()
43 k_spin_unlock(&mem_block->lock, key); in alloc_blocks()
48 blk = mem_block->buffer + (offset << mem_block->info.blk_sz_shift); in alloc_blocks()
61 if (blk < mem_block->buffer) { in free_blocks()
62 ret = -EFAULT; in free_blocks()
66 offset = (blk - mem_block->buffer) >> mem_block->info.blk_sz_shift; in free_blocks()
67 if (offset >= mem_block->info.num_blocks) { in free_blocks()
68 ret = -EFAULT; in free_blocks()
73 k_spinlock_key_t key = k_spin_lock(&mem_block->lock); in free_blocks()
75 ret = sys_bitarray_free(mem_block->bitmap, num_blocks, offset); in free_blocks()
79 mem_block->info.used_blocks -= (uint32_t)num_blocks; in free_blocks()
82 k_spin_unlock(&mem_block->lock, key); in free_blocks()
89 int sys_mem_blocks_alloc_contiguous(sys_mem_blocks_t *mem_block, size_t count, in sys_mem_blocks_alloc_contiguous() argument
97 if (count == 0) { in sys_mem_blocks_alloc_contiguous()
103 if (count > mem_block->info.num_blocks) { in sys_mem_blocks_alloc_contiguous()
105 ret = -ENOMEM; in sys_mem_blocks_alloc_contiguous()
109 void *ptr = alloc_blocks(mem_block, count); in sys_mem_blocks_alloc_contiguous()
112 ret = -ENOMEM; in sys_mem_blocks_alloc_contiguous()
119 ptr, count << mem_block->info.blk_sz_shift); in sys_mem_blocks_alloc_contiguous()
126 int sys_mem_blocks_alloc(sys_mem_blocks_t *mem_block, size_t count, in sys_mem_blocks_alloc() argument
134 __ASSERT_NO_MSG(mem_block->bitmap != NULL); in sys_mem_blocks_alloc()
135 __ASSERT_NO_MSG(mem_block->buffer != NULL); in sys_mem_blocks_alloc()
137 if (count == 0) { in sys_mem_blocks_alloc()
142 if (count > mem_block->info.num_blocks) { in sys_mem_blocks_alloc()
144 ret = -ENOMEM; in sys_mem_blocks_alloc()
148 for (i = 0; i < count; i++) { in sys_mem_blocks_alloc()
160 BIT(mem_block->info.blk_sz_shift)); in sys_mem_blocks_alloc()
165 if (i < count) { in sys_mem_blocks_alloc()
167 ret = -ENOMEM; in sys_mem_blocks_alloc()
175 size_t count) in sys_mem_blocks_is_region_free() argument
181 __ASSERT_NO_MSG(mem_block->bitmap != NULL); in sys_mem_blocks_is_region_free()
182 __ASSERT_NO_MSG(mem_block->buffer != NULL); in sys_mem_blocks_is_region_free()
184 offset = ((uint8_t *)in_block - mem_block->buffer) >> in sys_mem_blocks_is_region_free()
185 mem_block->info.blk_sz_shift; in sys_mem_blocks_is_region_free()
187 __ASSERT_NO_MSG(offset + count <= mem_block->info.num_blocks); in sys_mem_blocks_is_region_free()
189 result = sys_bitarray_is_region_cleared(mem_block->bitmap, count, in sys_mem_blocks_is_region_free()
194 int sys_mem_blocks_get(sys_mem_blocks_t *mem_block, void *in_block, size_t count) in sys_mem_blocks_get() argument
200 __ASSERT_NO_MSG(mem_block->bitmap != NULL); in sys_mem_blocks_get()
201 __ASSERT_NO_MSG(mem_block->buffer != NULL); in sys_mem_blocks_get()
203 if (count == 0) { in sys_mem_blocks_get()
208 offset = ((uint8_t *)in_block - mem_block->buffer) >> in sys_mem_blocks_get()
209 mem_block->info.blk_sz_shift; in sys_mem_blocks_get()
211 if (offset + count > mem_block->info.num_blocks) { in sys_mem_blocks_get()
213 ret = -ENOMEM; in sys_mem_blocks_get()
218 k_spinlock_key_t key = k_spin_lock(&mem_block->lock); in sys_mem_blocks_get()
221 ret = sys_bitarray_test_and_set_region(mem_block->bitmap, count, in sys_mem_blocks_get()
226 k_spin_unlock(&mem_block->lock, key); in sys_mem_blocks_get()
228 ret = -ENOMEM; in sys_mem_blocks_get()
233 mem_block->info.used_blocks += (uint32_t)count; in sys_mem_blocks_get()
235 if (mem_block->info.max_used_blocks < mem_block->info.used_blocks) { in sys_mem_blocks_get()
236 mem_block->info.max_used_blocks = mem_block->info.used_blocks; in sys_mem_blocks_get()
239 k_spin_unlock(&mem_block->lock, key); in sys_mem_blocks_get()
244 in_block, count << mem_block->info.blk_sz_shift); in sys_mem_blocks_get()
252 int sys_mem_blocks_free(sys_mem_blocks_t *mem_block, size_t count, in sys_mem_blocks_free() argument
260 __ASSERT_NO_MSG(mem_block->bitmap != NULL); in sys_mem_blocks_free()
261 __ASSERT_NO_MSG(mem_block->buffer != NULL); in sys_mem_blocks_free()
263 if (count == 0) { in sys_mem_blocks_free()
268 if (count > mem_block->info.num_blocks) { in sys_mem_blocks_free()
269 ret = -EINVAL; in sys_mem_blocks_free()
273 for (i = 0; i < count; i++) { in sys_mem_blocks_free()
284 * Since we do not keep track of failed free ops, in sys_mem_blocks_free()
285 * we need to notify free one-by-one, instead of in sys_mem_blocks_free()
289 ptr, BIT(mem_block->info.blk_sz_shift)); in sys_mem_blocks_free()
298 int sys_mem_blocks_free_contiguous(sys_mem_blocks_t *mem_block, void *block, size_t count) in sys_mem_blocks_free_contiguous() argument
303 __ASSERT_NO_MSG(mem_block->bitmap != NULL); in sys_mem_blocks_free_contiguous()
304 __ASSERT_NO_MSG(mem_block->buffer != NULL); in sys_mem_blocks_free_contiguous()
306 if (count == 0) { in sys_mem_blocks_free_contiguous()
311 if (count > mem_block->info.num_blocks) { in sys_mem_blocks_free_contiguous()
312 ret = -EINVAL; in sys_mem_blocks_free_contiguous()
316 ret = free_blocks(mem_block, block, count); in sys_mem_blocks_free_contiguous()
323 block, count << mem_block->info.blk_sz_shift); in sys_mem_blocks_free_contiguous()
333 group->num_allocators = 0; in sys_multi_mem_blocks_init()
334 group->choice_fn = choice_fn; in sys_multi_mem_blocks_init()
340 __ASSERT_NO_MSG(group->num_allocators < ARRAY_SIZE(group->allocators)); in sys_multi_mem_blocks_add_allocator()
342 group->allocators[group->num_allocators++] = alloc; in sys_multi_mem_blocks_add_allocator()
346 void *cfg, size_t count, in sys_multi_mem_blocks_alloc() argument
356 if (count == 0) { in sys_multi_mem_blocks_alloc()
363 allocator = group->choice_fn(group, cfg); in sys_multi_mem_blocks_alloc()
365 ret = -EINVAL; in sys_multi_mem_blocks_alloc()
369 if (count > allocator->info.num_blocks) { in sys_multi_mem_blocks_alloc()
370 ret = -ENOMEM; in sys_multi_mem_blocks_alloc()
374 ret = sys_mem_blocks_alloc(allocator, count, out_blocks); in sys_multi_mem_blocks_alloc()
377 *blk_size = BIT(allocator->info.blk_sz_shift); in sys_multi_mem_blocks_alloc()
385 size_t count, void **in_blocks) in sys_multi_mem_blocks_free() argument
394 if (count == 0) { in sys_multi_mem_blocks_free()
398 for (i = 0; i < group->num_allocators; i++) { in sys_multi_mem_blocks_free()
407 one_alloc = group->allocators[i]; in sys_multi_mem_blocks_free()
408 start = one_alloc->buffer; in sys_multi_mem_blocks_free()
409 end = start + (BIT(one_alloc->info.blk_sz_shift) * in sys_multi_mem_blocks_free()
410 one_alloc->info.num_blocks); in sys_multi_mem_blocks_free()
420 ret = sys_mem_blocks_free(allocator, count, in_blocks); in sys_multi_mem_blocks_free()
422 ret = -EINVAL; in sys_multi_mem_blocks_free()
434 return -EINVAL; in sys_mem_blocks_runtime_stats_get()
437 stats->allocated_bytes = mem_block->info.used_blocks << in sys_mem_blocks_runtime_stats_get()
438 mem_block->info.blk_sz_shift; in sys_mem_blocks_runtime_stats_get()
439 stats->free_bytes = (mem_block->info.num_blocks << in sys_mem_blocks_runtime_stats_get()
440 mem_block->info.blk_sz_shift) - in sys_mem_blocks_runtime_stats_get()
441 stats->allocated_bytes; in sys_mem_blocks_runtime_stats_get()
442 stats->max_allocated_bytes = mem_block->info.max_used_blocks << in sys_mem_blocks_runtime_stats_get()
443 mem_block->info.blk_sz_shift; in sys_mem_blocks_runtime_stats_get()
451 return -EINVAL; in sys_mem_blocks_runtime_stats_reset_max()
454 mem_block->info.max_used_blocks = mem_block->info.used_blocks; in sys_mem_blocks_runtime_stats_reset_max()
468 key = k_spin_lock(&block->lock); in sys_mem_blocks_stats_raw()
470 memcpy(stats, &block->info, sizeof(block->info)); in sys_mem_blocks_stats_raw()
472 k_spin_unlock(&block->lock, key); in sys_mem_blocks_stats_raw()
485 key = k_spin_lock(&block->lock); in sys_mem_blocks_stats_query()
487 ptr->free_bytes = (block->info.num_blocks - block->info.used_blocks) << in sys_mem_blocks_stats_query()
488 block->info.blk_sz_shift; in sys_mem_blocks_stats_query()
489 ptr->allocated_bytes = block->info.used_blocks << in sys_mem_blocks_stats_query()
490 block->info.blk_sz_shift; in sys_mem_blocks_stats_query()
491 ptr->max_allocated_bytes = block->info.max_used_blocks << in sys_mem_blocks_stats_query()
492 block->info.blk_sz_shift; in sys_mem_blocks_stats_query()
494 k_spin_unlock(&block->lock, key); in sys_mem_blocks_stats_query()
506 key = k_spin_lock(&block->lock); in sys_mem_blocks_stats_reset()
507 block->info.max_used_blocks = block->info.used_blocks; in sys_mem_blocks_stats_reset()
508 k_spin_unlock(&block->lock, key); in sys_mem_blocks_stats_reset()
549 &(*block_pp)->info, in init_sys_mem_blocks_obj_core_list()