From patchwork Wed Jun 8 03:05:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9163255 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 4F41D60831 for ; Wed, 8 Jun 2016 03:06:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 405DA2830C for ; Wed, 8 Jun 2016 03:06:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34C0B2836E; Wed, 8 Jun 2016 03:06:23 +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=ham 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 BFCDD2836E for ; Wed, 8 Jun 2016 03:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932253AbcFHDGA (ORCPT ); Tue, 7 Jun 2016 23:06:00 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34412 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932119AbcFHDF6 (ORCPT ); Tue, 7 Jun 2016 23:05:58 -0400 Received: by mail-pa0-f65.google.com with SMTP id ug1so5405639pab.1; Tue, 07 Jun 2016 20:05:58 -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=2gNZNVijg3i9hmwPF5r0MN2lnrt42XhuqFilWXbcvY0=; b=Djn9wNRXlZwug6K1K+drbjUjyRBpppTQpu/ahpCKly/z1p9n5RWqIYTkexq2fRkXeN pIZvdTtQvwZMzJ4bcc4M2nMdqlfjif7kt0uY5BJMVmi9pLjjKx77cAij7z5ksdLcRPFu NCxt00hZWcF5cZzQmSM1UXKU0atkCogONBUl+/wX8S6PDSmzMdRS1dve5fus+1hVU4XH NXjMXHQOEN6oMwEM+3ADSooRKQVYLnUwgp1l0yNzpKtRAGsnwOx3zi0pgKDQY41XqjY6 /X+s7iwg7kGyxmYW1L30nIXvhTDpzFHil/rssKEYuYh1FcElteTo+/bsTwrPRcTxRtBC YDnQ== 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=2gNZNVijg3i9hmwPF5r0MN2lnrt42XhuqFilWXbcvY0=; b=Gl6CgsUJtsk4yb8NCcXwrb/gODSChpPs24zcIr2nJ+sEl5D7JIOzPv/rhKGuzGcSuC 63D2Txtx8j/1R6MTBJF4kDcnWQfD0amqEGR/z3xE80r/XOo3UdMl4jGmOtv4E86Fb2+6 L8x7WDvrFtDNFxbuBRUZQVFmKTrPcPQ1xe+jqQqPLrWCcr8W8S7d/CLmxipw57RswrDk nQxOzxp48HO4j9Ch/9KQxHvV5k9U7tkowKP9DiZL6A7K6WQMV++2F6I8ckzMpsdnPpQM sTpqa1JVQqFJ4EsKf8ELxRQCqDgaGWqEmhzTzHbLQ1svKXfpVwjZj0/b2h+U+wblSnGF 91Fw== X-Gm-Message-State: ALyK8tLaR40A1JxCg/mw57Ja5iF86bExNto6xWNOny8IxMGFqcmFJEWmGb8Enmi5PmwzZw== X-Received: by 10.67.16.108 with SMTP id fv12mr3115580pad.8.1465355157562; Tue, 07 Jun 2016 20:05:57 -0700 (PDT) Received: from kernel.kingsoft.cn ([219.141.176.229]) by smtp.gmail.com with ESMTPSA id y70sm2368643pff.25.2016.06.07.20.05.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jun 2016 20:05:57 -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 v5 3/3] sched/cputime: Add steal time support to full dynticks CPU time accounting Date: Wed, 8 Jun 2016 11:05:10 +0800 Message-Id: <1465355110-21714-3-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465355110-21714-1-git-send-email-wanpeng.li@hotmail.com> References: <1465355110-21714-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 listened to ring boundaries, so steal_account_process_tick() is reused to account how many 'ticks' are stolen-time, after the last accumulation. Suggested-by: Rik van Riel 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 --- v4 -> v5: * apply same logic to account_idle_time, so change get_vtime_delta instead v3 -> v4: * fix grammar errors, thanks Ingo * cleanup fragile codes, thanks Ingo v2 -> v3: * convert steal time jiffies to cputime v1 -> v2: * fix divide zero bug, thanks Rik kernel/sched/cputime.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index 75f98c5..b62f9f8 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(void) { #ifdef CONFIG_PARAVIRT if (static_key_false(¶virt_steal_enabled)) { @@ -279,7 +279,7 @@ static __always_inline bool steal_account_process_tick(void) return steal_jiffies; } #endif - return false; + return 0; } /* @@ -681,12 +681,17 @@ 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; + cputime_t delta_time, steal_time; + steal_time = jiffies_to_cputime(steal_account_process_tick()); + delta_time = jiffies_to_cputime(now - tsk->vtime_snap); WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE); tsk->vtime_snap = now; - return jiffies_to_cputime(delta); + if (steal_time < delta_time) + delta_time -= steal_time; + + return delta_time; } static void __vtime_account_system(struct task_struct *tsk)