Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3168505imj; Mon, 18 Feb 2019 21:42:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IZq7+gGElq6lGFwlNRXQ4y0opO/6iLUS2K3c8MFROQnP6y4+WMo92P0Y7gNRl9aZ1cSJAQD X-Received: by 2002:aa7:808a:: with SMTP id v10mr28163090pff.8.1550554943496; Mon, 18 Feb 2019 21:42:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550554943; cv=none; d=google.com; s=arc-20160816; b=yt1s4EqU26Xy16r/Zk9yCh+J7SfXvzaRfOhhaeb4UqFJT+jYK6Kg+J6l2dMwuUllpQ kaw/pqiiwUtWBa3QQr1a2BeuKaDt9uBYR8KP1dKv768X1/cP42S+fcmTE+OUlgDeAU/M lQWRFRiBbwRVxDVpC3q2kkxV03+G2bUfp9jeKrgGWqlQVpFpyVhvihalGyhs3miuB2eO AbPsWCXC612m7eolZCnUnS2QzaL6Y5cVeIK4Mm87FwCdwI4dIhvgkRBY8QQQwkbYMwaf /ta3fCuoCSlWqvf/lc8FRyI1E67nKORyaADY0yBSgKvmQg5nOnNje3GVH85H9Ao08HKL EdEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id :user-agent:mime-version:in-reply-to:references:cc:to:subject:from :date:dkim-signature; bh=+EU00narZM+oAtb9nqVNjy8vCYE2Vcg6Zve0xM2lu1U=; b=q/jX6tpm9nbFwcooBJCtKJKNQrHjFWXpXJ+3tlwcjoII5MmFqLT1IqVV4OZDERqJyK DI2yMVNfhDwNjtW7awDl0Dzjdt1IAO5ZpJO9llWOJz1JaFZe695OmQQVztc2zI1QM3iZ twi0/fYyODyYQ2TaKixE9tqcuYegU1/WDyb1Vn0kOFFgFbwCLq7NloJ/a1dF7VpXryAq rT88xfJLUrF5i0mh3K5WgRznNQym2SmFv8itMdlsGwW4xxvJI8B1sIgE9sYM5DeOMfDH yIFD4C0cXjcSwDSd8VWU8CPSnAWRcB57X7MR4ZTE6oWjVA2/1JamaranFaE5W8DUglxL x0gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="k8RP/xCU"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v32si1950109pgn.342.2019.02.18.21.42.08; Mon, 18 Feb 2019 21:42:23 -0800 (PST) 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=@gmail.com header.s=20161025 header.b="k8RP/xCU"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725803AbfBSFls (ORCPT + 99 others); Tue, 19 Feb 2019 00:41:48 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40991 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbfBSFlr (ORCPT ); Tue, 19 Feb 2019 00:41:47 -0500 Received: by mail-pg1-f195.google.com with SMTP id m1so9540665pgq.8 for ; Mon, 18 Feb 2019 21:41:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:references:in-reply-to:mime-version :user-agent:message-id:content-transfer-encoding; bh=+EU00narZM+oAtb9nqVNjy8vCYE2Vcg6Zve0xM2lu1U=; b=k8RP/xCUxV5xtkryv/jf100lW4O5XaRbWAMk287JpR5LmMSL1lZAChVuWUoJxPOD3L hVov2BLsWjOMpP6nm4uVflQ+ATADIyGsuNwlawetV47BcEQ6zfD5kCgmH2hIQq04hYpZ tJkMCDsjVcHEXR9EKVOC+GJvBbJM/UNQmZQGnTMM5HX7F+TPT/bB4naLtaS4abrs7RCN ZFL+bzXRxyH3MBl62uTO9zC9fr2Co2LZQQYgM9FWtTWIuz+26nt4iBMsxPw2SXv6Wmkl Cojtg8EKS5le5bt280Xkwd7XVAB+GkykE9UrnBhMw31oI+5k6rLUd7HaEOu90FEj3Pws Vgkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:user-agent:message-id:content-transfer-encoding; bh=+EU00narZM+oAtb9nqVNjy8vCYE2Vcg6Zve0xM2lu1U=; b=ZWcRrIxhAMlY8cTAokZDsp4v0wmUIZAOKc8YXkShnuD8yDu6uLhLQWuV4E9gLA/Wno frpF4Oxvpps38jIwLliW5yupAjc0dqYDOnrt3iF7fDBr9BnuuCRoZKGz1wPGEBgHg/oF GXB0oOCdnuKWW/kwdhLagzyuJ5j7iGPLyMeQUzJMOkzwRgpeA86qoxK73MJF4BNcZJUi /ZCH/0TTve6MB7HWuOCbtUjeXZn+kgcEhU/2joFB2Zcos93JX7+z+Au7OebSN+vJeNWA VmSBeWhTTbj4KTdY4r6i6LsguQXLuMhlpPurHws8zStb7GCpoui8bq2VpYTqctDvztZR pJvw== X-Gm-Message-State: AHQUAuYWYh8Cszz/wH5r5CfSjsgIjTYQ4EV0Zy5YCmzfs+EqCGwbgTsh gvZZjUl4iVOi0UXoMVoRS5Q= X-Received: by 2002:a63:698a:: with SMTP id e132mr22420032pgc.136.1550554906838; Mon, 18 Feb 2019 21:41:46 -0800 (PST) Received: from localhost ([61.69.157.156]) by smtp.gmail.com with ESMTPSA id v15sm14400741pfa.75.2019.02.18.21.41.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 21:41:46 -0800 (PST) Date: Tue, 19 Feb 2019 15:41:38 +1000 From: Nicholas Piggin Subject: Re: [RFC PATCH v1] powerpc/accounting: do not account system time on transition to user. To: Benjamin Herrenschmidt , Christophe Leroy , Michael Ellerman , Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org References: In-Reply-To: MIME-Version: 1.0 User-Agent: astroid/0.14.0 (https://github.com/astroidmail/astroid) Message-Id: <1550554276.8eb89h3g4q.astroid@bobo.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe Leroy's on February 9, 2019 12:40 am: > Time spent in kernel mode don't need to be accounted on transition > to user space. As far as the time spent in user is known, it > is possible to calculate the time spent in kernel by substracting > the time spent in user. >=20 > To do so, this patch modifies vtime_delta() to substract the > time spent in user since the last call to vtime_delta(). >=20 > This patch gives a 2% improvment of null_syscall() selftest on a 83xx. >=20 > Signed-off-by: Christophe Leroy This looks like a clever little optimization, although I don't know this time accounting code very well. > --- > But surprisingly, this patch degrades the null_syscall selftest by 20% on= the 8xx. Any idea of the reason ? I don't know microarchitecture of any of those CPUs I'm afraid. On the 64s CPUs, mftb is what hurts. >=20 > arch/powerpc/include/asm/accounting.h | 1 + > arch/powerpc/include/asm/ppc_asm.h | 8 +------- > arch/powerpc/kernel/asm-offsets.c | 8 ++------ > arch/powerpc/kernel/time.c | 4 +++- > 4 files changed, 7 insertions(+), 14 deletions(-) >=20 > diff --git a/arch/powerpc/include/asm/accounting.h b/arch/powerpc/include= /asm/accounting.h > index c607c5d835cc..2f1ff5f9fd7a 100644 > --- a/arch/powerpc/include/asm/accounting.h > +++ b/arch/powerpc/include/asm/accounting.h > @@ -27,6 +27,7 @@ struct cpu_accounting_data { > /* Internal counters */ > unsigned long starttime; /* TB value snapshot */ > unsigned long starttime_user; /* TB value on exit to usermode */ > + unsigned long utime_asm; > #ifdef CONFIG_ARCH_HAS_SCALED_CPUTIME > unsigned long startspurr; /* SPURR value snapshot */ > unsigned long utime_sspurr; /* ->user_time when ->startspurr set */ > diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/as= m/ppc_asm.h > index e0637730a8e7..be17d570d484 100644 > --- a/arch/powerpc/include/asm/ppc_asm.h > +++ b/arch/powerpc/include/asm/ppc_asm.h > @@ -28,9 +28,8 @@ > #define ACCOUNT_STOLEN_TIME > #else > #define ACCOUNT_CPU_USER_ENTRY(ptr, ra, rb) \ > - MFTB(ra); /* get timebase */ \ > PPC_LL rb, ACCOUNT_STARTTIME_USER(ptr); \ > - PPC_STL ra, ACCOUNT_STARTTIME(ptr); \ > + MFTB(ra); /* get timebase */ \ > subf rb,rb,ra; /* subtract start value */ \ > PPC_LL ra, ACCOUNT_USER_TIME(ptr); \ > add ra,ra,rb; /* add on to user time */ \ > @@ -38,12 +37,7 @@ > =20 > #define ACCOUNT_CPU_USER_EXIT(ptr, ra, rb) \ > MFTB(ra); /* get timebase */ \ > - PPC_LL rb, ACCOUNT_STARTTIME(ptr); \ > PPC_STL ra, ACCOUNT_STARTTIME_USER(ptr); \ > - subf rb,rb,ra; /* subtract start value */ \ > - PPC_LL ra, ACCOUNT_SYSTEM_TIME(ptr); \ > - add ra,ra,rb; /* add on to system time */ \ > - PPC_STL ra, ACCOUNT_SYSTEM_TIME(ptr) > =20 > #ifdef CONFIG_PPC_SPLPAR > #define ACCOUNT_STOLEN_TIME \ > diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-= offsets.c > index 7a1b93c5af63..f2ba7735f56f 100644 > --- a/arch/powerpc/kernel/asm-offsets.c > +++ b/arch/powerpc/kernel/asm-offsets.c > @@ -260,19 +260,15 @@ int main(void) > OFFSET(PACAHWCPUID, paca_struct, hw_cpu_id); > OFFSET(PACAKEXECSTATE, paca_struct, kexec_state); > OFFSET(PACA_DSCR_DEFAULT, paca_struct, dscr_default); > - OFFSET(ACCOUNT_STARTTIME, paca_struct, accounting.starttime); > OFFSET(ACCOUNT_STARTTIME_USER, paca_struct, accounting.starttime_user); > - OFFSET(ACCOUNT_USER_TIME, paca_struct, accounting.utime); > - OFFSET(ACCOUNT_SYSTEM_TIME, paca_struct, accounting.stime); > + OFFSET(ACCOUNT_USER_TIME, paca_struct, accounting.utime_asm); > OFFSET(PACA_TRAP_SAVE, paca_struct, trap_save); > OFFSET(PACA_NAPSTATELOST, paca_struct, nap_state_lost); > OFFSET(PACA_SPRG_VDSO, paca_struct, sprg_vdso); > #else /* CONFIG_PPC64 */ > #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE > - OFFSET(ACCOUNT_STARTTIME, thread_info, accounting.starttime); > OFFSET(ACCOUNT_STARTTIME_USER, thread_info, accounting.starttime_user); > - OFFSET(ACCOUNT_USER_TIME, thread_info, accounting.utime); > - OFFSET(ACCOUNT_SYSTEM_TIME, thread_info, accounting.stime); > + OFFSET(ACCOUNT_USER_TIME, thread_info, accounting.utime_asm); > #endif > #endif /* CONFIG_PPC64 */ > =20 > diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c > index bc0503ef9c9c..79420643b45f 100644 > --- a/arch/powerpc/kernel/time.c > +++ b/arch/powerpc/kernel/time.c > @@ -331,8 +331,10 @@ static unsigned long vtime_delta(struct task_struct = *tsk, > WARN_ON_ONCE(!irqs_disabled()); > =20 > now =3D mftb(); > - stime =3D now - acct->starttime; > + stime =3D now - acct->starttime - acct->utime_asm; > acct->starttime =3D now; > + acct->utime +=3D acct->utime_asm; > + acct->utime_asm =3D 0; > =20 > *stime_scaled =3D vtime_delta_scaled(acct, now, stime); > =20 > --=20 > 2.13.3 >=20 >=20 =