From 7d6107969988145bb2cf5584eea654ab9ab979bb Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 7 Feb 2018 19:30:05 +0300 Subject: [PATCH] sampler: add cpu/hotplug support Change-Id: Ia23652587f808e24a3ecb7ac5c2d572768828359 Signed-off-by: Vyacheslav Cherkashin --- modules/sampler/Kbuild | 2 +- modules/sampler/cpu_notifier.c | 7 +++++ modules/sampler/cpu_notifier_hotplug.c | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 modules/sampler/cpu_notifier.c create mode 100644 modules/sampler/cpu_notifier_hotplug.c diff --git a/modules/sampler/Kbuild b/modules/sampler/Kbuild index 5fee897..e3877d1 100644 --- a/modules/sampler/Kbuild +++ b/modules/sampler/Kbuild @@ -2,7 +2,7 @@ EXTRA_CFLAGS := $(extra_cflags) KBUILD_EXTRA_SYMBOLS = $(src)/../writer/Module.symvers obj-m := swap_sampler.o -swap_sampler-y := swap_sampler_module.o cpu_notifier_hot.o +swap_sampler-y := swap_sampler_module.o cpu_notifier.o ifdef CONFIG_HIGH_RES_TIMERS swap_sampler-y += sampler_hrtimer.o diff --git a/modules/sampler/cpu_notifier.c b/modules/sampler/cpu_notifier.c new file mode 100644 index 0000000..00011ea --- /dev/null +++ b/modules/sampler/cpu_notifier.c @@ -0,0 +1,7 @@ +#include + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) +# include "cpu_notifier_hotplug.c" +#else +# include "cpu_notifier_hot.c" +#endif diff --git a/modules/sampler/cpu_notifier_hotplug.c b/modules/sampler/cpu_notifier_hotplug.c new file mode 100644 index 0000000..63b382d --- /dev/null +++ b/modules/sampler/cpu_notifier_hotplug.c @@ -0,0 +1,54 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2018 + * + * 2018 Vyacheslav Cherkashin + * + */ + + +#include +#include +#include +#include "kernel_operations.h" + + +static int dyn_state; + +int cpu_notifier_start(int (*cpu_setup)(unsigned int cpu), + int (*cpu_shutdown)(unsigned int cpu)) +{ + int ret; + BUG_ON(dyn_state != 0); + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "swap/sampler:online", + cpu_setup, cpu_shutdown); + if (ret < 0) { + print_err("Cannot allocate dynamic state, ret=%d\n", ret); + return ret; + } + + dyn_state = ret; + return 0; +} + +void cpu_notifier_stop(void) +{ + BUG_ON(dyn_state <= 0); + + cpuhp_remove_state(dyn_state); + dyn_state = 0; +} -- 2.7.4