From patchwork Mon Jul 22 10:33:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 169363 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp7351164ilk; Mon, 22 Jul 2019 03:33:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxWIlVw6Rk8JGMXu4HZ4H2GA3PHitr+eZlMIaVh8Of8x8rAi/rArcxcxbvNY9xH+83O2DG X-Received: by 2002:a63:460c:: with SMTP id t12mr70504108pga.69.1563791628491; Mon, 22 Jul 2019 03:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563791628; cv=none; d=google.com; s=arc-20160816; b=Td5DdPQvlzKR0N2kdMtHXa6K5jsf6LIKNSVYjMamyqHoHvzGqmQ6eKQCKDu+X63AmD 0NzmCGe66G51z9aHWD7fPX9/ikW3h3KOnhqgaWxrocmvaNV9wwn0+DRRYBrQXesGJ/jT dQstcP/hyj1BRLkbBlReLEnh6Ir7c79IWxRFHQAXkWEVPJErfY6HbH69grLbCfOASJFp WyE0h4hvWJlKgvs/eGCKLulMJaOKfXi3+Skv/ag9POSdWbS6PpcQZ5hKPbAEeEEbJiP1 L8XUlD+2fCoPUa6hHa2GN0X/3YHrLzmRB1aCffVE5oRZbo4AOi+EfYGvSaFbfj+GHmwq rIAw== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RaDbNuC4MBGvGcxqus51YpNE67ZY3nuUdVRjylRx8dM=; b=OEtIPIYBOdyLJKsfleuqirU5hxjFcs1v4F8uuBkv9IOXgNaaCgEE7g82sU2iNYMYD4 O4D1NC0UKKBvQG1AqXm6GkDPY9i7sfu/8MJhG8EGWseTLHavKnJCRJ0a5I0p5dJe5w3Y m3BanNz3NGDJCOjO+SlDjlqEN+YJdqHq6cNLN31Y9PgH1almynUiiEBsn4dPZKt1wU/H 6SUcrt6jXEwZrbFrska3kq6VRGcaV2rw2uKBa1i9TAIBfT1Tb+SvLXzrK/GDIV+VVyqB X2lY5eqv4Lu6PQUBG/TMf5OsE80dDTqJEk3MEecy1Qzu98rXbpK6ZFoFmrNrW9KZrjXH R3GA== 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 l15si8044557pjq.104.2019.07.22.03.33.48; Mon, 22 Jul 2019 03:33:48 -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 S1729684AbfGVKdr (ORCPT + 29 others); Mon, 22 Jul 2019 06:33:47 -0400 Received: from foss.arm.com ([217.140.110.172]:35440 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbfGVKdo (ORCPT ); Mon, 22 Jul 2019 06:33:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E27DD1576; Mon, 22 Jul 2019 03:33:43 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7347E3F71A; Mon, 22 Jul 2019 03:33:42 -0700 (PDT) From: Marc Zyngier To: Thomas Gleixner , John Stultz , Pavel Tatashin , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Will Deacon , Catalin Marinas , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] sched/clock: Allow sched_clock to inherit timestamp_clock epoch Date: Mon, 22 Jul 2019 11:33:29 +0100 Message-Id: <20190722103330.255312-3-marc.zyngier@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722103330.255312-1-marc.zyngier@arm.com> References: <20190722103330.255312-1-marc.zyngier@arm.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we can let an architecture override the timestamping function, it becomes desirable to ensure that, should the architecture code switch its timestamping code to sched_clock once it has been registered, the sched_clock inherits the timestamp value as its new epoch. This ensures that the time stamps are continuous and that there is no jitter other than that introduced by the lack of quality of the timestamping clock. Signed-off-by: Marc Zyngier --- kernel/time/sched_clock.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.20.1 diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c index 142b07619918..ee1bd449ec81 100644 --- a/kernel/time/sched_clock.c +++ b/kernel/time/sched_clock.c @@ -192,6 +192,16 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate) new_epoch = read(); cyc = cd.actual_read_sched_clock(); ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & rd.sched_clock_mask, rd.mult, rd.shift); + + /* + * If the architecture has a timestamp clock, and this is the + * first time we register a new sched_clock, use the timestamp + * clock as the epoch. + */ + if (IS_ENABLED(CONFIG_ARCH_HAS_TIMESTAMP_CLOCK) && + unlikely(cd.actual_read_sched_clock == jiffy_sched_clock_read)) + ns = timestamp_clock(); + cd.actual_read_sched_clock = read; rd.read_sched_clock = read;