public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Andi Kleen <ak@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Matt Mackall <mpm@selenic.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] lguest-fix-divide-error-implement-sched_clock
Date: Tue, 05 Jun 2007 23:11:00 +1000	[thread overview]
Message-ID: <1181049060.14054.30.camel@localhost.localdomain> (raw)
In-Reply-To: <200706051201.32137.ak@suse.de>

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;




  reply	other threads:[~2007-06-05 13:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-22 22:38 lguest broken in 2.6.22-rc1-mm1 Matt Mackall
2007-05-22 23:27 ` Rusty Russell
2007-06-04 17:19   ` lguest rebroken in 2.6.22-rc3-mm1 Matt Mackall
2007-06-04 17:28     ` Andrew Morton
2007-06-04 17:46       ` Matt Mackall
2007-06-04 18:12       ` Andi Kleen
2007-06-05  2:48         ` Rusty Russell
2007-06-05 10:01           ` Andi Kleen
2007-06-05 13:11             ` Rusty Russell [this message]
2007-06-05 14:24               ` [PATCH] lguest-fix-divide-error-implement-sched_clock Andi Kleen
2007-06-05 16:07                 ` Andrew Morton
2007-06-05 16:16                   ` H. Peter Anvin
2007-06-05 16:37                     ` Andi Kleen
2007-06-05 17:02                       ` H. Peter Anvin
2007-06-05 18:43                       ` H. Peter Anvin
2007-06-05 18:51                         ` Andi Kleen
2007-06-05 21:15                       ` H. Peter Anvin
2007-06-05 21:31                         ` Andi Kleen

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=1181049060.14054.30.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox