ks_feature: use kprobe for __switch_to detecting 70/157670/4
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 25 Oct 2017 13:12:56 +0000 (16:12 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 27 Nov 2017 12:49:11 +0000 (15:49 +0300)
Change-Id: I9d907645c241b29679659ef3fc0145ac956989b6
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
modules/ks_features/ks_features.c

index aa2adab8c4f702aa1700b08ec966d7d39da8f5e1..fe209eb13718733cc37394e0bedc4e07fe283052 100644 (file)
 
 
 /* ====================== SWITCH_CONTEXT ======================= */
-static DEFINE_MUTEX(mutex_sc_enable);
-static int sc_enable;
-
-
-#ifdef CONFIG_SWAP_HOOK_SWITCH_TO
-
-#include <swap/hook_switch_to.h>
-
-
 static void ksf_switch(struct task_struct *prev, struct task_struct *next)
 {
        if (check_event(prev))
@@ -64,16 +55,17 @@ static void ksf_switch(struct task_struct *prev, struct task_struct *next)
                ksf_switch_exit(next);
 }
 
+
+#ifdef CONFIG_SWAP_HOOK_SWITCH_TO
+
+#include <swap/hook_switch_to.h>
+
+
 static struct swap_hook_ctx hook_ctx = {
        .hook = ksf_switch,
 };
 
-/**
- * @brief Get scheduler address.
- *
- * @return 0 on success, negative error code on error.
- */
-int init_switch_context(void)
+static int init_switch_context(void)
 {
        return 0;
 }
@@ -90,42 +82,25 @@ static void unregister_ctx_handler(void)
 
 #else  /* CONFIG_SWAP_HOOK_SWITCH_TO */
 
-static int switch_entry_handler(struct kretprobe_instance *ri,
-                               struct pt_regs *regs)
-{
-       if (check_event(current))
-               ksf_switch_entry(current);
 
-       return 0;
-}
-
-static int switch_ret_handler(struct kretprobe_instance *ri,
-                             struct pt_regs *regs)
+static int switch_handler(struct kprobe *p, struct pt_regs *regs)
 {
-       if (check_event(current))
-               ksf_switch_exit(current);
+       struct task_struct *prev = swap_switch_to_prev(regs);
+       struct task_struct *next = swap_switch_to_next(regs);
+
+       ksf_switch(prev, next);
 
        return 0;
 }
 
-/**
- * @var switch_rp
- * Kretprobe for scheduler.
- */
-struct kretprobe switch_rp = {
-       .entry_handler = switch_entry_handler,
-       .handler = switch_ret_handler
+static struct kprobe switch_kp = {
+       .pre_handler = switch_handler,
 };
 
-/**
- * @brief Get scheduler address.
- *
- * @return 0 on success, negative error code on error.
- */
-int init_switch_context(void)
+static int init_switch_context(void)
 {
-       switch_rp.kp.addr = swap_ksyms("__switch_to");
-       if (switch_rp.kp.addr == 0) {
+       switch_kp.addr = swap_ksyms("__switch_to");
+       if (switch_kp.addr == 0) {
                printk(KERN_INFO "ERROR: not found '__switch_to'\n");
                return -EINVAL;
        }
@@ -135,16 +110,20 @@ int init_switch_context(void)
 
 static int register_ctx_handler(void)
 {
-       return swap_register_kretprobe(&switch_rp);
+       return swap_register_kprobe(&switch_kp);
 }
 
 static void unregister_ctx_handler(void)
 {
-       swap_unregister_kretprobe(&switch_rp);
+       swap_unregister_kprobe(&switch_kp);
 }
 #endif /* CONFIG_SWAP_HOOK_SWITCH_TO */
 
 
+
+static DEFINE_MUTEX(mutex_sc_enable);
+static int sc_enable;
+
 /**
  * @brief Unregisters probe on context switching.
  *