stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] MIPS: Fix r4k clockevents registration
@ 2016-07-21  6:27 Huacai Chen
  2016-07-21  6:27 ` [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled Huacai Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Huacai Chen @ 2016-07-21  6:27 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: John Crispin, Steven J . Hill, linux-mips, Fuxin Zhang,
	Zhangjin Wu, Huacai Chen, stable, Heiher

CPUFreq need min_delta_ticks/max_delta_ticks to be initialized, and
this can be done by clockevents_config_and_register().

Cc: stable@vger.kernel.org
Signed-off-by: Heiher <r@hev.cc>
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/kernel/cevt-r4k.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/mips/kernel/cevt-r4k.c b/arch/mips/kernel/cevt-r4k.c
index e4c21bb..804d2a2 100644
--- a/arch/mips/kernel/cevt-r4k.c
+++ b/arch/mips/kernel/cevt-r4k.c
@@ -276,12 +276,7 @@ int r4k_clockevent_init(void)
 				  CLOCK_EVT_FEAT_C3STOP |
 				  CLOCK_EVT_FEAT_PERCPU;
 
-	clockevent_set_clock(cd, mips_hpt_frequency);
-
-	/* Calculate the min / max delta */
-	cd->max_delta_ns	= clockevent_delta2ns(0x7fffffff, cd);
 	min_delta		= calculate_min_delta();
-	cd->min_delta_ns	= clockevent_delta2ns(min_delta, cd);
 
 	cd->rating		= 300;
 	cd->irq			= irq;
@@ -289,7 +284,7 @@ int r4k_clockevent_init(void)
 	cd->set_next_event	= mips_next_event;
 	cd->event_handler	= mips_event_handler;
 
-	clockevents_register_device(cd);
+	clockevents_config_and_register(cd, mips_hpt_frequency, min_delta, 0x7fffffff);
 
 	if (cp0_timer_irq_installed)
 		return 0;
-- 
2.7.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled
  2016-07-21  6:27 [PATCH 1/3] MIPS: Fix r4k clockevents registration Huacai Chen
@ 2016-07-21  6:27 ` Huacai Chen
  2016-07-22  2:20   ` Ralf Baechle
  2016-07-21  6:27 ` [PATCH 3/3] MIPS: hpet: Increase HPET_MIN_PROG_DELTA and decrease HPET_MIN_CYCLES Huacai Chen
  2016-07-22  3:25 ` [PATCH 1/3] MIPS: Fix r4k clockevents registration Ralf Baechle
  2 siblings, 1 reply; 6+ messages in thread
From: Huacai Chen @ 2016-07-21  6:27 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: John Crispin, Steven J . Hill, linux-mips, Fuxin Zhang,
	Zhangjin Wu, Huacai Chen, stable

Don't register r4k sched clock when CPUFREQ enabled because sched clock
need a constant frequency.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/kernel/csrc-r4k.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
index 1f91056..5131b98 100644
--- a/arch/mips/kernel/csrc-r4k.c
+++ b/arch/mips/kernel/csrc-r4k.c
@@ -82,7 +82,9 @@ int __init init_r4k_clocksource(void)
 
 	clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
 
+#ifndef CONFIG_CPUFREQ
 	sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency);
+#endif
 
 	return 0;
 }
-- 
2.7.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] MIPS: hpet: Increase HPET_MIN_PROG_DELTA and decrease HPET_MIN_CYCLES
  2016-07-21  6:27 [PATCH 1/3] MIPS: Fix r4k clockevents registration Huacai Chen
  2016-07-21  6:27 ` [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled Huacai Chen
@ 2016-07-21  6:27 ` Huacai Chen
  2016-07-22  3:25 ` [PATCH 1/3] MIPS: Fix r4k clockevents registration Ralf Baechle
  2 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2016-07-21  6:27 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: John Crispin, Steven J . Hill, linux-mips, Fuxin Zhang,
	Zhangjin Wu, Huacai Chen, stable

At first, we prefer to use mips clockevent device, so we decrease the
rating of hpet clockevent device.

For hpet, if HPET_MIN_PROG_DELTA (minimum delta of hpet programming) is
too small and HPET_MIN_CYCLES (threshold of -ETIME checking) is too
large, then hpet_next_event() can easily return -ETIME. After commit
c6eb3f70d44828 ("hrtimer: Get rid of hrtimer softirq") this will cause
a RCU stall.

So, HPET_MIN_PROG_DELTA must be sufficient that we don't re-trip the
-ETIME check -- if we do, we will return -ETIME, forward the next event
time, try to set it, return -ETIME again, and basically lock the system
up. Meanwhile, HPET_MIN_CYCLES doesn't need to be too large, 16 cycles
is enough.

This solution is similar to commit f9eccf24615672 ("clocksource/drivers
/vt8500: Increase the minimum delta").

By the way, this patch ensures hpet count/compare to be 32-bit long.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
 arch/mips/loongson64/loongson-3/hpet.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/mips/loongson64/loongson-3/hpet.c b/arch/mips/loongson64/loongson-3/hpet.c
index 249039a..4788bea 100644
--- a/arch/mips/loongson64/loongson-3/hpet.c
+++ b/arch/mips/loongson64/loongson-3/hpet.c
@@ -13,8 +13,8 @@
 #define SMBUS_PCI_REG64		0x64
 #define SMBUS_PCI_REGB4		0xb4
 
-#define HPET_MIN_CYCLES		64
-#define HPET_MIN_PROG_DELTA	(HPET_MIN_CYCLES + (HPET_MIN_CYCLES >> 1))
+#define HPET_MIN_CYCLES		16
+#define HPET_MIN_PROG_DELTA	(HPET_MIN_CYCLES * 12)
 
 static DEFINE_SPINLOCK(hpet_lock);
 DEFINE_PER_CPU(struct clock_event_device, hpet_clockevent_device);
@@ -157,14 +157,14 @@ static int hpet_tick_resume(struct clock_event_device *evt)
 static int hpet_next_event(unsigned long delta,
 		struct clock_event_device *evt)
 {
-	unsigned int cnt;
-	int res;
+	u32 cnt;
+	s32 res;
 
 	cnt = hpet_read(HPET_COUNTER);
-	cnt += delta;
+	cnt += (u32) delta;
 	hpet_write(HPET_T0_CMP, cnt);
 
-	res = (int)(cnt - hpet_read(HPET_COUNTER));
+	res = (s32)(cnt - hpet_read(HPET_COUNTER));
 
 	return res < HPET_MIN_CYCLES ? -ETIME : 0;
 }
@@ -230,7 +230,7 @@ void __init setup_hpet_timer(void)
 
 	cd = &per_cpu(hpet_clockevent_device, cpu);
 	cd->name = "hpet";
-	cd->rating = 320;
+	cd->rating = 100;
 	cd->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
 	cd->set_state_shutdown = hpet_set_state_shutdown;
 	cd->set_state_periodic = hpet_set_state_periodic;
-- 
2.7.0




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled
  2016-07-21  6:27 ` [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled Huacai Chen
@ 2016-07-22  2:20   ` Ralf Baechle
  2016-07-22  3:42     ` Huacai Chen
  0 siblings, 1 reply; 6+ messages in thread
From: Ralf Baechle @ 2016-07-22  2:20 UTC (permalink / raw)
  To: Huacai Chen
  Cc: John Crispin, Steven J . Hill, linux-mips, Fuxin Zhang,
	Zhangjin Wu, stable

On Thu, Jul 21, 2016 at 02:27:50PM +0800, Huacai Chen wrote:

> Don't register r4k sched clock when CPUFREQ enabled because sched clock
> need a constant frequency.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> ---
>  arch/mips/kernel/csrc-r4k.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> index 1f91056..5131b98 100644
> --- a/arch/mips/kernel/csrc-r4k.c
> +++ b/arch/mips/kernel/csrc-r4k.c
> @@ -82,7 +82,9 @@ int __init init_r4k_clocksource(void)
>  
>  	clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
>  
> +#ifndef CONFIG_CPUFREQ
>  	sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency);
> +#endif

There is no config symbol CONFIG_CPUFREQ and I think if the clock may
change, we shouldn't register it as csrc or cevt.

  Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] MIPS: Fix r4k clockevents registration
  2016-07-21  6:27 [PATCH 1/3] MIPS: Fix r4k clockevents registration Huacai Chen
  2016-07-21  6:27 ` [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled Huacai Chen
  2016-07-21  6:27 ` [PATCH 3/3] MIPS: hpet: Increase HPET_MIN_PROG_DELTA and decrease HPET_MIN_CYCLES Huacai Chen
@ 2016-07-22  3:25 ` Ralf Baechle
  2 siblings, 0 replies; 6+ messages in thread
From: Ralf Baechle @ 2016-07-22  3:25 UTC (permalink / raw)
  To: Huacai Chen
  Cc: John Crispin, linux-mips, Fuxin Zhang, Zhangjin Wu, stable,
	Heiher

Applied.

  Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled
  2016-07-22  2:20   ` Ralf Baechle
@ 2016-07-22  3:42     ` Huacai Chen
  0 siblings, 0 replies; 6+ messages in thread
From: Huacai Chen @ 2016-07-22  3:42 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: John Crispin, Linux MIPS Mailing List, Fuxin Zhang, Zhangjin Wu,
	stable

Oh, CONFIG_CPUFREQ should be CONFIG_CPU_FREQ. cevt-r4k can be used
because CPUFreq will call clockevents_update_freq() after frequency
changes, and csrc-r4k is need at boot time (then be replaced by other
csrc).

Huacai

On Fri, Jul 22, 2016 at 10:27 AM, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Thu, Jul 21, 2016 at 02:27:50PM +0800, Huacai Chen wrote:
>
>> Don't register r4k sched clock when CPUFREQ enabled because sched clock
>> need a constant frequency.
>>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Huacai Chen <chenhc@lemote.com>
>> ---
>>  arch/mips/kernel/csrc-r4k.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
>> index 1f91056..5131b98 100644
>> --- a/arch/mips/kernel/csrc-r4k.c
>> +++ b/arch/mips/kernel/csrc-r4k.c
>> @@ -82,7 +82,9 @@ int __init init_r4k_clocksource(void)
>>
>>       clocksource_register_hz(&clocksource_mips, mips_hpt_frequency);
>>
>> +#ifndef CONFIG_CPUFREQ
>>       sched_clock_register(r4k_read_sched_clock, 32, mips_hpt_frequency);
>> +#endif
>
> There is no config symbol CONFIG_CPUFREQ and I think if the clock may
> change, we shouldn't register it as csrc or cevt.
>
>   Ralf
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-07-22  3:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-21  6:27 [PATCH 1/3] MIPS: Fix r4k clockevents registration Huacai Chen
2016-07-21  6:27 ` [PATCH 2/3] MIPS: Don't register r4k sched clock when CPUFREQ enabled Huacai Chen
2016-07-22  2:20   ` Ralf Baechle
2016-07-22  3:42     ` Huacai Chen
2016-07-21  6:27 ` [PATCH 3/3] MIPS: hpet: Increase HPET_MIN_PROG_DELTA and decrease HPET_MIN_CYCLES Huacai Chen
2016-07-22  3:25 ` [PATCH 1/3] MIPS: Fix r4k clockevents registration Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).