[IMPROVE] add rational_debugfs in swap_energy module
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 15 Nov 2013 11:21:54 +0000 (15:21 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 18 Nov 2013 10:11:14 +0000 (14:11 +0400)
Change-Id: Id6711d8adf3413893b42ced9c44078513622a171
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
energy/Kbuild
energy/rational_debugfs.c [new file with mode: 0644]
energy/rational_debugfs.h [new file with mode: 0644]

index 39f2532..8434a61 100644 (file)
@@ -13,6 +13,7 @@ KBUILD_EXTRA_SYMBOLS = $(src)/../kprobe/Module.symvers \
 obj-m := swap_energy.o
 swap_energy-y := energy_module.o \
                  energy.o \
+                 rational_debugfs.o \
                  debugfs_energy.o \
                  lcd/lcd_base.o
 
diff --git a/energy/rational_debugfs.c b/energy/rational_debugfs.c
new file mode 100644 (file)
index 0000000..122a5a6
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ *  Dynamic Binary Instrumentation Module based on KProbes
+ *  energy/rational_debugfs.c
+ *
+ * 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>
+ *
+ */
+
+
+#include <linux/dcache.h>
+#include <linux/debugfs.h>
+#include <linux/export.h>
+#include "rational_debugfs.h"
+
+
+static int denom_set(void *data, u64 val)
+{
+       if (val == 0)
+               return -EINVAL;
+
+       *(u64 *)data = val;
+       return 0;
+}
+
+static int denom_get(void *data, u64 *val)
+{
+       *val = *(u64 *)data;
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(fops_denom, denom_get, denom_set, "%llu\n");
+
+int create_rational_files(struct dentry *parent, struct rational *r,
+                         const char *num_name, const char *denom_name)
+{
+       struct dentry *d_num, *d_denom;
+
+       d_num = debugfs_create_u64(num_name, 0600, parent, &r->num);
+       if (d_num == NULL)
+               return -ENOMEM;
+
+       d_denom = debugfs_create_file(denom_name, 0600, parent, &r->denom,
+                                 &fops_denom);
+       if (d_denom == NULL) {
+               debugfs_remove(d_num);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
diff --git a/energy/rational_debugfs.h b/energy/rational_debugfs.h
new file mode 100644 (file)
index 0000000..e6d19b1
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef _RATIONAL_DEBUGFS_H
+#define _RATIONAL_DEBUGFS_H
+
+/*
+ *  Dynamic Binary Instrumentation Module based on KProbes
+ *  energy/rational_debugfs.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>
+ *
+ */
+
+
+#include <linux/types.h>
+
+
+struct rational {
+       u64 num;
+       u64 denom;
+};
+
+
+#define DEFINE_RATIONAL(rational_name)         \
+       struct rational rational_name = {       \
+               .num = 1,                       \
+               .denom = 1                      \
+       }
+
+
+struct dentry;
+
+
+int create_rational_files(struct dentry *parent, struct rational *r,
+                         const char *num_name, const char *denom_name);
+
+
+#endif /* _RATIONAL_DEBUGFS_H */