Skip to content

Commit e5e1130

Browse files
yanzhao56zhenyw
authored andcommitted
drm/i915/gvt: combine access to consecutive guest context pages
IOVA(GPA)s of context pages are checked and if they are consecutive, read/write them together in one intel_gvt_hypervisor_read_gpa() / intel_gvt_hypervisor_write_gpa(). Signed-off-by: Yan Zhao <[email protected]> Reviewed-by: Zhenyu Wang <[email protected]> Signed-off-by: Zhenyu Wang <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 6c2f73e commit e5e1130

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

drivers/gpu/drm/i915/gvt/scheduler.c

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static int populate_shadow_context(struct intel_vgpu_workload *workload)
133133
void *dst;
134134
void *context_base;
135135
unsigned long context_gpa, context_page_num;
136+
unsigned long gpa_base; /* first gpa of consecutive GPAs */
137+
unsigned long gpa_size; /* size of consecutive GPAs */
136138
int i;
137139

138140
GEM_BUG_ON(!intel_context_is_pinned(ctx));
@@ -186,8 +188,11 @@ static int populate_shadow_context(struct intel_vgpu_workload *workload)
186188
if (IS_BROADWELL(gvt->gt->i915) && workload->engine->id == RCS0)
187189
context_page_num = 19;
188190

189-
i = 2;
190-
while (i < context_page_num) {
191+
/* find consecutive GPAs from gma until the first inconsecutive GPA.
192+
* read from the continuous GPAs into dst virtual address
193+
*/
194+
gpa_size = 0;
195+
for (i = 2; i < context_page_num; i++) {
191196
context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm,
192197
(u32)((workload->ctx_desc.lrca + i) <<
193198
I915_GTT_PAGE_SHIFT));
@@ -196,10 +201,24 @@ static int populate_shadow_context(struct intel_vgpu_workload *workload)
196201
return -EFAULT;
197202
}
198203

204+
if (gpa_size == 0) {
205+
gpa_base = context_gpa;
206+
dst = context_base + (i << I915_GTT_PAGE_SHIFT);
207+
} else if (context_gpa != gpa_base + gpa_size)
208+
goto read;
209+
210+
gpa_size += I915_GTT_PAGE_SIZE;
211+
212+
if (i == context_page_num - 1)
213+
goto read;
214+
215+
continue;
216+
217+
read:
218+
intel_gvt_hypervisor_read_gpa(vgpu, gpa_base, dst, gpa_size);
219+
gpa_base = context_gpa;
220+
gpa_size = I915_GTT_PAGE_SIZE;
199221
dst = context_base + (i << I915_GTT_PAGE_SHIFT);
200-
intel_gvt_hypervisor_read_gpa(vgpu, context_gpa, dst,
201-
I915_GTT_PAGE_SIZE);
202-
i++;
203222
}
204223
return 0;
205224
}
@@ -789,6 +808,8 @@ static void update_guest_context(struct intel_vgpu_workload *workload)
789808
void *context_base;
790809
void *src;
791810
unsigned long context_gpa, context_page_num;
811+
unsigned long gpa_base; /* first gpa of consecutive GPAs */
812+
unsigned long gpa_size; /* size of consecutive GPAs*/
792813
int i;
793814
u32 ring_base;
794815
u32 head, tail;
@@ -822,11 +843,14 @@ static void update_guest_context(struct intel_vgpu_workload *workload)
822843
if (IS_BROADWELL(rq->i915) && rq->engine->id == RCS0)
823844
context_page_num = 19;
824845

825-
i = 2;
826846
context_base = (void *) ctx->lrc_reg_state -
827847
(LRC_STATE_PN << I915_GTT_PAGE_SHIFT);
828848

829-
while (i < context_page_num) {
849+
/* find consecutive GPAs from gma until the first inconsecutive GPA.
850+
* write to the consecutive GPAs from src virtual address
851+
*/
852+
gpa_size = 0;
853+
for (i = 2; i < context_page_num; i++) {
830854
context_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm,
831855
(u32)((workload->ctx_desc.lrca + i) <<
832856
I915_GTT_PAGE_SHIFT));
@@ -835,10 +859,24 @@ static void update_guest_context(struct intel_vgpu_workload *workload)
835859
return;
836860
}
837861

862+
if (gpa_size == 0) {
863+
gpa_base = context_gpa;
864+
src = context_base + (i << I915_GTT_PAGE_SHIFT);
865+
} else if (context_gpa != gpa_base + gpa_size)
866+
goto write;
867+
868+
gpa_size += I915_GTT_PAGE_SIZE;
869+
870+
if (i == context_page_num - 1)
871+
goto write;
872+
873+
continue;
874+
875+
write:
876+
intel_gvt_hypervisor_write_gpa(vgpu, gpa_base, src, gpa_size);
877+
gpa_base = context_gpa;
878+
gpa_size = I915_GTT_PAGE_SIZE;
838879
src = context_base + (i << I915_GTT_PAGE_SHIFT);
839-
intel_gvt_hypervisor_write_gpa(vgpu, context_gpa, src,
840-
I915_GTT_PAGE_SIZE);
841-
i++;
842880
}
843881

844882
intel_gvt_hypervisor_write_gpa(vgpu, workload->ring_context_gpa +

0 commit comments

Comments
 (0)