Skip to contentSkip to conversation

drm/etnaviv: remove unnecessary local irq disable

PATCH In review Lucas Stach 2 participants 6 messages Dec 17, 2018

Subsystems (2)
lore
Share & tools
lore

Lucas Stach

author maintainer
#0 lore raw

PATCH 1/3 drm/etnaviv: remove unnecessary local irq disable

The only event function that is called from IRQ context is event_free, which is already using atomic bitmap operations, so we can avoid taking the event spinlock in this function completely. As other the other functions still using the event spinlock are all called from normal process context, we can avoid disabling IRQs while holding the spinlock.

---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -13
index 8fbe77cae810..293e248e1b29 100644
@@ -976,7 +976,6 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m)
 
 void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
 {
-	unsigned long flags;
 	unsigned int i = 0;
 
 	dev_err(gpu->dev, "recover hung GPU!\n");
@@ -989,11 +988,11 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
 	etnaviv_hw_reset(gpu);
 
 	/* complete all events, the GPU won't do it after the reset */
-	spin_lock_irqsave(&gpu->event_spinlock, flags);
+	spin_lock(&gpu->event_spinlock);
 	for_each_set_bit_from(i, gpu->event_bitmap, ETNA_NR_EVENTS)
 		complete(&gpu->event_free);
 	bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS);
-	spin_unlock_irqrestore(&gpu->event_spinlock, flags);
+	spin_unlock(&gpu->event_spinlock);
 
 	etnaviv_gpu_hw_init(gpu);
 	gpu->lastctx = NULL;
@@ -1083,7 +1082,7 @@ static inline bool fence_after(u32 a, u32 b)
 static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
 	unsigned int *events)
 {
-	unsigned long flags, timeout = msecs_to_jiffies(10 * 10000);
+	unsigned long timeout = msecs_to_jiffies(10 * 10000);
 	unsigned i, acquired = 0;
 
 	for (i = 0; i < nr_events; i++) {
@@ -1100,7 +1099,7 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
 		timeout = ret;
 	}
 
-	spin_lock_irqsave(&gpu->event_spinlock, flags);
+	spin_lock(&gpu->event_spinlock);
 
 	for (i = 0; i < nr_events; i++) {
 		int event = find_first_zero_bit(gpu->event_bitmap, ETNA_NR_EVENTS);
@@ -1110,7 +1109,7 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
 		set_bit(event, gpu->event_bitmap);
 	}
 
-	spin_unlock_irqrestore(&gpu->event_spinlock, flags);
+	spin_unlock(&gpu->event_spinlock);
 
 	return 0;
 
@@ -1123,18 +1122,11 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
 
 static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&gpu->event_spinlock, flags);
-
 	if (!test_bit(event, gpu->event_bitmap)) {
 		dev_warn(gpu->dev, "event %u is already marked as free",
 			 event);
-		spin_unlock_irqrestore(&gpu->event_spinlock, flags);
 	} else {
 		clear_bit(event, gpu->event_bitmap);
-		spin_unlock_irqrestore(&gpu->event_spinlock, flags);
-
 		complete(&gpu->event_free);
 	}
 }
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#1 lore raw

PATCH 2/3 drm/etnaviv: replace header include with forward declaration

The etnaviv_gpu header only needs to know about the pointer types, so replace by a forward declaration and only include the headers where needed.

---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 2 ++
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +2 -0
index 293e248e1b29..aefb17e39ad0 100644
@@ -3,10 +3,12 @@
  * Copyright (C) 2015-2018 Etnaviv Project
  */
 
+#include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/dma-fence.h>
 #include <linux/moduleparam.h>
 #include <linux/of_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/thermal.h>
 
 #include "etnaviv_cmdbuf.h"
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +2 -3
index 74758f21e5d3..56b6a8ee7ec0 100644
@@ -6,9 +6,6 @@
 #ifndef __ETNAVIV_GPU_H__
 #define __ETNAVIV_GPU_H__
 
-#include <linux/clk.h>
-#include <linux/regulator/consumer.h>
-
 #include "etnaviv_cmdbuf.h"
 #include "etnaviv_drv.h"
 
@@ -88,6 +85,8 @@ struct etnaviv_event {
 
 struct etnaviv_cmdbuf_suballoc;
 struct etnaviv_cmdbuf;
+struct regulator;
+struct clk;
 
 #define ETNA_NR_EVENTS 30
 
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
reviewer Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] drm/etnaviv: replace header include with forward declaration

Am Mo., 17. Dez. 2018 um 16:36 Uhr schrieb Lucas Stach <[email protected]>:

Quoted 5 lines

The etnaviv_gpu header only needs to know about the pointer types, so replace by a forward declaration and only include the headers where needed.

Quoted 48 lines
---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 2 ++
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +2 -0
index 293e248e1b29..aefb17e39ad0 100644
@@ -3,10 +3,12 @@
  * Copyright (C) 2015-2018 Etnaviv Project
  */
 
+#include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/dma-fence.h>
 #include <linux/moduleparam.h>
 #include <linux/of_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/thermal.h>
 
 #include "etnaviv_cmdbuf.h"
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +2 -4
index 74758f21e5d3..56b6a8ee7ec0 100644
@@ -6,9 +6,6 @@
 #ifndef __ETNAVIV_GPU_H__
 #define __ETNAVIV_GPU_H__
 
-#include <linux/clk.h>
-#include <linux/regulator/consumer.h>
-
 #include "etnaviv_cmdbuf.h"
 #include "etnaviv_drv.h"
 
@@ -88,6 +85,8 @@ struct etnaviv_event {
 
 struct etnaviv_cmdbuf_suballoc;
 struct etnaviv_cmdbuf;
+struct regulator;
+struct clk;
 
 #define ETNA_NR_EVENTS 30
 
--

2.19.1

Signature · 9 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#3 lore raw

PATCH 3/3 drm/etnaviv: remove lastctx member from gpu struct

In reply to Lucas Stach

It only written and we don't infer any useful information from it anymore. Remove it.

---
 drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 2 --
 drivers/gpu/drm/etnaviv/etnaviv_drv.c    | 8 +-------
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c    | 2 --
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h    | 1 -
 4 files changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_buffer.c +0 -2
index 7fea74861a87..160ce3c060a5 100644
@@ -439,6 +439,4 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
 
 	if (drm_debug & DRM_UT_DRIVER)
 		etnaviv_buffer_dump(gpu, buffer, 0, 0x50);
-
-	gpu->lastctx = cmdbuf->ctx;
 }
drivers/gpu/drm/etnaviv/etnaviv_drv.c +1 -7
index 1bb1d09e5fb0..96efc84396bf 100644
@@ -72,14 +72,8 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
 	for (i = 0; i < ETNA_MAX_PIPES; i++) {
 		struct etnaviv_gpu *gpu = priv->gpu[i];
 
-		if (gpu) {
-			mutex_lock(&gpu->lock);
-			if (gpu->lastctx == ctx)
-				gpu->lastctx = NULL;
-			mutex_unlock(&gpu->lock);
-
+		if (gpu)
 			drm_sched_entity_destroy(&ctx->sched_entity[i]);
-		}
 	}
 
 	kfree(ctx);
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +0 -2
index aefb17e39ad0..6904535475de 100644
@@ -997,7 +997,6 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
 	spin_unlock(&gpu->event_spinlock);
 
 	etnaviv_gpu_hw_init(gpu);
-	gpu->lastctx = NULL;
 	gpu->exec_state = -1;
 
 	mutex_unlock(&gpu->lock);
@@ -1546,7 +1545,6 @@ static int etnaviv_gpu_hw_resume(struct etnaviv_gpu *gpu)
 	etnaviv_gpu_update_clock(gpu);
 	etnaviv_gpu_hw_init(gpu);
 
-	gpu->lastctx = NULL;
 	gpu->exec_state = -1;
 
 	mutex_unlock(&gpu->lock);
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -1
index 56b6a8ee7ec0..9bcf151f706b 100644
@@ -97,7 +97,6 @@ struct etnaviv_gpu {
 	struct mutex lock;
 	struct etnaviv_chip_identity identity;
 	enum etnaviv_sec_mode sec_mode;
-	struct etnaviv_file_private *lastctx;
 	struct workqueue_struct *wq;
 	struct drm_gpu_scheduler sched;
 
Signature · 6 lines
2.19.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
reviewer Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] drm/etnaviv: remove lastctx member from gpu struct

Am Mo., 17. Dez. 2018 um 16:36 Uhr schrieb Lucas Stach <[email protected]>:

Quoted 5 lines

It only written and we don't infer any useful information from it anymore. Remove it.

Quoted 73 lines
---
 drivers/gpu/drm/etnaviv/etnaviv_buffer.c | 2 --
 drivers/gpu/drm/etnaviv/etnaviv_drv.c    | 8 +-------
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c    | 2 --
 drivers/gpu/drm/etnaviv/etnaviv_gpu.h    | 1 -
 4 files changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_buffer.c +0 -2
index 7fea74861a87..160ce3c060a5 100644
@@ -439,6 +439,4 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
 
        if (drm_debug & DRM_UT_DRIVER)
                etnaviv_buffer_dump(gpu, buffer, 0, 0x50);
-
-       gpu->lastctx = cmdbuf->ctx;
 }
drivers/gpu/drm/etnaviv/etnaviv_drv.c +1 -7
index 1bb1d09e5fb0..96efc84396bf 100644
@@ -72,14 +72,8 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
        for (i = 0; i < ETNA_MAX_PIPES; i++) {
                struct etnaviv_gpu *gpu = priv->gpu[i];
 
-               if (gpu) {
-                       mutex_lock(&gpu->lock);
-                       if (gpu->lastctx == ctx)
-                               gpu->lastctx = NULL;
-                       mutex_unlock(&gpu->lock);
-
+               if (gpu)
                        drm_sched_entity_destroy(&ctx->sched_entity[i]);
-               }
        }
 
        kfree(ctx);
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +0 -2
index aefb17e39ad0..6904535475de 100644
@@ -997,7 +997,6 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
        spin_unlock(&gpu->event_spinlock);
 
        etnaviv_gpu_hw_init(gpu);
-       gpu->lastctx = NULL;
        gpu->exec_state = -1;
 
        mutex_unlock(&gpu->lock);
@@ -1546,7 +1545,6 @@ static int etnaviv_gpu_hw_resume(struct etnaviv_gpu *gpu)
        etnaviv_gpu_update_clock(gpu);
        etnaviv_gpu_hw_init(gpu);
 
-       gpu->lastctx = NULL;
        gpu->exec_state = -1;
 
        mutex_unlock(&gpu->lock);
drivers/gpu/drm/etnaviv/etnaviv_gpu.h +0 -2
index 56b6a8ee7ec0..9bcf151f706b 100644
@@ -97,7 +97,6 @@ struct etnaviv_gpu {
        struct mutex lock;
        struct etnaviv_chip_identity identity;
        enum etnaviv_sec_mode sec_mode;
-       struct etnaviv_file_private *lastctx;
        struct workqueue_struct *wq;
        struct drm_gpu_scheduler sched;
 
--

2.19.1

Signature · 9 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
reviewer Reviewed-by on v1 1/3
#5 lore raw
In reply to Lucas Stach

Am Mo., 17. Dez. 2018 um 16:36 Uhr schrieb Lucas Stach <[email protected]>:

Quoted 8 lines

The only event function that is called from IRQ context is event_free, which is already using atomic bitmap operations, so we can avoid taking the event spinlock in this function completely. As other the other functions still using the event spinlock are all called from normal process context, we can avoid disabling IRQs while holding the spinlock.

Quoted 79 lines
---
 drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +5 -14
index 8fbe77cae810..293e248e1b29 100644
@@ -976,7 +976,6 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m)
 
 void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
 {
-       unsigned long flags;
        unsigned int i = 0;
 
        dev_err(gpu->dev, "recover hung GPU!\n");
@@ -989,11 +988,11 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu)
        etnaviv_hw_reset(gpu);
 
        /* complete all events, the GPU won't do it after the reset */
-       spin_lock_irqsave(&gpu->event_spinlock, flags);
+       spin_lock(&gpu->event_spinlock);
        for_each_set_bit_from(i, gpu->event_bitmap, ETNA_NR_EVENTS)
                complete(&gpu->event_free);
        bitmap_zero(gpu->event_bitmap, ETNA_NR_EVENTS);
-       spin_unlock_irqrestore(&gpu->event_spinlock, flags);
+       spin_unlock(&gpu->event_spinlock);
 
        etnaviv_gpu_hw_init(gpu);
        gpu->lastctx = NULL;
@@ -1083,7 +1082,7 @@ static inline bool fence_after(u32 a, u32 b)
 static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
        unsigned int *events)
 {
-       unsigned long flags, timeout = msecs_to_jiffies(10 * 10000);
+       unsigned long timeout = msecs_to_jiffies(10 * 10000);
        unsigned i, acquired = 0;
 
        for (i = 0; i < nr_events; i++) {
@@ -1100,7 +1099,7 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
                timeout = ret;
        }
 
-       spin_lock_irqsave(&gpu->event_spinlock, flags);
+       spin_lock(&gpu->event_spinlock);
 
        for (i = 0; i < nr_events; i++) {
                int event = find_first_zero_bit(gpu->event_bitmap, ETNA_NR_EVENTS);
@@ -1110,7 +1109,7 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
                set_bit(event, gpu->event_bitmap);
        }
 
-       spin_unlock_irqrestore(&gpu->event_spinlock, flags);
+       spin_unlock(&gpu->event_spinlock);
 
        return 0;
 
@@ -1123,18 +1122,11 @@ static int event_alloc(struct etnaviv_gpu *gpu, unsigned nr_events,
 
 static void event_free(struct etnaviv_gpu *gpu, unsigned int event)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&gpu->event_spinlock, flags);
-
        if (!test_bit(event, gpu->event_bitmap)) {
                dev_warn(gpu->dev, "event %u is already marked as free",
                         event);
-               spin_unlock_irqrestore(&gpu->event_spinlock, flags);
        } else {
                clear_bit(event, gpu->event_bitmap);
-               spin_unlock_irqrestore(&gpu->event_spinlock, flags);
-
                complete(&gpu->event_free);
        }
 }
--

2.19.1

Signature · 9 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel