From patchwork Wed Jul 12 15:01:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 787311 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x72JN033Cz9s72 for ; Thu, 13 Jul 2017 01:03:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P2ReDtG7"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3x72JM4wFHzDqhk for ; Thu, 13 Jul 2017 01:03:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P2ReDtG7"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-it0-x243.google.com (mail-it0-x243.google.com [IPv6:2607:f8b0:4001:c0b::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3x72GS1NtmzDqgX for ; Thu, 13 Jul 2017 01:01:36 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="P2ReDtG7"; dkim-atps=neutral Received: by mail-it0-x243.google.com with SMTP id o202so2373468itc.1 for ; Wed, 12 Jul 2017 08:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Z0Z8Ca4FktQi2K8wfixde3a/4H3DyHSK2QoWG1y/6Kg=; b=P2ReDtG7rMneP0konOBe3AKelo0GEqm2RkJE0W9TfDVZMFCg5Ueaq4VHD/YxdjBsYi WzrjxVc8ORVtlNrWoIhO4Pz1wCsPHCh/PhNBWRhQmkEdFsh97YgU3RL018GCBblzxHWB yCG+auZt2p2l5m3XI35sgU31FDfEWLw1YHNQU02Rb0WJcvYIrYdus+Xadq/KuMMGc4VZ ak74kMWfFNW384XiBuoIG10GzLSfHlgwTgLLeOdy0xHl/js4sbsKzstpaIL4yBqkyuZt rdE8uWozNmBPnqx7+H/fWljHY2P4RkxgNATafW9R0hDoe2AFZrZas4LAMNwSDkpXSa5s 5+BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Z0Z8Ca4FktQi2K8wfixde3a/4H3DyHSK2QoWG1y/6Kg=; b=KC6nsVpgZZG3VvEUFWyZansp0NXYP8dkbRnw1W7sYHCGsUVorDxTzhfwd62R9X1Oee AUVDoz0LsNyIpeRAUwg2pFZkNZ3dq+Qr3ollFC8YQoOdIFrLxWx0lx1+48wA4Vqn2VjV kKpdweST/rel2JC9j0DbNJy6nQOudv7QL3A48Dbe5sdKSj+/F65MAn8voY3q18xC8eG7 5bC+dPZQ7h8CTSBntVQxh1FNFomUjptV4bDAOxAtijeaVOM5JiuGGwyPWrp43qjCBK0G f89oICG03arnTPL8jgaM5ah46+qHCd/XfWFkVEZ44l3VJ1YMs+B6rgKSAXA8qh/CvIlW 9N+A== X-Gm-Message-State: AIVw110+vOgJ5vvnh1a9A1jBp21k7U6J6fDigQHn/o6dOI+j7tS90GqB us2zu0VOjJawcLyS X-Received: by 10.36.22.17 with SMTP id a17mr8571649ita.40.1499871693924; Wed, 12 Jul 2017 08:01:33 -0700 (PDT) Received: from localhost.localdomain.localdomain ([192.254.91.108]) by smtp.gmail.com with ESMTPSA id h196sm1616319ioe.41.2017.07.12.08.01.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 08:01:32 -0700 (PDT) From: Jia He To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/time: use get_tb instead of get_vtb in running_clock Date: Wed, 12 Jul 2017 23:01:10 +0800 Message-Id: <1499871670-24671-1-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.5.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stanislaw Gruszka , linux-kernel@vger.kernel.org, cyrilbur@gmail.com, Jia He , Paul Mackerras , fweisbec@gmail.com, John Stultz , Thomas Gleixner , Ivan Mikhaylov , Ingo Molnar Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Virtual time base(vtb) is a register which increases only in guest. Any exit from guest to host will stop the vtb(saved and restored by kvm). But if there is an IO causes guest exits to host, the guest's watchdog (watchdog_timer_fn -> is_softlockup -> get_timestamp -> running_clock) needs to also include the time elapsed in host. get_vtb is not correct in this case. Also, the TB_OFFSET is well saved and restored by qemu after commit [1]. So we can use get_tb here. [1] http://git.qemu.org/?p=qemu.git;a=commit;h=42043e4f1 Signed-off-by: Jia He --- arch/powerpc/kernel/time.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c index fe6f3a2..c542dd3 100644 --- a/arch/powerpc/kernel/time.c +++ b/arch/powerpc/kernel/time.c @@ -695,16 +695,15 @@ notrace unsigned long long sched_clock(void) unsigned long long running_clock(void) { /* - * Don't read the VTB as a host since KVM does not switch in host - * timebase into the VTB when it takes a guest off the CPU, reading the - * VTB would result in reading 'last switched out' guest VTB. + * Use get_tb instead of get_vtb for guest since the TB_OFFSET has been + * well saved/restored when qemu does suspend/resume. * * Host kernels are often compiled with CONFIG_PPC_PSERIES checked, it * would be unsafe to rely only on the #ifdef above. */ if (firmware_has_feature(FW_FEATURE_LPAR) && cpu_has_feature(CPU_FTR_ARCH_207S)) - return mulhdu(get_vtb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; + return mulhdu(get_tb() - boot_tb, tb_to_ns_scale) << tb_to_ns_shift; /* * This is a next best approximation without a VTB.