From patchwork Tue Jun 21 16:17:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 902562 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5LGINHh021408 for ; Tue, 21 Jun 2011 16:18:43 GMT Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 450B79F754 for ; Tue, 21 Jun 2011 09:18:23 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (server109-228-6-236.live-servers.net [109.228.6.236]) by gabe.freedesktop.org (Postfix) with ESMTP id EC9D19E738 for ; Tue, 21 Jun 2011 09:17:33 -0700 (PDT) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.66.37; Received: from arrandale.alporthouse.com (unverified [78.156.66.37]) by fireflyinternet.com (Firefly Internet SMTP) with ESMTP id 37599451-1500050 for multiple; Tue, 21 Jun 2011 17:17:28 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 21 Jun 2011 17:17:24 +0100 Message-Id: <1308673044-10612-4-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1308673044-10612-1-git-send-email-chris@chris-wilson.co.uk> References: <013811$h8tfb@fmsmga002.fm.intel.com> <1308673044-10612-1-git-send-email-chris@chris-wilson.co.uk> X-Originating-IP: 78.156.66.37 Subject: [Intel-gfx] [PATCH 3/3] x86, pat: Convert memtype_lock spinlock to a rwlock X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 21 Jun 2011 16:18:43 +0000 (UTC) Presuming that we lookup the memtype of an address far more often than we modify the PAT ranges, favour the reader. Signed-off-by: Chris Wilson --- arch/x86/mm/pat.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c index 18d4aa9..8cc67e5 100644 --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -130,7 +130,7 @@ void pat_init(void) #undef PAT -static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */ +static DEFINE_RWLOCK(memtype_lock); /* protects memtype accesses */ /* * Does intersection of PAT memory type and MTRR memory type and returns @@ -310,7 +310,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, new->end = end; new->type = actual_type; - spin_lock(&memtype_lock); + write_lock(&memtype_lock); err = rbt_memtype_check_insert(new, new_type); if (err) { @@ -318,12 +318,12 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type, "track %s, req %s\n", start, end, cattr_name(new->type), cattr_name(req_type)); kfree(new); - spin_unlock(&memtype_lock); + write_unlock(&memtype_lock); return err; } - spin_unlock(&memtype_lock); + write_unlock(&memtype_lock); dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n", start, end, cattr_name(new->type), cattr_name(req_type), @@ -355,9 +355,9 @@ int free_memtype(u64 start, u64 end) return -EINVAL; } - spin_lock(&memtype_lock); + write_lock(&memtype_lock); entry = rbt_memtype_erase(start, end); - spin_unlock(&memtype_lock); + write_unlock(&memtype_lock); if (!entry) { printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n", @@ -390,13 +390,13 @@ static unsigned long lookup_memtype(u64 paddr) if (x86_platform.is_untracked_pat_range(paddr, paddr + PAGE_SIZE)) return _PAGE_CACHE_WB; - spin_lock(&memtype_lock); + read_lock(&memtype_lock); entry = rbt_memtype_lookup(paddr); if (entry != NULL) rettype = entry->type; - spin_unlock(&memtype_lock); + read_unlock(&memtype_lock); if (rettype != -1) return rettype; @@ -754,9 +754,9 @@ static struct memtype *memtype_get_idx(loff_t pos) if (!print_entry) return NULL; - spin_lock(&memtype_lock); + read_lock(&memtype_lock); ret = rbt_memtype_copy_nth_element(print_entry, pos); - spin_unlock(&memtype_lock); + read_unlock(&memtype_lock); if (!ret) { return print_entry;