From patchwork Sun Aug 25 07:15:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hao X-Patchwork-Id: 269689 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id BB4712C0180 for ; Sun, 25 Aug 2013 17:19:22 +1000 (EST) Received: from mail1.windriver.com (mail1.windriver.com [147.11.146.13]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mail1.windriver.com", Issuer "Intel External Basic Issuing CA 3A" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 942892C01D1 for ; Sun, 25 Aug 2013 17:17:09 +1000 (EST) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.14.5/8.14.3) with ESMTP id r7P7H83O022355 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Sun, 25 Aug 2013 00:17:08 -0700 (PDT) Received: from pek-khao-d1.corp.ad.wrs.com (128.224.162.196) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server id 14.2.347.0; Sun, 25 Aug 2013 00:17:05 -0700 From: Kevin Hao To: Benjamin Herrenschmidt Subject: [PATCH 5/5] powerpc: use jump label for mmu_has_feature Date: Sun, 25 Aug 2013 15:15:52 +0800 Message-ID: <1377414952-15995-6-git-send-email-haokexin@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1377414952-15995-1-git-send-email-haokexin@gmail.com> References: <1377414952-15995-1-git-send-email-haokexin@gmail.com> MIME-Version: 1.0 Cc: linuxppc X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16rc2 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The mmu features are fixed once the probe of mmu features are done. And the function mmu_has_feature() does be used in some hot path. The checking of the mmu features for each time of invoking of mmu_has_feature() seems suboptimal. This tries to reduce this overhead of this check by using jump label. But we can only use the jump label for this check only after the execution of jump_label_init(), so we introduce another jump label to still do the feature check by default before all the mmu feature jump labels are initialized. Signed-off-by: Kevin Hao --- arch/powerpc/include/asm/mmu.h | 19 +++++++++++++++++++ arch/powerpc/kernel/cputable.c | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h index 691fd8a..163e9b1 100644 --- a/arch/powerpc/include/asm/mmu.h +++ b/arch/powerpc/include/asm/mmu.h @@ -121,10 +121,29 @@ DECLARE_PER_CPU(int, next_tlbcam_idx); #endif +#ifdef CONFIG_JUMP_LABEL +#include + +#define MAX_MMU_FEATURES 32 + +extern struct static_key mmu_feat_keys[MAX_MMU_FEATURES]; +extern struct static_key mmu_feat_keys_enabled; + +static inline int mmu_has_feature(unsigned long feature) +{ + if (static_key_false(&mmu_feat_keys_enabled)) { + int i = __builtin_ctzl(feature); + + return static_key_false(&mmu_feat_keys[i]); + } else + return !!(cur_cpu_spec->mmu_features & feature); +} +#else static inline int mmu_has_feature(unsigned long feature) { return (cur_cpu_spec->mmu_features & feature); } +#endif static inline void mmu_clear_feature(unsigned long feature) { diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c index 2014ab7..f25eb1d 100644 --- a/arch/powerpc/kernel/cputable.c +++ b/arch/powerpc/kernel/cputable.c @@ -2280,4 +2280,24 @@ static __init int cpu_feat_keys_init(void) return 0; } early_initcall(cpu_feat_keys_init); + +struct static_key mmu_feat_keys[MAX_MMU_FEATURES]; +struct static_key mmu_feat_keys_enabled; + +static __init int mmu_feat_keys_init(void) +{ + int i; + + for (i = 0; i < MAX_MMU_FEATURES; i++) { + unsigned long f = 1 << i; + + if (cur_cpu_spec->mmu_features & f) + static_key_slow_inc(&mmu_feat_keys[i]); + } + + static_key_slow_inc(&mmu_feat_keys_enabled); + + return 0; +} +early_initcall(mmu_feat_keys_init); #endif