00001
00002 #include <linux/kernel.h>
00003 #include <linux/version.h>
00004 #include <linux/module.h>
00005 #include <linux/moduleparam.h>
00006 #include <linux/init.h>
00007 #include <linux/spinlock.h>
00008
00009 #include <linux/aquosa/rres_interface.h>
00010
00011 #define UNASSIGNED -1
00012
00013 int pid = UNASSIGNED;
00014 int tid = UNASSIGNED;
00015 int sid = UNASSIGNED;
00016 int q = UNASSIGNED;
00017 int p = UNASSIGNED;
00018 int f = 0x00000000;
00019 int create = 0;
00020 int attach = 0;
00021 int detach = 0;
00022 int destroy = 0;
00023 int setparam = 0;
00024
00025 module_param(pid, int, 0);
00026 module_param(tid, int, 0);
00027 module_param(sid, int, 0);
00028 module_param(q, int, 0);
00029 module_param(p, int, 0);
00030 module_param(f, int, 0);
00031 module_param(create, int, 0);
00032 module_param(attach, int, 0);
00033 module_param(detach, int, 0);
00034 module_param(destroy, int, 0);
00035 module_param(setparam, int, 0);
00036
00037 struct server_t *srv;
00038
00039 static int test_rres_init_module(void) {
00040 kal_irq_state flags;
00041 qres_time_t param_q = q, param_p = p;
00042 kal_task_t *t = NULL;
00043
00044 if (tid == UNASSIGNED)
00045 tid = pid;
00046
00047 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00048
00049 if (create) {
00050 qos_chk_go_msg(param_q != UNASSIGNED && param_p != UNASSIGNED, err, "Need to specify q and p");
00051 qos_chk_ok(rres_create_server(&srv, param_q, param_p, f));
00052 } else if (sid != UNASSIGNED) {
00053 srv = rres_find_by_id(sid);
00054 qos_chk_go_msg(srv != NULL, err, "Could not find server with SID: %d", sid);
00055 }
00056 if (tid == 0) {
00057 t = current;
00058 } else if (tid != UNASSIGNED) {
00059 qos_log_crit("Searching task with tid: %d", tid);
00060 t = kal_find_task_by_pid(tid);
00061 qos_log_crit("Found");
00062 qos_chk_go_msg(t != NULL, err, "Could not find thread with tid: %d", tid);
00063 }
00064 if (attach) {
00065 qos_chk_go_msg(srv != NULL && t != NULL, err, "Invalid params");
00066 qos_log_crit("Attaching task %d to server %d", t->pid, srv->id);
00067 qos_chk_ok(rres_attach_task(srv, t));
00068 }
00069 if (detach) {
00070 qos_chk_go_msg(srv != NULL && t != NULL, err, "Invalid params");
00071 qos_log_crit("Detaching task %d from server %d", t->pid, srv->id);
00072 qos_chk_ok(rres_detach_task(srv, t));
00073 }
00074 if (destroy) {
00075 qos_chk_go_msg(srv != NULL, err, "No server specified");
00076 qos_chk_ok(rres_destroy_server(srv));
00077 }
00078 if (setparam) {
00079 if (srv != NULL && param_q != UNASSIGNED && param_p != UNASSIGNED)
00080 qos_chk_ok(rres_set_params(srv, param_q, param_p));
00081 else if (t != NULL && rres_find_by_task(t) != NULL)
00082 qos_chk_ok(rres_set_params(rres_find_by_task(t), param_q, param_p));
00083 else
00084 qos_chk_go_msg(0, err, "Invalid params");
00085 }
00086
00087 err:
00088
00089 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00090
00091
00092 return -1;
00093 }
00094
00095 static void test_rres_cleanup_module(void) {
00096 }
00097
00098 MODULE_AUTHOR("ReTiS Lab");
00099 MODULE_LICENSE("GPL");
00100 module_init(test_rres_init_module);
00101 module_exit(test_rres_cleanup_module);