Files
linux-nvgpu/drivers/gpu/nvgpu/gk20a/bitmap_allocator_priv.h
Alex Waterman ba2014d367 gpu: nvgpu: Implement a bitmap allocator
Implement a bitmap allocator for GPU use. This allocator is useful for
managing memory (or resource) regions where the buddy allocator is not
ideal. Some instances are small regions or where the resource management
must not make calls to the kernel's memory allocation routines (anything
that ultimately calls alloc_page()).

The code path where this avoidance of alloc_page() is most required is
the gpfifo submit path. In order to keep this routine fast and have
predicable time constraints no alloc_page() calls is necessary. The
buddy allocator does not work for this since every time a buddy is
allocated there is the possibility that a pair (or more) buddy structs
have to be made. These allocs could perhaps require a call into
alloc_page() if there is not enouch space in the kmem_cache slab for
the buddy structs.

Change-Id: Ia46fce62d4bdafcebbc153b21b515cb51641d241
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: http://git-master/r/1176446
Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
2016-07-19 11:32:38 -07:00

62 lines
1.6 KiB
C

/*
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BITMAP_ALLOCATOR_PRIV_H
#define BITMAP_ALLOCATOR_PRIV_H
#include <linux/rbtree.h>
struct gk20a_allocator;
struct gk20a_bitmap_allocator {
struct gk20a_allocator *owner;
u64 base; /* Base address of the space. */
u64 length; /* Length of the space. */
u64 blk_size; /* Size that corresponds to 1 bit. */
u64 blk_shift; /* Bit shift to divide by blk_size. */
u64 num_bits; /* Number of allocatable bits. */
u64 bit_offs; /* Offset of bitmap. */
unsigned long *bitmap; /* The actual bitmap! */
struct rb_root allocs; /* Tree of outstanding allocations. */
u64 flags;
bool inited;
/* Statistics */
u64 nr_allocs;
u64 nr_fixed_allocs;
u64 bytes_alloced;
u64 bytes_freed;
};
struct gk20a_bitmap_alloc {
u64 base;
u64 length;
struct rb_node alloc_entry; /* RB tree of allocations. */
};
static inline struct gk20a_bitmap_allocator *bitmap_allocator(
struct gk20a_allocator *a)
{
return (struct gk20a_bitmap_allocator *)(a)->priv;
}
#endif