Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9383287rwp; Thu, 20 Jul 2023 04:16:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlENiYUSiKhMybfAN2AXTLiG8dKjdsZLWvnlIUOWC4ELVEE0Jia+vMuXG4pEfe563ba3oPQI X-Received: by 2002:a05:6a20:938b:b0:12e:adbd:797a with SMTP id x11-20020a056a20938b00b0012eadbd797amr19302515pzh.62.1689851784507; Thu, 20 Jul 2023 04:16:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689851784; cv=none; d=google.com; s=arc-20160816; b=mYDSdBY29PBxD2kVcW+bAd5Sz8vpeKb7zuW2EJrScix+dhb/Zrf4lnLym7D5wtJEWQ fZTMa5fNIaaoZRPRH+Z8o8HtrEtafIuBNM8sarH5Y6OjNaHr+VmrDpflvPElHlMzxnlQ u8XuVGtZU3/chUoabEHwVBjxFLsSBre48oM9rpmyJtGikNyQLfXQjOdLk2/s6Kggmbz+ Grahfgbn1Hh+P/toDB3OG+V3NjeLjZUWA52yjjtvIUKzPPKLWbvaXZ+dB0ySW90D4lE9 3h6Nxs0SN5dpJIe1AKxxw6N+vUM0zaH2sjVY+KXKTaEU2FP8UwvtS4mYuk5KquEjNuLq lX4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bQIfEX3jdLPgeY6r+H0hIMqnc0pNiz7sqvIrDHFa7IQ=; fh=zIcYGqu5dc5+86T7p7oV1OqehhhxKY6jxvzasYgMQvc=; b=ruHvpN6sSdrhuTsLEpeP1hK1s7fncrkgaUfbX+YBnwFHmZmUSbwfpLytw5tHufbH4e EP4Smq5EmHcFhDlwghcbdGRCadUDxgaXyyCwHe44/0l7NCb6S+sIO3kvoOPzd7S8wTaU sBCnPtg27FSrgcNese8PvSXKiRMaMsmY6f5OaK8fvoAQMLvY/gAtRocsANOeCCGocsq5 Cz9bvbeR+ukPXEqIhkR3gblZz5JNvG1Vsh17vzxRTnbv07ovIJUTr8yW7UeQdnn2RH9g VoZJ06FPGGZGV4f093d9BgxwtoJ+S2TPjZUDsWf59+f1vC6c1ub47CmN50W5f55LQnQc bNzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=pbv2n7m2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a633306000000b00541710a9d44si630394pgz.114.2023.07.20.04.16.12; Thu, 20 Jul 2023 04:16:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=pbv2n7m2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjGTKiI (ORCPT + 99 others); Thu, 20 Jul 2023 06:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbjGTKhz (ORCPT ); Thu, 20 Jul 2023 06:37:55 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D6BC10F1 for ; Thu, 20 Jul 2023 03:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=bQIfEX3jdLPgeY6r+H0hIMqnc0pNiz7sqvIrDHFa7IQ=; b=pbv2n7m2GWEZBtUwG1Zlu+iUwU XdtJmruxFs8Sdaj8qYNh4o1G9EM19lSHqT86G5NP9ZayNsaV+KORG6qtEzr9Xu/n71gz4Srm4NO9k nAT9H05as1mDBZS7Tcn11DFA0dbvHyf0nXWiifVXVTim7/kiRWGFkTJDivq1Dl3niHQONjiNjuPVn LZ5hl7+vPbWTy7yB1vX6S2wdjNVZiM3/SbpZlWw11d8dK1XEXAkDJpeq9Iefb/KZVF6+dmGcotnks uwVZ26LU56LjpKeV/gZC6hrBLvNMhkW38j66bB/QMqFqFrhCcMrK+9dtOwCd9B1gj70+4iXoNx7r9 2A05q+tA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qMR2b-00FWew-1T; Thu, 20 Jul 2023 10:37:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7A57E300346; Thu, 20 Jul 2023 12:37:46 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 643D02612ABE5; Thu, 20 Jul 2023 12:37:46 +0200 (CEST) Date: Thu, 20 Jul 2023 12:37:46 +0200 From: Peter Zijlstra To: Arun KS Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Arun KS , pmladek@suse.com, tglx@linutronix.de Subject: Re: Question on sched_clock Message-ID: <20230720103746.GC3569127@hirez.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 20, 2023 at 03:54:56PM +0530, Arun KS wrote: > CCing maintainers > > On Wed, Jul 19, 2023 at 10:36 AM Arun KS wrote: > > > > Hi, > > > > Kernel’s printk uses local_clock() for timestamps and it is mapped to > > sched_clock(). Two problems/requirements I see, > > > > One, Kernel’s printk timestamps start from 0, I want to change this to > > match with actual time since boot. You can fundamentally only consistently tell time since the clock gets initialized. Starting at 0 is what you get. > > Two, sched_clock() doesn’t account for time spend in low power > > state(suspend to ram) Why would we do that? The next person will complain that they don't want this. Then another person complains they also want time spend in suspend-to-disk, and another person wants a pony. > > > > Could workout patches to modify these behaviours and found working in > > my system. But need to hear expert opinion on why this is not done in > > the upstream. > > > > diff --git a/kernel/time/sched_clock.c b/kernel/time/sched_clock.c > > index 68d6c1190ac7..b63b2ded5727 100644 > > --- a/kernel/time/sched_clock.c > > +++ b/kernel/time/sched_clock.c This is only one of many sched_clock implementations... > > @@ -190,7 +190,10 @@ sched_clock_register(u64 (*read)(void), int bits, > > unsigned long rate) > > /* Update epoch for new counter and update 'epoch_ns' from old counter*/ > > 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 (!cyc) > > + ns = cyc_to_ns(new_epoch, new_mult, new_shift) > > + else > > + ns = rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & > > rd.sched_clock_mask, rd.mult, rd.shift); > > cd.actual_read_sched_clock = read; > > > > rd.read_sched_clock = read; > > > > @@ -287,7 +290,6 @@ void sched_clock_resume(void) > > { > > struct clock_read_data *rd = &cd.read_data[0]; > > > > - rd->epoch_cyc = cd.actual_read_sched_clock(); And what if you've been suspended long enough to wrap the clock ?!? > > hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD); > > rd->read_sched_clock = cd.actual_read_sched_clock; > > } > > > > Regards, > > Arun