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"
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} \
${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}
--- /dev/null
+EXTRA_CFLAGS := $(extra_cflags)
+
+obj-m := swap_energy.o
+swap_writer-y := swap_writer_module.o kernel_operations.o
--- /dev/null
+#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");
--- /dev/null
+#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 */
#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 */
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);
.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,
/* 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 {
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
#!/bin/sh
rmmod swap_message_parser
+rmmod swap_energy
rmmod swap_sampler
rmmod swap_ks_features
rmmod swap_us_manager