From patchwork Fri Jun 14 16:43:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 10995991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B65D915E6 for ; Fri, 14 Jun 2019 16:44:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6BF026538 for ; Fri, 14 Jun 2019 16:44:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B2302834A; Fri, 14 Jun 2019 16:44:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4E06826538 for ; Fri, 14 Jun 2019 16:44:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71FBE89B20; Fri, 14 Jun 2019 16:44:06 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id D14EB89B06 for ; Fri, 14 Jun 2019 16:43:56 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2019 09:43:55 -0700 X-ExtLoop1: 1 Received: from rosetta.fi.intel.com ([10.237.72.186]) by orsmga007.jf.intel.com with ESMTP; 14 Jun 2019 09:43:54 -0700 Received: by rosetta.fi.intel.com (Postfix, from userid 1000) id E009D840684; Fri, 14 Jun 2019 19:43:50 +0300 (EEST) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Fri, 14 Jun 2019 19:43:48 +0300 Message-Id: <20190614164350.30415-8-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190614164350.30415-1-mika.kuoppala@linux.intel.com> References: <20190614164350.30415-1-mika.kuoppala@linux.intel.com> Subject: [Intel-gfx] [PATCH 08/10] drm/i915/gtt: Make swapping the pd entry generic X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Chris Wilson --- 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; }