mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@kalray.eu>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@kalray.eu>
Subject: [PATCH 2/4] clock: Update cs->cycle_last when switching clock
Date: Thu, 25 Mar 2021 14:38:35 +0100	[thread overview]
Message-ID: <20210325133837.30866-2-jmaselbas@kalray.eu> (raw)
In-Reply-To: <20210325133837.30866-1-jmaselbas@kalray.eu>

If clocksource is free-running it might have been running for a while
before barebox started, we only care about the time spent in barebox.
We can discard the cycles accumulated before switching clocks by
updating cs->cycle_last with the cycles read for the new clock right
before switching.

Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
 common/clock.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/common/clock.c b/common/clock.c
index 58c2964b1..e30c81a37 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -222,6 +222,12 @@ int init_clock(struct clocksource *cs)
 			return ret;
 	}
 
+	/*
+	 * If clocksource is freerunning it might have been running for a while
+	 * before barebox started, we only care about the time spent in barebox
+	 * thus we must discard the clocksource cycles up to this exact moment:
+	 */
+	cs->cycle_last = cs->read() & cs->mask;
 	current_clock = cs;
 	time_beginning = get_time_ns();
 
-- 
2.17.1



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-03-25 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 13:38 [PATCH 1/4] clock: Change cyc2ns return type to uint64_t Jules Maselbas
2021-03-25 13:38 ` Jules Maselbas [this message]
2021-03-25 13:38 ` [PATCH 3/4] clock: Remove time_beginning Jules Maselbas
2021-03-25 13:38 ` [PATCH 4/4] common: common_console: Rework log_print Jules Maselbas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210325133837.30866-2-jmaselbas@kalray.eu \
    --to=jmaselbas@kalray.eu \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox