All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Mike Turquette <mturquette@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>
Cc: "Linux Kernel" <linux-kernel@vger.kernel.org>,
	"Linux PM mailing list" <linux-pm@vger.kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Tomi Valkeinen" <tomi.valkeinen@ti.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Jim Quinlan" <jim2101024@gmail.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Gregory Fong" <gregory.0xf0@gmail.com>
Subject: clk: clock rates can overflow 32-bit fields
Date: Sun, 12 Apr 2015 21:24:22 -0700	[thread overview]
Message-ID: <CAN8TOE_7q1k_owngmwfzSADR_2Qe23A_PQfdmMCHcWqyrob2kQ@mail.gmail.com> (raw)

Hi,

I've recently been looking at using the common clock framework to
handle my CPU clocks for use by the cpufreq-dt driver, and I ran
across a few problems with integer overflow. On a 32-bit system,
'unsigned long' (the type used in clk_set_rate() and similar APIs) is
often a 32-bit integer. This constrains the maximum clock frequency to
~4.3 GHz, which is sufficient for most CPUs these days. However, I've
run into problems with high clock rates in the common clock framework
when

(1) using clk-divider.c; and/or
(2) using intermediate clocks that run faster than 4.3 GHz

With clk-divider.c, we can run into problems at lower clock rates due
to the usage of DIV_ROUND_UP (see, e.g., commit b11d282dbea2 "clk:
divider: fix rate calculation for fractional rates"), since this might
create overflows when doing the addition -- e.g., DIV_ROUND_UP(3 G,
1.5 G) = (3 G + 1.5 G - 1) / 1.5 G = (OVERFLOW) / 1.5 G

I could probably fix up the clk-divider.c issue locally, if necessary.
But problem (2) seems to suggest a larger change may be required
throughout the framework, and I'd like to solicit opinions before
hacking away.

So, any thoughts on how to best tackle this problem? Should we upgrade
the clock framework to use a guaranteed 64-bit type for clock rates
(e.g., u64)? I'm not sure if this will yield problems on certain
32-bit architectures when we start doing 64-bit integer division. But
I don't have many other great ideas at the moment...

Brian

             reply	other threads:[~2015-04-13  4:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13  4:24 Brian Norris [this message]
2015-04-13  5:53 ` clk: clock rates can overflow 32-bit fields Michael Turquette
2015-04-13 17:54   ` Brian Norris
     [not found]     ` <20150413184903.19585.42945@quantum>
2015-04-13 20:14       ` Brian Norris

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=CAN8TOE_7q1k_owngmwfzSADR_2Qe23A_PQfdmMCHcWqyrob2kQ@mail.gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregory.0xf0@gmail.com \
    --cc=jim2101024@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mturquette@linaro.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sboyd@codeaurora.org \
    --cc=tomi.valkeinen@ti.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.