Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2675915rwo; Sun, 23 Jul 2023 22:15:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/8lKzyJdpe3fqhSbBjPWUaz9kmtL3Mmkh5zuVCTYDUTNO5tR3l3uUZvKbXm/L9vvgCK9B X-Received: by 2002:a05:6a20:1590:b0:13a:8082:5324 with SMTP id h16-20020a056a20159000b0013a80825324mr2269511pzj.44.1690175708082; Sun, 23 Jul 2023 22:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690175708; cv=none; d=google.com; s=arc-20160816; b=I7tRJWPfAxiNa8OkWFexaOUrufBGon5ZRZ3HyW8f8Skb87lWozm1JdRO3jih4/4+vZ DgmXVIzKlAE+tjW5EUaKO7TZlAZWgefxHNtZRMU+bY7Pfw36uhuuLyC65FQ2U8jtBF0O plI8f7LVTFZq9hnw+txtjFo0zLY/H1NS7ofyqvFTupsOt+5Z6dXkvBBtnkQuUiPhZj8A 991mmRN70fdyMO4+0PDJSX7ygBvLI9Q9jRcEWddNBB8evJ9KKd6npzZg+sAK4qABDmZI XZJbDSliYBzuQn2n3WwmE9ynt2U20UEEfHcVq1ACYNtT/zr74F0AjIpEtMBaFDd1zvz1 OhgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:sender:in-reply-to:references:mime-version :dkim-signature; bh=5ZHcL0SOTF6CbMrr4QYrXlvClPug/NnsMz11+ZmmbM8=; fh=yADw8/Prh9EaptzmrKNXXH5S9KMydJecD+wT192FNoY=; b=pVkx2aJfUD1heMoqeSxMX1EeJ5ffzGBR6BunlXAbMiFHJ0a7f1kCfcbqimTeWBASmU pS6mPEivzsXJdqX20WyMw7NXhh13aqg3uqulxRW5bLH/vI6IBILjNsdDRVJeiKNBCIqO ReCp4iykAWSv8IhZWMBPQjWKFgN5Z4jfH1/umBrvoxiP7DaAJL3gbJVVjkiwR171gYQO wouqRz3SHnZkIE5bRaHeC16GronwwvwlVMFLm1VoEfdqUKLDfniqCgI1q0zTp623dCjy UmdGOU03f0sxXckQsiTofHGHdNMeBT2P1OJPuXowWE5BJltFt7ILy1u9lF8DOATMseTo GqUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=pRVTF3y5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c2-20020a170902d48200b001bba8a9e29dsi874113plg.100.2023.07.23.22.14.55; Sun, 23 Jul 2023 22:15:08 -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=@gmail.com header.s=20221208 header.b=pRVTF3y5; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbjGXEhp (ORCPT + 99 others); Mon, 24 Jul 2023 00:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbjGXEhn (ORCPT ); Mon, 24 Jul 2023 00:37:43 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 444B8122 for ; Sun, 23 Jul 2023 21:37:42 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3172144c084so3483384f8f.1 for ; Sun, 23 Jul 2023 21:37:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690173461; x=1690778261; h=content-transfer-encoding:cc:to:subject:message-id:date:from:sender :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5ZHcL0SOTF6CbMrr4QYrXlvClPug/NnsMz11+ZmmbM8=; b=pRVTF3y5289BhDzNt9u0jcEPcvWzv2e5agYEpVHKjp4efAMhzU2Y1KWeEc3iBjmOTB GHjpZBZhk6E+dmCxwx5g252rJDoX5bH2xPwGCGFS11GdMrooViXyS5uRpb4jo661utty 1surwvYC2qjVcs5TwnuA6hd93zdqMCMXqtK37FNTaqgHWJ9NX/3xDpuhY408BuW+7kqc aVd+JVpI5W0BiOM9JXLS3gy2VrrTYGh43+jdXnuiQ0u/TDQLofcY8AZhHXGU4H43jrFf wmqC2ja0a5h9ydRc+3C5S4TJjCuzopW8WRU98k/D896e7bHN5kG9TDdsl/JcE4DdDkUC 8M0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690173461; x=1690778261; h=content-transfer-encoding:cc:to:subject:message-id:date:from:sender :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5ZHcL0SOTF6CbMrr4QYrXlvClPug/NnsMz11+ZmmbM8=; b=fYq/KVO3brLOl433JDJGeOz2CvETka7carnw8XJ8HtsufhBUnVTpiJtx56VcijRSXs cJPTkEG5rISCqdix2W3dJOqVrp8IUv2EqZjnx1KBHbLVGnT2PMCqNH8jWhPschnfVedh 3igyO9w/sP8ar22Vitsl7FWzGOHJoPNTnv3I+bzEA6pLYsIgGJwwnDiFzdmesVbSHD/Q oh8ub4tN0zuMwI2OqMK0RiTIUsyE9FadbFkaOl6kOW6nS5tWzq0jxn7ibsI5BFr609UY SUCncddB/OpgWXSsu5JVPhkGrexG2dD/jrHPrOWFQOzXGVwjJDnLYZ+HE5wadOho+1pJ mzwA== X-Gm-Message-State: ABy/qLav4javuPtxMtnnnhoGLpiIbNZyjROo4gYQM+O75xy6DaXoWuF3 +yHl3o3G9vW88vqtNVBi4c+opIXFKkfWn2kTZY4= X-Received: by 2002:adf:ea0f:0:b0:313:f957:bf29 with SMTP id q15-20020adfea0f000000b00313f957bf29mr8589889wrm.65.1690173460414; Sun, 23 Jul 2023 21:37:40 -0700 (PDT) MIME-Version: 1.0 References: <20230720103746.GC3569127@hirez.programming.kicks-ass.net> In-Reply-To: <20230720103746.GC3569127@hirez.programming.kicks-ass.net> Sender: getarunks@gmail.com X-Google-Sender-Delegation: getarunks@gmail.com From: Arun KS Date: Mon, 24 Jul 2023 10:07:28 +0530 X-Google-Sender-Auth: ah61y3xgMv4f2_-0Sl_0CKUkub8 Message-ID: Subject: Re: Question on sched_clock To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Arun KS , pmladek@suse.com, tglx@linutronix.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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 4:07=E2=80=AFPM Peter Zijlstra wrote: > > On Thu, Jul 20, 2023 at 03:54:56PM +0530, Arun KS wrote: > > CCing maintainers > > > > On Wed, Jul 19, 2023 at 10:36=E2=80=AFAM Arun KS wrote: > > > > > > Hi, > > > > > > Kernel=E2=80=99s printk uses local_clock() for timestamps and it is m= apped to > > > sched_clock(). Two problems/requirements I see, > > > > > > One, Kernel=E2=80=99s printk timestamps start from 0, I want to chang= e 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=E2=80=99t account for time spend in low powe= r > > > 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. Thanks Peter, Got your point. I was trying to understand if there are any other side effects of doing this downstream. > > > > > > > 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 ol= d counter*/ > > > new_epoch =3D read(); > > > cyc =3D cd.actual_read_sched_clock(); > > > - ns =3D rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & > > > rd.sched_clock_mask, rd.mult, rd.shift); > > > + if (!cyc) > > > + ns =3D cyc_to_ns(new_epoch, new_mult, new_shift) > > > + else > > > + ns =3D rd.epoch_ns + cyc_to_ns((cyc - rd.epoch_cyc) & > > > rd.sched_clock_mask, rd.mult, rd.shift); > > > cd.actual_read_sched_clock =3D read; > > > > > > rd.read_sched_clock =3D read; > > > > > > @@ -287,7 +290,6 @@ void sched_clock_resume(void) > > > { > > > struct clock_read_data *rd =3D &cd.read_data[0]; > > > > > > - rd->epoch_cyc =3D cd.actual_read_sched_clock(); > > And what if you've been suspended long enough to wrap the clock ?!? Fair point. Will take a note. > > > > hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_RE= L_HARD); > > > rd->read_sched_clock =3D cd.actual_read_sched_clock; > > > } > > > > > > Regards, > > > Arun