lkml.org 
[lkml]   [2007]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] lguest-fix-divide-error-implement-sched_clock
From
Date
On Tue, 2007-06-05 at 12:01 +0200, Andi Kleen wrote:
> > But TSC is a "required feature", so "cpu_has_tsc" is always true.
>
> Hmm? It isn't. What makes you think so?

Interestingly it seems to be only in -mm.

> > How about this patch:
> > ===
> > Don't try to disable the TSC: it's a required feature under modern
> > configurations, so just mark the sched clock unstable which has the
> > same effect.
>
> No, using the cpuid bit is the correct way. Or better fix lguest to support
> TSC properly.

I have a patch for a tsc-based clock, but that's a little orthogonal: I
actually need to override sched_clock.

(I'd really like to do stolen time and everything, but looking at Xen
it's a lot of code to do right, and noone's asked for it yet).

This time for sure!

===
In recent -mm kernels, the TSC capability cannot be disabled,
resulting in a divide by zero error in the normal sched_clock.

The correct fix is to have a special lguest sched_clock
implementation: this is as simple as it gets.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
drivers/lguest/lguest.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

===================================================================
--- a/drivers/lguest/lguest.c
+++ b/drivers/lguest/lguest.c
@@ -351,11 +351,18 @@ static void lguest_time_irq(unsigned int
update_process_times(user_mode_vm(get_irq_regs()));
}

+static u64 sched_clock_base;
static void lguest_time_init(void)
{
set_irq_handler(0, lguest_time_irq);
hcall(LHCALL_TIMER_READ, 0, 0, 0);
+ sched_clock_base = jiffies_64;
enable_lguest_irq(0);
+}
+
+static unsigned long long lguest_sched_clock(void)
+{
+ return (jiffies_64 - sched_clock_base) * (1000000000 / HZ);
}

static void lguest_load_esp0(struct tss_struct *tss,
@@ -494,6 +501,7 @@ __init void lguest_init(void *boot)
paravirt_ops.time_init = lguest_time_init;
paravirt_ops.set_lazy_mode = lguest_lazy_mode;
paravirt_ops.wbinvd = lguest_wbinvd;
+ paravirt_ops.sched_clock = lguest_sched_clock;

hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0);

@@ -507,8 +515,6 @@ __init void lguest_init(void *boot)
cpu_detect(&new_cpu_data);
/* Math is always hard! */
new_cpu_data.hard_math = 1;
-
- tsc_disable = 1;

#ifdef CONFIG_X86_MCE
mce_disabled = 1;


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2007-06-05 15:13    [W:0.978 / U:0.328 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site