From patchwork Mon Apr 9 12:40:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 896274 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40KVRY1XHBz9s1r for ; Mon, 9 Apr 2018 22:46:33 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40KVRX6vldzF2B3 for ; Mon, 9 Apr 2018 22:46:32 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=c-s.fr (client-ip=93.17.236.30; helo=pegase1.c-s.fr; envelope-from=christophe.leroy@c-s.fr; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40KVJr6dBczDrnp for ; Mon, 9 Apr 2018 22:40:43 +1000 (AEST) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40KVJZ6Yclz9ty6F; Mon, 9 Apr 2018 14:40:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id Au2xLruTDr7z; Mon, 9 Apr 2018 14:40:30 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40KVJZ4x2Gz9ty63; Mon, 9 Apr 2018 14:40:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 515578B8E6; Mon, 9 Apr 2018 14:40:36 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id AV_5uS_g6-Of; Mon, 9 Apr 2018 14:40:36 +0200 (CEST) Received: from po15720vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.30]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 091ED8B8F5; Mon, 9 Apr 2018 14:40:36 +0200 (CEST) Received: by po15720vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0028A67B8D; Mon, 9 Apr 2018 14:40:35 +0200 (CEST) Message-Id: In-Reply-To: <61ed0c8c54d32d94ee7fb8c16d9f5c0873201bae.1523276971.git.christophe.leroy@c-s.fr> References: <61ed0c8c54d32d94ee7fb8c16d9f5c0873201bae.1523276971.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v2 2/2] powerpc/time: Only set ARCH_HAS_SCALED_CPUTIME on PPC64 To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Scott Wood Date: Mon, 9 Apr 2018 14:40:35 +0200 (CEST) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" scaled cputime is only meaningfull when the processor has SPURR and/or PURR, which means only on PPC64. Removing it on PPC32 significantly reduces the size of vtime_account_system() and vtime_account_idle() on an 8xx: Before: 00000114 l F .text 000000a8 vtime_delta 000004c0 g F .text 00000100 vtime_account_system 000005c0 g F .text 00000048 vtime_account_idle After: (vtime_delta gets inlined in the two functions) 00000418 g F .text 000000a0 vtime_account_system 000004b8 g F .text 00000054 vtime_account_idle In terms of performance, we also get approximatly 5% improvement on task switch: The following small benchmark app is run with perf stat: #include void *thread(void *arg) { int i; for (i = 0; i < atoi((char*)arg); i++) pthread_yield(); } int main(int argc, char **argv) { pthread_t th1, th2; pthread_create(&th1, NULL, thread, argv[1]); pthread_create(&th2, NULL, thread, argv[1]); pthread_join(th1, NULL); pthread_join(th2, NULL); return 0; } Before the patch: ~# perf stat chrt -f 98 ./sched 100000 Performance counter stats for 'chrt -f 98 ./sched 100000': 8622.166272 task-clock (msec) # 0.955 CPUs utilized 200027 context-switches # 0.023 M/sec After the patch: ~# perf stat chrt -f 98 ./sched 100000 Performance counter stats for 'chrt -f 98 ./sched 100000': 8207.090048 task-clock (msec) # 0.958 CPUs utilized 200025 context-switches # 0.024 M/sec Signed-off-by: Christophe Leroy --- v2: added ifdefs in xmon to fix compilation error arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/accounting.h | 4 ++++ arch/powerpc/include/asm/cputime.h | 2 ++ arch/powerpc/kernel/time.c | 29 +++++++++++++++++++++++------ arch/powerpc/xmon/xmon.c | 4 ++++ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 0c76d93d5da5..8c9f54779ff1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -142,7 +142,7 @@ config PPC select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_PMEM_API if PPC64 select ARCH_HAS_MEMBARRIER_CALLBACKS - select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE + select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE && PPC64 select ARCH_HAS_SG_CHAIN select ARCH_HAS_STRICT_KERNEL_RWX if ((PPC_BOOK3S_64 || PPC32) && !RELOCATABLE && !HIBERNATION) select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST diff --git a/arch/powerpc/include/asm/accounting.h b/arch/powerpc/include/asm/accounting.h index 3abcf98ed2e0..f1096d4cc658 100644 --- a/arch/powerpc/include/asm/accounting.h +++ b/arch/powerpc/include/asm/accounting.h @@ -15,8 +15,10 @@ struct cpu_accounting_data { /* Accumulated cputime values to flush on ticks*/ unsigned long utime; unsigned long stime; +#ifdef ARCH_HAS_SCALED_CPUTIME unsigned long utime_scaled; unsigned long stime_scaled; +#endif unsigned long gtime; unsigned long hardirq_time; unsigned long softirq_time; @@ -25,8 +27,10 @@ struct cpu_accounting_data { /* Internal counters */ unsigned long starttime; /* TB value snapshot */ unsigned long starttime_user; /* TB value on exit to usermode */ +#ifdef ARCH_HAS_SCALED_CPUTIME unsigned long startspurr; /* SPURR value snapshot */ unsigned long utime_sspurr; /* ->user_time when ->startspurr set */ +#endif }; #endif diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h index bc4903badb3f..8fd3c1338822 100644 --- a/arch/powerpc/include/asm/cputime.h +++ b/arch/powerpc/include/asm/cputime.h @@ -62,7 +62,9 @@ static inline void arch_vtime_task_switch(struct task_struct *prev) struct cpu_accounting_data *acct0 = get_accounting(prev); acct->starttime = acct0->starttime; +#ifdef ARCH_HAS_SCALED_CPUTIME acct->startspurr = acct0->startspurr; +#endif } #endif diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index a3ed2eb99d88..7d6040233003 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -175,6 +175,7 @@ static void calc_cputime_factors(void) * Read the SPURR on systems that have it, otherwise the PURR, * or if that doesn't exist return the timebase value passed in. */ +#ifdef ARCH_HAS_SCALED_CPUTIME static unsigned long read_spurr(unsigned long tb) { if (cpu_has_feature(CPU_FTR_SPURR)) @@ -183,6 +184,7 @@ static unsigned long read_spurr(unsigned long tb) return mfspr(SPRN_PURR); return tb; } +#endif #ifdef CONFIG_PPC_SPLPAR @@ -285,22 +287,28 @@ static unsigned long vtime_delta(struct task_struct *tsk, unsigned long *stime_scaled, unsigned long *steal_time) { - unsigned long now, nowscaled, deltascaled; + unsigned long now; unsigned long stime; +#ifdef ARCH_HAS_SCALED_CPUTIME + unsigned long nowscaled, deltascaled; unsigned long utime, utime_scaled; +#endif struct cpu_accounting_data *acct = get_accounting(tsk); WARN_ON_ONCE(!irqs_disabled()); now = mftb(); +#ifdef ARCH_HAS_SCALED_CPUTIME nowscaled = read_spurr(now); +#endif stime = now - acct->starttime; acct->starttime = now; - deltascaled = nowscaled - acct->startspurr; - acct->startspurr = nowscaled; *steal_time = calculate_stolen_time(now); +#ifdef ARCH_HAS_SCALED_CPUTIME + deltascaled = nowscaled - acct->startspurr; + acct->startspurr = nowscaled; utime = acct->utime - acct->utime_sspurr; acct->utime_sspurr = acct->utime; @@ -325,6 +333,7 @@ static unsigned long vtime_delta(struct task_struct *tsk, } } acct->utime_scaled += utime_scaled; +#endif return stime; } @@ -341,7 +350,9 @@ void vtime_account_system(struct task_struct *tsk) if ((tsk->flags & PF_VCPU) && !irq_count()) { acct->gtime += stime; +#ifdef ARCH_HAS_SCALED_CPUTIME acct->utime_scaled += stime_scaled; +#endif } else { if (hardirq_count()) acct->hardirq_time += stime; @@ -350,7 +361,9 @@ void vtime_account_system(struct task_struct *tsk) else acct->stime += stime; +#ifdef ARCH_HAS_SCALED_CPUTIME acct->stime_scaled += stime_scaled; +#endif } } EXPORT_SYMBOL_GPL(vtime_account_system); @@ -378,8 +391,12 @@ void vtime_flush(struct task_struct *tsk) if (acct->utime) account_user_time(tsk, cputime_to_nsecs(acct->utime)); +#ifdef ARCH_HAS_SCALED_CPUTIME if (acct->utime_scaled) tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled); + if (acct->stime_scaled) + tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled); +#endif if (acct->gtime) account_guest_time(tsk, cputime_to_nsecs(acct->gtime)); @@ -393,8 +410,6 @@ void vtime_flush(struct task_struct *tsk) if (acct->stime) account_system_index_time(tsk, cputime_to_nsecs(acct->stime), CPUTIME_SYSTEM); - if (acct->stime_scaled) - tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled); if (acct->hardirq_time) account_system_index_time(tsk, cputime_to_nsecs(acct->hardirq_time), @@ -404,13 +419,15 @@ void vtime_flush(struct task_struct *tsk) CPUTIME_SOFTIRQ); acct->utime = 0; +#ifdef ARCH_HAS_SCALED_CPUTIME acct->utime_scaled = 0; acct->utime_sspurr = 0; + acct->stime_scaled = 0; +#endif acct->gtime = 0; acct->steal_time = 0; acct->idle_time = 0; acct->stime = 0; - acct->stime_scaled = 0; acct->hardirq_time = 0; acct->softirq_time = 0; } diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c index a0842f1ff72c..8a3116faf4f6 100644 --- a/arch/powerpc/xmon/xmon.c +++ b/arch/powerpc/xmon/xmon.c @@ -2427,11 +2427,15 @@ static void dump_one_paca(int cpu) DUMP(p, accounting.utime, "llx"); DUMP(p, accounting.stime, "llx"); +#ifdef ARCH_HAS_SCALED_CPUTIME DUMP(p, accounting.utime_scaled, "llx"); +#endif DUMP(p, accounting.starttime, "llx"); DUMP(p, accounting.starttime_user, "llx"); +#ifdef ARCH_HAS_SCALED_CPUTIME DUMP(p, accounting.startspurr, "llx"); DUMP(p, accounting.utime_sspurr, "llx"); +#endif DUMP(p, accounting.steal_time, "llx"); #undef DUMP