rres.c File Reference

Main resource reservation implementation file. More...

#include "rres_config.h"
#include "qos_debug.h"
#include "rres_ready_queue.h"
#include "qos_prof.h"
#include "kal_config.h"
#include "kal_timer_hrtimer.h"
#include "qos_ul.h"
#include <linux/aquosa/rres_config.h>
#include <sys/types.h>
#include "qos_func.h"
#include "qos_list.h"
#include "qos_types.h"
#include "kal_timer.h"
#include "kal_sched.h"
#include "rres_ready_queue.h"
#include "qos_memory.h"
#include <linux/aquosa/kal_generic.h>
#include <linux/aquosa/rres_time.h>
#include <linux/aquosa/qos_debug.h>
#include <linux/aquosa/rres_server.h>

Go to the source code of this file.

Defines

#define QOS_DEBUG_LEVEL   RRES_MOD_DEBUG_LEVEL
#define rres_dump(srv)

Functions

 kal_lock_define (rres_lock)
 EXPORT_SYMBOL_GPL (rres_lock)
static void iris_hr_reactive_timer_handler (unsigned long v)
 IRIS HR reactivate timer handler.
void stop_pending_timers (server_t *srv, int pending_unexpected)
 Stop pending timers relative to reactivation from recharging state.
int rres_empty (server_t *srv)
 Check if the server has no tasks attached (no matter if running or blocked).
 EXPORT_SYMBOL_GPL (rres_empty)
qos_bool_t rres_has_server (kal_task_t *task)
 Return true if task is served by any server.
 EXPORT_SYMBOL_GPL (rres_has_server)
server_trres_find_by_id (qres_sid_t sid)
 Return the current time, as a qres_time_t value (microseconds), with respect to a point in the past (usually the machine boot time).
 EXPORT_SYMBOL_GPL (rres_find_by_id)
static void set_enforce_timer (kal_time_t delta)
 Forward the enforce timer (for budget exhaustion) for the specified time, or, if it is not pending, set it to now plus the specified time.
qres_sid_t new_server_id (void)
 Allocate a new server identifier.
qos_bw_t _rres_get_bandwidth (server_t *srv)
 Return the bandwidth approved for the server.
 EXPORT_SYMBOL_GPL (_rres_get_bandwidth)
static void rres_remove_from_srv_set (server_t *srv)
 remove the server from the set of servers
static void rres_add_to_srv_set (server_t *srv)
 Add the server to the set of servers.
static void tasklist_init (struct task_list *task_l, server_t *srv, kal_task_t *task)
 Initialize an already allocated task list entry so to link it to a task and server.
static void tasklist_cleanup (struct task_list *tl)
 Unlink a task list entry from the referenced task and server.
static qos_rv rres_add (server_t *srv, kal_task_t *task)
 Add a task to the tasklist of a server.
static void rres_del (kal_task_t *task)
 Remove the task from the tasklist of the attached server.
void recharge (server_t *srv)
 Recharge budget and add server period to previously set deadline.
void recharge_reset_from_now (server_t *srv)
 Set deadline to last sampled time (now) and call recharge().
static void update_budgets (kal_time_t consumed_time)
static void rres_update_budget (void)
 Update the budget of currently executing server and the last_update_time.
static void enforce_timer_handler (kal_arg_t dummy)
 Enforcement timer handler, called when the budget gets exausted.
static qos_rv rres_activate_nosched (server_t *srv)
 Activate a server whose ready tasks set has just become non-empty.
qos_rv rres_deactivate_nosched (server_t *srv)
 Deactivate a server that has no ready tasks attached.
int rres_has_ready_tasks (server_t *srv)
 EXPORT_SYMBOL_GPL (rres_has_ready_tasks)
void stop_task_safe (server_t *srv, kal_task_t *task)
 Avoids stopping a task twice, as well as stopping a non-ready task.
void dispatch_task_safe (server_t *srv, kal_task_t *task)
 Avoids dispatching a task twice.
static qos_rv rres_attach_task_nosched (server_t *srv, kal_task_t *task)
 Attach a task to an existing (possibly empty) server (internal use only!).
qos_rv rres_attach_task (server_t *srv, kal_task_t *task)
 Attach a task to a server.
 EXPORT_SYMBOL_GPL (rres_attach_task)
qos_rv rres_check_destroy (server_t *srv)
 Destroy server if empty and not tagged as persistent.
 EXPORT_SYMBOL_GPL (rres_check_destroy)
qos_rv rres_detach_task_nosched (server_t *srv, kal_task_t *task)
 Remove a task from its server and let it be scheduled by the system default scheduling policy (e.g., SCHED_OTHER on Linux).
qos_rv rres_detach_task (server_t *srv, kal_task_t *task)
 Detach a task from a server.
 EXPORT_SYMBOL_GPL (rres_detach_task)
qos_rv rres_detach_all_tasks_nosched (server_t *srv)
 Remove all tasks from the server.
qos_rv rres_move_nosched (server_t *new_srv, kal_task_t *task)
 Move a task from a server to another.
qos_rv rres_attach_all_tasks_nosched (server_t *srv)
 Put all tasks without a server in a dedicated server, usually the default one.
qos_rv rres_init_server (server_t *srv, qres_time_t max_budget, qres_time_t period, unsigned long flags)
 Allocate and inizialise the structure for a new server.
 EXPORT_SYMBOL_GPL (rres_init_server)
qos_rv _rres_cleanup_server (server_t *srv)
 Now server must already be emtpy, when calling this !! Deallocate server structure and schedule the served task in background After this call all the tasks are no more in any server or is in the default server (if CONFIG_RRES_DEFAULT_SRV is enabled) Remove from ready_queue, stop pending timers and update reserved bandwidth.
 EXPORT_SYMBOL_GPL (_rres_cleanup_server)
qos_rv rres_create_server (server_t **new_srv, qres_time_t max_budget, qres_time_t period, unsigned long type)
 Create a void server (no tasks attached).
 EXPORT_SYMBOL_GPL (rres_create_server)
qos_rv rres_destroy_server (server_t *srv)
 Detach all tasks, reschedule servers if needed, and deallocate any resources associated with the server.
 EXPORT_SYMBOL_GPL (rres_destroy_server)
qres_sid_t rres_get_sid (server_t *srv)
 get the server ID
 EXPORT_SYMBOL_GPL (rres_get_sid)
qos_rv rres_set_params (server_t *srv, qres_time_t new_budget, qres_time_t new_period)
 Change the budget and/or the period of a server.
 EXPORT_SYMBOL_GPL (rres_set_params)
qos_rv rres_set_budget (server_t *srv, qres_time_t new_budget)
 Change the maximum budget and update current server and total bandwidths.
 EXPORT_SYMBOL_GPL (rres_set_budget)
qres_time_t rres_get_actual_budget (server_t *srv)
qos_rv rres_get_params (server_t *srv, qres_time_t *budget, qres_time_t *period)
 Return the budget and the period.
 EXPORT_SYMBOL_GPL (rres_get_params)
qres_time_t rres_get_period (server_t *srv)
 return the period (the value are returned via function parameters)
 EXPORT_SYMBOL_GPL (rres_get_period)
qres_time_t rres_get_exec_time (server_t *srv)
 Return the effective execution time of the specified server, in microseconds.
 EXPORT_SYMBOL_GPL (rres_get_exec_time)
server_trres_get_default_server (void)
 Return the pointer to the default server.
 EXPORT_SYMBOL_GPL (rres_get_default_server)
void rres_stop (server_t *srv)
 Stop all tasks handled by the server and rotate the order of its tasks as enqueued in the srv->tasks list (reversed attachment order, modified by blocks and unblocks).
void rres_dispatch (server_t *srv)
 Dispatch (force scheduling) of all tasks handled by the server.
kal_time_t get_max_time_slice (server_t *srv)
 Update the active servers total bandwidth and weight, and return the max time slice that can be assigned to the currently executing server, according to its budget and relative decrease rate.
void rres_schedule (void)
 The server scheduler.
qos_rv rres_init (void)
 Initialise server lists, timers, and algorithm-related data, then calls rres_schedule().
qos_rv rres_cleanup (void)
 Destroy all servers in the system.
int rres_running (server_t *srv)
 Check if the server is currently running.
 EXPORT_SYMBOL_GPL (rres_running)
qos_rv rres_on_task_unblock (kal_task_t *task)
 BLOCK / UNBLOCK.
qos_rv rres_on_task_block (kal_task_t *task)
 EXPORT_SYMBOL_GPL (server_list)

Variables

server_texec = NULL
 current executing server
qres_sid_t server_id = 1
 next tentative server ID
struct list_head server_list
 list of system's servers
kal_timer_tenforce = NULL
 timer for enforcement of maximum budget
kal_time_t last_update_time
 time of last budget update
qos_bw_t U_tot = 0
 total allocated bandwidth
server_tdefault_srv = NULL
 pointer to the default server
kal_time_t sched_time
 used to avoid reading too frequently the time.

Detailed Description

Main resource reservation implementation file.

Handle creation, destruction and all other main operations on server.

Note:
All operations defined on RRES Server are not synchronised: the caller must have gained access to a global lock before calling.
Todo:

Check flow diagram of task add/remove/block/unblock/stop/continue w.r.t. call to rres_schedule() and/or to sync_with_server() and related

fare versioni con attach/detach_all (pensarle gia' con un interfaccia comoda da usare con dei set di task?)

Definition in file rres.c.


Define Documentation

#define QOS_DEBUG_LEVEL   RRES_MOD_DEBUG_LEVEL

Definition at line 15 of file rres.c.

#define rres_dump ( srv   ) 
Value:
do {                                            \
  struct list_head *h;                                                  \
  kal_task_t *task;                                             \
  char s[256];                                                          \
  char *t = s;                                                          \
  qos_chk(srv != NULL);                                                 \
  if (srv != NULL) {                                                    \
    for_each_ready_task_in_server(srv, task, h) {                       \
      int written = snprintf(t, s + sizeof(s) - t, "%d,", kal_task_get_id(task)); \
      if (written >= s + sizeof(s) - t)                                 \
        break;                                                          \
    }                                                                   \
    for_each_blocked_task_in_server(srv, task, h) {                     \
      int written = snprintf(t, s + sizeof(s) - t, "%d,", kal_task_get_id(task)); \
      if (written >= s + sizeof(s) - t)                                 \
        break;                                                          \
    }                                                                   \
    qos_log_debug("(s:%d): rdy=%d, c=" KAL_TIME_FMT ", dl=" KAL_TIME_FMT ", rchg=%d, tasks=%s", \
                  srv->id, in_ready_queue(srv), KAL_TIME_FMT_ARG(srv->c), KAL_TIME_FMT_ARG(srv->deadline), \
                  kal_timer_pending(&srv->reactive), s);                \
  }                                                                     \
} while (0)

Definition at line 44 of file rres.c.

Referenced by rres_activate_nosched(), rres_deactivate_nosched(), rres_schedule(), and stop_pending_timers().


Function Documentation

void dispatch_task_safe ( server_t srv,
kal_task_t task 
)

Avoids dispatching a task twice.

Also, if a server is soft, then its tasks only need a priority change to RT, because they were never stopped by stop_task_safe().

Definition at line 555 of file rres.c.

References dispatch_task(), server_t::flags, task_list::is_stopped, qos_chk_do, QOS_F_SOFT, rres_find_task_list(), rres_init_sched_param, and RRES_PARANOID.

Referenced by rres_detach_task_nosched(), rres_dispatch(), and rres_on_task_block().

static void enforce_timer_handler ( kal_arg_t  dummy  )  [static]

Enforcement timer handler, called when the budget gets exausted.

After source refactoring, this function only needs to acquire global lock, sample time and call rres_schedule(), that manages budget exhaustion.

Definition at line 437 of file rres.c.

References qos_log_debug, rres_get_spinlock(), rres_sample_time(), and rres_schedule().

Referenced by rres_init().

EXPORT_SYMBOL_GPL ( server_list   ) 
EXPORT_SYMBOL_GPL ( rres_running   ) 
EXPORT_SYMBOL_GPL ( rres_get_default_server   ) 
EXPORT_SYMBOL_GPL ( rres_get_exec_time   ) 
EXPORT_SYMBOL_GPL ( rres_get_period   ) 
EXPORT_SYMBOL_GPL ( rres_get_params   ) 
EXPORT_SYMBOL_GPL ( rres_set_budget   ) 
EXPORT_SYMBOL_GPL ( rres_set_params   ) 
EXPORT_SYMBOL_GPL ( rres_get_sid   ) 
EXPORT_SYMBOL_GPL ( rres_destroy_server   ) 
EXPORT_SYMBOL_GPL ( rres_create_server   ) 
EXPORT_SYMBOL_GPL ( _rres_cleanup_server   ) 
EXPORT_SYMBOL_GPL ( rres_init_server   ) 
EXPORT_SYMBOL_GPL ( rres_detach_task   ) 
EXPORT_SYMBOL_GPL ( rres_check_destroy   ) 
EXPORT_SYMBOL_GPL ( rres_attach_task   ) 
EXPORT_SYMBOL_GPL ( rres_has_ready_tasks   ) 
EXPORT_SYMBOL_GPL ( _rres_get_bandwidth   ) 
EXPORT_SYMBOL_GPL ( rres_find_by_id   ) 
EXPORT_SYMBOL_GPL ( rres_has_server   ) 
EXPORT_SYMBOL_GPL ( rres_empty   ) 
EXPORT_SYMBOL_GPL ( rres_lock   ) 
kal_time_t get_max_time_slice ( server_t srv  ) 

Update the active servers total bandwidth and weight, and return the max time slice that can be assigned to the currently executing server, according to its budget and relative decrease rate.

Note:
Currently, the budget decrease rate is different from 1 only for the SHRUB algorithm.

Definition at line 1172 of file rres.c.

References server_t::c.

Referenced by rres_schedule().

static void iris_hr_reactive_timer_handler ( unsigned long  v  )  [static]

IRIS HR reactivate timer handler.

Put again the server in the ready queue after a sleep waiting for recharging starts when the server becomes active after being blocked (when the timer reactive fires)

Definition at line 74 of file rres.c.

References qos_chk_do, qos_chk_ok, qos_log_debug, ready_queue_add(), recharge(), rres_empty(), rres_get_spinlock(), rres_has_ready_tasks(), RRES_PARANOID, rres_sample_time(), rres_schedule(), and srv.

Referenced by rres_init_server().

kal_lock_define ( rres_lock   ) 
qres_sid_t new_server_id ( void   ) 

Allocate a new server identifier.

Definition at line 175 of file rres.c.

References qos_log_debug, QRES_SID_NULL, rres_find_by_id(), and server_id.

Referenced by rres_init_server().

static qos_rv rres_activate_nosched ( server_t srv  )  [static]
static qos_rv rres_add ( server_t srv,
kal_task_t task 
) [inline, static]

Add a task to the tasklist of a server.

Allocate a task_list entry, initialize it and link it to the tasks list of the specified server.

It does not initialize task scheduling policy and priority, and does not schedule servers.

Definition at line 233 of file rres.c.

References server_t::id, kal_task_get_id(), qos_create, QOS_E_NO_MEMORY, qos_log_debug, QOS_OK, and tasklist_init().

Referenced by rres_attach_task_nosched().

static void rres_add_to_srv_set ( server_t srv  )  [inline, static]

Add the server to the set of servers.

Definition at line 201 of file rres.c.

References INIT_LIST_HEAD_NULL, server_list, and server_t::slist.

Referenced by rres_init_server().

qos_rv rres_attach_all_tasks_nosched ( server_t srv  ) 

Put all tasks without a server in a dedicated server, usually the default one.

Note:
It does not call rres_schedule(): the caller must do it

Definition at line 934 of file rres.c.

References for_each_task, qos_chk_do, qos_chk_ok_ret, QOS_E_INTERNAL_ERROR, QOS_OK, rres_attach_task_nosched(), and rres_find_by_task().

Referenced by rres_init_server().

qos_rv rres_attach_task ( server_t srv,
kal_task_t task 
)

Attach a task to a server.

If the task is already attached to the default server, then detach from it and attach to the new server.

Definition at line 611 of file rres.c.

References QOS_E_INVALID_PARAM, qos_log_err, rres_attach_task_nosched(), rres_find_by_task(), rres_move_nosched(), rres_sample_time(), and rres_schedule().

Referenced by qos_func_define(), rres_fork_hook(), and test_rres_init_module().

static qos_rv rres_attach_task_nosched ( server_t srv,
kal_task_t task 
) [static]

Attach a task to an existing (possibly empty) server (internal use only!).

Note:
The task must not be attached to any server (including the default one) when calling this function.
Todo:
Remove the rres_sync_after_add() stuff, which should be dealt with in rres_schedule().
Todo:
Check that, while moving from default_srv, task is dispatched before removal from default_srv

Definition at line 579 of file rres.c.

References server_t::id, kal_task_get_id(), qos_chk_do, qos_chk_ok_ret, QOS_E_INTERNAL_ERROR, QOS_E_INVALID_PARAM, qos_log_debug, QOS_OK, rres_activate_nosched(), rres_add(), rres_find_by_task(), rres_get_default_server(), rres_has_ready_tasks(), rres_init_sched_param, RRES_PARANOID, rres_running(), stop_task_safe(), and task_ready().

Referenced by rres_attach_all_tasks_nosched(), rres_attach_task(), and rres_move_nosched().

qos_rv rres_deactivate_nosched ( server_t srv  ) 

Deactivate a server that has no ready tasks attached.

Remove server from the ready queue, if needed, and remove pending timers (recharge, currently), if any.

Note:
This is called when the last ready task either blocks or is detached from the server.

Definition at line 493 of file rres.c.

References in_ready_queue(), qos_chk_do, QOS_E_INTERNAL_ERROR, qos_log_debug, QOS_OK, ready_queue_remove(), rres_dump, rres_has_ready_tasks(), RRES_PARANOID, and stop_pending_timers().

Referenced by rres_detach_task_nosched(), and rres_on_task_block().

static void rres_del ( kal_task_t task  )  [inline, static]

Remove the task from the tasklist of the attached server.

Does not deal with scheduling of servers.

Definition at line 248 of file rres.c.

References qos_chk_do, qos_free(), rres_find_task_list(), and tasklist_cleanup().

Referenced by rres_detach_task_nosched().

qos_rv rres_detach_all_tasks_nosched ( server_t srv  ) 

Remove all tasks from the server.

The tasks will be scheduled the default scheduling policy.

Note:
The server may still be referenced by exec, after this call returs. Call rres_schedule() afterwards in order to be sure it is not referenced anymore.
If you also need to destroy the server, then you have to call explicitly rres_destroy_server().

Definition at line 719 of file rres.c.

References server_t::forbid_reorder, server_t::id, qos_chk_do, qos_chk_ok_ret, QOS_E_INTERNAL_ERROR, qos_log_debug, QOS_OK, rres_any_blocked_task(), rres_any_ready_task(), rres_detach_task_nosched(), and task_list::task.

qos_rv rres_detach_task ( server_t srv,
kal_task_t task 
)

Detach a task from a server.

If the default server is configured, then reattach the task to it. For this reason, do not call this from the cleanup_hook of a task. Then, calls rres_schedule().

Note:
If you need to destroy an empty server after this call, then you should explicitly call rres_check_destroy().
See also:
rres_detach_task_nosched(server_t *), rres_schedule(void), rres_check_destroy(server_t *)

Definition at line 683 of file rres.c.

References qos_chk, qos_chk_ok_do, QOS_E_INVALID_PARAM, qos_log_err, QOS_OK, rres_detach_task_nosched(), rres_empty(), rres_find_by_task(), rres_get_default_server(), rres_move_nosched(), rres_running(), rres_sample_time(), and rres_schedule().

Referenced by qos_func_define(), rres_destroy_server(), and test_rres_init_module().

qos_rv rres_detach_task_nosched ( server_t srv,
kal_task_t task 
)
qres_time_t rres_get_actual_budget ( server_t srv  ) 

Definition at line 1030 of file rres.c.

References bw2Q(), server_t::period_us, and rres_get_bandwidth().

qos_bool_t rres_has_server ( kal_task_t task  ) 

Return true if task is served by any server.

Definition at line 118 of file rres.c.

References rres_find_by_task().

qos_rv rres_move_nosched ( server_t new_srv,
kal_task_t task 
)

Move a task from a server to another.

Todo:
Here we may optimize by avoiding deallocating task_list and reallocating again.

Definition at line 740 of file rres.c.

References qos_chk_ok_ret, qos_chk_rv, QOS_E_INTERNAL_ERROR, QOS_OK, rres_attach_task_nosched(), rres_detach_task_nosched(), and rres_find_by_task().

Referenced by rres_attach_task(), and rres_detach_task().

qos_rv rres_on_task_block ( kal_task_t task  ) 
qos_rv rres_on_task_unblock ( kal_task_t task  ) 
static void rres_remove_from_srv_set ( server_t srv  )  [inline, static]

remove the server from the set of servers

Definition at line 195 of file rres.c.

References INIT_LIST_HEAD_NULL, and server_t::slist.

Referenced by _rres_cleanup_server(), and rres_init_server().

static void rres_update_budget ( void   )  [static]

Update the budget of currently executing server and the last_update_time.

The caller must be sure that exec != NULL.

Todo:
Budget Should be considered as exhausted when it is slightly positive or at last exactly zero, rather than strictly negative.

Definition at line 399 of file rres.c.

References server_t::c, server_t::deadline, server_t::rres_stat::exec_time, server_t::id, in_ready_queue(), kal_time_add(), KAL_TIME_FMT, KAL_TIME_FMT_ARG, kal_time_le(), kal_time_sub(), KAL_TIME_US, kal_timer_set(), last_update_time, qos_chk_do, qos_log_debug, server_t::reactive, ready_queue_remove(), RRES_PARANOID, sched_time, server_t::stat, and update_budgets().

Referenced by rres_schedule().

static void set_enforce_timer ( kal_time_t  delta  )  [static]

Forward the enforce timer (for budget exhaustion) for the specified time, or, if it is not pending, set it to now plus the specified time.

Note:
The last_update_time assignment is only needed when passing from a null exec to a non-null exec.

Definition at line 164 of file rres.c.

References kal_time_add(), KAL_TIME_FMT, KAL_TIME_FMT_ARG, kal_timer_set(), last_update_time, qos_log_debug, and sched_time.

Referenced by rres_schedule().

void stop_pending_timers ( server_t srv,
int  pending_unexpected 
)

Stop pending timers relative to reactivation from recharging state.

Parameters:
pending_unexpected If set, we check if the recharge timer is (unexpectedly) pending and, in such a case, a critical message and a dump of the server are generated.
Todo:
(high) check that is called when needed

Definition at line 101 of file rres.c.

References server_t::id, kal_timer_del(), kal_timer_pending(), qos_log_crit, server_t::reactive, and rres_dump.

Referenced by _rres_cleanup_server(), rres_deactivate_nosched(), and rres_schedule().

void stop_task_safe ( server_t srv,
kal_task_t task 
)

Avoids stopping a task twice, as well as stopping a non-ready task.

If server is soft, then schedule all tasks with Linux.

Todo:
With soft servers, tasks should be pushed to a priority below the normal Linux prio. Also, check issues related to pushing tasks always in the same position into the Linux normal priority queues.

Definition at line 531 of file rres.c.

References server_t::flags, task_list::is_stopped, qos_chk_do, QOS_F_SOFT, qos_log_debug, rres_find_task_list(), RRES_PARANOID, rres_task_sched_default, stop_task(), and task_ready().

Referenced by rres_attach_task_nosched(), rres_on_task_unblock(), and rres_stop().

static void tasklist_cleanup ( struct task_list tl  )  [inline, static]

Unlink a task list entry from the referenced task and server.

Definition at line 219 of file rres.c.

References task_list::is_stopped, kal_task_unlink_data(), task_list::node, qos_chk, and task_list::task.

Referenced by rres_del().

static void tasklist_init ( struct task_list task_l,
server_t srv,
kal_task_t task 
) [inline, static]

Initialize an already allocated task list entry so to link it to a task and server.

Definition at line 207 of file rres.c.

References server_t::blocked_tasks, task_list::is_stopped, kal_task_link_data(), task_list::node, server_t::ready_tasks, task_list::srv, task_list::task, and task_ready().

Referenced by rres_add().

static void update_budgets ( kal_time_t  consumed_time  )  [static]

Variable Documentation

pointer to the default server

Definition at line 39 of file rres.c.

timer for enforcement of maximum budget

Definition at line 35 of file rres.c.

server_t* exec = NULL

current executing server

Definition at line 32 of file rres.c.

next tentative server ID

Definition at line 33 of file rres.c.

Referenced by new_server_id(), and qres_gw_ks().

Generated on Mon Aug 2 22:39:17 2010 for qosres by  doxygen 1.6.3