[FEATURE] create empty swap_energy module
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 19 Aug 2013 17:11:10 +0000 (21:11 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 19 Aug 2013 17:11:10 +0000 (21:11 +0400)
build.sh
energy/Kbuild [new file with mode: 0644]
energy/swap_energy.c [new file with mode: 0644]
energy/swap_energy.h [new file with mode: 0644]
parser/features.c
start.sh
stop.sh

index 85f7f04..976d611 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -33,6 +33,7 @@ us_manager_dir=${modules_dir}/us_manager
 ks_features_dir=${modules_dir}/ks_features
 sampler_dir=${modules_dir}/sampler
 parser_dir=${modules_dir}/parser
+energy_dir=${modules_dir}/energy
 
 install_dir="/opt/swap/sdk"
 
@@ -86,6 +87,10 @@ parser_module_name=swap_message_parser.ko
 make CROSS_COMPILE=${cross_compile} ARCH=${arch} -C ${kernel_dir} M=${parser_dir} \
        extra_cflags="-I${modules_dir}" modules || exit 1
 
+energy_module_name=swap_energy.ko
+make CROSS_COMPILE=${cross_compile} ARCH=${arch} -C ${kernel_dir} M=${energy_dir} \
+       extra_cflags="-I${modules_dir} -I${kprobe_dir} -I${kprobe_arch_dir}" modules || exit 1
+
 modules=\
 "${buffer_dir}/${buffer_module_name} \
 ${writer_dir}/${writer_module_name} \
@@ -96,7 +101,8 @@ ${uprobe_dir}/${uprobe_module_name} \
 ${us_manager_dir}/${us_manager_module_name} \
 ${ks_features_dir}/${ks_features_module_name} \
 ${sampler_dir}/${sampler_module_name} \
-${parser_dir}/${parser_module_name}"
+${parser_dir}/${parser_module_name} \
+${energy_dir}/${energy_module_name}"
 
 # for m in ${modules} ; do
 #      sdb -e push $m ${install_dir}
diff --git a/energy/Kbuild b/energy/Kbuild
new file mode 100644 (file)
index 0000000..fcc0c40
--- /dev/null
@@ -0,0 +1,4 @@
+EXTRA_CFLAGS := $(extra_cflags)
+
+obj-m := swap_energy.o
+swap_writer-y := swap_writer_module.o kernel_operations.o
diff --git a/energy/swap_energy.c b/energy/swap_energy.c
new file mode 100644 (file)
index 0000000..c21832a
--- /dev/null
@@ -0,0 +1,159 @@
+#include <linux/module.h>
+#include <linux/time.h>
+#include <kprobe/dbi_kprobes.h>
+
+static u64 get_ntime(void)
+{
+       struct timespec ts;
+
+       getnstimeofday(&ts);
+
+       return (u64)ts.tv_sec * 1000*1000*1000 + ts.tv_nsec;
+}
+
+/* ============================================================================
+ * =                             __switch_to                                  =
+ * ============================================================================
+ */
+static int entry_handler_switch(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static int ret_handler_switch(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static struct kretprobe switch_to_krp = {
+       .entry_handler = entry_handler_switch,
+       .handler = ret_handler_switch,
+};
+
+
+
+
+
+/* ============================================================================
+ * =                                sys_read                                  =
+ * ============================================================================
+ */
+static int entry_handler_sys_read(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static int ret_handler_sys_read(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static struct kretprobe sys_read_krp = {
+       .entry_handler = entry_handler_sys_read,
+       .handler = ret_handler_sys_read,
+};
+
+
+
+
+
+/* ============================================================================
+ * =                               sys_write                                  =
+ * ============================================================================
+ */
+static int entry_handler_sys_write(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static int ret_handler_sys_write(struct kretprobe_instance *ri, struct pt_regs *regs)
+{
+       return 0;
+}
+
+static struct kretprobe sys_write_krp = {
+       .entry_handler = entry_handler_sys_write,
+       .handler = ret_handler_sys_write,
+};
+
+
+
+
+
+int set_energy(void)
+{
+       int ret = 0;
+
+       ret = dbi_register_kretprobe(&sys_read_krp);
+       if (ret) {
+               printk("dbi_register_kretprobe(sys_read) result=%d!\n", ret);
+               return ret;
+       }
+
+       ret = dbi_register_kretprobe(&sys_write_krp);
+       if (ret != 0) {
+               printk("dbi_register_kretprobe(sys_write) result=%d!\n", ret);
+               goto unregister_sys_read;
+       }
+
+       ret = dbi_register_kretprobe(&switch_to_krp);
+       if (ret) {
+               printk("dbi_register_kretprobe(__switch_to) result=%d!\n", ret);
+               goto unregister_sys_write;
+       }
+
+       return ret;
+
+unregister_sys_read:
+       dbi_unregister_kretprobe(&sys_read_krp);
+
+unregister_sys_write:
+       dbi_unregister_kretprobe(&sys_write_krp);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(set_energy);
+
+void unset_energy(void)
+{
+       dbi_unregister_kretprobe(&switch_to_krp);
+       dbi_unregister_kretprobe(&sys_write_krp);
+       dbi_unregister_kretprobe(&sys_read_krp);
+}
+EXPORT_SYMBOL_GPL(unset_energy);
+
+static int __init swap_energy_init(void)
+{
+       unsigned long addr;
+       addr = swap_ksyms("__switch_to");
+       if (addr == 0) {
+               printk("Cannot find address for __switch_to function!\n");
+               return -EINVAL;
+       }
+       switch_to_krp.kp.addr = (kprobe_opcode_t *)addr;
+
+       addr = swap_ksyms("sys_read");
+       if (addr == 0) {
+               printk("Cannot find address for sys_read function!\n");
+               return -EINVAL;
+       }
+       sys_read_krp.kp.addr = (kprobe_opcode_t *)addr;
+
+       addr = swap_ksyms("sys_write");
+       if (addr == 0) {
+               printk("Cannot find address for sys_write function!\n");
+               return -EINVAL;
+       }
+       sys_write_krp.kp.addr = (kprobe_opcode_t *)addr;
+
+       return 0;
+}
+
+static void __exit swap_energy_exit(void)
+{
+}
+
+module_init(swap_energy_init);
+module_exit(swap_energy_exit);
+
+MODULE_LICENSE("GPL");
diff --git a/energy/swap_energy.h b/energy/swap_energy.h
new file mode 100644 (file)
index 0000000..e8f94a0
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef _SWAP_ENERGY_H
+#define _SWAP_ENERGY_H
+
+/*
+ *  Dynamic Binary Instrumentation Module based on KProbes
+ *  modules/energy/swap_energy.h
+ *
+ * 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, 2013
+ *
+ * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+int set_energy(void);
+void unset_energy(void);
+
+#endif /* _SWAP_ENERGY_H */
index b105687..37ab241 100644 (file)
@@ -32,6 +32,7 @@
 #include "msg_parser.h"
 
 #include <sampler/swap_sampler_module.h>
+#include <energy/swap_energy.h>
 
 enum features_list {
        syscall_file    = (1 << 10),    /* File operation syscalls tracing */
@@ -206,6 +207,17 @@ int unset_func_sampling(void)
        return ret;
 }
 
+static int set_func_energy(struct conf_data *conf)
+{
+       return set_energy();
+}
+
+static int unset_func_energy(void)
+{
+       unset_energy();
+       return 0;
+}
+
 struct feature_item {
        char *name;
        int (*set)(struct conf_data *conf);
@@ -266,6 +278,12 @@ static struct feature_item feature_func_sampling = {
        .unset = unset_func_sampling
 };
 
+static struct feature_item feature_func_energy = {
+       .name = "energy",
+       .set = set_func_energy,
+       .unset = unset_func_energy
+};
+
 static struct feature_item *feature_list[] = {
  /*  0 */      NULL,
  /*  1 */      NULL,
@@ -286,7 +304,14 @@ static struct feature_item *feature_list[] = {
  /* 16 */      &feature_context_switch,
  /* 17 */      NULL,
  /* 18 */      NULL,
- /* 19 */      &feature_func_sampling
+ /* 19 */      &feature_func_sampling,
+ /* 20 */      NULL,
+ /* 21 */      NULL,
+ /* 22 */      NULL,
+ /* 23 */      NULL,
+ /* 24 */      NULL,
+ /* 25 */      NULL,
+ /* 26 */      &feature_func_energy
 };
 
 enum {
index 9ca21fc..6086786 100755 (executable)
--- a/start.sh
+++ b/start.sh
@@ -9,4 +9,5 @@ insmod swap_uprobe.ko || exit 1  # uprobe is loaded
 insmod swap_us_manager.ko || exit 1  # us_manager is loaded
 insmod swap_ks_features.ko || exit 1  # ks_features is loaded
 insmod swap_sampler.ko || exit 1
+insmod swap_energy.ko || exit 1
 insmod swap_message_parser.ko || exit 1  # parser is loaded
diff --git a/stop.sh b/stop.sh
index 2f181cb..daac091 100755 (executable)
--- a/stop.sh
+++ b/stop.sh
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 rmmod swap_message_parser
+rmmod swap_energy
 rmmod swap_sampler
 rmmod swap_ks_features
 rmmod swap_us_manager