Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp9554imm; Tue, 17 Jul 2018 19:27:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfhgpIPgg3WCUXKWkAuDlrPonbC3c65yomgkxsfCDolfxBNdjU3W/qZW5rDghyDcHynFXFv X-Received: by 2002:a62:9f85:: with SMTP id v5-v6mr3199126pfk.27.1531880838229; Tue, 17 Jul 2018 19:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531880838; cv=none; d=google.com; s=arc-20160816; b=YL1jqu9sFun9gz/Qe+iMD8Ar1k1EudVFDNFBbQ76QNINLhk150wzf08K2OSg5jEPfk KbbqnqjdGmxsh9HD4aub1A9JydH2OfdxntHQdK/Y0jIwR8GBImlBwteE3N0nJ/MQbVsc 7/hy0ebVWFMRPTgVgHEffd3XM6qLqBO/fY6q7HMnbIP6Wmwpmzo6pdKR8bVRf+hic4jg 3+WkdJezAJ1PXxaAwdzhwnN+m4/TNG7ZlTj+aU0qss+vM+5Y2d4rI7YoO3bWWoHIz06X 6/Gm9efsDTw2HvEgmMokPJsksoUDR1F1Y1N6MCFCxcv/8MOIntbgTjBomNcnoSwGZxyb BZQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=5hjyk2dD33x04Cj4BddolvqMLS1cRPCrW3/wBUG7AgE=; b=Vh7DlEpYP9yPkgBEmnw+GyjUBiH0NupxQCgXVQFKWCLmGRJUkpdhq7egqU3yA3n4AB lwlikOrTXtdd3cz0GQmwTUTmsgQDIFhd4vHFaNHo9m9iGomHUynAAHgzMGLGefEC7OJ4 UmbegM+hVG6wcNN4vYcGYl73zM5FOtlX/2rP/Bj8UUyILNtvr9UnPymvFdaCI5w6mh+h k3AOfwvDQLh3iyK8+wfGXQ29hMl0lFlZ1QU2hgxDw5+ZP/HqO1CVVfZWGw5ISp52bw+u uYu/UazKffPKDp2/ovMpeoAgv3oScl/okHIPNedfe4sQDXJgTUCKuYL4IC9zp1asRHcJ WBlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=yXAIdtwm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8-v6si2061424pgq.432.2018.07.17.19.27.03; Tue, 17 Jul 2018 19:27:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=yXAIdtwm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731788AbeGRC7i (ORCPT + 99 others); Tue, 17 Jul 2018 22:59:38 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:45018 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731209AbeGRC7h (ORCPT ); Tue, 17 Jul 2018 22:59:37 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6I2K3Mh001258; Wed, 18 Jul 2018 02:23:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=5hjyk2dD33x04Cj4BddolvqMLS1cRPCrW3/wBUG7AgE=; b=yXAIdtwmv5L91cVKZXAcqTBD2A9zWsHhGM/j51Z6Rz4s0u6ek+2Zoy6uYS7rR/8Q4mZ8 0TqZGiUHCU6VgYjbUNLBAsWA1fAvFKcDJvG34bTwCbCRer4HI3yeIVlmcdyPdbAHafM+ uOfUjl9Xq4hBN2rvz2BtpmdQQ/HiWa88pSblgQiM6DkRp43AK0np5hGw9EtYC/UIdKVI CdZ7IRSns7/oGGGO+KgPf7nDlhCflJUZwz1lXvakPgQQK+yx7WGBTupmH+6i4hcXd/TU +9ICTenaKZv9NWTQ4dEEORTsISnHwxZsksKtUr0MnDrIec9BNcXn+Nyab8i15xWPJSu8 TQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2k7a3t34dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Jul 2018 02:23:24 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6I2NNto024718 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Jul 2018 02:23:23 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6I2NM7M020876; Wed, 18 Jul 2018 02:23:22 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 17 Jul 2018 19:23:22 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux@armlinux.org.uk, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, john.stultz@linaro.org, sboyd@codeaurora.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com, peterz@infradead.org, prarit@redhat.com, feng.tang@intel.com, pmladek@suse.com, gnomes@lxorguk.ukuu.org.uk, linux-s390@vger.kernel.org, pasha.tatashin@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, pbonzini@redhat.com Subject: [PATCH v14 25/25] sched: use static key for sched_clock_running Date: Tue, 17 Jul 2018 22:22:11 -0400 Message-Id: <20180718022211.6259-26-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180718022211.6259-1-pasha.tatashin@oracle.com> References: <20180718022211.6259-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8957 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807180026 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org sched_clock_running may be read every time sched_clock_cpu() is called. Yet, this variable is updated only twice during boot, and never changes again, therefore it is better to make it a static key. Signed-off-by: Pavel Tatashin --- kernel/sched/clock.c | 16 ++++++++-------- kernel/sched/debug.c | 2 -- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index 7a8a63b940ee..858a1c8f594c 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -67,7 +67,7 @@ unsigned long long __weak sched_clock(void) } EXPORT_SYMBOL_GPL(sched_clock); -__read_mostly int sched_clock_running; +static DEFINE_STATIC_KEY_FALSE(sched_clock_running); #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK /* @@ -191,7 +191,7 @@ void clear_sched_clock_stable(void) smp_mb(); /* matches sched_clock_init_late() */ - if (sched_clock_running == 2) + if (static_key_count(&sched_clock_running.key) == 2) __clear_sched_clock_stable(); } @@ -204,7 +204,7 @@ void __init sched_clock_init(void) { unsigned long flags; - sched_clock_running = 1; + static_branch_inc(&sched_clock_running); /* Adjust __gtod_offset for contigious transition from early clock */ local_irq_save(flags); @@ -218,7 +218,7 @@ void __init sched_clock_init(void) */ static int __init sched_clock_init_late(void) { - sched_clock_running = 2; + static_branch_inc(&sched_clock_running); /* * Ensure that it is impossible to not do a static_key update. * @@ -363,7 +363,7 @@ u64 sched_clock_cpu(int cpu) if (sched_clock_stable()) return sched_clock() + __sched_clock_offset; - if (unlikely(!sched_clock_running)) + if (!static_branch_unlikely(&sched_clock_running)) return sched_clock(); preempt_disable_notrace(); @@ -386,7 +386,7 @@ void sched_clock_tick(void) if (sched_clock_stable()) return; - if (unlikely(!sched_clock_running)) + if (!static_branch_unlikely(&sched_clock_running)) return; lockdep_assert_irqs_disabled(); @@ -445,13 +445,13 @@ EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event); void __init sched_clock_init(void) { - sched_clock_running = 1; + static_branch_inc(&sched_clock_running); generic_sched_clock_init(); } u64 sched_clock_cpu(int cpu) { - if (unlikely(!sched_clock_running)) + if (!static_branch_unlikely(&sched_clock_running)) return 0; return sched_clock(); diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c index e593b4118578..b0212f489a33 100644 --- a/kernel/sched/debug.c +++ b/kernel/sched/debug.c @@ -623,8 +623,6 @@ void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq) #undef PU } -extern __read_mostly int sched_clock_running; - static void print_cpu(struct seq_file *m, int cpu) { struct rq *rq = cpu_rq(cpu); -- 2.18.0