diff options
author | Thomas Hellstrom <thellstrom@vmware.com> | 2010-05-28 05:21:57 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2010-05-31 19:37:15 -0400 |
commit | 1925d4565888eb313cc923372da6a08bbfb3a859 (patch) | |
tree | ef8dbcc9ba34a0b1075433147808cc56067d17c5 /drivers/gpu/drm/vmwgfx | |
parent | 04e9e94dba3e564ce810cedab88e957dfd681b4a (diff) |
drm/vmwgfx: Add kernel throttling support. Bump minor.
The throttle_us member in the execbuf argument is now honored.
If the member is 0, no waiting for lag will occur, which
guarantees backwards compatibility with well-behaved clients.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/vmwgfx')
-rw-r--r-- | drivers/gpu/drm/vmwgfx/Makefile | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 27 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | 9 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 173 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c | 5 | ||||
-rw-r--r-- | drivers/gpu/drm/vmwgfx/vmwgfx_irq.c | 17 |
6 files changed, 227 insertions, 6 deletions
diff --git a/drivers/gpu/drm/vmwgfx/Makefile b/drivers/gpu/drm/vmwgfx/Makefile index 1a3cb6816d1c..4505e17df3f5 100644 --- a/drivers/gpu/drm/vmwgfx/Makefile +++ b/drivers/gpu/drm/vmwgfx/Makefile | |||
@@ -4,6 +4,6 @@ ccflags-y := -Iinclude/drm | |||
4 | vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \ | 4 | vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \ |
5 | vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_buffer.o \ | 5 | vmwgfx_fb.o vmwgfx_ioctl.o vmwgfx_resource.o vmwgfx_buffer.o \ |
6 | vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \ | 6 | vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \ |
7 | vmwgfx_overlay.o | 7 | vmwgfx_overlay.o vmwgfx_fence.o |
8 | 8 | ||
9 | obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o | 9 | obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o |
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index 356dc935ec13..9a0a82b41c3e 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | |||
@@ -41,7 +41,7 @@ | |||
41 | 41 | ||
42 | #define VMWGFX_DRIVER_DATE "20100209" | 42 | #define VMWGFX_DRIVER_DATE "20100209" |
43 | #define VMWGFX_DRIVER_MAJOR 1 | 43 | #define VMWGFX_DRIVER_MAJOR 1 |
44 | #define VMWGFX_DRIVER_MINOR 0 | 44 | #define VMWGFX_DRIVER_MINOR 1 |
45 | #define VMWGFX_DRIVER_PATCHLEVEL 0 | 45 | #define VMWGFX_DRIVER_PATCHLEVEL 0 |
46 | #define VMWGFX_FILE_PAGE_OFFSET 0x00100000 | 46 | #define VMWGFX_FILE_PAGE_OFFSET 0x00100000 |
47 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) | 47 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) |
@@ -102,6 +102,13 @@ struct vmw_surface { | |||
102 | struct vmw_cursor_snooper snooper; | 102 | struct vmw_cursor_snooper snooper; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | struct vmw_fence_queue { | ||
106 | struct list_head head; | ||
107 | struct timespec lag; | ||
108 | struct timespec lag_time; | ||
109 | spinlock_t lock; | ||
110 | }; | ||
111 | |||
105 | struct vmw_fifo_state { | 112 | struct vmw_fifo_state { |
106 | unsigned long reserved_size; | 113 | unsigned long reserved_size; |
107 | __le32 *dynamic_buffer; | 114 | __le32 *dynamic_buffer; |
@@ -115,6 +122,7 @@ struct vmw_fifo_state { | |||
115 | uint32_t capabilities; | 122 | uint32_t capabilities; |
116 | struct mutex fifo_mutex; | 123 | struct mutex fifo_mutex; |
117 | struct rw_semaphore rwsem; | 124 | struct rw_semaphore rwsem; |
125 | struct vmw_fence_queue fence_queue; | ||
118 | }; | 126 | }; |
119 | 127 | ||
120 | struct vmw_relocation { | 128 | struct vmw_relocation { |
@@ -441,6 +449,23 @@ extern int vmw_fallback_wait(struct vmw_private *dev_priv, | |||
441 | uint32_t sequence, | 449 | uint32_t sequence, |
442 | bool interruptible, | 450 | bool interruptible, |
443 | unsigned long timeout); | 451 | unsigned long timeout); |
452 | extern void vmw_update_sequence(struct vmw_private *dev_priv, | ||
453 | struct vmw_fifo_state *fifo_state); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Rudimentary fence objects currently used only for throttling - | ||
458 | * vmwgfx_fence.c | ||
459 | */ | ||
460 | |||
461 | extern void vmw_fence_queue_init(struct vmw_fence_queue *queue); | ||
462 | extern void vmw_fence_queue_takedown(struct vmw_fence_queue *queue); | ||
463 | extern int vmw_fence_push(struct vmw_fence_queue *queue, | ||
464 | uint32_t sequence); | ||
465 | extern int vmw_fence_pull(struct vmw_fence_queue *queue, | ||
466 | uint32_t signaled_sequence); | ||
467 | extern int vmw_wait_lag(struct vmw_private *dev_priv, | ||
468 | struct vmw_fence_queue *queue, uint32_t us); | ||
444 | 469 | ||
445 | /** | 470 | /** |
446 | * Kernel framebuffer - vmwgfx_fb.c | 471 | * Kernel framebuffer - vmwgfx_fb.c |
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c index dbd36b8910cf..bdd67cf83315 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c | |||
@@ -669,6 +669,15 @@ int vmw_execbuf_ioctl(struct drm_device *dev, void *data, | |||
669 | goto out_err; | 669 | goto out_err; |
670 | 670 | ||
671 | vmw_apply_relocations(sw_context); | 671 | vmw_apply_relocations(sw_context); |
672 | |||
673 | if (arg->throttle_us) { | ||
674 | ret = vmw_wait_lag(dev_priv, &dev_priv->fifo.fence_queue, | ||
675 | arg->throttle_us); | ||
676 | |||
677 | if (unlikely(ret != 0)) | ||
678 | goto out_err; | ||
679 | } | ||
680 | |||
672 | vmw_fifo_commit(dev_priv, arg->command_size); | 681 | vmw_fifo_commit(dev_priv, arg->command_size); |
673 | 682 | ||
674 | ret = vmw_fifo_send_fence(dev_priv, &sequence); | 683 | ret = vmw_fifo_send_fence(dev_priv, &sequence); |
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c new file mode 100644 index 000000000000..61eacc1b5ca3 --- /dev/null +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | |||
@@ -0,0 +1,173 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright (C) 2010 VMware, Inc., Palo Alto, CA., USA | ||
4 | * All Rights Reserved. | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
7 | * copy of this software and associated documentation files (the | ||
8 | * "Software"), to deal in the Software without restriction, including | ||
9 | * without limitation the rights to use, copy, modify, merge, publish, | ||
10 | * distribute, sub license, and/or sell copies of the Software, and to | ||
11 | * permit persons to whom the Software is furnished to do so, subject to | ||
12 | * the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice (including the | ||
15 | * next paragraph) shall be included in all copies or substantial portions | ||
16 | * of the Software. | ||
17 | * | ||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | ||
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, | ||
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
25 | * | ||
26 | **************************************************************************/ | ||
27 | |||
28 | |||
29 | #include "vmwgfx_drv.h" | ||
30 | |||
31 | struct vmw_fence { | ||
32 | struct list_head head; | ||
33 | uint32_t sequence; | ||
34 | struct timespec submitted; | ||
35 | }; | ||
36 | |||
37 | void vmw_fence_queue_init(struct vmw_fence_queue *queue) | ||
38 | { | ||
39 | INIT_LIST_HEAD(&queue->head); | ||
40 | queue->lag = ns_to_timespec(0); | ||
41 | getrawmonotonic(&queue->lag_time); | ||
42 | spin_lock_init(&queue->lock); | ||
43 | } | ||
44 | |||
45 | void vmw_fence_queue_takedown(struct vmw_fence_queue *queue) | ||
46 | { | ||
47 | struct vmw_fence *fence, *next; | ||
48 | |||
49 | spin_lock(&queue->lock); | ||
50 | list_for_each_entry_safe(fence, next, &queue->head, head) { | ||
51 | kfree(fence); | ||
52 | } | ||
53 | spin_unlock(&queue->lock); | ||
54 | } | ||
55 | |||
56 | int vmw_fence_push(struct vmw_fence_queue *queue, | ||
57 | uint32_t sequence) | ||
58 | { | ||
59 | struct vmw_fence *fence = kmalloc(sizeof(*fence), GFP_KERNEL); | ||
60 | |||
61 | if (unlikely(!fence)) | ||
62 | return -ENOMEM; | ||
63 | |||
64 | fence->sequence = sequence; | ||
65 | getrawmonotonic(&fence->submitted); | ||
66 | spin_lock(&queue->lock); | ||
67 | list_add_tail(&fence->head, &queue->head); | ||
68 | spin_unlock(&queue->lock); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | int vmw_fence_pull(struct vmw_fence_queue *queue, | ||
74 | uint32_t signaled_sequence) | ||
75 | { | ||
76 | struct vmw_fence *fence, *next; | ||
77 | struct timespec now; | ||
78 | bool updated = false; | ||
79 | |||
80 | spin_lock(&queue->lock); | ||
81 | getrawmonotonic(&now); | ||
82 | |||
83 | if (list_empty(&queue->head)) { | ||
84 | queue->lag = ns_to_timespec(0); | ||
85 | queue->lag_time = now; | ||
86 | updated = true; | ||
87 | goto out_unlock; | ||
88 | } | ||
89 | |||
90 | list_for_each_entry_safe(fence, next, &queue->head, head) { | ||
91 | if (signaled_sequence - fence->sequence > (1 << 30)) | ||
92 | continue; | ||
93 | |||
94 | queue->lag = timespec_sub(now, fence->submitted); | ||
95 | queue->lag_time = now; | ||
96 | updated = true; | ||
97 | list_del(&fence->head); | ||
98 | kfree(fence); | ||
99 | } | ||
100 | |||
101 | out_unlock: | ||
102 | spin_unlock(&queue->lock); | ||
103 | |||
104 | return (updated) ? 0 : -EBUSY; | ||
105 | } | ||
106 | |||
107 | static struct timespec vmw_timespec_add(struct timespec t1, | ||
108 | struct timespec t2) | ||
109 | { | ||
110 | t1.tv_sec += t2.tv_sec; | ||
111 | t1.tv_nsec += t2.tv_nsec; | ||
112 | if (t1.tv_nsec >= 1000000000L) { | ||
113 | t1.tv_sec += 1; | ||
114 | t1.tv_nsec -= 1000000000L; | ||
115 | } | ||
116 | |||
117 | return t1; | ||
118 | } | ||
119 | |||
120 | static struct timespec vmw_fifo_lag(struct vmw_fence_queue *queue) | ||
121 | { | ||
122 | struct timespec now; | ||
123 | |||
124 | spin_lock(&queue->lock); | ||
125 | getrawmonotonic(&now); | ||
126 | queue->lag = vmw_timespec_add(queue->lag, | ||
127 | timespec_sub(now, queue->lag_time)); | ||
128 | queue->lag_time = now; | ||
129 | spin_unlock(&queue->lock); | ||
130 | return queue->lag; | ||
131 | } | ||
132 | |||
133 | |||
134 | static bool vmw_lag_lt(struct vmw_fence_queue *queue, | ||
135 | uint32_t us) | ||
136 | { | ||
137 | struct timespec lag, cond; | ||
138 | |||
139 | cond = ns_to_timespec((s64) us * 1000); | ||
140 | lag = vmw_fifo_lag(queue); | ||
141 | return (timespec_compare(&lag, &cond) < 1); | ||
142 | } | ||
143 | |||
144 | int vmw_wait_lag(struct vmw_private *dev_priv, | ||
145 | struct vmw_fence_queue *queue, uint32_t us) | ||
146 | { | ||
147 | struct vmw_fence *fence; | ||
148 | uint32_t sequence; | ||
149 | int ret; | ||
150 | |||
151 | while (!vmw_lag_lt(queue, us)) { | ||
152 | spin_lock(&queue->lock); | ||
153 | if (list_empty(&queue->head)) | ||
154 | sequence = atomic_read(&dev_priv->fence_seq); | ||
155 | else { | ||
156 | fence = list_first_entry(&queue->head, | ||
157 | struct vmw_fence, head); | ||
158 | sequence = fence->sequence; | ||
159 | } | ||
160 | spin_unlock(&queue->lock); | ||
161 | |||
162 | ret = vmw_wait_fence(dev_priv, false, sequence, true, | ||
163 | 3*HZ); | ||
164 | |||
165 | if (unlikely(ret != 0)) | ||
166 | return ret; | ||
167 | |||
168 | (void) vmw_fence_pull(queue, sequence); | ||
169 | } | ||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | |||
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c index 39d43a01d846..a8e5445f94ec 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c | |||
@@ -120,7 +120,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) | |||
120 | 120 | ||
121 | atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence); | 121 | atomic_set(&dev_priv->fence_seq, dev_priv->last_read_sequence); |
122 | iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE); | 122 | iowrite32(dev_priv->last_read_sequence, fifo_mem + SVGA_FIFO_FENCE); |
123 | 123 | vmw_fence_queue_init(&fifo->fence_queue); | |
124 | return vmw_fifo_send_fence(dev_priv, &dummy); | 124 | return vmw_fifo_send_fence(dev_priv, &dummy); |
125 | out_err: | 125 | out_err: |
126 | vfree(fifo->static_buffer); | 126 | vfree(fifo->static_buffer); |
@@ -159,6 +159,7 @@ void vmw_fifo_release(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo) | |||
159 | dev_priv->enable_state); | 159 | dev_priv->enable_state); |
160 | 160 | ||
161 | mutex_unlock(&dev_priv->hw_mutex); | 161 | mutex_unlock(&dev_priv->hw_mutex); |
162 | vmw_fence_queue_takedown(&fifo->fence_queue); | ||
162 | 163 | ||
163 | if (likely(fifo->last_buffer != NULL)) { | 164 | if (likely(fifo->last_buffer != NULL)) { |
164 | vfree(fifo->last_buffer); | 165 | vfree(fifo->last_buffer); |
@@ -484,6 +485,8 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *sequence) | |||
484 | fifo_state->last_buffer_add = true; | 485 | fifo_state->last_buffer_add = true; |
485 | vmw_fifo_commit(dev_priv, bytes); | 486 | vmw_fifo_commit(dev_priv, bytes); |
486 | fifo_state->last_buffer_add = false; | 487 | fifo_state->last_buffer_add = false; |
488 | (void) vmw_fence_push(&fifo_state->fence_queue, *sequence); | ||
489 | vmw_update_sequence(dev_priv, fifo_state); | ||
487 | 490 | ||
488 | out_err: | 491 | out_err: |
489 | return ret; | 492 | return ret; |
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c index 4d7cb5393860..e92298a6a383 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c | |||
@@ -64,22 +64,33 @@ static bool vmw_fifo_idle(struct vmw_private *dev_priv, uint32_t sequence) | |||
64 | return (busy == 0); | 64 | return (busy == 0); |
65 | } | 65 | } |
66 | 66 | ||
67 | void vmw_update_sequence(struct vmw_private *dev_priv, | ||
68 | struct vmw_fifo_state *fifo_state) | ||
69 | { | ||
70 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; | ||
71 | |||
72 | uint32_t sequence = ioread32(fifo_mem + SVGA_FIFO_FENCE); | ||
73 | |||
74 | if (dev_priv->last_read_sequence != sequence) { | ||
75 | dev_priv->last_read_sequence = sequence; | ||
76 | vmw_fence_pull(&fifo_state->fence_queue, sequence); | ||
77 | } | ||
78 | } | ||
67 | 79 | ||
68 | bool vmw_fence_signaled(struct vmw_private *dev_priv, | 80 | bool vmw_fence_signaled(struct vmw_private *dev_priv, |
69 | uint32_t sequence) | 81 | uint32_t sequence) |
70 | { | 82 | { |
71 | __le32 __iomem *fifo_mem = dev_priv->mmio_virt; | ||
72 | struct vmw_fifo_state *fifo_state; | 83 | struct vmw_fifo_state *fifo_state; |
73 | bool ret; | 84 | bool ret; |
74 | 85 | ||
75 | if (likely(dev_priv->last_read_sequence - sequence < VMW_FENCE_WRAP)) | 86 | if (likely(dev_priv->last_read_sequence - sequence < VMW_FENCE_WRAP)) |
76 | return true; | 87 | return true; |
77 | 88 | ||
78 | dev_priv->last_read_sequence = ioread32(fifo_mem + SVGA_FIFO_FENCE); | 89 | fifo_state = &dev_priv->fifo; |
90 | vmw_update_sequence(dev_priv, fifo_state); | ||
79 | if (likely(dev_priv->last_read_sequence - sequence < VMW_FENCE_WRAP)) | 91 | if (likely(dev_priv->last_read_sequence - sequence < VMW_FENCE_WRAP)) |
80 | return true; | 92 | return true; |
81 | 93 | ||
82 | fifo_state = &dev_priv->fifo; | ||
83 | if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE) && | 94 | if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE) && |
84 | vmw_fifo_idle(dev_priv, sequence)) | 95 | vmw_fifo_idle(dev_priv, sequence)) |
85 | return true; | 96 | return true; |