Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2138499imm; Thu, 19 Jul 2018 13:59:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfWwcIfNvCN88Iyk+BgicZ2aDKRrvS7B6FJ4KN5DCIUXjO3LeXxJKIygDsPxKBXQx9WeH9N X-Received: by 2002:a62:f206:: with SMTP id m6-v6mr10970549pfh.171.1532033955616; Thu, 19 Jul 2018 13:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532033955; cv=none; d=google.com; s=arc-20160816; b=pRr74w5hbKE5NyL1QSi9zFsp/azJ7ZFhMt76KnwZbXPLXkPDJBAk/iK/LK3nXZSXFm /C7OmOCO2EmYvf539zopPjITL/DSGLLLKqyN/CKBHIIlc+BhzVHHB6P8WRjGnUF7HeKJ 93+CW5T24fLZ3GJGaRd95bzxE9Hucy7F0SVeWjGzNw+MTrMprrgKBowKeez5GJLOZgyZ 6REeZgPB92HmPoimfqUUwi2hSYJggioAPvNPvK2YvlRAkK+ImFpyzslHanr2P9TYaiRV F9yNI/wq6EBqtYvtqnm9yFTHQe5ZKnRbzhUOiavmxj5TrhK0yEQA8wBdOYeN9GxiIiBQ Th+Q== 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=dzbdRsVcpRd3puPdtQhsnK0yjNMaBBFaHdmsNTI7sFw=; b=vgWOgC/8qSeVFNBtdJbyjI+ry/t7txgB2SGfOZmCIPeHxIvmk8mOd4CcUMjFupOxto l04DbJqv+pXMsnAMzt3Im8hP5GLdRXNSQSrJ+SOuH/F0TfuzaaB00IS86gZX9LGXPFmc qFTR8QdOZvyBJ0WydtIzr5iBF702vPnp8/NUKL7iCSUpzqNJu75cKnKBe165b8f/UuUp P3EkDe10F9PYWCSqjBlOKX/aKUFxdWbtLaf3Mkqccva+8BZeykQ5QYPb1iDj7kNmiaDI ndLWri9NWskl4wf/nvtQJ5BtYUcHyQegcXZ8qok8BoVl5MAVPx1mmY+mxtUAawgu0MJr HiMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=cvzS80tn; 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 d22-v6si159332pfd.182.2018.07.19.13.59.00; Thu, 19 Jul 2018 13:59:15 -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=cvzS80tn; 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 S1731675AbeGSVmu (ORCPT + 99 others); Thu, 19 Jul 2018 17:42:50 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:45804 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730315AbeGSVmt (ORCPT ); Thu, 19 Jul 2018 17:42:49 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6JKtWCr193100; Thu, 19 Jul 2018 20:57:00 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=dzbdRsVcpRd3puPdtQhsnK0yjNMaBBFaHdmsNTI7sFw=; b=cvzS80tnaGeD0aFzwCOseYCCla/K8HVZJXqjfVxEd1Y6O+Ow4LiqcUDixYHm0W/tyZBV 7LnQ4vsA+pg4jRVgHPS09xb39d8+Eufk0fsM+sPdyOEMrR+FrLTT5Q9qd7NfTLiALlwb MhfPSCnrkpAGUWvSPQElvsFTzhao2shJ/NdPiiikZLQK12L32kDR0rSRlip8UpjOhP82 mz5C8UNPZ2jNHdQtj6dhsrGP5r1fjcIeQoUIB2mPzFeNZUFyE2vxIJ4Stoh9zyU8cicL w/Vyx7iwtM6fs3pbq7nj4o662udLUgH82VEFMtwQYd5GOfl2u9zE8j6KAskX993tRlIl fA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2k9yjgruhj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:57:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6JKuxVO011883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:56:59 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6JKuwd7027025; Thu, 19 Jul 2018 20:56:58 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Jul 2018 20:56:58 +0000 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 v15 24/26] sched: use static key for sched_clock_running Date: Thu, 19 Jul 2018 16:55:43 -0400 Message-Id: <20180719205545.16512-25-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180719205545.16512-1-pasha.tatashin@oracle.com> References: <20180719205545.16512-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8959 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-1807190218 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 Acked-by: Peter Zijlstra --- 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 422cd63f8f17..c5c47ad3f386 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(); } @@ -215,7 +215,7 @@ void __init sched_clock_init(void) __sched_clock_gtod_offset(); local_irq_restore(flags); - sched_clock_running = 1; + static_branch_inc(&sched_clock_running); /* Now that sched_clock_running is set adjust scd */ local_irq_save(flags); @@ -228,7 +228,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. * @@ -373,7 +373,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(); @@ -396,7 +396,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(); @@ -455,13 +455,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