* [PATCH] drm/ttm: use drm calloc large and free large
@ 2010-03-09 6:33 Dave Airlie
2010-03-16 12:58 ` Thomas Hellstrom
0 siblings, 1 reply; 2+ messages in thread
From: Dave Airlie @ 2010-03-09 6:33 UTC (permalink / raw)
To: dri-devel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5940 bytes --]
From: Dave Airlie <airlied@redhat.com>
Now that the drm core can do this, lets just use it, split the code out
so TTM doesn't have to drag all of drmP.h in.
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
drivers/gpu/drm/ttm/ttm_tt.c | 23 ++------------
include/drm/drmP.h | 34 +--------------------
include/drm/drm_mem_util.h | 65 +++++++++++++++++++++++++++++++++++++++
include/drm/ttm/ttm_bo_driver.h | 1 -
4 files changed, 69 insertions(+), 54 deletions(-)
create mode 100644 include/drm/drm_mem_util.h
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index a759170..bab6cd8 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -28,13 +28,13 @@
* Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
*/
-#include <linux/vmalloc.h>
#include <linux/sched.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/file.h>
#include <linux/swap.h>
#include "drm_cache.h"
+#include "drm_mem_util.h"
#include "ttm/ttm_module.h"
#include "ttm/ttm_bo_driver.h"
#include "ttm/ttm_placement.h"
@@ -43,32 +43,15 @@ static int ttm_tt_swapin(struct ttm_tt *ttm);
/**
* Allocates storage for pointers to the pages that back the ttm.
- *
- * Uses kmalloc if possible. Otherwise falls back to vmalloc.
*/
static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
{
- unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
- ttm->pages = NULL;
-
- if (size <= PAGE_SIZE)
- ttm->pages = kzalloc(size, GFP_KERNEL);
-
- if (!ttm->pages) {
- ttm->pages = vmalloc_user(size);
- if (ttm->pages)
- ttm->page_flags |= TTM_PAGE_FLAG_VMALLOC;
- }
+ ttm->pages = drm_calloc_large(ttm->num_pages, sizeof(*ttm->pages));
}
static void ttm_tt_free_page_directory(struct ttm_tt *ttm)
{
- if (ttm->page_flags & TTM_PAGE_FLAG_VMALLOC) {
- vfree(ttm->pages);
- ttm->page_flags &= ~TTM_PAGE_FLAG_VMALLOC;
- } else {
- kfree(ttm->pages);
- }
+ drm_free_large(ttm->pages);
ttm->pages = NULL;
}
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 829e524..22e60af 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1595,39 +1595,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)
{
}
-
-static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
-{
- if (size != 0 && nmemb > ULONG_MAX / size)
- return NULL;
-
- if (size * nmemb <= PAGE_SIZE)
- return kcalloc(nmemb, size, GFP_KERNEL);
-
- return __vmalloc(size * nmemb,
- GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
-}
-
-/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
-static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
-{
- if (size != 0 && nmemb > ULONG_MAX / size)
- return NULL;
-
- if (size * nmemb <= PAGE_SIZE)
- return kmalloc(nmemb * size, GFP_KERNEL);
-
- return __vmalloc(size * nmemb,
- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
-}
-
-static __inline void drm_free_large(void *ptr)
-{
- if (!is_vmalloc_addr(ptr))
- return kfree(ptr);
-
- vfree(ptr);
-}
+#include "drm_mem_util.h"
/*@}*/
#endif /* __KERNEL__ */
diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h
new file mode 100644
index 0000000..6bd325f
--- /dev/null
+++ b/include/drm/drm_mem_util.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2008 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Jesse Barnes <jbarnes@virtuousgeek.org>
+ *
+ */
+#ifndef _DRM_MEM_UTIL_H_
+#define _DRM_MEM_UTIL_H_
+
+#include <linux/vmalloc.h>
+
+static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
+{
+ if (size != 0 && nmemb > ULONG_MAX / size)
+ return NULL;
+
+ if (size * nmemb <= PAGE_SIZE)
+ return kcalloc(nmemb, size, GFP_KERNEL);
+
+ return __vmalloc(size * nmemb,
+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
+}
+
+/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
+static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
+{
+ if (size != 0 && nmemb > ULONG_MAX / size)
+ return NULL;
+
+ if (size * nmemb <= PAGE_SIZE)
+ return kmalloc(nmemb * size, GFP_KERNEL);
+
+ return __vmalloc(size * nmemb,
+ GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
+}
+
+static __inline void drm_free_large(void *ptr)
+{
+ if (!is_vmalloc_addr(ptr))
+ return kfree(ptr);
+
+ vfree(ptr);
+}
+
+#endif
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 7fdac3d..cc02b57 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -116,7 +116,6 @@ struct ttm_backend {
struct ttm_backend_func *func;
};
-#define TTM_PAGE_FLAG_VMALLOC (1 << 0)
#define TTM_PAGE_FLAG_USER (1 << 1)
#define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)
#define TTM_PAGE_FLAG_WRITE (1 << 3)
--
1.6.6
[-- Attachment #2: Type: text/plain, Size: 345 bytes --]
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
[-- Attachment #3: Type: text/plain, Size: 161 bytes --]
--
_______________________________________________
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] drm/ttm: use drm calloc large and free large
2010-03-09 6:33 [PATCH] drm/ttm: use drm calloc large and free large Dave Airlie
@ 2010-03-16 12:58 ` Thomas Hellstrom
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Hellstrom @ 2010-03-16 12:58 UTC (permalink / raw)
To: Dave Airlie; +Cc: dri-devel
Dave Airlie wrote:
> Now that the drm core can do this, lets just use it, split the code out
> so TTM doesn't have to drag all of drmP.h in.
>
>
Acked-by: Thomas Hellstrom <thellstrom@vmware.com>
It's funny, though. The original code used code similar to
"is_vmalloc_addr()" now in linux/mm.h to distinguish between kmalloc /
vmalloc pointers. That code was deemed 'too ugly to live' by Arjan. Oh
well, I guess things change over time....
/Thomas
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
> drivers/gpu/drm/ttm/ttm_tt.c | 23 ++------------
> include/drm/drmP.h | 34 +--------------------
> include/drm/drm_mem_util.h | 65 +++++++++++++++++++++++++++++++++++++++
> include/drm/ttm/ttm_bo_driver.h | 1 -
> 4 files changed, 69 insertions(+), 54 deletions(-)
> create mode 100644 include/drm/drm_mem_util.h
>
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index a759170..bab6cd8 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -28,13 +28,13 @@
> * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
> */
>
> -#include <linux/vmalloc.h>
> #include <linux/sched.h>
> #include <linux/highmem.h>
> #include <linux/pagemap.h>
> #include <linux/file.h>
> #include <linux/swap.h>
> #include "drm_cache.h"
> +#include "drm_mem_util.h"
> #include "ttm/ttm_module.h"
> #include "ttm/ttm_bo_driver.h"
> #include "ttm/ttm_placement.h"
> @@ -43,32 +43,15 @@ static int ttm_tt_swapin(struct ttm_tt *ttm);
>
> /**
> * Allocates storage for pointers to the pages that back the ttm.
> - *
> - * Uses kmalloc if possible. Otherwise falls back to vmalloc.
> */
> static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
> {
> - unsigned long size = ttm->num_pages * sizeof(*ttm->pages);
> - ttm->pages = NULL;
> -
> - if (size <= PAGE_SIZE)
> - ttm->pages = kzalloc(size, GFP_KERNEL);
> -
> - if (!ttm->pages) {
> - ttm->pages = vmalloc_user(size);
> - if (ttm->pages)
> - ttm->page_flags |= TTM_PAGE_FLAG_VMALLOC;
> - }
> + ttm->pages = drm_calloc_large(ttm->num_pages, sizeof(*ttm->pages));
> }
>
> static void ttm_tt_free_page_directory(struct ttm_tt *ttm)
> {
> - if (ttm->page_flags & TTM_PAGE_FLAG_VMALLOC) {
> - vfree(ttm->pages);
> - ttm->page_flags &= ~TTM_PAGE_FLAG_VMALLOC;
> - } else {
> - kfree(ttm->pages);
> - }
> + drm_free_large(ttm->pages);
> ttm->pages = NULL;
> }
>
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 829e524..22e60af 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -1595,39 +1595,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)
> {
> }
>
> -
> -static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
> -{
> - if (size != 0 && nmemb > ULONG_MAX / size)
> - return NULL;
> -
> - if (size * nmemb <= PAGE_SIZE)
> - return kcalloc(nmemb, size, GFP_KERNEL);
> -
> - return __vmalloc(size * nmemb,
> - GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
> -}
> -
> -/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
> -static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
> -{
> - if (size != 0 && nmemb > ULONG_MAX / size)
> - return NULL;
> -
> - if (size * nmemb <= PAGE_SIZE)
> - return kmalloc(nmemb * size, GFP_KERNEL);
> -
> - return __vmalloc(size * nmemb,
> - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
> -}
> -
> -static __inline void drm_free_large(void *ptr)
> -{
> - if (!is_vmalloc_addr(ptr))
> - return kfree(ptr);
> -
> - vfree(ptr);
> -}
> +#include "drm_mem_util.h"
> /*@}*/
>
> #endif /* __KERNEL__ */
> diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h
> new file mode 100644
> index 0000000..6bd325f
> --- /dev/null
> +++ b/include/drm/drm_mem_util.h
> @@ -0,0 +1,65 @@
> +/*
> + * Copyright © 2008 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + *
> + * Authors:
> + * Jesse Barnes <jbarnes@virtuousgeek.org>
> + *
> + */
> +#ifndef _DRM_MEM_UTIL_H_
> +#define _DRM_MEM_UTIL_H_
> +
> +#include <linux/vmalloc.h>
> +
> +static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
> +{
> + if (size != 0 && nmemb > ULONG_MAX / size)
> + return NULL;
> +
> + if (size * nmemb <= PAGE_SIZE)
> + return kcalloc(nmemb, size, GFP_KERNEL);
> +
> + return __vmalloc(size * nmemb,
> + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
> +}
> +
> +/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
> +static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
> +{
> + if (size != 0 && nmemb > ULONG_MAX / size)
> + return NULL;
> +
> + if (size * nmemb <= PAGE_SIZE)
> + return kmalloc(nmemb * size, GFP_KERNEL);
> +
> + return __vmalloc(size * nmemb,
> + GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
> +}
> +
> +static __inline void drm_free_large(void *ptr)
> +{
> + if (!is_vmalloc_addr(ptr))
> + return kfree(ptr);
> +
> + vfree(ptr);
> +}
> +
> +#endif
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7fdac3d..cc02b57 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -116,7 +116,6 @@ struct ttm_backend {
> struct ttm_backend_func *func;
> };
>
> -#define TTM_PAGE_FLAG_VMALLOC (1 << 0)
> #define TTM_PAGE_FLAG_USER (1 << 1)
> #define TTM_PAGE_FLAG_USER_DIRTY (1 << 2)
> #define TTM_PAGE_FLAG_WRITE (1 << 3)
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> ------------------------------------------------------------------------
>
> --
> _______________________________________________
> Dri-devel mailing list
> Dri-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dri-devel
>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-16 12:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-09 6:33 [PATCH] drm/ttm: use drm calloc large and free large Dave Airlie
2010-03-16 12:58 ` Thomas Hellstrom
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.