00001
00014
00015
00016
00017
00018 #ifdef QOS_KS
00019
00020 #ifndef CONFIG_GENERIC_SCHEDULER
00021 #error "The Generic Scheduler is not enabled !"
00022 #endif
00023
00024
00025
00026 #include <linux/kernel.h>
00027 #include <linux/version.h>
00028 #include <linux/module.h>
00029 #include <linux/moduleparam.h>
00030 #include <linux/spinlock.h>
00031 #include <linux/sched.h>
00032 #else
00033 #include "kal_generic.h"
00034 #define module_init(func) int main_func(void) { return func(); }
00035 #define module_exit(x)
00036 #define MODULE_LICENSE(x)
00037 #endif
00038
00039 #include "rres_config.h"
00040 #define QOS_DEBUG_LEVEL RRES_MOD_DEBUG_LEVEL
00041 #include "qos_debug.h"
00042
00043 #include "rres.h"
00044 #include "rres_hooks.h"
00045 #include "rres_proc_fs.h"
00046
00047 #include <linux/version.h>
00048
00049 #ifdef GENSCHED_VERSION_CODE
00050
00051 # if GENSCHED_VERSION_CODE < GENSCHED_VERSION(2,0)
00052 # error "Need a kernel patched with a generic scheduler patch with version 2.x"
00053 # endif
00054 #else
00055
00056 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
00057 # include <linux/utsrelease.h>
00058 # endif
00059 #endif
00060
00065 int rres_mod_removed = 0;
00066
00073 int rres_init_module(void) {
00074 unsigned long flags;
00075 int err = 0;
00076
00077
00078 #ifndef GENSCHED_VERSION_CODE
00079 if (strstr(UTS_RELEASE, "gs-2.") == NULL) {
00080 qos_log_crit("Need a kernel patched with a generic scheduler patch with version gs-2.x");
00081 return -1;
00082 }
00083 #endif
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00101
00102 qos_log_debug("Initializing rres module... ");
00103 rres_sample_time();
00104 if (rres_init() != QOS_OK) {
00105 qos_log_err("rres_init() failed");
00106 err = 1;
00107 }
00108
00109 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00110
00111 if (err)
00112 return -1;
00113
00114 write_lock(&hook_lock);
00115 if (! check_gensched_hooks()) {
00116 qos_log_crit("Hooks already initialized !!!");
00117 err = 1;
00118 goto out_hooks;
00119 }
00120 set_gensched_hooks();
00121 out_hooks:
00122 write_unlock(&hook_lock);
00123
00124 if (err) {
00125 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00126 rres_cleanup();
00127 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00128 return -1;
00129 }
00130
00131 qos_log_debug("Hooks initialized");
00132
00134 if (rres_proc_register())
00135 qos_log_err("Failed to register rres module in /proc filesystem");
00136
00137 qos_log_debug("rres module initialization finished");
00138
00139 return 0;
00140 }
00141
00148 void rres_cleanup_module(void) {
00149 unsigned long flags;
00150
00151 rres_mod_removed = 1;
00152 rres_proc_unregister();
00153
00154 qos_log_debug("Unsetting hooks... ");
00155 write_lock(&hook_lock);
00156 unset_gensched_hooks();
00157 write_unlock(&hook_lock);
00158
00159 qos_log_debug("Cleaning up module... ");
00160 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00161 qos_chk_ok(rres_cleanup());
00162
00163 if (! qos_mem_clean()) {
00164 qos_log_err("MEMORY NOT CLEAN AFTER MODULE CLEANUP");
00165 } else {
00166 qos_log_info("Memory clean");
00167 }
00168
00169 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00170 qos_log_debug("rres module removed from kernel");
00171 }
00172
00173 module_init(rres_init_module);
00174 module_exit(rres_cleanup_module);
00175
00176 MODULE_LICENSE("GPL");
00177 MODULE_AUTHOR("ReTiS Lab");
00178 MODULE_DESCRIPTION("AQuoSA Resource Reservation - Core CPU Scheduler");