/* ====================== 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))
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;
}
#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;
}
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.
*