summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2016-10-04 17:04:01 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-02-10 14:57:31 -0500
commitcf0ef133e6e3075c808bb3f553b35e94fc000afd (patch)
tree13cace143fe43034791570514a05bf06cfcc47cb /drivers/gpu/nvgpu/common/linux
parent24e8ee192a02ff75a569f8c734efa9b4b5267fc8 (diff)
gpu: nvgpu: Move kmem_caches to allocator
Instead of using a single static kmem_cache for each type of data structure the allocators may want to allocate each allocator now has its own instance of the kmem_cache. This is done so that each GPU driver instance can accurately track how much memory it is using. In order to support this on older kernels a new NVGPU API has been made, nvgpu_kmem_cache_create(struct gk20a *g, size_t size) To handle the possibility that caches cannot be created with the same name. This patch also fixes numerous places where kfree() was wrongly used to free kmem_cache allocs. Bug 1799159 Bug 1823380 Change-Id: Id674f9a5445fde3f95db65ad6bf3ea990444603d Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1283826 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> GVS: Gerrit_Virtual_Submit
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux')
-rw-r--r--drivers/gpu/nvgpu/common/linux/kmem.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/kmem.c b/drivers/gpu/nvgpu/common/linux/kmem.c
new file mode 100644
index 00000000..24e0ca5d
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/kmem.c
@@ -0,0 +1,83 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/kernel.h>
18#include <linux/slab.h>
19#include <linux/atomic.h>
20
21#include <nvgpu/kmem.h>
22
23/*
24 * Statically declared because this needs to be shared across all nvgpu driver
25 * instances. This makes sure that all kmem caches are _definitely_ uniquely
26 * named.
27 */
28static atomic_t kmem_cache_id;
29
30/*
31 * Linux specific version of the nvgpu_kmem_cache struct. This type is
32 * completely opaque to the rest of the driver.
33 */
34struct nvgpu_kmem_cache {
35 struct gk20a *g;
36 struct kmem_cache *cache;
37
38 /*
39 * Memory to hold the kmem_cache unique name. Only necessary on our
40 * k3.10 kernel when not using the SLUB allocator but it's easier to
41 * just carry this on to newer kernels.
42 */
43 char name[128];
44};
45
46struct nvgpu_kmem_cache *nvgpu_kmem_cache_create(struct gk20a *g, size_t size)
47{
48 struct nvgpu_kmem_cache *cache =
49 kzalloc(sizeof(struct nvgpu_kmem_cache), GFP_KERNEL);
50
51 if (!cache)
52 return NULL;
53
54 cache->g = g;
55
56 snprintf(cache->name, sizeof(cache->name),
57 "nvgpu-cache-0x%p-%d-%d", g, (int)size,
58 atomic_inc_return(&kmem_cache_id));
59 cache->cache = kmem_cache_create(cache->name,
60 size, size, 0, NULL);
61 if (!cache->cache) {
62 kfree(cache);
63 return NULL;
64 }
65
66 return cache;
67}
68
69void nvgpu_kmem_cache_destroy(struct nvgpu_kmem_cache *cache)
70{
71 kmem_cache_destroy(cache->cache);
72 kfree(cache);
73}
74
75void *nvgpu_kmem_cache_alloc(struct nvgpu_kmem_cache *cache)
76{
77 return kmem_cache_alloc(cache->cache, GFP_KERNEL);
78}
79
80void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr)
81{
82 kmem_cache_free(cache->cache, ptr);
83}