All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
To: "linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>
Cc: "linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"mturquette@baylibre.com" <mturquette@baylibre.com>,
	"sboyd@codeaurora.org" <sboyd@codeaurora.org>,
	"linux-snps-arc@lists.infradead.org"
	<linux-snps-arc@lists.infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Setting CPU clock frequency on early boot
Date: Tue, 5 Sep 2017 15:37:48 +0000	[thread overview]
Message-ID: <1504625867.32565.34.camel@synopsys.com> (raw)

Hello,

I'd like to get some feedback on our idea as well as check
if somebody faces similar situations and if so what would be the best
way to implement some generic solution that suits everyone.

So that's our problem:
1. On power-on hardware might start clocking CPU with either
   too high frequency (such that CPU may get stuck at some point)
   or too low frequency.

   That all sounds stupid but let me elaborate a bit here.
   I'm talking about FPGA-based devboards firmware for which
   (here I mean just image loaded in FPGA with CPU implementation
   but not some software yet) might not be stable or be even experimental.

   For example we may deal with dual-core or quad-core designs.
   Former might be OK running @100MHz and latter is only usable
   @75MHz and lower. The simplest solution might be to use some safe
   value before something like CPUfreq kicks in. But we don't yet have
   CPUfreq for ARC (we do plan to get it working sometime soon) which
   means simple change of CPU frequency once time-keeping infrastructure
   was brought-up is not an option... I.e. we'll end up with the system running
   much slower compared what could have been possible.

2. Up until now we used to do dirty hacks in early platform init code.
   Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
    1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
       boot stage still so no expanded DevTree yet exists).
    2) Check how many cores we have and which freq is usable
    3) Update PLL settings right in place if new freq != existing in PLL.

   Even though it is proven to work but with more platforms in the pipeline
   we'll need to copy-paste pretty much the same stuff across all affected
   plats. Which is not nice.

   Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
   Thus acting on PLL registers right in place was the only thing we were able
   to do. Now with introduction of normal clk driver
   (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
   it and have a cleaner and more universal solution to the problem.

   That's how it could be done - http://patchwork.ozlabs.org/patch/801240/
   Basically in architecture's time_init() we check if there's explicitly
   specified "clock-frequency" parameter in cpu's node in Device Tree and
   if there's one we set it via just instantiated clk driver.

We may indeed proceed with mentioned solution for ARC but if that makes
sense for somebody else it might worth getting something similar in generic
init code. Any thoughts?

All comments and suggestions are more than welcome.

-Alexey

WARNING: multiple messages have this Message-ID (diff)
From: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
To: "linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>
Cc: "linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"mturquette@baylibre.com" <mturquette@baylibre.com>,
	"sboyd@codeaurora.org" <sboyd@codeaurora.org>,
	"linux-snps-arc@lists.infradead.org"
	<linux-snps-arc@lists.infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>
Subject: Setting CPU clock frequency on early boot
Date: Tue, 5 Sep 2017 15:37:48 +0000	[thread overview]
Message-ID: <1504625867.32565.34.camel@synopsys.com> (raw)

SGVsbG8sDQoNCkknZCBsaWtlIHRvIGdldCBzb21lIGZlZWRiYWNrIG9uIG91ciBpZGVhIGFzIHdl
bGwgYXMgY2hlY2sNCmlmIHNvbWVib2R5IGZhY2VzIHNpbWlsYXIgc2l0dWF0aW9ucyBhbmQgaWYg
c28gd2hhdCB3b3VsZCBiZSB0aGUgYmVzdA0Kd2F5IHRvIGltcGxlbWVudCBzb21lIGdlbmVyaWMg
c29sdXRpb24gdGhhdCBzdWl0cyBldmVyeW9uZS4NCg0KU28gdGhhdCdzIG91ciBwcm9ibGVtOg0K
MS4gT24gcG93ZXItb24gaGFyZHdhcmUgbWlnaHQgc3RhcnQgY2xvY2tpbmcgQ1BVIHdpdGggZWl0
aGVyDQrCoCDCoHRvbyBoaWdoIGZyZXF1ZW5jeSAoc3VjaCB0aGF0IENQVSBtYXk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HNvbWV0aGluZyBzaW1pbGFyIGluIGdlbmVy
aWMNCmluaXQgY29kZS4gQW55IHRob3VnaHRzPw0KDQpBbGwgY29tbWVudHMgYW5kIHN1Z2dlc3Rp
b25zIGFyZSBtb3JlIHRoYW4gd2VsY29tZS4NCg0KLUFsZXhleQ==

WARNING: multiple messages have this Message-ID (diff)
From: Alexey.Brodkin@synopsys.com (Alexey Brodkin)
To: linux-snps-arc@lists.infradead.org
Subject: Setting CPU clock frequency on early boot
Date: Tue, 5 Sep 2017 15:37:48 +0000	[thread overview]
Message-ID: <1504625867.32565.34.camel@synopsys.com> (raw)

Hello,

I'd like to get some feedback on our idea as well as check
if somebody faces similar situations and if so what would be the best
way to implement some generic solution that suits everyone.

So that's our problem:
1. On power-on hardware might start clocking CPU with either
? ?too high frequency (such that CPU may get stuck at some point)
? ?or too low frequency.

? ?That all sounds stupid but let me elaborate a bit here.
? ?I'm talking about FPGA-based devboards firmware for which
? ?(here I mean just image loaded in FPGA with CPU implementation
? ?but not some software yet) might not be stable or be even experimental.

? ?For example we may deal with dual-core or quad-core designs.
? ?Former might be OK running @100MHz and latter is only usable
? ?@75MHz and lower. The simplest solution might be to use some safe
? ?value before something like CPUfreq kicks in. But we don't yet have
? ?CPUfreq for ARC (we do plan to get it working sometime soon) which
? ?means simple change of CPU frequency once time-keeping infrastructure
? ?was brought-up is not an option... I.e. we'll end up with the system running
? ?much slower compared what could have been possible.

2. Up until now we used to do dirty hacks in early platform init code.
? ?Namely (see?axs103_early_init() in?arch/arc/plat-axs10x/axs10x.c):
? ? 1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
? ? ? ?boot stage still so no expanded DevTree yet exists).
? ? 2) Check how many cores we have and which freq is usable
? ? 3) Update PLL settings right in place if new freq != existing in PLL.

? ?Even though it is proven to work but with more platforms in the pipeline
? ?we'll need to copy-paste pretty much the same stuff across all affected
? ?plats. Which is not nice.

? ?Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
? ?Thus acting on PLL registers right in place was the only thing we were able
? ?to do. Now with introduction of normal clk driver
? ?(see?drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
? ?it and have a cleaner and more universal solution to the problem.

? ?That's how it could be done -?http://patchwork.ozlabs.org/patch/801240/
? ?Basically in architecture's time_init() we check if there's explicitly
? ?specified "clock-frequency" parameter in cpu's node in Device Tree and
? ?if there's one we set it via just instantiated clk driver.

We may indeed proceed with mentioned solution for ARC but if that makes
sense for somebody else it might worth getting something similar in generic
init code. Any thoughts?

All comments and suggestions are more than welcome.

-Alexey

             reply	other threads:[~2017-09-05 15:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-05 15:37 Alexey Brodkin [this message]
2017-09-05 15:37 ` Setting CPU clock frequency on early boot Alexey Brodkin
2017-09-05 15:37 ` Alexey Brodkin
2017-09-05 22:03 ` Rob Herring
2017-09-05 22:03   ` Rob Herring
2017-09-05 23:40   ` Vineet Gupta
2017-09-05 23:40     ` Vineet Gupta
2017-09-06 13:51     ` Alexey Brodkin
2017-09-06 13:51       ` Alexey Brodkin
2017-09-06 13:51       ` Alexey Brodkin
2017-09-06 15:25       ` Rob Herring
2017-09-06 15:25         ` Rob Herring
     [not found]         ` <CAL_Jsq+B74keQ3N=8x6jx1URkLq8fa9gwsc5JAuiV86Wwczi9Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-06 16:22           ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 19:20             ` Rob Herring
2017-09-06 19:20               ` Rob Herring

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=1504625867.32565.34.camel@synopsys.com \
    --to=alexey.brodkin@synopsys.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@codeaurora.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 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.