Misc TTM patches for drm-next
Subsystems (3)
cover Misc TTM patches for drm-next
The patch series mainly contains minor optimizations and documentation, except for patch 5/6 which is really a bugfix, but the synchronization bug shouldn't affect x86 processors.
PATCH 1/6 drm/ttm: Documentation update
Remove an obsolete comment about mm nodes.
Document the new bo range manager interface.
--- drivers/gpu/drm/ttm/ttm_bo.c | 8 ---- include/drm/ttm/ttm_bo_driver.h | 79 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 13 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -8
@@ -27,14 +27,6 @@/* * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> */ -/* Notes: -* -* We store bo pointer in drm_mm_node struct so we know which bo own a -* specific node. There is no protection on the pointer, thus to make -* sure things don't go berserk you have to access this pointer while -* holding the global lru lock and make sure anytime you free a node you -* reset the pointer to NULL. -*/ #include "ttm/ttm_module.h" #include "ttm/ttm_bo_driver.h"
include/drm/ttm/ttm_bo_driver.h +74 -5
102 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 2/6 drm/ttm: Use private locks for the default bo range manager
Searching for a free block in the range manager may in some situations be a lenghty operation, and we want to avoid holding the global lru lock during that time. Instead use a per-manager spinlock.
This leaves the global lru lock for quick lru list and swap list manipulation only, including list manipulation associated with reserving buffer objects.
--- drivers/gpu/drm/ttm/ttm_bo_manager.c | 81 +++++++++++++++++++--------------- 1 files changed, 45 insertions(+), 36 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_manager.c +45 -36
@@ -1,6 +1,6 @@/************************************************************************** * -* Copyright (c) 2007-2009 VMware, Inc., Palo Alto, CA., USA +* Copyright (c) 2007-2010 VMware, Inc., Palo Alto, CA., USA * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a
@@ -31,20 +31,29 @@#include "ttm/ttm_module.h" #include "ttm/ttm_bo_driver.h" #include "ttm/ttm_placement.h" -#include <linux/jiffies.h> +#include "drm_mm.h" #include <linux/slab.h> -#include <linux/sched.h> -#include <linux/mm.h> -#include <linux/file.h> +#include <linux/spinlock.h> #include <linux/module.h> +/** +* Currently we use a spinlock for the lock, but a mutex *may* be +* more appropriate to reduce scheduling latency if the range manager +* ends up with very fragmented allocation patterns. +*/ + +struct ttm_range_manager { +struct drm_mm mm; +spinlock_t lock; +}; +static int ttm_bo_man_get_node (struct ttm_mem_type_manager *man,struct ttm_buffer_object *bo,struct ttm_placement *placement,struct ttm_mem_reg *mem) { -struct ttm_bo_global *glob = man->bdev->glob; -struct drm_mm *mm = man->priv; +struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; +struct drm_mm *mm = &rman->mm;struct drm_mm_node *node =NULL ;unsigned long lpfn;int ret;
@@ -57,19 +66,19 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,if (unlikely (ret))return ret; -spin_lock (&glob->lru_lock); +spin_lock (&rman->lock); node =drm_mm_search_free_in_range (mm, mem->num_pages, mem->page_alignment, placement->fpfn, lpfn,1 );if (unlikely (node ==NULL )) { -spin_unlock (&glob->lru_lock); +spin_unlock (&rman->lock);return 0 ; } node =drm_mm_get_block_atomic_range (node, mem->num_pages, - mem->page_alignment, - placement->fpfn, - lpfn); -spin_unlock (&glob->lru_lock); + mem->page_alignment, + placement->fpfn, + lpfn); +spin_unlock (&rman->lock); }while (node ==NULL ); mem->mm_node = node;
@@ -80,12 +89,12 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,static void ttm_bo_man_put_node (struct ttm_mem_type_manager *man,struct ttm_mem_reg *mem) { -struct ttm_bo_global *glob = man->bdev->glob; +struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;if (mem->mm_node) { -spin_lock (&glob->lru_lock); +spin_lock (&rman->lock);drm_mm_put_block (mem->mm_node); -spin_unlock (&glob->lru_lock); +spin_unlock (&rman->lock); mem->mm_node =NULL ; } }
@@ -93,49 +102,49 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,static int ttm_bo_man_init (struct ttm_mem_type_manager *man,unsigned long p_size) { -struct drm_mm *mm; +struct ttm_range_manager *rman;int ret; - mm =kzalloc (sizeof (*mm),GFP_KERNEL ); -if (!mm) + rman =kzalloc (sizeof (*rman),GFP_KERNEL ); +if (!rman)return -ENOMEM ; - ret =drm_mm_init (mm,0 , p_size); + ret =drm_mm_init (&rman->mm,0 , p_size);if (ret) { -kfree (mm); +kfree (rman);return ret; } - man->priv = mm; +spin_lock_init (&rman->lock); + man->priv = rman;return 0 ; }static int ttm_bo_man_takedown (struct ttm_mem_type_manager *man) { -struct ttm_bo_global *glob = man->bdev->glob; -struct drm_mm *mm = man->priv; -int ret =0 ; +struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; +struct drm_mm *mm = &rman->mm; -spin_lock (&glob->lru_lock); +spin_lock (&rman->lock);if (drm_mm_clean (mm)) {drm_mm_takedown (mm); -kfree (mm); +spin_unlock (&rman->lock); +kfree (rman); man->priv =NULL ; - }else - ret = -EBUSY ; -spin_unlock (&glob->lru_lock); -return ret; +return 0 ; + } +spin_unlock (&rman->lock); +return -EBUSY ; }static void ttm_bo_man_debug (struct ttm_mem_type_manager *man,const char *prefix) { -struct ttm_bo_global *glob = man->bdev->glob; -struct drm_mm *mm = man->priv; +struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv; -spin_lock (&glob->lru_lock); -drm_mm_debug_table (mm, prefix); -spin_unlock (&glob->lru_lock); +spin_lock (&rman->lock); +drm_mm_debug_table (&rman->mm, prefix); +spin_unlock (&rman->lock); }const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
Signature · 1 line
1.6.2.5
PATCH 3/6 drm/ttm: Remove pointless list_empty check
--- drivers/gpu/drm/ttm/ttm_bo.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -7
@@ -814,7 +814,6 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, bool no_wait_gpu) {struct ttm_bo_device *bdev = bo->bdev; -struct ttm_bo_global *glob = bdev->glob;struct ttm_mem_type_manager *man = &bdev->man[mem_type];int ret;
@@ -824,12 +823,6 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,return ret;if (mem->mm_node)break ; -spin_lock (&glob->lru_lock); -if (list_empty (&man->lru)) { -spin_unlock (&glob->lru_lock); -break ; - } -spin_unlock (&glob->lru_lock); ret =ttm_mem_evict_first (bdev, mem_type, interruptible, no_wait_reserve, no_wait_gpu);if (unlikely (ret !=0 ))
Signature · 1 line
1.6.2.5
PATCH 4/6 drm/ttm: Remove mm init error printouts and checks
Replace with BUG_ON(). These error messages remained from the time when TTM was initialized from user-space. Nowadays hitting one of those is really a kernel bug.
--- drivers/gpu/drm/ttm/ttm_bo.c | 20 ++------------------ 1 files changed, 2 insertions(+), 18 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -18
@@ -1354,18 +1354,9 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,int ret = -EINVAL ;struct ttm_mem_type_manager *man; -if (type >=TTM_NUM_MEM_TYPES ) { - printk(KERN_ERR TTM_PFX "Illegal memory type %d\n", type); -return ret; - } - +BUG_ON (type >=TTM_NUM_MEM_TYPES ); man = &bdev->man[type]; -if (man->has_type) { - printk(KERN_ERR TTM_PFX -"Memory manager already initialized for type %d\n" , - type); -return ret; - } +BUG_ON (man->has_type); ret = bdev->driver->init_mem_type (bdev, type, man);if (ret)
@@ -1374,13 +1365,6 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, ret =0 ;if (type !=TTM_PL_SYSTEM ) { -if (!p_size) { - printk(KERN_ERR TTM_PFX -"Zero size memory manager type %d\n" , - type); -return ret; - } - ret = (*man->func->init)(man, p_size);if (ret)return ret;
Signature · 1 line
1.6.2.5
PATCH 5/6 drm/ttm: Add a barrier when unreserving
Since we're doing this outside of a spinlock to provide the necessary barriers, add an explicit barrier.
--- drivers/gpu/drm/ttm/ttm_bo.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +6 -0
@@ -37,6 +37,7 @@#include <linux/mm.h> #include <linux/file.h> #include <linux/module.h> +#include <asm/atomic.h> #define TTM_ASSERT_LOCKED (param) #define TTM_DEBUG(fmt, arg...)
@@ -444,6 +445,11 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)ttm_bo_mem_put (bo, &bo->mem);atomic_set (&bo->reserved,0 ); + +/* +* Make processes trying to reserve really pick it up. +*/ +smp_mb__after_atomic_dec ();wake_up_all (&bo->event_queue); }
Signature · 1 line
1.6.2.5
PATCH 6/6 drm/ttm: remove failed ttm binding error printout
The driver (for example vmwgfx) may want to silently deal with the error itself.
--- drivers/gpu/drm/ttm/ttm_tt.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +1 -3
@@ -440,10 +440,8 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem)return ret; ret = be->func->bind (be, bo_mem); -if (ret) { - printk(KERN_ERR TTM_PFX "Couldn't bind backend.\n"); +if (unlikely (ret !=0 ))return ret; - } ttm->state = tt_bound;
Signature · 1 line
1.6.2.5