00001
00005
00006
00007
00008
00009
00010 #include "rres_config.h"
00011 #define QOS_DEBUG_LEVEL RRES_MOD_DEBUG_LEVEL
00012 #include "qos_debug.h"
00013
00014 #ifdef PROF_RRES_HOOKS
00015 # define QOS_PROFILE
00016 #endif
00017 #include "qos_prof.h"
00018 #include "qos_list.h"
00019 #include "qos_func.h"
00020
00021 #include "kal_generic.h"
00022 #include "rres_interface.h"
00023 #include "rres_kpi_protected.h"
00024 #include "rres.h"
00025 #include "rres_dispatch.h"
00026
00027 #include "rres_time.h"
00028
00029 #ifdef RRES_DISABLE_ACTIVATIONS
00030 # warning "Servers activation counting, along with block/stop hook pairs, are disabled"
00031 #endif
00032
00033 #ifndef RRES_DISABLE_ACTIVATIONS
00034
00041 qos_func_define(void, rres_unblock_hook, kal_task_t *t, long old_state) {
00042 unsigned long flags;
00043 prof_vars;
00044
00045 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00046 prof_func();
00047 qos_chk_ok(rres_on_task_unblock(t));
00048 prof_end();
00049 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00050 }
00051
00064 qos_func_define(void, rres_block_hook, kal_task_t *t) {
00065 unsigned long flags;
00066 prof_vars;
00067
00068 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00069 prof_func();
00070 rres_on_task_block(t);
00071 prof_end();
00072 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00073 }
00074
00076 qos_func_define(void, rres_stop_hook, kal_task_t *t) {
00077 #ifdef RRES_DISPATCH_NEW
00078 qos_log_debug("Stop hook");
00079 rres_block_hook(t);
00080 #else
00081 qos_log_debug("Stop hook ignored");
00082 #endif
00083 }
00084
00086 qos_func_define(void, rres_continue_hook, kal_task_t *t, long old_state) {
00087 #ifdef RRES_DISPATCH_NEW
00088 qos_log_debug("Continue hook");
00089 rres_unblock_hook(t, old_state);
00090 #else
00091 qos_log_debug("Continue hook ignored");
00092 #endif
00093 }
00094
00095 #else
00096
00098 void rres_unblock_hook(kal_task_t *t, long old_state) {
00099 }
00100
00102 void rres_block_hook(kal_task_t *t) {
00103 }
00104
00106 void rres_stop_hook(kal_task_t *t) {
00107 }
00108
00110 void rres_continue_hook(kal_task_t *t, long old_state) {
00111 }
00112
00113 #endif
00114
00116 qos_func_define(void, rres_fork_hook, kal_task_t *t, kal_task_t *prev) {
00117 server_t* srv;
00118 unsigned long flags;
00119 prof_vars;
00120
00121 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00122 prof_func();
00123 srv = rres_find_by_task(prev);
00124 if (srv != NULL) {
00125 qos_log_debug("(%d), t->private_data: %p", kal_task_get_id(t), kal_task_get_data(t));
00126
00127
00128 qos_chk_ok(rres_attach_task(srv, t));
00129 }
00130 prof_end();
00131 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00132 }
00133
00138 qos_func_define(void, rres_cleanup_hook, kal_task_t *t) {
00139 server_t* srv;
00140 unsigned long flags;
00141 prof_vars;
00142
00143 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00144 prof_func();
00145 srv = rres_find_by_task(t);
00146 if (srv != NULL) {
00147 rres_sample_time();
00148 qos_chk_ok_do(rres_detach_task_nosched(srv, t), goto err);
00149 rres_schedule();
00150 qos_chk_do((! rres_empty(srv)) || (! rres_has_ready_tasks(srv)), goto err);
00151 qos_chk_do((! rres_empty(srv)) || (! rres_running(srv)), goto err);
00152 rres_check_destroy(srv);
00153 srv = NULL;
00154
00155 }
00156 err:
00157 prof_end();
00158 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00159 }
00160
00162 qos_func_define(void, set_gensched_hooks, void) {
00163 block_hook = rres_block_hook;
00164 unblock_hook = rres_unblock_hook;
00165 stop_hook = rres_stop_hook;
00166 continue_hook = rres_continue_hook;
00167 fork_hook = rres_fork_hook;
00168 cleanup_hook = rres_cleanup_hook;
00169
00170
00171 }
00172
00173 qos_func_define(int, check_gensched_hooks, void) {
00174 return (
00175 (block_hook == NULL)
00176 && (unblock_hook == NULL)
00177 && (stop_hook == NULL)
00178 && (continue_hook == NULL)
00179 && (fork_hook == NULL)
00180 && (cleanup_hook == NULL)
00181 );
00182 }
00183
00185 qos_func_define(void, unset_gensched_hooks, void) {
00186 block_hook = NULL;
00187 unblock_hook = NULL;
00188 stop_hook = NULL;
00189 continue_hook = NULL;
00190 fork_hook = NULL;
00191 cleanup_hook = NULL;
00192
00193
00194 }
00195
00196 #if 0
00197
00198 void switch_hook_handler(kal_task_t *prev, kal_task_t *next ) {
00199 unsigned long flags;
00200 qres_clock_t old_sched_time = sched_time;
00201 server_t *srv;
00202
00203 spin_lock_irqsave(rres_get_spinlock(), &flags);
00204 rres_sample_time();
00205 qos_log_debug("- %6ld, + %6ld", prev->pid, next->pid);
00206 qos_log_state_simple(prev);
00207 qos_log_state_simple(next);
00208 srv = rres_find_by_task(next);
00209 if (srv && rres_running(srv))
00210 qos_log_debug("!%d", next->pid);
00211 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00212 }
00213
00214 void activate_hook_handler(kal_task_t *p, void *rq) {
00215 qos_log_state_simple(p);
00216 }
00217 void deactivate_hook_handler(kal_task_t *p, void *rq) {
00218 qos_log_state_simple(p);
00219 }
00220 #endif