| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| From: Connor O'Brien <connoro@google.com> |
| Date: Tue, 19 Feb 2019 17:36:53 -0800 |
| Subject: ANDROID: cpufreq: create dummy cpufreq driver |
| |
| /proc/uid_time_in_state has no data on cuttlefish because its cpu |
| frequency tables are empty. Because time in state & concurrent time |
| accounting are intertwined this causes the |
| /proc/uid_concurrent_{policy,active}_time files to also not contain |
| any data. |
| |
| Add a minimal, fake cpufreq driver that creates a freq table with 2 |
| frequencies per policy, to allow testing time in state functionality. |
| |
| Test: all 3 proc files show reasonable data on cuttlefish |
| Test: log shows no errors from bad /proc/uid_time_in_state format |
| Bug: 139763108 |
| Bug: 140796321 |
| Bug: 141206930 |
| Change-Id: I8c7fe1007a80c21a9bcba9455bf837947cf42963 |
| Signed-off-by: Connor O'Brien <connoro@google.com> |
| [maennich: Folded the following patch into this patch |
| 50118fa88e6a ("ANDROID: dummy_cpufreq: Implement get()")] |
| Signed-off-by: Matthias Maennich <maennich@google.com> |
| --- |
| arch/arm64/configs/gki_defconfig | 1 + |
| arch/x86/configs/gki_defconfig | 1 + |
| drivers/cpufreq/Kconfig | 9 +++++ |
| drivers/cpufreq/Makefile | 2 ++ |
| drivers/cpufreq/dummy-cpufreq.c | 60 ++++++++++++++++++++++++++++++++ |
| 5 files changed, 73 insertions(+) |
| create mode 100644 drivers/cpufreq/dummy-cpufreq.c |
| |
| diff --git a/arch/arm64/configs/gki_defconfig b/arch/arm64/configs/gki_defconfig |
| index 8e6a20e0b64d..0933c134a2d0 100644 |
| --- a/arch/arm64/configs/gki_defconfig |
| +++ b/arch/arm64/configs/gki_defconfig |
| @@ -61,6 +61,7 @@ CONFIG_CPU_FREQ_TIMES=y |
| CONFIG_CPU_FREQ_DEFAULT_GOV_SCHEDUTIL=y |
| CONFIG_CPU_FREQ_GOV_POWERSAVE=y |
| CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y |
| +CONFIG_CPUFREQ_DUMMY=m |
| CONFIG_ARM_SCPI_CPUFREQ=y |
| CONFIG_ARM_SCMI_CPUFREQ=y |
| CONFIG_ARM_SCMI_PROTOCOL=y |
| diff --git a/arch/x86/configs/gki_defconfig b/arch/x86/configs/gki_defconfig |
| index 46ec1d98f998..277b0069671e 100644 |
| --- a/arch/x86/configs/gki_defconfig |
| +++ b/arch/x86/configs/gki_defconfig |
| @@ -46,6 +46,7 @@ CONFIG_PM_WAKELOCKS_LIMIT=0 |
| # CONFIG_PM_WAKELOCKS_GC is not set |
| CONFIG_CPU_FREQ_TIMES=y |
| CONFIG_CPU_FREQ_GOV_POWERSAVE=y |
| +CONFIG_CPUFREQ_DUMMY=m |
| CONFIG_IA32_EMULATION=y |
| CONFIG_KPROBES=y |
| CONFIG_MODULES=y |
| diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig |
| index f711715aa579..2075100319fb 100644 |
| --- a/drivers/cpufreq/Kconfig |
| +++ b/drivers/cpufreq/Kconfig |
| @@ -229,6 +229,15 @@ config CPUFREQ_DT_PLATDEV |
| |
| If in doubt, say N. |
| |
| +config CPUFREQ_DUMMY |
| + tristate "Dummy CPU frequency driver" |
| + help |
| + This option adds a generic dummy CPUfreq driver, which sets a fake |
| + 2-frequency table when initializing each policy and otherwise does |
| + nothing. |
| + |
| + If in doubt, say N |
| + |
| if X86 |
| source "drivers/cpufreq/Kconfig.x86" |
| endif |
| diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile |
| index 93d52a112cab..33d6b64f9203 100644 |
| --- a/drivers/cpufreq/Makefile |
| +++ b/drivers/cpufreq/Makefile |
| @@ -20,6 +20,8 @@ obj-$(CONFIG_CPU_FREQ_GOV_ATTR_SET) += cpufreq_governor_attr_set.o |
| obj-$(CONFIG_CPUFREQ_DT) += cpufreq-dt.o |
| obj-$(CONFIG_CPUFREQ_DT_PLATDEV) += cpufreq-dt-platdev.o |
| |
| +obj-$(CONFIG_CPUFREQ_DUMMY) += dummy-cpufreq.o |
| + |
| ################################################################################## |
| # x86 drivers. |
| # Link order matters. K8 is preferred to ACPI because of firmware bugs in early |
| diff --git a/drivers/cpufreq/dummy-cpufreq.c b/drivers/cpufreq/dummy-cpufreq.c |
| new file mode 100644 |
| index 000000000000..ea40d5c7a9fa |
| --- /dev/null |
| +++ b/drivers/cpufreq/dummy-cpufreq.c |
| @@ -0,0 +1,60 @@ |
| +// SPDX-License-Identifier: GPL-2.0 |
| +/* |
| + * Copyright (C) 2019 Google, Inc. |
| + */ |
| +#include <linux/cpufreq.h> |
| +#include <linux/module.h> |
| + |
| +static struct cpufreq_frequency_table freq_table[] = { |
| + { .frequency = 1 }, |
| + { .frequency = 2 }, |
| + { .frequency = CPUFREQ_TABLE_END }, |
| +}; |
| + |
| +static int dummy_cpufreq_target_index(struct cpufreq_policy *policy, |
| + unsigned int index) |
| +{ |
| + return 0; |
| +} |
| + |
| +static int dummy_cpufreq_driver_init(struct cpufreq_policy *policy) |
| +{ |
| + policy->freq_table = freq_table; |
| + return 0; |
| +} |
| + |
| +static unsigned int dummy_cpufreq_get(unsigned int cpu) |
| +{ |
| + return 1; |
| +} |
| + |
| +static int dummy_cpufreq_verify(struct cpufreq_policy *policy) |
| +{ |
| + return 0; |
| +} |
| + |
| +static struct cpufreq_driver dummy_cpufreq_driver = { |
| + .name = "dummy", |
| + .target_index = dummy_cpufreq_target_index, |
| + .init = dummy_cpufreq_driver_init, |
| + .get = dummy_cpufreq_get, |
| + .verify = dummy_cpufreq_verify, |
| + .attr = cpufreq_generic_attr, |
| +}; |
| + |
| +static int __init dummy_cpufreq_init(void) |
| +{ |
| + return cpufreq_register_driver(&dummy_cpufreq_driver); |
| +} |
| + |
| +static void __exit dummy_cpufreq_exit(void) |
| +{ |
| + cpufreq_unregister_driver(&dummy_cpufreq_driver); |
| +} |
| + |
| +module_init(dummy_cpufreq_init); |
| +module_exit(dummy_cpufreq_exit); |
| + |
| +MODULE_AUTHOR("Connor O'Brien <connoro@google.com>"); |
| +MODULE_DESCRIPTION("dummy cpufreq driver"); |
| +MODULE_LICENSE("GPL"); |