[REFACTOR] Move events checking out from msg packing routines 13/20413/11
authorVasiliy Ulyanov <v.ulyanov@samsung.com>
Wed, 7 May 2014 05:33:47 +0000 (09:33 +0400)
committerVasiliy Ulyanov <v.ulyanov@samsung.com>
Fri, 18 Jul 2014 09:26:31 +0000 (13:26 +0400)
Now the checking is performed only when it is actually needed so
the functions from the writer module can be used even if events
filtering is undesirable.

Change-Id: Id0e2a2077bc0bca8f2919a4683a77f0982265166
Signed-off-by: Vasiliy Ulyanov <v.ulyanov@samsung.com>
ks_features/ks_features.c
sampler/swap_sampler_module.c
writer/swap_writer_module.c

index 04e0f12..a5fe06f 100644 (file)
@@ -35,6 +35,7 @@
 #include <ksyms/ksyms.h>
 #include <kprobe/swap_kprobes.h>
 #include <writer/swap_writer_module.h>
+#include <writer/event_filter.h>
 #include "ks_features.h"
 #include "syscall_list.h"
 #include "features_data.c"
@@ -117,7 +118,7 @@ static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
        struct kretprobe *rp = ri->rp;
 
-       if (rp) {
+       if (rp && check_event(current)) {
                struct ks_probe *ksp = container_of(rp, struct ks_probe, rp);
                const char *fmt = ksp->args;
                unsigned long addr = (unsigned long)ksp->rp.kp.addr;
@@ -133,7 +134,7 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
        struct kretprobe *rp = ri->rp;
 
-       if (rp) {
+       if (rp && check_event(current)) {
                unsigned long func_addr = (unsigned long)rp->kp.addr;
                unsigned long ret_addr = (unsigned long)ri->ret_addr;
 
@@ -150,14 +151,16 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 /* ====================== SWITCH_CONTEXT ======================= */
 static int switch_entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
-       switch_entry(regs);
+       if (check_event(current))
+               switch_entry(regs);
 
        return 0;
 }
 
 static int switch_ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
 {
-       switch_exit(regs);
+       if (check_event(current))
+               switch_exit(regs);
 
        return 0;
 }
index 4528743..9867ccf 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/module.h>
 
 #include <writer/swap_writer_module.h>
+#include <writer/event_filter.h>
 
 #include "swap_sampler_module.h"
 #include "swap_sampler_errors.h"
@@ -47,7 +48,7 @@ static BLOCKING_NOTIFIER_HEAD(swap_sampler_notifier_list);
 
 static restart_ret swap_timer_restart(swap_timer *timer)
 {
-       if (current)
+       if (check_event(current))
                sample_msg(task_pt_regs(current));
 
        return sampler_timers_restart(timer);
index cca749c..fcc2c30 100644 (file)
@@ -707,9 +707,6 @@ int sample_msg(struct pt_regs *regs)
        char *buf, *payload, *buf_end;
        int ret;
 
-       if (!check_event(current))
-               return 0;
-
        buf = get_current_buf();
        payload = pack_basic_msg_fmt(buf, MSG_SAMPLE);
        buf_end = pack_sample(payload, regs);
@@ -876,9 +873,6 @@ int entry_event(const char *fmt, unsigned long func_addr, struct pt_regs *regs,
        char *buf, *payload, *args, *buf_end;
        int ret;
 
-       if (pt == PT_KS && !check_event(current))
-               return 0;
-
        buf = get_current_buf();
        payload = pack_basic_msg_fmt(buf, MSG_FUNCTION_ENTRY);
        args = pack_msg_func_entry(payload, fmt, func_addr,
@@ -1046,9 +1040,6 @@ int exit_event(char ret_type, struct pt_regs *regs, unsigned long func_addr,
        char *buf, *payload, *buf_end;
        int ret;
 
-       if (!check_event(current))
-               return 0;
-
        buf = get_current_buf();
        payload = pack_basic_msg_fmt(buf, MSG_FUNCTION_EXIT);
        /* FIXME: len=1024 */
@@ -1126,9 +1117,6 @@ static int context_switch(struct pt_regs *regs, enum MSG_ID id)
  */
 int switch_entry(struct pt_regs *regs)
 {
-       if (!check_event(current))
-               return 0;
-
        return context_switch(regs, MSG_CONTEXT_SWITCH_ENTRY);
 }
 EXPORT_SYMBOL_GPL(switch_entry);
@@ -1141,9 +1129,6 @@ EXPORT_SYMBOL_GPL(switch_entry);
  */
 int switch_exit(struct pt_regs *regs)
 {
-       if (!check_event(current))
-               return 0;
-
        return context_switch(regs, MSG_CONTEXT_SWITCH_EXIT);
 }
 EXPORT_SYMBOL_GPL(switch_exit);