Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 807 → Rev 808

/shark/trunk/include/kernel/model.h
21,11 → 21,11
 
/**
------------
CVS : $Id: model.h,v 1.13 2004-09-01 08:48:20 trimarchi Exp $
CVS : $Id: model.h,v 1.14 2004-09-03 13:26:05 trimarchi Exp $
 
File: $File$
Revision: $Revision: 1.13 $
Last update: $Date: 2004-09-01 08:48:20 $
Revision: $Revision: 1.14 $
Last update: $Date: 2004-09-03 13:26:05 $
------------
 
This file contains the definitions of the task and resource models.
788,14 → 788,10
PISTAR_mutexattr_t: Priority Inheritance Mutex Attribute for server
----------------------------------------------------------------------- */
 
typedef struct {
mutexattr_t a;
TIME wcet;
} PISTAR_mutexattr_t;
typedef mutexattr_t PISTAR_mutexattr_t;
 
#define PISTAR_MUTEXATTR_INITIALIZER {PISTAR_MCLASS}
#define PISTAR_mutexattr_default(at, w) mutexattr_default((at.a), PISTAR_MCLASS); \
(at).wcet = (w)
#define PISTAR_mutexattr_default(a) mutexattr_default(a, PISTAR_MCLASS);
 
/* -----------------------------------------------------------------------
NPP_mutexattr_t: Non Preemptive Protocol Mutex Attribute
/shark/trunk/ports/first/first-contract.c
12,7 → 12,30
//=====================================================================
 
#include "fsf_contract.h"
#include "fsf_server.h"
#include <kernel/descr.h>
#include <kernel/func.h>
#include <pistar.h>
 
struct hash_entry {
mutex_t mx;
fsf_shared_obj_id_t id;
};
 
 
#define MAX_HASH_ENTRY FSF_MAX_SHARED_OPERATION
struct hash_entry htable[MAX_HASH_ENTRY];
 
 
/*----------------------------------------------------------------------*/
/* hash_fun() : address hash table */
/*----------------------------------------------------------------------*/
static int hash_fun(fsf_shared_obj_id_t *id)
{
return (*id % MAX_HASH_ENTRY);
}
 
 
int fsf_initialize_contract
(fsf_contract_parameters_t *contract)
{
189,6 → 212,7
 
}
 
/* OLD VERSION
int fsf_set_contract_synchronization_parameters
(fsf_contract_parameters_t *contract,
fsf_preemption_level_t preemption_level,
204,6 → 228,7
return 0;
 
}
*/
int
fsf_get_contract_synchronization_parameters
250,5 → 275,113
 
}
 
// mutex lock function
 
int fsf_lock_object(fsf_shared_operation_t *op) {
int index, oldindex;
 
index=hash_fun(&op->obj_id);
 
if (htable[index].id!=op->obj_id) {
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// find
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % MAX_HASH_ENTRY);
if (index==oldindex) return -1;
}
 
// we need a special implementation for mutex_lock ... additional parameter
 
return PISTAR_lock(FSF_get_shared_object_level(), &htable[index].mx,TIMESPEC2USEC(&op->wcet) );
 
}
 
int fsf_unlock_object(fsf_shared_operation_t *op) {
 
int index, oldindex;
 
index=hash_fun(&op->obj_id);
 
if (htable[index].id!=op->obj_id) {
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// find
for (;htable[index].id != op->obj_id, index!=oldindex; (index++) % MAX_HASH_ENTRY);
if (index==oldindex) return -1;
}
return mutex_unlock(&htable[index].mx);
 
 
}
 
void fsf_init_shared_object(fsf_shared_object_t *obj,
fsf_shared_obj_id_t id) {
int index;
int oldindex;
PISTAR_mutexattr_t a;
 
PISTAR_mutexattr_default(a);
 
obj->size=0;
index=hash_fun(&id);
if (htable[index].id>=0) {
oldindex=index;
index = (index + 1) % MAX_HASH_ENTRY;
// collision detection
for (;htable[index].id >=0, index!=oldindex; (index++) % MAX_HASH_ENTRY);
// table is full
if (index==oldindex) return;
}
mutex_init(&(htable[index]).mx, &a);
obj->obj_id=id;
 
}
 
 
// Declare an operation
// This function is used to declare that a shared object has
// a synchronized operation on it.
// It checks if another operation with the same id has already been
// declared; if so, return false (-1).
// The obj_id field of the operation is set equal to the shared object id.
// the structure op is copied in the first free element in the array
// shared_op pof the structure obj. If there are no more free element,
// returns -1.
// Returns 0 if the operation has been completed, -1 otherwise.
 
int fsf_declare_shared_object_operation(fsf_shared_object_t *obj,
fsf_shared_operation_t *op) {
int i;
for (i=0; i<obj->size; i++) {
// fail if the operation already declared
if (op->op_id==obj->shared_op[i].op_id)
return -1;
}
// fail if the object is full
if (obj->size>(FSF_MAX_SHARED_OPERATION-1))
return -1;
 
obj->size++;
obj->shared_op[i].op_id=op->op_id;
obj->shared_op[i].wcet=op->wcet;
obj->shared_op[i].obj_id=obj->obj_id;
op->obj_id=obj->obj_id;
return 0;
 
 
}
 
int fsf_set_contract_synchronization_parameters(
fsf_contract_parameters_t *contract,
const fsf_shared_operation_t *shared_ops,
size_t op_num)
{
if (shared_ops && op_num < FSF_MAX_SHARED_OPERATION)
memcpy(&contract->shared_operations,shared_ops,op_num);
else return -1;
return 0;
}
/shark/trunk/ports/first/include/grubstar.h
98,5 → 98,7
 
bandwidth_t GRUBSTAR_return_bandwidth(LEVEL l);
 
void GRUBSTAR_disable_server(LEVEL l, int budget);
 
#endif
 
/shark/trunk/ports/first/include/fsf_contract.h
56,11 → 56,52
fsf_preemption_level_t plevel; // Preemption_Level, range 1..2**32-1
} fsf_critical_section_data_t;
 
 
// Definition of basic types
 
typedef unsigned int fsf_shared_op_id_t;
typedef unsigned int fsf_shared_obj_id_t;
 
// Operations
// The first field contains the id of the related object
// the second field contains an identifier of the operation
// this identifier is unique for the object but needs not to be unique
// for the system. In other words, there can be two operations with the
// same identifier belonging to different shared objects: they are
// effectively two distinct operations; two different operations on the
// same object must have different identifiers
 
typedef struct {
fsf_shared_obj_id_t obj_id; // Object identification
fsf_shared_op_id_t op_id; // Operation Identification
struct timespec wcet; // Execution time
} fsf_shared_operation_t;
 
// Shared object
// the first field is the number of distinct operations on the
// shared object. It is initialized to 0.
// the second field is the id of the object, must be unique in the system.
// the third field is a list of shared operations.
 
 
 
 
typedef struct {
int size; // = 0
fsf_critical_section_data_t section[FSF_MAX_N_CRITICAL_SECTIONS];
} fsf_critical_sections_t;
 
typedef struct {
int size; // = 0
fsf_shared_obj_id_t obj_id; // object id
fsf_shared_operation_t shared_op[FSF_MAX_SHARED_OPERATION];
} fsf_shared_object_t;
 
typedef struct {
int size; // =0
fsf_shared_operation_t operation[FSF_MAX_SHARED_OPERATION];
} fsf_shared_operations_t;
 
typedef int fsf_scheduler_id_t;
 
#define FSF_SCHEDULER_POSIX 0
132,6 → 173,7
// preemption_level => 0; (range 1..2**32-1)
// critical_sections; => size = 0
 
int
fsf_set_contract_basic_parameters
(fsf_contract_parameters_t *contract,
218,6 → 260,8
//Only the utilization_values of the utilization_set that are in use, are
//copied (according to its size field).
 
 
/* OLD VERSION
int
fsf_set_contract_synchronization_parameters
(fsf_contract_parameters_t *contract,
228,6 → 272,8
//object by setting its preemption level and critical sections to the
//specified input parameters.
 
*/
 
int
fsf_get_contract_synchronization_parameters
(const fsf_contract_parameters_t *contract,
523,4 → 569,50
//on-line admission test enabled, or false otherwise.
 
 
// Mutex function
 
// Initialization
// here we initialize the second and third field of the structure
void fsf_init_shared_op(fsf_shared_operation_t *op,
fsf_shared_op_id_t op_id,
struct timespec wcet);
 
// initialization
// The shared object id is set equal to the second parameter.
void fsf_init_shared_object(fsf_shared_object_t *obj,
fsf_shared_obj_id_t id);
 
// Declare an operation
// This function is used to declare that a shared object has
// a synchronized operation on it.
// It checks if another operation with the same id has already been
// declared; if so, return false (-1).
// The obj_id field of the operation is set equal to the shared object id.
// the structure op is copied in the first free element in the array
// shared_op pof the structure obj. If there are no more free element,
// returns -1.
// Returns 0 if the operation has been completed, -1 otherwise.
 
int fsf_declare_shared_object_operation(fsf_shared_object_t *obj,
fsf_shared_operation_t *op);
 
 
int fsf_lock_object(fsf_shared_operation_t *op);
 
int fsf_unlock_object(fsf_shared_operation_t *op);
 
// set contract parameters
// specify a list of operations for each contract
// the list is specified as a pointer to an array.
// the size of the array is specified as third parameter
// returns 0 if all operations are correctly initialized
// returns -1 otherwise.
 
int fsf_set_contract_synchronization_parameters(
fsf_contract_parameters_t *contract,
const fsf_shared_operation_t *shared_ops,
size_t op_num);
 
 
 
#endif // _FSF_CONTRACT_H_
/shark/trunk/ports/first/include/fsf_opaque_types.h
41,6 → 41,7
\
fsf_preemption_level_t preemption_level; \
fsf_critical_sections_t critical_sections; \
fsf_shared_operations_t shared_operations; \
\
}
 
/shark/trunk/ports/first/include/fsf_server.h
4,7 → 4,12
#define FSF_GRUBSTAR
 
int fsf_get_server_level(void);
int fsf_get_remain_budget(fsf_server_id_t );
int fsf_settask_nopreemptive(fsf_server_id_t *server, pthread_t thread);
int fsf_settask_preemptive(fsf_server_id_t *server, pthread_t thread);
int FSF_get_shared_object_level(void);
 
 
#ifdef FSF_CBSSTAR
 
#include "cbsstar.h"
17,7 → 22,7
#define SERVER_get_local_scheduler_level_from_pid CBSSTAR_get_local_scheduler_level_from_pid
#define SERVER_getbudgetinfo CBSSTAR_getbudgetinfo
#define SERVER_get_last_reclaiming CBSSTAR_get_last_reclaiming
 
#define SERVER_disable_server CBSSTAR_disable_server
#endif
 
#ifdef FSF_GRUBSTAR
34,6 → 39,7
#define SERVER_get_last_reclaiming GRUBSTAR_get_last_reclaiming
#define SERVER_get_remain_capacity GRUBSTAR_get_remain_capacity
#define SERVER_return_bandwidth GRUBSTAR_return_bandwidth
#define SERVER_disable_server GRUBSTAR_disable_server
#endif
 
#endif
/shark/trunk/ports/first/include/fsf_configuration_parameters.h
44,4 → 44,7
 
#define FSF_MAX_N_BIND_THREAD 1
 
// Define Max Shared Operation for object
#define FSF_MAX_SHARED_OPERATION 20
 
#endif
/shark/trunk/ports/first/modules/mpegstar.c
43,6 → 43,7
#include <kernel/var.h>
#include <kernel/func.h>
#include "mpegstar.h"
#include "fsf_contract.h"
#include "fsf_server.h"
 
//#define MPEGSTAR_DEBUG
/shark/trunk/ports/first/modules/rmstar.c
51,6 → 51,7
/* #include "iqueue.h" Now iqueues are the only queue type into the kernel */
 
/* for BUDGET_TASK_MODEL */
#include "fsf_contract.h"
#include "fsf_server.h"
 
/*
/shark/trunk/ports/first/modules/grubstar.c
813,3 → 813,13
 
}
 
void GRUBSTAR_disable_server(LEVEL l, int budget)
{
GRUBSTAR_level_des *lev = (GRUBSTAR_level_des *)(level_table[l]);
 
/* Force the server in the NOACTIVE state */
lev->b[lev->tb[exec_shadow]].flags=GRUBSTAR_NOACTIVE;
 
}
 
 
/shark/trunk/ports/first/modules/posixstar.c
43,6 → 43,7
#include <kernel/var.h>
#include <kernel/func.h>
#include "posixstar.h"
#include "fsf_contract.h"
#include "fsf_server.h"
 
//#define POSIXSTAR_DEBUG
/shark/trunk/ports/first/first-server.c
24,6 → 24,7
 
#include <pthread.h>
#include <stdlib.h>
#include "pistar.h"
 
 
//#define FSF_DEBUG
33,10 → 34,17
bandwidth_t fsf_max_bw = 0;
int fsf_server_level;
int shared_object_level;
 
PID server_task;
 
PORT channel[2];
 
int FSF_register_shared_object_module(void) {
return PISTAR_register_module();
}
 
 
int FSF_register_module(int server_level, bandwidth_t max_bw)
{
printk("FSF Module\n");
43,6 → 51,7
current_server=0;
fsf_server_level = server_level;
fsf_max_bw = max_bw;
// shared_object_level = FSF_register_shared_object_module();
return 0;
 
357,7 → 366,7
}
 
int fsf_get_server
int fsf_settask_nopreemptive
(fsf_server_id_t *server,
pthread_t thread)
{
367,6 → 376,64
scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread);
 
switch (scheduler_id) {
case FSF_SCHEDULER_POSIX:
 
break;
case FSF_SCHEDULER_EDF:
EDFSTAR_set_nopreemtive_current(local_scheduler_level);
return 1;
break;
case FSF_SCHEDULER_RM:
break;
case FSF_SCHEDULER_MPEG:
break;
default:
return -1;
}
return -1;
}
 
 
int fsf_settask_preemptive
(fsf_server_id_t *server,
pthread_t thread)
{
int local_scheduler_level, scheduler_id;
 
local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread);
scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread);
 
switch (scheduler_id) {
case FSF_SCHEDULER_POSIX:
 
break;
case FSF_SCHEDULER_EDF:
EDFSTAR_unset_nopreemtive_current(local_scheduler_level);
return 1;
break;
case FSF_SCHEDULER_RM:
break;
case FSF_SCHEDULER_MPEG:
break;
default:
return -1;
}
 
return -1;
 
}
 
 
int fsf_get_server
(fsf_server_id_t *server,
pthread_t thread)
{
int local_scheduler_level, scheduler_id;
 
local_scheduler_level = SERVER_get_local_scheduler_level_from_pid(fsf_server_level,thread);
scheduler_id = SERVER_get_local_scheduler_id_from_pid(fsf_server_level, thread);
switch (scheduler_id) {
case FSF_SCHEDULER_POSIX:
return POSIXSTAR_getbudget(local_scheduler_level,thread);
case FSF_SCHEDULER_EDF:
587,3 → 654,10
}
 
}
 
 
int fsf_get_remain_budget(fsf_server_id_t server) {
 
return SERVER_get_remain_capacity(fsf_server_level, server);
 
}
/shark/trunk/ports/first/makefile
13,7 → 13,7
FIRST = first-contract.o first-server.o first-sync.o server-task.o \
./modules/grubstar.o ./modules/posixstar.o \
./modules/edfstar.o ./modules/cbsstar.o ./modules/rmstar.o \
./modules/mpegstar.o
./modules/mpegstar.o ./modules/pistar.o
 
OBJS = $(FIRST)