From patchwork Mon Jun 13 10:32:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9172587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA5EC608A2 for ; Mon, 13 Jun 2016 10:33:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C84FA27BC3 for ; Mon, 13 Jun 2016 10:33:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2E2B27D45; Mon, 13 Jun 2016 10:33:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44E4927BC3 for ; Mon, 13 Jun 2016 10:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965390AbcFMKdE (ORCPT ); Mon, 13 Jun 2016 06:33:04 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:35934 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964910AbcFMKdB (ORCPT ); Mon, 13 Jun 2016 06:33:01 -0400 Received: by mail-pa0-f68.google.com with SMTP id fg1so10255890pad.3; Mon, 13 Jun 2016 03:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sNjmzL0ZSeLnud4sy6yvDX6agKt1gd/ULa+wYt8KI3k=; b=bMymfL5wHpfBcFpnj6BF11lCEiilHlhMycXZNKsEAd8KFZ20usUrF/+poxnt5QF2zE WxaLzBh0VQjNZezQJLLObDBmrLoxLL7e3BryYXp3QbWooDbsRVauYMRq9HKj9z7/7YfZ jpthc4jP4o1uo7Weu18liIN/obl5WSiJUIdt0CR6ptTaiODGTOlklDmOcDR6Z5jeV7Bo hU/IzQzwLp2kU+HIip5gX7BEnOJm00LxhPt0jIsQY2ETbwW8omyZIstnTlPiNXOu9LIr sqJky8fdSJYGxkpGFeVkVSUQreDnM8r2p/I2IrvGJ2fe0k95lhUH87yV6MWJmeqY788K lX5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sNjmzL0ZSeLnud4sy6yvDX6agKt1gd/ULa+wYt8KI3k=; b=ZkB5MPScM/SvUaIj7Ja81IcBZTz0PV07J2Y5UrlrXMXayp28Yck9AmEBXfoDvDO4fV Mgv0OACblMXcd96I+ZtqlUhJqZYiTsWi5ra1iMmorJvah9MYyirXpR03fzZlIQ5VNisp +V8PwT9/BanOmwz7qhK0Yz8C9CB//UcNIyqytFxErqeU6BleASTzhZ2BjqGTvWOJ/OVR Pfxhqy/mqsKs9oroRLnKdJoAdkc9ZBKPDvvPsiZ1zQmc7U5SYYIOJsl8HngCVWZQ9Nsq t21TaOjRPSnKKD+Lh+tpHxdTg6/prQ7XuaiWH0NfN7fqU8OAOzU0OPsWfC5Qb7taU4Rm CvpQ== X-Gm-Message-State: ALyK8tJExIsU0PcCgeYlo3JfKOvIM64zQx485sGrq5CVSttTB+RDU27XnWQ6WwUu0Y6oyw== X-Received: by 10.66.47.133 with SMTP id d5mr21696578pan.48.1465813980237; Mon, 13 Jun 2016 03:33:00 -0700 (PDT) Received: from kernel.kingsoft.cn ([114.255.44.132]) by smtp.gmail.com with ESMTPSA id ih15sm36520885pab.38.2016.06.13.03.32.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Jun 2016 03:32:59 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Wanpeng Li , Ingo Molnar , "Peter Zijlstra (Intel)" , Rik van Riel , Thomas Gleixner , Frederic Weisbecker , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH v6 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting Date: Mon, 13 Jun 2016 18:32:46 +0800 Message-Id: <1465813966-3116-4-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465813966-3116-1-git-send-email-wanpeng.li@hotmail.com> References: <1465813966-3116-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li This patch adds guest steal-time support to full dynticks CPU time accounting. After the following commit: ff9a9b4c4334 ("sched, time: Switch VIRT_CPU_ACCOUNTING_GEN to jiffy granularity") ... time sampling became jiffy based, even if it's still listening to ring boundaries, so steal_account_process_tick() is reused to account how many 'ticks' are stolen-time, after the last accumulation. Cc: Ingo Molnar Cc: Peter Zijlstra (Intel) Cc: Rik van Riel Cc: Thomas Gleixner Cc: Frederic Weisbecker Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li Reviewed-by: Paolo Bonzini --- kernel/sched/cputime.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 75f98c5..3d60e5d 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -257,7 +257,7 @@ void account_idle_time(cputime_t cputime) cpustat[CPUTIME_IDLE] += (__force u64) cputime; } -static __always_inline bool steal_account_process_tick(void) +static __always_inline unsigned long steal_account_process_tick(unsigned long max_jiffies) { #ifdef CONFIG_PARAVIRT if (static_key_false(¶virt_steal_enabled)) { @@ -272,14 +272,14 @@ static __always_inline bool steal_account_process_tick(void) * time in jiffies. Lets cast the result to jiffies * granularity and account the rest on the next rounds. */ - steal_jiffies = nsecs_to_jiffies(steal); + steal_jiffies = min(nsecs_to_jiffies(steal), max_jiffies); this_rq()->prev_steal_time += jiffies_to_nsecs(steal_jiffies); account_steal_time(jiffies_to_cputime(steal_jiffies)); return steal_jiffies; } #endif - return false; + return 0; } /* @@ -346,7 +346,7 @@ static void irqtime_account_process_tick(struct task_struct *p, int user_tick, u64 cputime = (__force u64) cputime_one_jiffy; u64 *cpustat = kcpustat_this_cpu->cpustat; - if (steal_account_process_tick()) + if (steal_account_process_tick(ULONG_MAX)) return; cputime *= ticks; @@ -477,7 +477,7 @@ void account_process_tick(struct task_struct *p, int user_tick) return; } - if (steal_account_process_tick()) + if (steal_account_process_tick(ULONG_MAX)) return; if (user_tick) @@ -681,12 +681,14 @@ static cputime_t vtime_delta(struct task_struct *tsk) static cputime_t get_vtime_delta(struct task_struct *tsk) { unsigned long now = READ_ONCE(jiffies); - unsigned long delta = now - tsk->vtime_snap; + unsigned long delta_jiffies, steal_jiffies; + delta_jiffies = now - tsk->vtime_snap; + steal_jiffies = steal_account_process_tick(delta_jiffies); WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE); tsk->vtime_snap = now; - return jiffies_to_cputime(delta); + return jiffies_to_cputime(delta_jiffies - steal_jiffies); } static void __vtime_account_system(struct task_struct *tsk)