From: "Mark Langsdorf" <mark.langsdorf@amd.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] 1/2: cpufreq/PowerNow! in Xen: Time and platform changes
Date: Wed, 29 Aug 2007 17:02:33 -0500 [thread overview]
Message-ID: <200708291702.33634.mark.langsdorf@amd.com> (raw)
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__ */
next reply other threads:[~2007-08-29 22:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-29 22:02 Mark Langsdorf [this message]
2007-08-30 6:41 ` [PATCH] 1/2: cpufreq/PowerNow! in Xen: Time and platform changes 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
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=200708291702.33634.mark.langsdorf@amd.com \
--to=mark.langsdorf@amd.com \
--cc=xen-devel@lists.xensource.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 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.