mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Vikram Narayanan <vikram186@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH] Helper function clocksource_khz2mult in clock.c
Date: Tue, 31 May 2011 02:51:45 +0530	[thread overview]
Message-ID: <1306790505.10548.6.camel@ubuntu.ubuntu-domain> (raw)

Hi,

Won't this helper function be a good one to add in the clock.c code?
Taken from the kernel file "include/linux/clocksource.h"
If it can be, please find below the patch.
---
diff --git a/common/clock.c b/common/clock.c
index 15df0ab..b07b449 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -57,6 +57,31 @@ uint64_t get_time_ns(void)
 EXPORT_SYMBOL(get_time_ns);
 
 /**
+ * clocksource_khz2mult - calculates mult from khz and shift
+ * @khz:		Clocksource frequency in KHz
+ * @shift_constant:	Clocksource shift factor
+ *
+ * Helper functions that converts a khz counter frequency to a
timsource
+ * multiplier, given the clocksource shift value
+ */
+static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
+{
+	/*  khz = cyc/(Million ns)
+	 *  mult/2^shift  = ns/cyc
+	 *  mult = ns/cyc * 2^shift
+	 *  mult = 1Million/khz * 2^shift
+	 *  mult = 1000000 * 2^shift / khz
+	 *  mult = (1000000<<shift) / khz
+	 */
+	u64 tmp = ((u64)1000000) << shift_constant;
+
+	tmp += khz/2; /* round for do_div */
+	do_div(tmp, khz);
+
+	return (u32)tmp;
+}
+
+/**
  * clocksource_hz2mult - calculates mult from hz and shift
  * @hz:                 Clocksource frequency in Hz
  * @shift_constant:     Clocksource shift factor

-
Thanks,
Vikram



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

                 reply	other threads:[~2011-05-30 21:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1306790505.10548.6.camel@ubuntu.ubuntu-domain \
    --to=vikram186@gmail.com \
    --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