Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1798549imm; Thu, 2 Aug 2018 00:55:09 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc6p7cY3C7UZtbpqzqMWP9iIUFrYtelSoxUb00bIgC7XwRneEwOnp3EyaIqBDDz8p43Aitq X-Received: by 2002:a17:902:bb0d:: with SMTP id l13-v6mr1463159pls.5.1533196509393; Thu, 02 Aug 2018 00:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533196509; cv=none; d=google.com; s=arc-20160816; b=idn6Vx1E8XxuLGOtxSCxqsVgzxyb2QTuPuMrTSJ9friB0lc9ww0Iw4dK6Qn8YOvS8e Y6/EfKlmFPGFBarcAYVdHZKkj2r9UXM6M/2dSQoWfA679pPw7mwz0uygb4MC2pGrwcy3 v0YndzjH3wEf91b37OPiYbSyZ16+1uYI415AP3+zW7SQ2X3XJwJyvrUfIDvR73A9sS5F YzWRf7Uj3huvSUE76xpC4t/feIBLZ7zAfl+CfCm0eJBQDuAN72Yg3fnLq8nV4ntQvEmv Bc47FGuh7BqdR+eykfLN2ZWDTKvqQC09293922Fv1PsiUhIJP5X8URxlR8QDRXZRsxgn Nkuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :arc-authentication-results; bh=+18A7DXWE+8CjEE4NXVK4zcsIUaFd+5fYlszo9+Ikko=; b=aDH7ueGjsAxDi/Fubv09OjKXayOuOFPcRT7DOjVCedOESX51xQbtQsyGqXTMzcR5ue yceg3SPamG9cb+juUJiGErRg9O3RNk/OPH/dM5Vb9JzOFd2ibjehL19YQEtf6p+XcLwj qNWm0PnIDFigsPyH7uy/APSjfTEEBxT15P6qF/9SMSThzSct13HJ3Lx9l8OgxbruXez1 osrKjzzq8A2K/QCeu4iaAUrSIzkfRVQLMiUOrScpDkXSUF1tO+UMvwxr+yx7S0zFRAY/ n432BdocTvQiX8oIEIFcS4L3Dj8o6p/3uKsjxR/cQMmBDn6HzCFTImzFL5Q77kWT1Bg6 gipg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12-v6si1308712pgg.653.2018.08.02.00.54.54; Thu, 02 Aug 2018 00:55:09 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbeHBJnz (ORCPT + 99 others); Thu, 2 Aug 2018 05:43:55 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:15523 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbeHBJnz (ORCPT ); Thu, 2 Aug 2018 05:43:55 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 41h2Vs3ZLmz9ttRq; Thu, 2 Aug 2018 09:53:57 +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 Xc4bp5f_MOhs; Thu, 2 Aug 2018 09:53:57 +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 41h2Vs338Bz9ttRp; Thu, 2 Aug 2018 09:53:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9C81B8B842; Thu, 2 Aug 2018 09:53:58 +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 M3sh0_gUDjZS; Thu, 2 Aug 2018 09:53:58 +0200 (CEST) Received: from po14934vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 53A3C8B755; Thu, 2 Aug 2018 09:53:58 +0200 (CEST) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id EEC6E6C0CC; Thu, 2 Aug 2018 07:53:57 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH v5 1/3] powerpc/time: isolate scaled cputime accounting in dedicated functions. To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Thu, 2 Aug 2018 07:53:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org scaled cputime is only meaningfull when the processor has SPURR and/or PURR, which means only on PPC64. In preparation of the following patch that will remove CONFIG_ARCH_HAS_SCALED_CPUTIME on PPC32, this patch moves all scaled cputing accounting logic into dedicated functions. This patch doesn't change any functionality. It's only code reorganisation. Signed-off-by: Christophe Leroy --- v5: - v4 patch split in two patches. First part isolates scaled cputime accounting in dedicated functions, second part activates it only on PPC64. - read_spurr() kept as a separate function. v4: - Using the correct symbol CONFIG_ARCH_HAS_SCALED_CPUTIME instead of ARCH_HAS_SCALED_CPUTIME - Grouped CONFIG_ARCH_HAS_SCALED_CPUTIME related code in dedicated functions to reduce the number of #ifdefs - Integrated read_spurr() directly into the related function. v3: Rebased following modifications in xmon.c v2: added ifdefs in xmon to fix compilation error arch/powerpc/kernel/time.c | 69 +++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index 70f145e02487..6196bd7393a3 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -281,26 +281,16 @@ static inline u64 calculate_stolen_time(u64 stop_tb) * Account time for a transition between system, hard irq * or soft irq state. */ -static unsigned long vtime_delta(struct task_struct *tsk, - unsigned long *stime_scaled, - unsigned long *steal_time) +static unsigned long vtime_delta_scaled(struct cpu_accounting_data *acct, + unsigned long now, unsigned long stime) { - unsigned long now, nowscaled, deltascaled; - unsigned long stime; + unsigned long stime_scaled; + unsigned long nowscaled, deltascaled; unsigned long utime, utime_scaled; - struct cpu_accounting_data *acct = get_accounting(tsk); - WARN_ON_ONCE(!irqs_disabled()); - - now = mftb(); nowscaled = read_spurr(now); - stime = now - acct->starttime; - acct->starttime = now; deltascaled = nowscaled - acct->startspurr; acct->startspurr = nowscaled; - - *steal_time = calculate_stolen_time(now); - utime = acct->utime - acct->utime_sspurr; acct->utime_sspurr = acct->utime; @@ -314,18 +304,38 @@ static unsigned long vtime_delta(struct task_struct *tsk, * the user ticks get saved up in paca->user_time_scaled to be * used by account_process_tick. */ - *stime_scaled = stime; + stime_scaled = stime; utime_scaled = utime; if (deltascaled != stime + utime) { if (utime) { - *stime_scaled = deltascaled * stime / (stime + utime); - utime_scaled = deltascaled - *stime_scaled; + stime_scaled = deltascaled * stime / (stime + utime); + utime_scaled = deltascaled - stime_scaled; } else { - *stime_scaled = deltascaled; + stime_scaled = deltascaled; } } acct->utime_scaled += utime_scaled; + return stime_scaled; +} + +static unsigned long vtime_delta(struct task_struct *tsk, + unsigned long *stime_scaled, + unsigned long *steal_time) +{ + unsigned long now, stime; + struct cpu_accounting_data *acct = get_accounting(tsk); + + WARN_ON_ONCE(!irqs_disabled()); + + now = mftb(); + stime = now - acct->starttime; + acct->starttime = now; + + *stime_scaled = vtime_delta_scaled(acct, now, stime); + + *steal_time = calculate_stolen_time(now); + return stime; } @@ -364,6 +374,19 @@ void vtime_account_idle(struct task_struct *tsk) acct->idle_time += stime + steal_time; } +static void vtime_flush_scaled(struct task_struct *tsk, + struct cpu_accounting_data *acct) +{ + if (acct->utime_scaled) + tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled); + if (acct->stime_scaled) + tsk->stimescaled += cputime_to_nsecs(acct->stime_scaled); + + acct->utime_scaled = 0; + acct->utime_sspurr = 0; + acct->stime_scaled = 0; +} + /* * Account the whole cputime accumulated in the paca * Must be called with interrupts disabled. @@ -378,9 +401,6 @@ void vtime_flush(struct task_struct *tsk) if (acct->utime) account_user_time(tsk, cputime_to_nsecs(acct->utime)); - if (acct->utime_scaled) - tsk->utimescaled += cputime_to_nsecs(acct->utime_scaled); - if (acct->gtime) account_guest_time(tsk, cputime_to_nsecs(acct->gtime)); @@ -393,8 +413,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), @@ -403,14 +421,13 @@ void vtime_flush(struct task_struct *tsk) account_system_index_time(tsk, cputime_to_nsecs(acct->softirq_time), CPUTIME_SOFTIRQ); + vtime_flush_scaled(tsk, acct); + acct->utime = 0; - acct->utime_scaled = 0; - acct->utime_sspurr = 0; 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; } -- 2.13.3