sampler: add cpu/hotplug support 45/170145/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 7 Feb 2018 16:30:05 +0000 (19:30 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 14 Feb 2018 10:57:21 +0000 (13:57 +0300)
Change-Id: Ia23652587f808e24a3ecb7ac5c2d572768828359
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/sampler/Kbuild
modules/sampler/cpu_notifier.c [new file with mode: 0644]
modules/sampler/cpu_notifier_hotplug.c [new file with mode: 0644]

index 5fee897..e3877d1 100644 (file)
@@ -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 (file)
index 0000000..00011ea
--- /dev/null
@@ -0,0 +1,7 @@
+#include <linux/version.h>
+
+#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 (file)
index 0000000..63b382d
--- /dev/null
@@ -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 <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/bug.h>
+#include <linux/errno.h>
+#include <linux/cpuhotplug.h>
+#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;
+}