xen_cpufreq implementation in kernel
Subsystems (8)
v2 cover xen_cpufreq implementation in kernel
Hi to all.
Next series of patches implements xen-cpufreq driver in kernel.
Cpufreq core and registered cpufreq governors are located in xen. Dom0 has CPU driver which can only change frequency of the physical CPUs. In addition this driver can change CPUs regulator voltage. At start time xen-cpufreq driver in kernel uploads to Xen information about physical cpus.
Xen notifies Dom0 kernel using VIRQ_CPUFREQ interrupt. Then xen-cpufreq driver in kernel uses XEN_SYSCTL_cpufreq_op operation from HYPERVISOR_sysctl hypercall to get some parameters from Xen (frequency, relation and cpu number). Then xen-cpufreq changes frequency on physical cpu and uses the same XEN_SYSCTL_cpufreq_op operation ti give the result to Xen.
Next configs should be enabled to use xen-cpufreq driver:CONFIG_GENERIC_CPUFREQ_CPU0CONFIG_XEN_CPUFREQ
Changed since v1:
* added cpufreq_drv_ops which allows to use more than one high-level cpufreq driver
* reworked xen-cpufreq and drivers so the same kernel is able to run on bare metal and within Xen.
Oleksandr Dmytryshyn (8):
PM / OPP: make cpufreq functions dependent on CONFIG_CPU_FREQ_TABLE xen/arm: implement HYPERVISOR_sysctl
xen/arm: implement HYPERVISOR_dom0_op
xen/arm: add XEN_SYSCTL_cpufreq_op definition
cpufreq: cpufreq-cpu0: change cpus data path in devtree for Dom0
kernel
cpufreq: introduce cpufreq_drv_ops
cpufreq: make cpufreq low-level drivers visible for CPUFREQ_DRV_OPS
config
xen/arm: cpufreq: add xen-cpufreq driver
arch/arm/include/asm/xen/hypercall.h | 2 + arch/arm/include/asm/xen/interface.h | 2 + arch/arm/xen/enlighten.c | 2 + arch/arm/xen/hypercall.S | 2 + drivers/Makefile | 2 +- drivers/base/power/opp.c | 4 +- drivers/cpufreq/Kconfig | 39 +- drivers/cpufreq/Makefile | 2 + drivers/cpufreq/acpi-cpufreq.c | 5 +- drivers/cpufreq/cpufreq-cpu0.c | 10 +- drivers/cpufreq/cpufreq.c | 116 +++-- drivers/cpufreq/cpufreq_drv_ops.c | 196 ++++++++ drivers/cpufreq/cpufreq_drv_ops.h | 54 +++ drivers/cpufreq/cpufreq_governor.c | 4 +- drivers/cpufreq/xen-cpufreq.c | 888 +++++++++++++++++++++++++++++++++++ include/linux/cpufreq.h | 2 +- include/linux/opp.h | 2 +- include/xen/interface/sysctl.h | 664 ++++++++++++++++++++++++++ include/xen/interface/xen.h | 7 + 19 files changed, 1937 insertions(+), 66 deletions(-) create mode 100644 drivers/cpufreq/cpufreq_drv_ops.c create mode 100644 drivers/cpufreq/cpufreq_drv_ops.h create mode 100644 drivers/cpufreq/xen-cpufreq.c create mode 100644 include/xen/interface/sysctl.h
Signature · 1 line
1.9.1
RFC PATCH v2 1/8 PM / OPP: make cpufreq functions dependent on CONFIG_CPU_FREQ_TABLE
Those functions should be dependent on CONFIG_CPU_FREQ_TABLE instead of the CONFIG_CPU_FREQ.
--- drivers/base/power/opp.c | 4 ++-- include/linux/opp.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/power/opp.c +2 -2
@@ -592,7 +592,7 @@ int opp_disable(struct device *dev, unsigned long freq) }EXPORT_SYMBOL_GPL (opp_disable); -#ifdef CONFIG_CPU_FREQ +#ifdef CONFIG_CPU_FREQ_TABLE /** * opp_init_cpufreq_table() - create a cpufreq table for a device * @dev: device for which we do this operation
@@ -680,7 +680,7 @@ void opp_free_cpufreq_table(struct device *dev, *table = NULL; }EXPORT_SYMBOL_GPL (opp_free_cpufreq_table); -#endif /* CONFIG_CPU_FREQ */ +#endif /* CONFIG_CPU_FREQ_TABLE */ /** * opp_get_notifier() - find notifier_head of the device with opp
include/linux/opp.h +1 -1
@@ -112,7 +112,7 @@ static inline struct srcu_notifier_head *opp_get_notifier(struct device *dev) }#endif /* CONFIG_PM_OPP */ -#if defined(CONFIG_CPU_FREQ ) && defined(CONFIG_PM_OPP ) +#if defined(CONFIG_CPU_FREQ_TABLE ) && defined(CONFIG_PM_OPP )int opp_init_cpufreq_table (struct device *dev,struct cpufreq_frequency_table **table); void opp_free_cpufreq_table(struct device *dev,
Signature · 1 line
1.9.1
RFC PATCH v2 2/8 xen/arm: implement HYPERVISOR_sysctl
In reply to Oleksandr Dmytryshyn--- arch/arm/include/asm/xen/hypercall.h | 1 + arch/arm/include/asm/xen/interface.h | 2 + arch/arm/xen/enlighten.c | 1 + arch/arm/xen/hypercall.S | 1 + include/xen/interface/sysctl.h | 646 +++++++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 6 + 6 files changed, 657 insertions(+) create mode 100644 include/xen/interface/sysctl.h
arch/arm/include/asm/xen/hypercall.h +1 -0
@@ -48,6 +48,7 @@ int HYPERVISOR_memory_op(unsigned int cmd, void *arg);int HYPERVISOR_physdev_op (int cmd,void *arg);int HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args);int HYPERVISOR_tmem_op (void *arg); +int HYPERVISOR_sysctl (void *arg); static inline void MULTI_update_va_mapping(struct multicall_entry *mcl, unsigned long va,
arch/arm/include/asm/xen/interface.h +2 -0
@@ -19,6 +19,7 @@ __DEFINE_GUEST_HANDLE(name, struct name)#define DEFINE_GUEST_HANDLE (name) __DEFINE_GUEST_HANDLE(name, name)#define GUEST_HANDLE (name) __guest_handle_ ## name +#define GUEST_HANDLE_64 (name) GUEST_HANDLE(name)#define set_xen_guest_handle (hnd, val) \ do { \
@@ -48,6 +49,7 @@ DEFINE_GUEST_HANDLE(int);DEFINE_GUEST_HANDLE (void);DEFINE_GUEST_HANDLE (uint64_t);DEFINE_GUEST_HANDLE (uint32_t); +DEFINE_GUEST_HANDLE (uint8_t);DEFINE_GUEST_HANDLE (xen_pfn_t);DEFINE_GUEST_HANDLE (xen_ulong_t);
arch/arm/xen/enlighten.c +1 -0
@@ -350,4 +350,5 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_memory_op);EXPORT_SYMBOL_GPL (HYPERVISOR_physdev_op);EXPORT_SYMBOL_GPL (HYPERVISOR_vcpu_op);EXPORT_SYMBOL_GPL (HYPERVISOR_tmem_op); +EXPORT_SYMBOL_GPL (HYPERVISOR_sysctl);EXPORT_SYMBOL_GPL (privcmd_call);
arch/arm/xen/hypercall.S +1 -0
@@ -89,6 +89,7 @@ HYPERCALL2(memory_op); HYPERCALL2(physdev_op); HYPERCALL3(vcpu_op); HYPERCALL1(tmem_op); +HYPERCALL1(sysctl); ENTRY(privcmd_call) stmdb sp!, {r4}
include/xen/interface/sysctl.h new file +646 -0
646 lines not on this page · raw message
include/xen/interface/xen.h +6 -0
@@ -57,6 +57,7 @@#define __HYPERVISOR_event_channel_op 32#define __HYPERVISOR_physdev_op 33#define __HYPERVISOR_hvm_op 34 +#define __HYPERVISOR_sysctl 35#define __HYPERVISOR_tmem_op 38/* Architecture-specific hypercall definitions. */
@@ -526,6 +527,11 @@ struct tmem_op {DEFINE_GUEST_HANDLE (u64); +struct xenctl_bitmap { +GUEST_HANDLE_64 (uint8_t ) bitmap; +uint32_t nr_bits; +}; +#else /* __ASSEMBLY__ */ /* In assembly code we cannot use C numeric constant suffixes. */
Signature · 1 line
1.9.1
RFC PATCH v2 3/8 xen/arm: implement HYPERVISOR_dom0_op
In reply to Oleksandr Dmytryshyn--- arch/arm/include/asm/xen/hypercall.h | 1 + arch/arm/xen/enlighten.c | 1 + arch/arm/xen/hypercall.S | 1 + 3 files changed, 3 insertions(+)
arch/arm/include/asm/xen/hypercall.h +1 -0
@@ -48,6 +48,7 @@ int HYPERVISOR_memory_op(unsigned int cmd, void *arg);int HYPERVISOR_physdev_op (int cmd,void *arg);int HYPERVISOR_vcpu_op (int cmd,int vcpuid,void *extra_args);int HYPERVISOR_tmem_op (void *arg); +int HYPERVISOR_dom0_op (void *arg);int HYPERVISOR_sysctl (void *arg); static inline void
arch/arm/xen/enlighten.c +1 -0
@@ -350,5 +350,6 @@ EXPORT_SYMBOL_GPL(HYPERVISOR_memory_op);EXPORT_SYMBOL_GPL (HYPERVISOR_physdev_op);EXPORT_SYMBOL_GPL (HYPERVISOR_vcpu_op);EXPORT_SYMBOL_GPL (HYPERVISOR_tmem_op); +EXPORT_SYMBOL_GPL (HYPERVISOR_dom0_op);EXPORT_SYMBOL_GPL (HYPERVISOR_sysctl);EXPORT_SYMBOL_GPL (privcmd_call);
arch/arm/xen/hypercall.S +1 -0
@@ -89,6 +89,7 @@ HYPERCALL2(memory_op); HYPERCALL2(physdev_op); HYPERCALL3(vcpu_op); HYPERCALL1(tmem_op); +HYPERCALL1(dom0_op); HYPERCALL1(sysctl); ENTRY(privcmd_call)
Signature · 1 line
1.9.1
RFC PATCH v2 4/8 xen/arm: add XEN_SYSCTL_cpufreq_op definition
In reply to Oleksandr Dmytryshynxen-cpufreq driver uses this op to get some
parameters to change CPUs frequency.
--- include/xen/interface/sysctl.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/xen/interface/sysctl.h +18 -0
@@ -597,6 +597,22 @@ struct xen_sysctl_coverage_op { };DEFINE_GUEST_HANDLE_STRUCT (xen_sysctl_coverage_op); +#define XEN_SYSCTL_CPUFREQ_get_target 0 +#define XEN_SYSCTL_CPUFREQ_set_result 1 + +struct xen_sysctl_cpufreq_op { +uint32_t cmd; +union { +struct { +uint32_t cpu; +uint32_t freq; +uint32_t relation; + } target; +uint32_t result; + } u; +}; +DEFINE_GUEST_HANDLE_STRUCT (xen_sysctl_cpufreq_op); +struct xen_sysctl {uint32_t cmd;
@@ -618,6 +634,7 @@ struct xen_sysctl {#define XEN_SYSCTL_cpupool_op 18#define XEN_SYSCTL_scheduler_op 19#define XEN_SYSCTL_coverage_op 20 +#define XEN_SYSCTL_cpufreq_op 21uint32_t interface_version;/* XEN_SYSCTL_INTERFACE_VERSION */ union {struct xen_sysctl_readconsole readconsole;
@@ -638,6 +655,7 @@ struct xen_sysctl {struct xen_sysctl_cpupool_op cpupool_op;struct xen_sysctl_scheduler_op scheduler_op;struct xen_sysctl_coverage_op coverage_op; +struct xen_sysctl_cpufreq_op cpufreq_op;uint8_t pad[128 ]; } u; };
Signature · 1 line
1.9.1
RFC PATCH v2 5/8 cpufreq: cpufreq-cpu0: change cpus data path in devtree for Dom0 kernel
In reply to Oleksandr DmytryshynXen hypervisor creates standard cpus nodes for virtual cpus. All information needed for this driver about physical cpus now located in /hypervisor/pcpus node instead of the /cpus node in case if kernel is running as Dom0 domain.
--- drivers/cpufreq/cpufreq-cpu0.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/cpufreq/cpufreq-cpu0.c +9 -1
@@ -21,6 +21,8 @@#include <linux/regulator/consumer.h> #include <linux/slab.h> +#include <xen/xen.h> +static unsigned int transition_latency;static unsigned int voltage_tolerance;/* in percentage */
@@ -182,7 +184,13 @@ static int cpu0_cpufreq_probe(struct platform_device *pdev)struct device_node *np;int ret; - np =of_find_node_by_path ("/cpus/cpu@0" ); +#ifdef CONFIG_XEN_DOM0 +if (xen_initial_domain ()) + np =of_find_node_by_path ("/hypervisor/pcpus/cpu@0" ); + else +#endif + np =of_find_node_by_path ("/cpus/cpu@0" ); +if (!np) {pr_err ("failed to find cpu0 node\n" );return -ENOENT ;
Signature · 1 line
1.9.1
RFC PATCH v2 6/8 cpufreq: introduce cpufreq_drv_ops
In reply to Oleksandr DmytryshynThis patch allows to use more than one high-level cpufreq driver. This patch is needed for implementation xen-based high-level cpufreq driver.
--- drivers/cpufreq/Kconfig | 4 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/acpi-cpufreq.c | 5 +- drivers/cpufreq/cpufreq.c | 116 ++++++++++++----------- drivers/cpufreq/cpufreq_drv_ops.c | 187 +++++++++++++++++++++++++++++++++++++ drivers/cpufreq/cpufreq_drv_ops.h | 50 ++++++++++ drivers/cpufreq/cpufreq_governor.c | 4 +- include/linux/cpufreq.h | 2 +- 8 files changed, 312 insertions(+), 57 deletions(-) create mode 100644 drivers/cpufreq/cpufreq_drv_ops.c create mode 100644 drivers/cpufreq/cpufreq_drv_ops.h
drivers/cpufreq/Kconfig +4 -0
@@ -1,7 +1,11 @@ menu "CPU Frequency scaling" +config CPUFREQ_DRV_OPS + bool + config CPU_FREQ bool "CPU Frequency scaling" + select CPUFREQ_DRV_OPS help CPU Frequency scaling allows you to change the clock speed of CPUs on the fly. This is a nice method to save power, because
drivers/cpufreq/Makefile +1 -0
@@ -1,5 +1,6 @@ # CPUfreq core obj-$(CONFIG_CPU_FREQ) += cpufreq.o +obj-$(CONFIG_CPUFREQ_DRV_OPS) += cpufreq_drv_ops.o # CPUfreq stats obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o
drivers/cpufreq/acpi-cpufreq.c +3 -2
@@ -950,7 +950,8 @@ static void __init acpi_cpufreq_boost_init(void)/* We create the boost file in any case, though for systems without * hardware support it will be read-only and hardwired to return 0. */ -if (sysfs_create_file (cpufreq_global_kobject, &(global_boost.attr))) +if (sysfs_create_file (get_cpufreq_global_kobject (), + &(global_boost.attr)))pr_warn (PFX "could not register global boost sysfs file\n" );else pr_debug ("registered global boost sysfs file\n" );
@@ -958,7 +959,7 @@ static void __init acpi_cpufreq_boost_init(void) static void __exit acpi_cpufreq_boost_exit(void) { -sysfs_remove_file (cpufreq_global_kobject, &(global_boost.attr)); +sysfs_remove_file (get_cpufreq_global_kobject (), &(global_boost.attr));if (msrs) {unregister_cpu_notifier (&boost_nb);
drivers/cpufreq/cpufreq.c +64 -52
358 lines not on this page · raw message
drivers/cpufreq/cpufreq_drv_ops.c new file +187 -0
187 lines not on this page · raw message
drivers/cpufreq/cpufreq_drv_ops.h new file +50 -0
50 lines not on this page · raw message
drivers/cpufreq/cpufreq_governor.c +2 -2
@@ -226,7 +226,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,if (dbs_data->enable !=1 ) goto second_time; - rc =sysfs_create_group (cpufreq_global_kobject, + rc =sysfs_create_group (get_cpufreq_global_kobject (), dbs_data->attr_group);if (rc) {mutex_unlock (&dbs_data->mutex);
@@ -291,7 +291,7 @@ second_time:if (!dbs_data->enable) {struct cs_ops *ops = dbs_data->gov_ops; -sysfs_remove_group (cpufreq_global_kobject, +sysfs_remove_group (get_cpufreq_global_kobject (), dbs_data->attr_group);if (dbs_data->governor ==GOV_CONSERVATIVE ) cpufreq_unregister_notifier(ops->notifier_block,
include/linux/cpufreq.h +1 -1
@@ -70,7 +70,7 @@ static inline void disable_cpufreq(void) { }struct cpufreq_governor ;/* /sys/devices/system/cpu/cpufreq: entry point for global variables */ -extern struct kobject *cpufreq_global_kobject; +struct kobject *get_cpufreq_global_kobject (void );#define CPUFREQ_ETERNAL (-1)struct cpufreq_cpuinfo {
Signature · 1 line
1.9.1
RFC PATCH v2 7/8 cpufreq: make cpufreq low-level drivers visible for CPUFREQ_DRV_OPS config
In reply to Oleksandr DmytryshynLow-level cpufreq drivers should depend from CPUFREQ_DRV_OPS config instead of the CPU_FREQ config in case if we want to use additional high-level cpufreq driver. This patch is needed for implementation xen-based high-level cpufreq driver.
--- drivers/Makefile | 2 +- drivers/cpufreq/Kconfig | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-)
drivers/Makefile +1 -1
@@ -107,7 +107,7 @@ obj-$(CONFIG_ISDN) += isdn/ obj-$(CONFIG_EDAC) += edac/ obj-$(CONFIG_EISA) += eisa/ obj-y += lguest/ -obj-$(CONFIG_CPU_FREQ) += cpufreq/ +obj-$(CONFIG_CPUFREQ_DRV_OPS) += cpufreq/ obj-$(CONFIG_CPU_IDLE) += cpuidle/ obj-y += mmc/ obj-$(CONFIG_MEMSTICK) += memstick/
drivers/cpufreq/Kconfig +12 -4
@@ -19,14 +19,11 @@ config CPU_FREQ If in doubt, say N. -if CPU_FREQ +if CPUFREQ_DRV_OPS config CPU_FREQ_TABLE tristate -config CPU_FREQ_GOV_COMMON - bool - config CPU_FREQ_STAT tristate "CPU frequency translation statistics" select CPU_FREQ_TABLE
@@ -49,6 +46,13 @@ config CPU_FREQ_STAT_DETAILS If in doubt, say N. +endif + +if CPU_FREQ + +config CPU_FREQ_GOV_COMMON + bool + choice prompt "Default CPUFreq governor" default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110
@@ -188,6 +192,10 @@ config CPU_FREQ_GOV_CONSERVATIVE If in doubt, say N. +endif + +if CPUFREQ_DRV_OPS + config GENERIC_CPUFREQ_CPU0 tristate "Generic CPU0 cpufreq driver" depends on HAVE_CLK && REGULATOR && PM_OPP && OF
Signature · 1 line
1.9.1
RFC PATCH v2 8/8 xen/arm: cpufreq: add xen-cpufreq driver
In reply to Oleksandr DmytryshynXen changes frequencies on CPUs using this high-level cpufreq driver.
--- drivers/cpufreq/Kconfig | 19 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/cpufreq_drv_ops.c | 13 +- drivers/cpufreq/cpufreq_drv_ops.h | 4 + drivers/cpufreq/xen-cpufreq.c | 888 ++++++++++++++++++++++++++++++++++++++ include/xen/interface/xen.h | 1 + 6 files changed, 924 insertions(+), 2 deletions(-) create mode 100644 drivers/cpufreq/xen-cpufreq.c
drivers/cpufreq/Kconfig +19 -0
@@ -19,6 +19,25 @@ config CPU_FREQ If in doubt, say N. +config XEN_CPUFREQ + bool "Xen Cpufreq driver" + depends on XEN_DOM0 + default n + select CPUFREQ_DRV_OPS + help + This driver uploads Power Management information to the Xen + hypervisor and changes CPUs frequency using CPU Frequency scaling + drivers. + + To do that the driver uses CPU Frequency scaling drivers to parse + the Power Management data and uploads said information to the Xen + hypervisor. Then the Xen hypervisor can select the proper Pxx states. + + Then the Xen hypervisor can change CPUs frequency by giving commands + via this driver to the CPU Frequency scaling driver. + + If in doubt, say N. + if CPUFREQ_DRV_OPS config CPU_FREQ_TABLE
drivers/cpufreq/Makefile +1 -0
@@ -1,5 +1,6 @@ # CPUfreq core obj-$(CONFIG_CPU_FREQ) += cpufreq.o +obj-$(CONFIG_XEN_CPUFREQ) += xen-cpufreq.o obj-$(CONFIG_CPUFREQ_DRV_OPS) += cpufreq_drv_ops.o # CPUfreq stats obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o
drivers/cpufreq/cpufreq_drv_ops.c +11 -2
@@ -18,6 +18,8 @@#include <linux/init.h> #include <linux/export.h> +#include <xen/xen.h> +static struct cpufreq_drv_ops *ops;struct kobject *get_cpufreq_global_kobject (void )
@@ -177,10 +179,17 @@ EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);static int __init cpufreq_drv_ops_init (void ) { +if (xen_initial_domain ()) { +#ifdef CONFIG_XEN_CPUFREQ + ops = &xen_cpufreq_drv_ops; +pr_debug ("using xen_cpufreq_drv_ops\n" ); +#endif + }else {#ifdef CONFIG_CPU_FREQ - ops = &kern_cpufreq_drv_ops; -pr_debug ("using kern_cpufreq_drv_ops\n" ); + ops = &kern_cpufreq_drv_ops; +pr_debug ("using kern_cpufreq_drv_ops\n" );#endif + }return 0 ; }
drivers/cpufreq/cpufreq_drv_ops.h +4 -0
@@ -47,4 +47,8 @@ struct cpufreq_drv_ops {extern struct cpufreq_drv_ops kern_cpufreq_drv_ops;#endif +#ifdef CONFIG_XEN_CPUFREQ +extern struct cpufreq_drv_ops xen_cpufreq_drv_ops; +#endif +#endif /* _CPUFREQ_DRV_OPS_H */
drivers/cpufreq/xen-cpufreq.c new file +888 -0
888 lines not on this page · raw message
include/xen/interface/xen.h +1 -0
@@ -81,6 +81,7 @@#define VIRQ_DOM_EXC 3/* (DOM0) Exceptional event for some domain. */ #define VIRQ_DEBUGGER 6/* (DOM0) A domain has paused for debugging. */ #define VIRQ_PCPU_STATE 9/* (DOM0) PCPU state changed */ +#define VIRQ_CPUFREQ 13/* (DOM0) Notify dom0-cpufreq driver. */ /* Architecture-specific VIRQ definitions. */ #define VIRQ_ARCH_0 16
Signature · 1 line
1.9.1