From patchwork Wed Jul 19 05:06:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arun KS X-Patchwork-Id: 13318134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3178EB64DA for ; Wed, 19 Jul 2023 05:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3wnRbjGacPT2pdpZyf1am+/LG9qNZbcIXKLw0mV0lz0=; b=C4U/2ow00CqTOn 827zRdL/9AIn+tziKmv0abNZ6t+tsY7YoU1DQaMtHLEdvE87Mhmk6tP6taps9i5hYzXhFPoTgcmbN vwfkQAeKG2w9yy5NcqiF8oOhXdqiiSmOOgfc0ZuH96lEpVa3/3XuWWu+xmduRGmEq/bB+NwNFD1Bz et5dE3lyhF6WaEBTLX/uJ5yYNfbdJ1VtBtfxw8quaOCt9UAYAVvbsU/eb0qqWrDcaszmU3wo9CMJr ym7+XBvV75nymQIvj1DEtZmQ0zArfxVWIZgyH5UPqlxbaSKwO28RCagrqyAKa/nrm4cVe6FAtWuKB VSqY50VbddWvDdnieTdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qLzON-0059D2-2P; Wed, 19 Jul 2023 05:06:27 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qLzOL-0059Bg-0L for linux-arm-kernel@lists.infradead.org; Wed, 19 Jul 2023 05:06:26 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-316f589549cso3663629f8f.1 for ; Tue, 18 Jul 2023 22:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689743182; x=1690347982; h=content-transfer-encoding:cc:to:subject:message-id:date:from:sender :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CacrP58zq0+usnB3XTcjIP1l3ZG/LBc8uVYTg+/ZhHE=; b=Qb9kl0E+ZO7vXpPckqwd3jjLELhISRRpLrsYJM4qyJ57r3ok98H1UGb4QpVxiQAB08 Ej/Vn04W4zns4jGYhiCa+7AhlzB67v62QGo0RQDNQrnN+ZkhZbQJD7J1PNBOy091l8kI 48X13h9L5pu5qUo29Rq2fLdR0MidmQMhfX1suFioLhcaNoqRIB8rmU9J9qMym9ZodmqE vzv7ZFECkHrxOZpQsZ/RsxNKldCNwxSh7/+oZKJ3yhlohW7AEEsHZcg8Rqro6r5YGV3Y FyhamBLuHfhUj5U6g8JSNi3Qa1OsG7WAsiNioqRzUB4NjdEJ6WEs2HxtmNEY5TV2X4ef vQfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689743182; x=1690347982; h=content-transfer-encoding:cc:to:subject:message-id:date:from:sender :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CacrP58zq0+usnB3XTcjIP1l3ZG/LBc8uVYTg+/ZhHE=; b=bTfXmalRslHn6zcJduOhahklrv5FyqLvYI/X18+OObrO1YwO6iuBWHaJBw9/fuTjf0 n9LLrtc0+VD6fxpXGT28gci+cq6jQA0SY01xjvnC/qK1LztoA2uU23OmOQvgKRchK5g5 gGM04aldkdFTfJ/mJu8/UDpzsemvgMFmeZwEvIOQoS6hVSZ7pFMQ7RdXfTTkuz6hL3PK 8w+nA3lQUTZV7D9zcM+Wp40ucchlgbTvFTLd9bNJJEw8z7S8DbDtM41lx2LQsnZSlk2W At91nmkzdlsNNjkIiQpxcPKWLo7X0LYK3qVzHYwX/2OM+7kkx95KaWNrHB2I4AAA++XZ JgAg== X-Gm-Message-State: ABy/qLZn5aVvlEMahbm9fERurGkTuS7nxuECaAuJ2wkZmxmKoYCykAlN RcEgpGA/ZAOeYK2jf2xBtjbvsY1HOCTyLiZB4S8= X-Google-Smtp-Source: APBJJlHyXo//D6l20y7ps/JakIZR/7tky4G6kIPHac2NdZy1caEM8dtk5Tce7IxyeVSp88egGmVCE8cxi+FRPay/Dbs= X-Received: by 2002:adf:fd89:0:b0:314:4437:beab with SMTP id d9-20020adffd89000000b003144437beabmr11779504wrr.55.1689743180159; Tue, 18 Jul 2023 22:06:20 -0700 (PDT) MIME-Version: 1.0 X-Google-Sender-Delegation: getarunks@gmail.com From: Arun KS Date: Wed, 19 Jul 2023 10:36:08 +0530 X-Google-Sender-Auth: yKFI9T3yjp-s4_w89q2fM5l5iV4 Message-ID: Subject: Question on sched_clock To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Arun KS X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230718_220625_146830_C3143054 X-CRM114-Status: GOOD ( 11.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Two, sched_clock() doesn’t account for time spend in low power state(suspend to ram) 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. 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(); hrtimer_start(&sched_clock_timer, cd.wrap_kt, HRTIMER_MODE_REL_HARD); rd->read_sched_clock = cd.actual_read_sched_clock; } Regards, Arun 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 @@ -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);