[IMPROVE] use ktd in preload 48/51248/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 5 Nov 2015 17:01:12 +0000 (20:01 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 5 Nov 2015 17:01:12 +0000 (20:01 +0300)
Remove dependent on task_data

Change-Id: Ib41f74a302a9bcc59e783374a2eaaf1142bc6627
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
preload/preload_threads.c

index c700b96..eb8a2e4 100644 (file)
@@ -5,7 +5,7 @@
 #include <linux/mm.h>
 #include <linux/mman.h>
 #include <linux/list.h>
-#include <task_data/task_data.h>
+#include <kprobe/swap_ktd.h>
 #include "preload.h"
 #include "preload_threads.h"
 #include "preload_debugfs.h"
@@ -31,50 +31,40 @@ struct disabled_addr {
        unsigned long addr;
 };
 
-static inline struct preload_td *get_preload_td(struct task_struct *task)
+static void preload_ktd_init(struct task_struct *task, void *data)
 {
-       struct preload_td *td = NULL;
-       int ok;
-
-       td = swap_task_data_get(task, &ok);
-       WARN(!ok, "Preload td[%d/%d] seems corrupted", task->tgid, task->pid);
-
-       if (!td) {
-               td = kzalloc(sizeof(*td), GFP_ATOMIC);
-               WARN(!td, "Failed to allocate preload_td");
-
-               if (td) {
-                       INIT_LIST_HEAD(&td->slots);
-                       /* We use SWAP_TD_FREE flag, i.e. the data will be
-                        * kfree'd by task_data module. */
-                       swap_task_data_set(task, td, SWAP_TD_FREE);
-               }
-       }
+       struct preload_td *td = (struct preload_td *)data;
 
-       return td;
+       INIT_LIST_HEAD(&td->slots);
+       td->flags = 0;
 }
 
-unsigned long get_preload_flags(struct task_struct *task)
+static void preload_ktd_exit(struct task_struct *task, void *data)
 {
-       struct preload_td *td = get_preload_td(task);
+       /* TODO: to be implement */
+}
 
-       if (td == NULL)
-               return 0;
+static struct ktask_data preload_ktd = {
+       .init = preload_ktd_init,
+       .exit = preload_ktd_exit,
+       .size = sizeof(struct preload_td),
+};
+
+
+static inline struct preload_td *get_preload_td(struct task_struct *task)
+{
+       return (struct preload_td *)swap_ktd(&preload_ktd, task);
+}
 
-       return td->flags;
+unsigned long get_preload_flags(struct task_struct *task)
+{
+       return get_preload_td(task)->flags;
 }
 
 void set_preload_flags(struct task_struct *task,
                       unsigned long flags)
 {
-       struct preload_td *td = get_preload_td(task);
-
-       if (td == NULL) {
-               printk(KERN_ERR "%s: invalid arguments\n", __FUNCTION__);
-               return;
-       }
-
-       td->flags = flags;
+       get_preload_td(task)->flags = flags;
 }
 
 
@@ -182,9 +172,6 @@ static inline struct thread_slot *__get_task_slot(struct task_struct *task)
 {
        struct preload_td *td = get_preload_td(task);
 
-       if (td == NULL)
-               return NULL;
-
        return list_empty(&td->slots) ? NULL :
                list_last_entry(&td->slots, struct thread_slot, list);
 }
@@ -325,9 +312,10 @@ put_data_done:
 
 int preload_threads_init(void)
 {
-       return 0;
+       return swap_ktd_reg(&preload_ktd);
 }
 
 void preload_threads_exit(void)
 {
+       swap_ktd_unreg(&preload_ktd);
 }