All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 1/2: cpufreq/PowerNow! in Xen: Time and platform changes
@ 2007-08-29 22:02 Mark Langsdorf
  2007-08-30  6:41 ` Tian, Kevin
  2007-10-01  8:30 ` xeb
  0 siblings, 2 replies; 41+ messages in thread
From: Mark Langsdorf @ 2007-08-29 22:02 UTC (permalink / raw)
  To: xen-devel

Enable cpufreq support in Xen for AMD Operton processors by:

1) Allowing the PowerNow! driver in dom0 to write to the PowerNow!
MSRs.
2) Adding the cpufreq notifier chain to time-xen.c in dom0.
On a frequency change, a platform hypercall is performed to
scale the frequency multiplier in the hypervisor.
3) Adding a platform hypercall to the hypervisor the scale
the frequency multiplier and reset the time stamps so that
next calibration remains reasonably correct.

Patch 1 covers the frequency scaling platform call.
Patch 2 covers the changes necessary to the PowerNow! driver
to make it correctly associate shared cores under Xen and to
write to MSRs.

This code can be readily expanded to cover Intel or other
non-AMD processors by modifying xen/arch/x8/traps.c to
allow the appropriate MSR accesses.

Caveat: currently, this code does not support the in-kernel
ondemand cpufreq governor.  Dom0 must run a userspace 
daemon to monitor the utilization of the physical cpus
with the getcpuinfo sysctl hypercall.

Caveat 2: on SMP systems, dom0_vcpus_pin is strongly
advised.

Caveat 3: Even though the clock multipliers are being
scaled and recorded correctly in both dom0 and the
hypervisor, time errors appear immediately after a
frequency change.  They are not more likely when
the frequency is constant.


Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com>

diff -r 05c22f282023 arch/i386/kernel/time-xen.c
--- a/arch/i386/kernel/time-xen.c	Tue Aug 14 16:20:55 2007 +0100
+++ b/arch/i386/kernel/time-xen.c	Tue Aug 28 14:55:24 2007 -0500
@@ -50,6 +50,7 @@
 #include <linux/percpu.h>
 #include <linux/kernel_stat.h>
 #include <linux/posix-timers.h>
+#include <linux/cpufreq.h>
 
 #include <asm/io.h>
 #include <asm/smp.h>
@@ -1118,6 +1119,65 @@ void local_teardown_timer(unsigned int c
 	BUG_ON(cpu == 0);
 	unbind_from_irqhandler(per_cpu(timer_irq, cpu), NULL);
 }
+#endif
+
+#if CONFIG_CPU_FREQ
+/* 
+ * cpufreq scaling handling
+ */
+static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, 
+				void *data)
+{
+	struct cpufreq_freqs *freq = data;
+        struct vcpu_time_info *info = &vcpu_info(freq->cpu)->time;
+	struct xen_platform_op op;
+	cpumask_t oldmask;
+	unsigned int cpu;
+
+	if (cpu_has(&cpu_data[freq->cpu], X86_FEATURE_CONSTANT_TSC))
+		return 0;
+
+	if (val == CPUFREQ_PRECHANGE)
+		return 0;
+
+	/* change the frequency inside the hypervisor */
+	oldmask = current->cpus_allowed;
+	set_cpus_allowed(current, cpumask_of_cpu(freq->cpu));
+	schedule();
+	op.cmd = XENPF_change_freq;
+	op.u.change_freq.info = info;
+	op.u.change_freq.old = freq->old;
+	op.u.change_freq.new = freq->new;
+	op.u.change_freq.cpu_num = freq->cpu;
+	HYPERVISOR_platform_op(&op);
+
+	for_each_online_cpu(cpu) {
+		get_time_values_from_xen(cpu);
+		per_cpu(processed_system_time, cpu) =
+                        per_cpu(shadow_time, cpu).system_timestamp;
+	}
+
+	set_cpus_allowed(current, oldmask);
+	schedule();
+
+	return 0;
+}
+
+static struct notifier_block time_cpufreq_notifier_block = {
+	.notifier_call = time_cpufreq_notifier
+};
+
+static int __init cpufreq_time_setup(void)
+{
+	if (!cpufreq_register_notifier(&time_cpufreq_notifier_block,
+			CPUFREQ_TRANSITION_NOTIFIER)) {
+		printk(KERN_ERR "failed to set up cpufreq notifier\n");
+		return -ENODEV;
+	}
+	return 0;
+}
+
+core_initcall(cpufreq_time_setup);
 #endif
 
 /*
diff -r 05c22f282023 include/xen/interface/platform.h
--- a/include/xen/interface/platform.h	Tue Aug 14 16:20:55 2007 +0100
+++ b/include/xen/interface/platform.h	Tue Aug 28 14:55:24 2007 -0500
@@ -153,6 +153,17 @@ typedef struct xenpf_firmware_info xenpf
 typedef struct xenpf_firmware_info xenpf_firmware_info_t;
 DEFINE_XEN_GUEST_HANDLE(xenpf_firmware_info_t);
 
+#define XENPF_change_freq       52
+struct xenpf_change_freq {
+    /* IN variables */
+    struct vcpu_time_info *info; /* vcpu time info for changing vcpu */
+    uint32_t old;  /* original frequency */
+    uint32_t new;  /* new frequency */
+    uint32_t cpu_num;
+};
+typedef struct xenpf_change_freq xenpf_change_freq_t;
+DEFINE_XEN_GUEST_HANDLE(xenpf_change_freq_t);
+
 #define XENPF_enter_acpi_sleep    51
 struct xenpf_enter_acpi_sleep {
     /* IN variables */
@@ -175,6 +186,7 @@ struct xen_platform_op {
         struct xenpf_microcode_update  microcode;
         struct xenpf_platform_quirk    platform_quirk;
         struct xenpf_firmware_info     firmware_info;
+        struct xenpf_change_freq       change_freq;
         struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
         uint8_t                        pad[128];
     } u;
diff -r 256160ff19b7 xen/include/xen/time.h
--- a/xen/include/xen/time.h	Thu Aug 16 13:27:59 2007 +0100
+++ b/xen/include/xen/time.h	Wed Aug 29 17:10:06 2007 -0500
@@ -74,6 +74,8 @@ extern void do_settime(
 extern void do_settime(
     unsigned long secs, unsigned long nsecs, u64 system_time_base);
 
+extern void do_change_freq(struct vcpu_time_info *info, unsigned int old, unsigned int new, int cpu_num);
+
 extern void send_timer_event(struct vcpu *v);
 
 #endif /* __XEN_TIME_H__ */

^ permalink raw reply	[flat|nested] 41+ messages in thread
* Re: [PATCH] 1/2: cpufreq/PowerNow! in Xen: Time and platform changes
@ 2007-10-02 13:05 xeb
  0 siblings, 0 replies; 41+ messages in thread
From: xeb @ 2007-10-02 13:05 UTC (permalink / raw)
  To: xen-devel

> On 1/10/07 09:30, "xeb" <xeb@mail.ru> wrote:
> > Hello!
> > I have did some tests and it works well. Frequencies successfully
> > switches from userspace.
> > But there is clock glitches as on dom0 as on dumU.
>
> Should be fixed by xen-unstable changeset 15982:b3814860d170 (currently in
> the staging tree).
>
>  -- Keir

Clock glitches still occurs.
Kernel reports next messages:
Timer ISR/1: Time went backwards: delta=-312990340 delta_cpu=863676209 
shadow=55606869012 off=866802928 processed=56786660988 
cpu_processed=55609994439
 0: 56783327655
 1: 55609994439
Timer ISR/1: Time went backwards: delta=-316323654 delta_cpu=3676314 
shadow=55606869012 off=870136739 processed=56793327654 
cpu_processed=56473327686
 0: 56789994321
 1: 56473327686
Timer ISR/1: Time went backwards: delta=-319657223 delta_cpu=3676078 
shadow=55606869012 off=873469685 processed=56799994320 
cpu_processed=56476661019
 0: 56799994320
 1: 56476661019
Timer ISR/1: Time went backwards: delta=-321045750 delta_cpu=5620884 
shadow=55606869012 off=878747355 processed=56806660986 
cpu_processed=56479994352
 0: 56806660986
 1: 56479994352
Timer ISR/1: Time went backwards: delta=-321049645 delta_cpu=5616989 
shadow=55606869012 off=882077351 processed=56809994319 
cpu_processed=56483327685
 0: 56809994319
 1: 56483327685

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

end of thread, other threads:[~2007-10-02 13:05 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-29 22:02 [PATCH] 1/2: cpufreq/PowerNow! in Xen: Time and platform changes Mark Langsdorf
2007-08-30  6:41 ` Tian, Kevin
2007-08-30  9:30   ` Keir Fraser
2007-08-30  9:45     ` Tian, Kevin
2007-08-30 10:12       ` Keir Fraser
2007-08-31  1:20         ` Tian, Kevin
2007-08-31 10:04           ` Keir Fraser
2007-08-31 15:09             ` Tian, Kevin
2007-08-31 15:25               ` Keir Fraser
2007-09-01  0:23                 ` Tian, Kevin
2007-09-01 11:07                   ` Keir Fraser
2007-09-01 13:31                     ` Tian, Kevin
2007-09-01 13:57                       ` Keir Fraser
2007-09-01 14:14                         ` Tian, Kevin
2007-09-01 14:22                         ` Tian, Kevin
2007-09-01 14:12                       ` Keir Fraser
2007-09-01 14:18                         ` Tian, Kevin
2007-09-01 15:26                           ` Keir Fraser
2007-09-01 15:45                             ` Tian, Kevin
2007-09-01 16:41                               ` Keir Fraser
2007-09-03  4:25                                 ` Tian, Kevin
2007-09-04 17:23                             ` Rik van Riel
2007-08-30 14:45     ` Langsdorf, Mark
2007-08-30 15:04       ` Keir Fraser
2007-08-30 18:23         ` Rik van Riel
     [not found]           ` <1449F58C868D8D4E9C72945771150BDF0207700B@SAUSEXMB1.amd.com>
2007-08-30 20:56             ` Rik van Riel
2007-08-31  2:43           ` Tian, Kevin
2007-08-31  8:41           ` Jan Beulich
2007-08-30 14:59     ` Rik van Riel
2007-08-31  2:42       ` Tian, Kevin
2007-08-31  9:23         ` Keir Fraser
2007-08-31 13:50         ` Rik van Riel
2007-08-30 14:57   ` Langsdorf, Mark
2007-08-30 15:08     ` Keir Fraser
2007-10-01  8:30 ` xeb
2007-10-01  8:33   ` Keir Fraser
2007-10-02 12:56     ` xeb
2007-10-02 12:57     ` xeb
2007-10-02 13:00     ` xeb
2007-10-02 13:02     ` xeb
  -- strict thread matches above, loose matches on Subject: below --
2007-10-02 13:05 xeb

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.