* [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63().
@ 2009-11-22 13:04 Wu Zhangjin
2009-11-22 19:03 ` Sergei Shtylyov
0 siblings, 1 reply; 5+ messages in thread
From: Wu Zhangjin @ 2009-11-22 13:04 UTC (permalink / raw)
To: Ralf Baechle
Cc: Ingo Molnar, Thomas Gleixner, linux-mips, Michal Simek,
Sergei Shtylyov, Wu Zhangjin
From: Wu Zhangjin <wuzhangjin@gmail.com>
(This v3 revision incorporates with the feedbacks from Ingo, Ralf and Sergei.)
This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(),
which provides high resolution. and also, one new kernel option
(HR_SCHED_CLOCK) is added to enable/disable this sched_clock().
Without it, the Ftrace for MIPS will give useless timestamp information.
Because cnt32_to_63() needs to be called at least once per half period
to work properly, Differ from the old version, this v2 revision set up a
kernel timer to ensure the requirement of some MIPSs which have short c0
count period.
Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
---
arch/mips/Kconfig | 18 ++++++++++++++
arch/mips/kernel/csrc-r4k.c | 55 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index b342197..5ea55f5 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1952,6 +1952,24 @@ config NR_CPUS
source "kernel/time/Kconfig"
#
+# High Resolution sched_clock() Configuration
+#
+
+config HR_SCHED_CLOCK
+ bool "High Resolution sched_clock()"
+ depends on CSRC_R4K
+ default n
+ help
+ This option enables the MIPS c0 count based high resolution
+ sched_clock().
+
+ If you need a ns precision timestamp, you are recommended to enable
+ this option. For example, If you are using the Ftrace subsystem to do
+ real time tracing, this option is needed.
+
+ If unsure, disable it.
+
+#
# Timer Interrupt Frequency Configuration
#
diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
index e95a3cd..e287f0d 100644
--- a/arch/mips/kernel/csrc-r4k.c
+++ b/arch/mips/kernel/csrc-r4k.c
@@ -10,6 +10,57 @@
#include <asm/time.h>
+#ifdef CONFIG_HR_SCHED_CLOCK
+#include <linux/cnt32_to_63.h>
+#include <linux/timer.h>
+
+/*
+ * MIPS sched_clock implementation.
+ *
+ * because cnt32_to_63() needs to be called at least once per half period to
+ * work properly, and some of the MIPS frequency is high, perhaps a kernel
+ * timer is needed to be set up to ensure this requirement is always met.
+ * Please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h
+ */
+static unsigned long __read_mostly tclk2ns_scale;
+static unsigned long __read_mostly tclk2ns_scale_factor;
+
+unsigned long long notrace sched_clock(void)
+{
+ unsigned long long v = cnt32_to_63(read_c0_count());
+ return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
+}
+
+static struct timer_list cnt32_to_63_keepwarm_timer;
+
+static void cnt32_to_63_keepwarm(unsigned long data)
+{
+ mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
+ (void) sched_clock();
+}
+
+static void __init setup_sched_clock(struct clocksource *cs, unsigned long tclk)
+{
+ unsigned long long v;
+ unsigned long data;
+
+ v = cs->mult;
+ /*
+ * We want an even value to automatically clear the top bit
+ * returned by cnt32_to_63() without an additional run time
+ * instruction. So if the LSB is 1 then round it up.
+ */
+ if (v & 1)
+ v++;
+ tclk2ns_scale = v;
+ tclk2ns_scale_factor = cs->shift;
+
+ data = 0x80000000 / tclk * HZ;
+ setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
+ mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
+}
+#endif /* !CONFIG_HR_SCHED_CLOCK */
+
static cycle_t c0_hpt_read(struct clocksource *cs)
{
return read_c0_count();
@@ -32,6 +83,10 @@ int __init init_r4k_clocksource(void)
clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
+#ifdef CONFIG_HR_SCHED_CLOCK
+ setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
+#endif
+
clocksource_register(&clocksource_mips);
return 0;
--
1.6.2.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63().
2009-11-22 13:04 [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63() Wu Zhangjin
@ 2009-11-22 19:03 ` Sergei Shtylyov
2009-11-23 1:00 ` Wu Zhangjin
0 siblings, 1 reply; 5+ messages in thread
From: Sergei Shtylyov @ 2009-11-22 19:03 UTC (permalink / raw)
To: Wu Zhangjin
Cc: Ralf Baechle, Ingo Molnar, Thomas Gleixner, linux-mips, Michal Simek
Hello.
Wu Zhangjin wrote:
> From: Wu Zhangjin <wuzhangjin@gmail.com>
>
> (This v3 revision incorporates with the feedbacks from Ingo, Ralf and Sergei.)
>
> This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(),
> which provides high resolution. and also, one new kernel option
> (HR_SCHED_CLOCK) is added to enable/disable this sched_clock().
>
> Without it, the Ftrace for MIPS will give useless timestamp information.
>
> Because cnt32_to_63() needs to be called at least once per half period
> to work properly, Differ from the old version, this v2 revision set up a
> kernel timer to ensure the requirement of some MIPSs which have short c0
> count period.
>
> Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> ---
> arch/mips/Kconfig | 18 ++++++++++++++
> arch/mips/kernel/csrc-r4k.c | 55 +++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 73 insertions(+), 0 deletions(-)
>
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index b342197..5ea55f5 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -1952,6 +1952,24 @@ config NR_CPUS
> source "kernel/time/Kconfig"
>
> #
> +# High Resolution sched_clock() Configuration
> +#
> +
> +config HR_SCHED_CLOCK
> + bool "High Resolution sched_clock()"
> + depends on CSRC_R4K
> + default n
> + help
> + This option enables the MIPS c0 count based high resolution
> + sched_clock().
> +
> + If you need a ns precision timestamp, you are recommended to enable
> + this option. For example, If you are using the Ftrace subsystem to do
> + real time tracing, this option is needed.
> +
> + If unsure, disable it.
> +
> +#
> # Timer Interrupt Frequency Configuration
> #
>
> diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> index e95a3cd..e287f0d 100644
> --- a/arch/mips/kernel/csrc-r4k.c
> +++ b/arch/mips/kernel/csrc-r4k.c
> @@ -10,6 +10,57 @@
>
> #include <asm/time.h>
>
> +#ifdef CONFIG_HR_SCHED_CLOCK
> +#include <linux/cnt32_to_63.h>
> +#include <linux/timer.h>
> +
> +/*
> + * MIPS sched_clock implementation.
> + *
> + * because cnt32_to_63() needs to be called at least once per half period to
> + * work properly, and some of the MIPS frequency is high, perhaps a kernel
> + * timer is needed to be set up to ensure this requirement is always met.
> + * Please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h
> + */
> +static unsigned long __read_mostly tclk2ns_scale;
> +static unsigned long __read_mostly tclk2ns_scale_factor;
> +
> +unsigned long long notrace sched_clock(void)
> +{
> + unsigned long long v = cnt32_to_63(read_c0_count());
> + return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
> +}
> +
> +static struct timer_list cnt32_to_63_keepwarm_timer;
> +
> +static void cnt32_to_63_keepwarm(unsigned long data)
> +{
> + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> + (void) sched_clock();
> +}
> +
> +static void __init setup_sched_clock(struct clocksource *cs, unsigned long tclk)
> +{
> + unsigned long long v;
> + unsigned long data;
> +
> + v = cs->mult;
> + /*
> + * We want an even value to automatically clear the top bit
> + * returned by cnt32_to_63() without an additional run time
> + * instruction. So if the LSB is 1 then round it up.
> + */
> + if (v & 1)
> + v++;
> + tclk2ns_scale = v;
> + tclk2ns_scale_factor = cs->shift;
> +
> + data = 0x80000000 / tclk * HZ;
> + setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
> + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> +}
> +#endif /* !CONFIG_HR_SCHED_CLOCK */
> +
> static cycle_t c0_hpt_read(struct clocksource *cs)
> {
> return read_c0_count();
> @@ -32,6 +83,10 @@ int __init init_r4k_clocksource(void)
>
> clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
>
> +#ifdef CONFIG_HR_SCHED_CLOCK
> + setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
> +#endif
> +
>
According to CodingStyle #ifdef's in the code are frowned upon. I
suggest that you add an empty setup_sched_clock() definition under #else
above and have the call here without #ifdef. That's the preferred way of
doing such things...
WBR, Sergei
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63().
2009-11-22 19:03 ` Sergei Shtylyov
@ 2009-11-23 1:00 ` Wu Zhangjin
2009-11-23 8:44 ` Ingo Molnar
0 siblings, 1 reply; 5+ messages in thread
From: Wu Zhangjin @ 2009-11-23 1:00 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: Ralf Baechle, Ingo Molnar, Thomas Gleixner, linux-mips, Michal Simek
On Sun, 2009-11-22 at 22:03 +0300, Sergei Shtylyov wrote:
> Hello.
>
> Wu Zhangjin wrote:
>
> > From: Wu Zhangjin <wuzhangjin@gmail.com>
> >
> > (This v3 revision incorporates with the feedbacks from Ingo, Ralf and Sergei.)
> >
> > This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(),
> > which provides high resolution. and also, one new kernel option
> > (HR_SCHED_CLOCK) is added to enable/disable this sched_clock().
> >
> > Without it, the Ftrace for MIPS will give useless timestamp information.
> >
> > Because cnt32_to_63() needs to be called at least once per half period
> > to work properly, Differ from the old version, this v2 revision set up a
> > kernel timer to ensure the requirement of some MIPSs which have short c0
> > count period.
> >
> > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > ---
> > arch/mips/Kconfig | 18 ++++++++++++++
> > arch/mips/kernel/csrc-r4k.c | 55 +++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 73 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> > index b342197..5ea55f5 100644
> > --- a/arch/mips/Kconfig
> > +++ b/arch/mips/Kconfig
> > @@ -1952,6 +1952,24 @@ config NR_CPUS
> > source "kernel/time/Kconfig"
> >
> > #
> > +# High Resolution sched_clock() Configuration
> > +#
> > +
> > +config HR_SCHED_CLOCK
> > + bool "High Resolution sched_clock()"
> > + depends on CSRC_R4K
> > + default n
> > + help
> > + This option enables the MIPS c0 count based high resolution
> > + sched_clock().
> > +
> > + If you need a ns precision timestamp, you are recommended to enable
> > + this option. For example, If you are using the Ftrace subsystem to do
> > + real time tracing, this option is needed.
> > +
> > + If unsure, disable it.
> > +
> > +#
> > # Timer Interrupt Frequency Configuration
> > #
> >
> > diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> > index e95a3cd..e287f0d 100644
> > --- a/arch/mips/kernel/csrc-r4k.c
> > +++ b/arch/mips/kernel/csrc-r4k.c
> > @@ -10,6 +10,57 @@
> >
> > #include <asm/time.h>
> >
> > +#ifdef CONFIG_HR_SCHED_CLOCK
> > +#include <linux/cnt32_to_63.h>
> > +#include <linux/timer.h>
> > +
> > +/*
> > + * MIPS sched_clock implementation.
> > + *
> > + * because cnt32_to_63() needs to be called at least once per half period to
> > + * work properly, and some of the MIPS frequency is high, perhaps a kernel
> > + * timer is needed to be set up to ensure this requirement is always met.
> > + * Please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h
> > + */
> > +static unsigned long __read_mostly tclk2ns_scale;
> > +static unsigned long __read_mostly tclk2ns_scale_factor;
> > +
> > +unsigned long long notrace sched_clock(void)
> > +{
> > + unsigned long long v = cnt32_to_63(read_c0_count());
> > + return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
> > +}
> > +
> > +static struct timer_list cnt32_to_63_keepwarm_timer;
> > +
> > +static void cnt32_to_63_keepwarm(unsigned long data)
> > +{
> > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > + (void) sched_clock();
> > +}
> > +
> > +static void __init setup_sched_clock(struct clocksource *cs, unsigned long tclk)
> > +{
> > + unsigned long long v;
> > + unsigned long data;
> > +
> > + v = cs->mult;
> > + /*
> > + * We want an even value to automatically clear the top bit
> > + * returned by cnt32_to_63() without an additional run time
> > + * instruction. So if the LSB is 1 then round it up.
> > + */
> > + if (v & 1)
> > + v++;
> > + tclk2ns_scale = v;
> > + tclk2ns_scale_factor = cs->shift;
> > +
> > + data = 0x80000000 / tclk * HZ;
> > + setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
> > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > +}
> > +#endif /* !CONFIG_HR_SCHED_CLOCK */
> > +
> > static cycle_t c0_hpt_read(struct clocksource *cs)
> > {
> > return read_c0_count();
> > @@ -32,6 +83,10 @@ int __init init_r4k_clocksource(void)
> >
> > clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
> >
> > +#ifdef CONFIG_HR_SCHED_CLOCK
> > + setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
> > +#endif
> > +
> >
>
> According to CodingStyle #ifdef's in the code are frowned upon. I
> suggest that you add an empty setup_sched_clock() definition under #else
> above and have the call here without #ifdef. That's the preferred way of
> doing such things...
>
Done, thanks!
Wil resend it later.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63().
2009-11-23 1:00 ` Wu Zhangjin
@ 2009-11-23 8:44 ` Ingo Molnar
2009-11-23 9:00 ` Wu Zhangjin
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2009-11-23 8:44 UTC (permalink / raw)
To: Wu Zhangjin
Cc: Sergei Shtylyov, Ralf Baechle, Thomas Gleixner, linux-mips, Michal Simek
* Wu Zhangjin <wuzhangjin@gmail.com> wrote:
> On Sun, 2009-11-22 at 22:03 +0300, Sergei Shtylyov wrote:
> > Hello.
> >
> > Wu Zhangjin wrote:
> >
> > > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > >
> > > (This v3 revision incorporates with the feedbacks from Ingo, Ralf and Sergei.)
> > >
> > > This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(),
> > > which provides high resolution. and also, one new kernel option
> > > (HR_SCHED_CLOCK) is added to enable/disable this sched_clock().
> > >
> > > Without it, the Ftrace for MIPS will give useless timestamp information.
> > >
> > > Because cnt32_to_63() needs to be called at least once per half period
> > > to work properly, Differ from the old version, this v2 revision set up a
> > > kernel timer to ensure the requirement of some MIPSs which have short c0
> > > count period.
> > >
> > > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > > ---
> > > arch/mips/Kconfig | 18 ++++++++++++++
> > > arch/mips/kernel/csrc-r4k.c | 55 +++++++++++++++++++++++++++++++++++++++++++
> > > 2 files changed, 73 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> > > index b342197..5ea55f5 100644
> > > --- a/arch/mips/Kconfig
> > > +++ b/arch/mips/Kconfig
> > > @@ -1952,6 +1952,24 @@ config NR_CPUS
> > > source "kernel/time/Kconfig"
> > >
> > > #
> > > +# High Resolution sched_clock() Configuration
> > > +#
> > > +
> > > +config HR_SCHED_CLOCK
> > > + bool "High Resolution sched_clock()"
> > > + depends on CSRC_R4K
> > > + default n
> > > + help
> > > + This option enables the MIPS c0 count based high resolution
> > > + sched_clock().
> > > +
> > > + If you need a ns precision timestamp, you are recommended to enable
> > > + this option. For example, If you are using the Ftrace subsystem to do
> > > + real time tracing, this option is needed.
> > > +
> > > + If unsure, disable it.
> > > +
> > > +#
> > > # Timer Interrupt Frequency Configuration
> > > #
> > >
> > > diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> > > index e95a3cd..e287f0d 100644
> > > --- a/arch/mips/kernel/csrc-r4k.c
> > > +++ b/arch/mips/kernel/csrc-r4k.c
> > > @@ -10,6 +10,57 @@
> > >
> > > #include <asm/time.h>
> > >
> > > +#ifdef CONFIG_HR_SCHED_CLOCK
> > > +#include <linux/cnt32_to_63.h>
> > > +#include <linux/timer.h>
> > > +
> > > +/*
> > > + * MIPS sched_clock implementation.
> > > + *
> > > + * because cnt32_to_63() needs to be called at least once per half period to
> > > + * work properly, and some of the MIPS frequency is high, perhaps a kernel
> > > + * timer is needed to be set up to ensure this requirement is always met.
> > > + * Please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h
> > > + */
> > > +static unsigned long __read_mostly tclk2ns_scale;
> > > +static unsigned long __read_mostly tclk2ns_scale_factor;
> > > +
> > > +unsigned long long notrace sched_clock(void)
> > > +{
> > > + unsigned long long v = cnt32_to_63(read_c0_count());
> > > + return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
> > > +}
> > > +
> > > +static struct timer_list cnt32_to_63_keepwarm_timer;
> > > +
> > > +static void cnt32_to_63_keepwarm(unsigned long data)
> > > +{
> > > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > > + (void) sched_clock();
> > > +}
> > > +
> > > +static void __init setup_sched_clock(struct clocksource *cs, unsigned long tclk)
> > > +{
> > > + unsigned long long v;
> > > + unsigned long data;
> > > +
> > > + v = cs->mult;
> > > + /*
> > > + * We want an even value to automatically clear the top bit
> > > + * returned by cnt32_to_63() without an additional run time
> > > + * instruction. So if the LSB is 1 then round it up.
> > > + */
> > > + if (v & 1)
> > > + v++;
> > > + tclk2ns_scale = v;
> > > + tclk2ns_scale_factor = cs->shift;
> > > +
> > > + data = 0x80000000 / tclk * HZ;
> > > + setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
> > > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > > +}
> > > +#endif /* !CONFIG_HR_SCHED_CLOCK */
> > > +
> > > static cycle_t c0_hpt_read(struct clocksource *cs)
> > > {
> > > return read_c0_count();
> > > @@ -32,6 +83,10 @@ int __init init_r4k_clocksource(void)
> > >
> > > clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
> > >
> > > +#ifdef CONFIG_HR_SCHED_CLOCK
> > > + setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
> > > +#endif
> > > +
> > >
> >
> > According to CodingStyle #ifdef's in the code are frowned upon. I
> > suggest that you add an empty setup_sched_clock() definition under #else
> > above and have the call here without #ifdef. That's the preferred way of
> > doing such things...
> >
>
> Done, thanks!
>
> Wil resend it later.
The proper solution would be what i suggested in my previous mail: to
put it into a separate .c file. It's easy as the code has its own
Kconfig value already. The only #ifdef is out of sight in a .h file.
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63().
2009-11-23 8:44 ` Ingo Molnar
@ 2009-11-23 9:00 ` Wu Zhangjin
0 siblings, 0 replies; 5+ messages in thread
From: Wu Zhangjin @ 2009-11-23 9:00 UTC (permalink / raw)
To: Ingo Molnar
Cc: Sergei Shtylyov, Ralf Baechle, Thomas Gleixner, linux-mips, Michal Simek
On Mon, 2009-11-23 at 09:44 +0100, Ingo Molnar wrote:
> * Wu Zhangjin <wuzhangjin@gmail.com> wrote:
>
> > On Sun, 2009-11-22 at 22:03 +0300, Sergei Shtylyov wrote:
> > > Hello.
> > >
> > > Wu Zhangjin wrote:
> > >
> > > > From: Wu Zhangjin <wuzhangjin@gmail.com>
> > > >
> > > > (This v3 revision incorporates with the feedbacks from Ingo, Ralf and Sergei.)
> > > >
> > > > This patch adds a cnt32_to_63() and MIPS c0 count based sched_clock(),
> > > > which provides high resolution. and also, one new kernel option
> > > > (HR_SCHED_CLOCK) is added to enable/disable this sched_clock().
> > > >
> > > > Without it, the Ftrace for MIPS will give useless timestamp information.
> > > >
> > > > Because cnt32_to_63() needs to be called at least once per half period
> > > > to work properly, Differ from the old version, this v2 revision set up a
> > > > kernel timer to ensure the requirement of some MIPSs which have short c0
> > > > count period.
> > > >
> > > > Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
> > > > ---
> > > > arch/mips/Kconfig | 18 ++++++++++++++
> > > > arch/mips/kernel/csrc-r4k.c | 55 +++++++++++++++++++++++++++++++++++++++++++
> > > > 2 files changed, 73 insertions(+), 0 deletions(-)
> > > >
> > > > diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> > > > index b342197..5ea55f5 100644
> > > > --- a/arch/mips/Kconfig
> > > > +++ b/arch/mips/Kconfig
> > > > @@ -1952,6 +1952,24 @@ config NR_CPUS
> > > > source "kernel/time/Kconfig"
> > > >
> > > > #
> > > > +# High Resolution sched_clock() Configuration
> > > > +#
> > > > +
> > > > +config HR_SCHED_CLOCK
> > > > + bool "High Resolution sched_clock()"
> > > > + depends on CSRC_R4K
> > > > + default n
> > > > + help
> > > > + This option enables the MIPS c0 count based high resolution
> > > > + sched_clock().
> > > > +
> > > > + If you need a ns precision timestamp, you are recommended to enable
> > > > + this option. For example, If you are using the Ftrace subsystem to do
> > > > + real time tracing, this option is needed.
> > > > +
> > > > + If unsure, disable it.
> > > > +
> > > > +#
> > > > # Timer Interrupt Frequency Configuration
> > > > #
> > > >
> > > > diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> > > > index e95a3cd..e287f0d 100644
> > > > --- a/arch/mips/kernel/csrc-r4k.c
> > > > +++ b/arch/mips/kernel/csrc-r4k.c
> > > > @@ -10,6 +10,57 @@
> > > >
> > > > #include <asm/time.h>
> > > >
> > > > +#ifdef CONFIG_HR_SCHED_CLOCK
> > > > +#include <linux/cnt32_to_63.h>
> > > > +#include <linux/timer.h>
> > > > +
> > > > +/*
> > > > + * MIPS sched_clock implementation.
> > > > + *
> > > > + * because cnt32_to_63() needs to be called at least once per half period to
> > > > + * work properly, and some of the MIPS frequency is high, perhaps a kernel
> > > > + * timer is needed to be set up to ensure this requirement is always met.
> > > > + * Please refer to arch/arm/plat-orion/time.c and include/linux/cnt32_to_63.h
> > > > + */
> > > > +static unsigned long __read_mostly tclk2ns_scale;
> > > > +static unsigned long __read_mostly tclk2ns_scale_factor;
> > > > +
> > > > +unsigned long long notrace sched_clock(void)
> > > > +{
> > > > + unsigned long long v = cnt32_to_63(read_c0_count());
> > > > + return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
> > > > +}
> > > > +
> > > > +static struct timer_list cnt32_to_63_keepwarm_timer;
> > > > +
> > > > +static void cnt32_to_63_keepwarm(unsigned long data)
> > > > +{
> > > > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > > > + (void) sched_clock();
> > > > +}
> > > > +
> > > > +static void __init setup_sched_clock(struct clocksource *cs, unsigned long tclk)
> > > > +{
> > > > + unsigned long long v;
> > > > + unsigned long data;
> > > > +
> > > > + v = cs->mult;
> > > > + /*
> > > > + * We want an even value to automatically clear the top bit
> > > > + * returned by cnt32_to_63() without an additional run time
> > > > + * instruction. So if the LSB is 1 then round it up.
> > > > + */
> > > > + if (v & 1)
> > > > + v++;
> > > > + tclk2ns_scale = v;
> > > > + tclk2ns_scale_factor = cs->shift;
> > > > +
> > > > + data = 0x80000000 / tclk * HZ;
> > > > + setup_timer(&cnt32_to_63_keepwarm_timer, cnt32_to_63_keepwarm, data);
> > > > + mod_timer(&cnt32_to_63_keepwarm_timer, round_jiffies(jiffies + data));
> > > > +}
> > > > +#endif /* !CONFIG_HR_SCHED_CLOCK */
> > > > +
> > > > static cycle_t c0_hpt_read(struct clocksource *cs)
> > > > {
> > > > return read_c0_count();
> > > > @@ -32,6 +83,10 @@ int __init init_r4k_clocksource(void)
> > > >
> > > > clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
> > > >
> > > > +#ifdef CONFIG_HR_SCHED_CLOCK
> > > > + setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
> > > > +#endif
> > > > +
> > > >
> > >
> > > According to CodingStyle #ifdef's in the code are frowned upon. I
> > > suggest that you add an empty setup_sched_clock() definition under #else
> > > above and have the call here without #ifdef. That's the preferred way of
> > > doing such things...
> > >
> >
> > Done, thanks!
> >
> > Wil resend it later.
>
> The proper solution would be what i suggested in my previous mail: to
> put it into a separate .c file. It's easy as the code has its own
> Kconfig value already. The only #ifdef is out of sight in a .h file.
>
Done, thanks!
Regards,
Wu Zhangjin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-23 9:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-22 13:04 [PATCH v3] MIPS: Add a high resolution sched_clock() via cnt32_to_63() Wu Zhangjin
2009-11-22 19:03 ` Sergei Shtylyov
2009-11-23 1:00 ` Wu Zhangjin
2009-11-23 8:44 ` Ingo Molnar
2009-11-23 9:00 ` Wu Zhangjin
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.