From: Mika Kuoppala <mika.kuoppala@linux.intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 08/10] drm/i915/gtt: Make swapping the pd entry generic
Date: Fri, 14 Jun 2019 19:43:48 +0300 [thread overview]
Message-ID: <20190614164350.30415-8-mika.kuoppala@linux.intel.com> (raw)
In-Reply-To: <20190614164350.30415-1-mika.kuoppala@linux.intel.com>
Swapping a pd entry is same across the page directories, if
we succeed we need to increment the count and write the phys page
entry. Make a common function for it.
v2: inline (Chris)
Signed-off-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
---
drivers/gpu/drm/i915/i915_gem_gtt.c | 42 +++++++++++++++++++----------
1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 8baceb9f64c5..0fffa0608ea5 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -754,6 +754,28 @@ static void __set_pd_entry(struct i915_page_directory * const pd,
gen8_pde_encode(px_dma(to), I915_CACHE_LLC)); \
})
+static inline void *
+__swap_pd_entry(struct i915_page_directory * const pd,
+ const unsigned short pde,
+ void * const old_val,
+ void * const new_val,
+ const dma_addr_t daddr,
+ u64 (*encode)(const dma_addr_t, const enum i915_cache_level))
+{
+ void * const old = cmpxchg(&pd->entry[pde], old_val, new_val);
+
+ if (likely(old == old_val)) {
+ atomic_inc(&pd->used);
+ if (likely(pd_has_phys_page(pd)))
+ __set_pd_entry(pd, pde, encode(daddr, I915_CACHE_LLC));
+ }
+
+ return old;
+}
+
+#define swap_pd_entry(pd, pde, old, to) \
+ __swap_pd_entry((pd), (pde), (old), (to), px_dma(to), gen8_pde_encode)
+
/*
* PDE TLBs are a pain to invalidate on GEN8+. When we modify
* the page table structures, we mark them dirty so that
@@ -1328,11 +1350,8 @@ static int gen8_ppgtt_alloc_pd(struct i915_address_space *vm,
if (count < GEN8_PTES || intel_vgpu_active(vm->i915))
gen8_initialize_pt(vm, pt);
- old = cmpxchg(&pd->entry[pde], vm->scratch_pt, pt);
- if (old == vm->scratch_pt) {
- set_pd_entry(pd, pde, pt);
- atomic_inc(&pd->used);
- } else {
+ old = swap_pd_entry(pd, pde, vm->scratch_pt, pt);
+ if (unlikely(old != vm->scratch_pt)) {
free_pt(vm, pt);
pt = old;
}
@@ -1373,11 +1392,8 @@ static int gen8_ppgtt_alloc_pdp(struct i915_address_space *vm,
init_pd(vm, pd, vm->scratch_pt);
- old = cmpxchg(&pdp->entry[pdpe], vm->scratch_pd, pd);
- if (old == vm->scratch_pd) {
- set_pd_entry(pdp, pdpe, pd);
- atomic_inc(&pdp->used);
- } else {
+ old = swap_pd_entry(pdp, pdpe, vm->scratch_pd, pd);
+ if (unlikely(old != vm->scratch_pd)) {
free_pd(vm, pd);
pd = old;
}
@@ -1442,10 +1458,8 @@ static int gen8_ppgtt_alloc_4lvl(struct i915_address_space *vm,
init_pd(vm, pdp, vm->scratch_pd);
- old = cmpxchg(&pml4->entry[pml4e], vm->scratch_pdp, pdp);
- if (old == vm->scratch_pdp) {
- set_pd_entry(pml4, pml4e, pdp);
- } else {
+ old = swap_pd_entry(pml4, pml4e, vm->scratch_pdp, pdp);
+ if (unlikely(old != vm->scratch_pdp)) {
free_pd(vm, pdp);
pdp = old;
}
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2019-06-14 16:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-14 16:43 [PATCH 01/10] drm/i915/gtt: No need to zero the table for page dirs Mika Kuoppala
2019-06-14 16:43 ` [PATCH 02/10] drm/i915/gtt: Use a common type for page directories Mika Kuoppala
2019-06-14 16:56 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 03/10] drm/i915/gtt: Introduce init_pd_with_page Mika Kuoppala
2019-06-14 17:10 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 04/10] drm/i915/gtt: Introduce init_pd Mika Kuoppala
2019-06-14 17:13 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 05/10] drm/i915/gtt: Generalize alloc_pd Mika Kuoppala
2019-06-14 17:17 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 06/10] drm/i915/gtt: pde entry encoding is identical Mika Kuoppala
2019-06-14 17:21 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 07/10] drm/i915/gtt: Check for physical page for pd entry always Mika Kuoppala
2019-06-14 17:22 ` Chris Wilson
2019-06-14 16:43 ` Mika Kuoppala [this message]
2019-06-14 17:26 ` [PATCH 08/10] drm/i915/gtt: Make swapping the pd entry generic Chris Wilson
2019-06-14 16:43 ` [PATCH 09/10] drm/i915/gtt: Tear down setup and cleanup macros for page dma Mika Kuoppala
2019-06-14 17:30 ` Chris Wilson
2019-06-14 16:43 ` [PATCH 10/10] drm/i915/gtt: Setup phys pages for 3lvl pdps Mika Kuoppala
2019-06-14 17:36 ` Chris Wilson
2019-06-14 17:00 ` ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/10] drm/i915/gtt: No need to zero the table for page dirs Patchwork
2019-06-14 17:04 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-06-15 4:59 ` ✓ Fi.CI.BAT: success " Patchwork
2019-06-17 10:32 ` ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190614164350.30415-8-mika.kuoppala@linux.intel.com \
--to=mika.kuoppala@linux.intel.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox