[PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-11-06 Thread Maarten Lankhorst
Op 25-10-12 09:42, Thomas Hellstrom schreef:
> On 10/12/2012 04:58 PM, Maarten Lankhorst wrote:
>> Signed-off-by: Maarten Lankhorst 
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
>>   include/drm/ttm/ttm_bo_api.h |   14 ++
>>   2 files changed, 20 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index be1148e..d9d8541 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
>> bool interruptible)
>>   {
>>   if (interruptible) {
>>   return wait_event_interruptible(bo->event_queue,
>> -   atomic_read(>reserved) == 0);
>> +   !ttm_bo_is_reserved(bo));
>>   } else {
>> -wait_event(bo->event_queue, atomic_read(>reserved) == 0);
>> +wait_event(bo->event_queue, !ttm_bo_is_reserved(bo));
>>   return 0;
>>   }
>>   }
>> @@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>>   struct ttm_bo_device *bdev = bo->bdev;
>>   struct ttm_mem_type_manager *man;
>>   -BUG_ON(!atomic_read(>reserved));
>> +BUG_ON(!ttm_bo_is_reserved(bo));
>> if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>>   @@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, 
>> bool interruptible,
>>   goto out;
>>   }
>>   -BUG_ON(!atomic_read(>reserved));
>> +BUG_ON(!ttm_bo_is_reserved(bo));
>> evict_mem = bo->mem;
>>   evict_mem.mm_node = NULL;
>> @@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
>>   struct ttm_mem_reg mem;
>>   struct ttm_bo_device *bdev = bo->bdev;
>>   -BUG_ON(!atomic_read(>reserved));
>> +BUG_ON(!ttm_bo_is_reserved(bo));
>> /*
>>* FIXME: It's possible to pipeline buffer moves.
>> @@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>>   {
>>   int ret;
>>   -BUG_ON(!atomic_read(>reserved));
>> +BUG_ON(!ttm_bo_is_reserved(bo));
>>   /* Check that range is valid */
>>   if (placement->lpfn || placement->fpfn)
>>   if (placement->fpfn > placement->lpfn ||
>> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
>> index 9654451..1d71f6b 100644
>> --- a/include/drm/ttm/ttm_bo_api.h
>> +++ b/include/drm/ttm/ttm_bo_api.h
>> @@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
>> struct file *filp,
>> extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>>   +/**
>> + * ttm_bo_is_reserved - return an indication if a ttm buffer object is 
>> reserved
>> + *
>> + * @bo: The buffer object to check.
>> + *
>> + * This function returns an indication if a bo is reserved or not, and 
>> should
>> + * only be used to print an error when it is not from incorrect api usage, 
>> since
>> + * there's no guarantee that it is the caller that is holding the 
>> reservation.
>> + */
>> +static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
>> +{
>> +return atomic_read(>reserved);
>> +}
>> +
>>   #endif
> This looks good, although for clarity we should add in the comments that
> if the caller is holding the reservation, the function is guaranteed to 
> return true.
>
> Otherwise
> Reviewed-by: Thomas Hellstrom 

Unless you use lockdep, you can't say with 100% certainty if the CALLER is 
holding it or not. :-)
But lockdep can actually check if that's the case with 
lockdep_is_held(>reservation_lock);
which iterates over all locks held by the current task.

~Maarten

Updated version with a comment about return value in ttm_bo_is_reserved:

drm/ttm: Add ttm_bo_is_reserved function

Signed-off-by: Maarten Lankhorst 
Reviewed-by: Thomas Hellstrom 

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 2b3f69b..82e2633 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -162,9 +162,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
bool interruptible)
 {
if (interruptible) {
return wait_event_interruptible(bo->event_queue,
-  atomic_read(>reserved) == 0);
+  !ttm_bo_is_reserved(bo));
} else {
-   wait_event(bo->event_queue, atomic_read(>reserved) == 0);
+   wait_event(bo->event_queue, !ttm_bo_is_reserved(bo));
return 0;
}
 }
@@ -175,7 +175,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
struct ttm_bo_device *bdev = bo->bdev;
struct ttm_mem_type_manager *man;

-   BUG_ON(!atomic_read(>reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));

if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {

@@ -756,7 +756,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool 
interruptible,
goto out;
}

-   

Re: [PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-11-06 Thread Maarten Lankhorst
Op 25-10-12 09:42, Thomas Hellstrom schreef:
 On 10/12/2012 04:58 PM, Maarten Lankhorst wrote:
 Signed-off-by: Maarten Lankhorst maarten.lankho...@canonical.com
 ---
   drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
   include/drm/ttm/ttm_bo_api.h |   14 ++
   2 files changed, 20 insertions(+), 6 deletions(-)

 diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
 index be1148e..d9d8541 100644
 --- a/drivers/gpu/drm/ttm/ttm_bo.c
 +++ b/drivers/gpu/drm/ttm/ttm_bo.c
 @@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
 bool interruptible)
   {
   if (interruptible) {
   return wait_event_interruptible(bo-event_queue,
 -   atomic_read(bo-reserved) == 0);
 +   !ttm_bo_is_reserved(bo));
   } else {
 -wait_event(bo-event_queue, atomic_read(bo-reserved) == 0);
 +wait_event(bo-event_queue, !ttm_bo_is_reserved(bo));
   return 0;
   }
   }
 @@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
   struct ttm_bo_device *bdev = bo-bdev;
   struct ttm_mem_type_manager *man;
   -BUG_ON(!atomic_read(bo-reserved));
 +BUG_ON(!ttm_bo_is_reserved(bo));
 if (!(bo-mem.placement  TTM_PL_FLAG_NO_EVICT)) {
   @@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, 
 bool interruptible,
   goto out;
   }
   -BUG_ON(!atomic_read(bo-reserved));
 +BUG_ON(!ttm_bo_is_reserved(bo));
 evict_mem = bo-mem;
   evict_mem.mm_node = NULL;
 @@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
   struct ttm_mem_reg mem;
   struct ttm_bo_device *bdev = bo-bdev;
   -BUG_ON(!atomic_read(bo-reserved));
 +BUG_ON(!ttm_bo_is_reserved(bo));
 /*
* FIXME: It's possible to pipeline buffer moves.
 @@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
   {
   int ret;
   -BUG_ON(!atomic_read(bo-reserved));
 +BUG_ON(!ttm_bo_is_reserved(bo));
   /* Check that range is valid */
   if (placement-lpfn || placement-fpfn)
   if (placement-fpfn  placement-lpfn ||
 diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
 index 9654451..1d71f6b 100644
 --- a/include/drm/ttm/ttm_bo_api.h
 +++ b/include/drm/ttm/ttm_bo_api.h
 @@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
 struct file *filp,
 extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
   +/**
 + * ttm_bo_is_reserved - return an indication if a ttm buffer object is 
 reserved
 + *
 + * @bo: The buffer object to check.
 + *
 + * This function returns an indication if a bo is reserved or not, and 
 should
 + * only be used to print an error when it is not from incorrect api usage, 
 since
 + * there's no guarantee that it is the caller that is holding the 
 reservation.
 + */
 +static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
 +{
 +return atomic_read(bo-reserved);
 +}
 +
   #endif
 This looks good, although for clarity we should add in the comments that
 if the caller is holding the reservation, the function is guaranteed to 
 return true.

 Otherwise
 Reviewed-by: Thomas Hellstrom thellst...@vmware.com

Unless you use lockdep, you can't say with 100% certainty if the CALLER is 
holding it or not. :-)
But lockdep can actually check if that's the case with 
lockdep_is_held(ttm-reservation_lock);
which iterates over all locks held by the current task.

~Maarten

Updated version with a comment about return value in ttm_bo_is_reserved:

drm/ttm: Add ttm_bo_is_reserved function

Signed-off-by: Maarten Lankhorst maarten.lankho...@canonical.com
Reviewed-by: Thomas Hellstrom thellst...@vmware.com

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 2b3f69b..82e2633 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -162,9 +162,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
bool interruptible)
 {
if (interruptible) {
return wait_event_interruptible(bo-event_queue,
-  atomic_read(bo-reserved) == 0);
+  !ttm_bo_is_reserved(bo));
} else {
-   wait_event(bo-event_queue, atomic_read(bo-reserved) == 0);
+   wait_event(bo-event_queue, !ttm_bo_is_reserved(bo));
return 0;
}
 }
@@ -175,7 +175,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
struct ttm_bo_device *bdev = bo-bdev;
struct ttm_mem_type_manager *man;
 
-   BUG_ON(!atomic_read(bo-reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
 
if (!(bo-mem.placement  TTM_PL_FLAG_NO_EVICT)) {
 
@@ -756,7 +756,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool 
interruptible,
goto out;
}
 
-   BUG_ON(!atomic_read(bo-reserved));
+   

[PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-10-25 Thread Thomas Hellstrom
On 10/12/2012 04:58 PM, Maarten Lankhorst wrote:
> Signed-off-by: Maarten Lankhorst 
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
>   include/drm/ttm/ttm_bo_api.h |   14 ++
>   2 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index be1148e..d9d8541 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
> bool interruptible)
>   {
>   if (interruptible) {
>   return wait_event_interruptible(bo->event_queue,
> -atomic_read(>reserved) == 0);
> +!ttm_bo_is_reserved(bo));
>   } else {
> - wait_event(bo->event_queue, atomic_read(>reserved) == 0);
> + wait_event(bo->event_queue, !ttm_bo_is_reserved(bo));
>   return 0;
>   }
>   }
> @@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
>   struct ttm_bo_device *bdev = bo->bdev;
>   struct ttm_mem_type_manager *man;
>   
> - BUG_ON(!atomic_read(>reserved));
> + BUG_ON(!ttm_bo_is_reserved(bo));
>   
>   if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {
>   
> @@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, 
> bool interruptible,
>   goto out;
>   }
>   
> - BUG_ON(!atomic_read(>reserved));
> + BUG_ON(!ttm_bo_is_reserved(bo));
>   
>   evict_mem = bo->mem;
>   evict_mem.mm_node = NULL;
> @@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
>   struct ttm_mem_reg mem;
>   struct ttm_bo_device *bdev = bo->bdev;
>   
> - BUG_ON(!atomic_read(>reserved));
> + BUG_ON(!ttm_bo_is_reserved(bo));
>   
>   /*
>* FIXME: It's possible to pipeline buffer moves.
> @@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
>   {
>   int ret;
>   
> - BUG_ON(!atomic_read(>reserved));
> + BUG_ON(!ttm_bo_is_reserved(bo));
>   /* Check that range is valid */
>   if (placement->lpfn || placement->fpfn)
>   if (placement->fpfn > placement->lpfn ||
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 9654451..1d71f6b 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
> struct file *filp,
>   
>   extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
>   
> +/**
> + * ttm_bo_is_reserved - return an indication if a ttm buffer object is 
> reserved
> + *
> + * @bo: The buffer object to check.
> + *
> + * This function returns an indication if a bo is reserved or not, and should
> + * only be used to print an error when it is not from incorrect api usage, 
> since
> + * there's no guarantee that it is the caller that is holding the 
> reservation.
> + */
> +static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
> +{
> + return atomic_read(>reserved);
> +}
> +
>   #endif
This looks good, although for clarity we should add in the comments that
if the caller is holding the reservation, the function is guaranteed to 
return true.

Otherwise
Reviewed-by: Thomas Hellstrom 
>
> ___
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel





Re: [PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-10-25 Thread Thomas Hellstrom

On 10/12/2012 04:58 PM, Maarten Lankhorst wrote:

Signed-off-by: Maarten Lankhorst maarten.lankho...@canonical.com
---
  drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
  include/drm/ttm/ttm_bo_api.h |   14 ++
  2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index be1148e..d9d8541 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
bool interruptible)
  {
if (interruptible) {
return wait_event_interruptible(bo-event_queue,
-  atomic_read(bo-reserved) == 0);
+  !ttm_bo_is_reserved(bo));
} else {
-   wait_event(bo-event_queue, atomic_read(bo-reserved) == 0);
+   wait_event(bo-event_queue, !ttm_bo_is_reserved(bo));
return 0;
}
  }
@@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
struct ttm_bo_device *bdev = bo-bdev;
struct ttm_mem_type_manager *man;
  
-	BUG_ON(!atomic_read(bo-reserved));

+   BUG_ON(!ttm_bo_is_reserved(bo));
  
  	if (!(bo-mem.placement  TTM_PL_FLAG_NO_EVICT)) {
  
@@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible,

goto out;
}
  
-	BUG_ON(!atomic_read(bo-reserved));

+   BUG_ON(!ttm_bo_is_reserved(bo));
  
  	evict_mem = bo-mem;

evict_mem.mm_node = NULL;
@@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
struct ttm_mem_reg mem;
struct ttm_bo_device *bdev = bo-bdev;
  
-	BUG_ON(!atomic_read(bo-reserved));

+   BUG_ON(!ttm_bo_is_reserved(bo));
  
  	/*

 * FIXME: It's possible to pipeline buffer moves.
@@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
  {
int ret;
  
-	BUG_ON(!atomic_read(bo-reserved));

+   BUG_ON(!ttm_bo_is_reserved(bo));
/* Check that range is valid */
if (placement-lpfn || placement-fpfn)
if (placement-fpfn  placement-lpfn ||
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 9654451..1d71f6b 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
struct file *filp,
  
  extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
  
+/**

+ * ttm_bo_is_reserved - return an indication if a ttm buffer object is reserved
+ *
+ * @bo: The buffer object to check.
+ *
+ * This function returns an indication if a bo is reserved or not, and should
+ * only be used to print an error when it is not from incorrect api usage, 
since
+ * there's no guarantee that it is the caller that is holding the reservation.
+ */
+static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
+{
+   return atomic_read(bo-reserved);
+}
+
  #endif

This looks good, although for clarity we should add in the comments that
if the caller is holding the reservation, the function is guaranteed to 
return true.


Otherwise
Reviewed-by: Thomas Hellstrom thellst...@vmware.com


___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel




___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-10-12 Thread Maarten Lankhorst
Signed-off-by: Maarten Lankhorst 
---
 drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
 include/drm/ttm/ttm_bo_api.h |   14 ++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index be1148e..d9d8541 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
bool interruptible)
 {
if (interruptible) {
return wait_event_interruptible(bo->event_queue,
-  atomic_read(>reserved) == 0);
+  !ttm_bo_is_reserved(bo));
} else {
-   wait_event(bo->event_queue, atomic_read(>reserved) == 0);
+   wait_event(bo->event_queue, !ttm_bo_is_reserved(bo));
return 0;
}
 }
@@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
struct ttm_bo_device *bdev = bo->bdev;
struct ttm_mem_type_manager *man;

-   BUG_ON(!atomic_read(>reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));

if (!(bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) {

@@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool 
interruptible,
goto out;
}

-   BUG_ON(!atomic_read(>reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));

evict_mem = bo->mem;
evict_mem.mm_node = NULL;
@@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
struct ttm_mem_reg mem;
struct ttm_bo_device *bdev = bo->bdev;

-   BUG_ON(!atomic_read(>reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));

/*
 * FIXME: It's possible to pipeline buffer moves.
@@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 {
int ret;

-   BUG_ON(!atomic_read(>reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
/* Check that range is valid */
if (placement->lpfn || placement->fpfn)
if (placement->fpfn > placement->lpfn ||
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 9654451..1d71f6b 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
struct file *filp,

 extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);

+/**
+ * ttm_bo_is_reserved - return an indication if a ttm buffer object is reserved
+ *
+ * @bo: The buffer object to check.
+ *
+ * This function returns an indication if a bo is reserved or not, and should
+ * only be used to print an error when it is not from incorrect api usage, 
since
+ * there's no guarantee that it is the caller that is holding the reservation.
+ */
+static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
+{
+   return atomic_read(>reserved);
+}
+
 #endif



[PATCH 1/3] drm/ttm: add ttm_bo_is_reserved

2012-10-12 Thread Maarten Lankhorst
Signed-off-by: Maarten Lankhorst maarten.lankho...@canonical.com
---
 drivers/gpu/drm/ttm/ttm_bo.c |   12 ++--
 include/drm/ttm/ttm_bo_api.h |   14 ++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index be1148e..d9d8541 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -161,9 +161,9 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, 
bool interruptible)
 {
if (interruptible) {
return wait_event_interruptible(bo-event_queue,
-  atomic_read(bo-reserved) == 0);
+  !ttm_bo_is_reserved(bo));
} else {
-   wait_event(bo-event_queue, atomic_read(bo-reserved) == 0);
+   wait_event(bo-event_queue, !ttm_bo_is_reserved(bo));
return 0;
}
 }
@@ -174,7 +174,7 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
struct ttm_bo_device *bdev = bo-bdev;
struct ttm_mem_type_manager *man;
 
-   BUG_ON(!atomic_read(bo-reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
 
if (!(bo-mem.placement  TTM_PL_FLAG_NO_EVICT)) {
 
@@ -748,7 +748,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool 
interruptible,
goto out;
}
 
-   BUG_ON(!atomic_read(bo-reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
 
evict_mem = bo-mem;
evict_mem.mm_node = NULL;
@@ -1058,7 +1058,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
struct ttm_mem_reg mem;
struct ttm_bo_device *bdev = bo-bdev;
 
-   BUG_ON(!atomic_read(bo-reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
 
/*
 * FIXME: It's possible to pipeline buffer moves.
@@ -1115,7 +1115,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 {
int ret;
 
-   BUG_ON(!atomic_read(bo-reserved));
+   BUG_ON(!ttm_bo_is_reserved(bo));
/* Check that range is valid */
if (placement-lpfn || placement-fpfn)
if (placement-fpfn  placement-lpfn ||
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 9654451..1d71f6b 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -705,4 +705,18 @@ extern ssize_t ttm_bo_io(struct ttm_bo_device *bdev, 
struct file *filp,
 
 extern void ttm_bo_swapout_all(struct ttm_bo_device *bdev);
 
+/**
+ * ttm_bo_is_reserved - return an indication if a ttm buffer object is reserved
+ *
+ * @bo: The buffer object to check.
+ *
+ * This function returns an indication if a bo is reserved or not, and should
+ * only be used to print an error when it is not from incorrect api usage, 
since
+ * there's no guarantee that it is the caller that is holding the reservation.
+ */
+static inline bool ttm_bo_is_reserved(struct ttm_buffer_object *bo)
+{
+   return atomic_read(bo-reserved);
+}
+
 #endif

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel