Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Commit

Permalink
Aggiunta documentazione mancante #2 e raffinamenti;
Browse files Browse the repository at this point in the history
System call 5 e 6 ora ritornano errore per semaforo NULL #19 ;
Rimossa scheduler_Get()  per information hiding su implementazione #12 ;
Separata inizializzazione nuovi campi pcb per separare compiti di phase 1 ;
  • Loading branch information
jjak0b committed May 23, 2020
1 parent e9414be commit 2e8681e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 97 deletions.
45 changes: 37 additions & 8 deletions include/handler/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include <system/system.h>

#define SYSNO2INDEX( n )( (n)-1 )

/* Macro per utilizzo specpassup */
/* colonna matrice specpassup nel pcb */
#define SYS_SPECPASSUP_AREA_OLD 0
#define SYS_SPECPASSUP_AREA_NEW 1
/* riga matrice specpassup nel pcb */
#define SYS_SPECPASSUP_TYPE_SYSBK 0
#define SYS_SPECPASSUP_TYPE_TLB 1
#define SYS_SPECPASSUP_TYPE_PGMTRAP 2
Expand Down Expand Up @@ -52,15 +53,32 @@ int Sys2_CreateProcess( state_t *child_state, int child_priority, pcb_t **child_
/**
* @brief Implementazione della syscall TERMINATE_PROCESS.
* Termina il processo corrente e tutta la sua progenie.
* Infine, richiama lo scheduler.
* @param pid
* @return int
*/
int Sys3_TerminateProcess( pcb_t *pid );

void Sys4_Verhogen( int* semaddr );
/**
* @brief Incrementa il valore del semaforo, se il suo valore diventa <= 0, allora il primo processo in coda
* associato al semaforo specificato è risvegliato; cioè aggiunto alla ready queue
*
* @param semaddr
* @return int
* * 0 se l'operazione è stata effettuata correttamente
* * -1 altrimenti ( semaddr == NULL )
*/
int Sys4_Verhogen( int* semaddr );

void Sys5_Passeren( int* semaddr );
/**
* @brief Decrementa il valore del semaforo, se diventa < 0, allora il processo corrente viene sospeso;
* cioè rimosso dalla ready queue dello scheduler e posto in attesa sulla coda del semaforo specificato
* @param semkey
* @param p
* @return int
* * 0 se è l'operazione è avvenuta correttamente ( quindi anche se è stato sospeso )
* * -1 se p == NULL ( oppure se non è stato possibile allocare un semd per il processo specificato, ma non si può mai verificare perchè i semd sono quanti i pcb, ma la si annota per future revisioni )
*/
int Sys5_Passeren( int* semaddr );

/**
* @brief Invia il comando fornito al (sub)device fornito dai parametri
Expand All @@ -72,12 +90,23 @@ void Sys5_Passeren( int* semaddr );
* @param devreg
* @param subdevice
* @return int
* 0 se l'operazione è avvenuta correttamente ed il processo è in attesa della risposta del device
* != 0 se non è stato possibile sospendere il processo, e quindi non è stato inviato il comando
* * 0 se l'operazione è avvenuta correttamente ed il processo è in attesa della risposta del device
* * -1 se non è stato possibile mettere il processo in attesa, e quindi non è stato inviato il comando
*/
int Sys6_DoIO( word command, word *devreg, int subdevice );

int Sys7_SpecPassup( state_t* currState, int type, state_t *old_area, state_t *new_area );
/**
* @brief registra gli indirizzi delle rispettive new e old area dei gestori di livello superiore del tipo specificato sul processo corrente
*
* @PostCondition se è già stato definito in precedenza un gestore dello stesso tipo, termina il processo corrente e tutta la sua progenie
* @param type tipo dell gestore ( SYS_SPECPASSUP_TYPE_SYSBK 0; SYS_SPECPASSUP_TYPE_TLB 1; SYS_SPECPASSUP_TYPE_PGMTRAP 2 )
* @param old_area area in cui verrà memorizzato lo stato del processo quando causerà l'eccezione
* @param new_area area che verrà caricata sul processore al verificarsi dell'eccezione del tipo fornito
* @return int
* * 0 se l'operazione è avvenuta correttamente
* * -1 altrimenti
*/
int Sys7_SpecPassup( int type, state_t *old_area, state_t *new_area );

/**
* @brief assegna pid il puntatore al processo corrente, a ppid il puntatore al processo genitore
Expand Down
2 changes: 0 additions & 2 deletions include/pcb/pcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ void insertChild(pcb_t *prnt, pcb_t *p);
pcb_t *removeChild(pcb_t *p);
pcb_t *outChild(pcb_t *p);

/* Inizializza un singolo pcb con valori NULL/0 e liste vuote */
void pcb_init( pcb_t *p );
#endif
12 changes: 12 additions & 0 deletions include/pcb/utils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifndef PCB_UTILS_H
#define PCB_UTILS_H
#include <pcb/pcb.h>

/**
Expand All @@ -7,3 +9,13 @@
* @param new_parent il nuovo genitore dei figli
*/
void pcb_SetChildrenParent( pcb_t* old_parent, pcb_t* new_parent );

/**
* @brief Inizializza un singolo pcb con valori NULL/0 e liste vuote
* @param p
* @param b_shouldInitState se FALSE si limiterà alla inizializzazione dei campi, eccetto lo state_t,
* altrimenti inizializzerà anche i campi dello state_t in base all'architettura
*/
void pcb_init( pcb_t *p, int b_shouldInitState );

#endif
2 changes: 0 additions & 2 deletions include/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ int scheduler_StateToTerminate( pcb_t* pid, int b_flag_terminate_progeny );
*/
pcb_t *scheduler_GetRunningProcess();

scheduler_t *scheduler_Get();

/**
* @brief Inserisce un descrittore di processo nella ready queue
* @PreCondition Da utilizzare solo se p non è presente nella ready queue
Expand Down
39 changes: 24 additions & 15 deletions src/handler/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <scheduler/scheduler.h>
#include <asl/asl.h>
#include <pcb/pcb.h>
#include <pcb/utils.h>
#include <system/shared/device/device.h>
#include <utilities/semaphore.h>
#include <shared/device/terminal.h>
Expand All @@ -43,18 +44,20 @@ word Syscaller( state_t *state, word sysNo, word param1, word param2, word param
*returnValue = (int) Sys3_TerminateProcess( (pcb_t*) param1 );
break;
case VERHOGEN:
Sys4_Verhogen( (int*)param1 );
b_hasReturnValue = TRUE;
*returnValue = (int) Sys4_Verhogen( (int*)param1 );
break;
case PASSEREN:
Sys5_Passeren( (int*)param1 );
b_hasReturnValue = TRUE;
*returnValue = (int) Sys5_Passeren( (int*)param1 );
break;
case WAITIO:
b_hasReturnValue = TRUE;
*returnValue = (int) Sys6_DoIO( param1, (word*)param2, (int)param3 );
break;
case SPECPASSUP:
b_hasReturnValue = TRUE;
*returnValue = (int) Sys7_SpecPassup( state, (int)param1, (state_t*)param2, (state_t*)param3 );
*returnValue = (int) Sys7_SpecPassup( (int)param1, (state_t*)param2, (state_t*)param3 );
break;
case GETPID:
Sys8_GetPID( (pcb_t**)param1, (pcb_t**)param2 );
Expand Down Expand Up @@ -94,6 +97,7 @@ int Sys2_CreateProcess( state_t *child_state, int child_priority, pcb_t **child_
if ( child_state != NULL ) {
pcb_t *child = allocPcb(); /* il puntatore sarà nullo in caso non vi siano PCB disponibili */
if ( child != NULL ) {
pcb_init( child, FALSE );
moveState( child_state, &child->p_s );
child->priority = child_priority;
child->original_priority = child_priority;
Expand All @@ -113,19 +117,25 @@ int Sys3_TerminateProcess( pcb_t *pid ) {
return ( b_error ? -1 : 0 );
}

void Sys4_Verhogen( int* semaddr ) {
semaphore_V( semaddr );
/* dovremmo ripristinare la priorità ? */
int Sys4_Verhogen( int* semaddr ) {
int status = -1;
if( semaddr != NULL ){
semaphore_V( semaddr );
status = 0;
}
return status;
}

void Sys5_Passeren( int* semaddr ) {
int Sys5_Passeren( int* semaddr ) {
pcb_t *pid = scheduler_GetRunningProcess();
int status = semaphore_P( semaddr, pid );
// nel caso ritornasse 1 non può accadere perchè ad ogni processo può essere nella ASL al massimo 1 volta
// infatti se non fosse disponibile un semd, non esisterebbe neanche questo processo
if( status == 1 ) {
scheduler_StateToTerminate( pid, FALSE );
int status = -1;
if( semaddr != NULL ){
status = semaphore_P( semaddr, pid );
}
// il caso semaphore_P ritorni 1 non può accadere perchè ad ogni processo può essere nella ASL al massimo 1 volta
// infatti se non fosse disponibile un semd, non esisterebbe neanche questo processo

return (status ? -1 : 0 );
}

int Sys6_DoIO( word command, word *devregAddr, int subdevice ) {
Expand All @@ -151,10 +161,10 @@ int Sys6_DoIO( word command, word *devregAddr, int subdevice ) {
devreg->dtp.command = command;
}
}
return b_error;
return ( b_error ? -1 : 0 );
}

int Sys7_SpecPassup( state_t* currState, int type, state_t *old_area, state_t *new_area ) {
int Sys7_SpecPassup( int type, state_t *old_area, state_t *new_area ) {
pcb_t* p = scheduler_GetRunningProcess();
if( p != NULL && (0 <= type && type < 3) ) {
if( p->specPassup[ type ][ SYS_SPECPASSUP_AREA_NEW ] == NULL ) {
Expand All @@ -170,7 +180,6 @@ int Sys7_SpecPassup( state_t* currState, int type, state_t *old_area, state_t *n
}

void Sys8_GetPID( pcb_t **pid, pcb_t **ppid ) {
/* la procedura ritorna errore in caso di puntatori non validi */
pcb_t *p = scheduler_GetRunningProcess();
if ( pid != NULL )
*pid = p;
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <system/shared/device/device.h>

int main(){
//---------------------Inizialializzazione del sistema
//---------------------Inizializzazione del sistema
initAreas();
initPcbs();
initASL();
Expand Down
67 changes: 3 additions & 64 deletions src/pcb/pcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Stefano De Santis, Cristiano Guidotti, Iacopo Porcedda, Jacopo Rimediotti
*/

#include <pcb.h>

#include <pcb/pcb.h>
#include <pcb/utils.h>
#include <types_bikaya.h>
#include <const.h>

Expand Down Expand Up @@ -101,71 +101,10 @@ void insertProcQ(struct list_head *head, pcb_t *p){
*/
pcb_t *allocPcb(void){
pcb_t *new = removeProcQ(pcbFree_h);
pcb_init( new );
pcb_init( new, TRUE );
return new;
}

/*
inizializza
tutti i campi (NULL/0)
e le liste come liste vuote
*/
void pcb_init( pcb_t *new ){
if(new != NULL){
//inizializzazione pcb
INIT_LIST_HEAD(&(new->p_child));
INIT_LIST_HEAD(&(new->p_sib));
INIT_LIST_HEAD(&(new->p_next));
new->p_parent = NULL;
new->p_semkey = NULL;
new->priority = 0;
new->original_priority = 0;
new->first_activation_tod = 0;
new->chrono_start_tod = 0;
new->kernel_timelapse = 0;
new->user_timelapse = 0;
int i, j;
for( i = 0; i < 3; i++ )
for( j = 0; j < 2; j++ )
new->specPassup[ i ][ j ] = NULL;
#ifdef TARGET_UMPS
new->p_s.entry_hi = 0;
new->p_s.cause = 0;
new->p_s.status = 0;
new->p_s.pc_epc = 0;
new->p_s.hi = 0;
new->p_s.lo = 0;
for( i = 0; i < STATE_GPR_LEN; i++ ){
new->p_s.gpr[ i ] = 0;
}
#endif
#ifdef TARGET_UARM
new->p_s.a1 = 0;
new->p_s.a2 = 0;
new->p_s.a3 = 0;
new->p_s.a4 = 0;
new->p_s.v1 = 0;
new->p_s.v2 = 0;
new->p_s.v3 = 0;
new->p_s.v4 = 0;
new->p_s.v5 = 0;
new->p_s.v6 = 0;
new->p_s.sl = 0;
new->p_s.fp = 0;
new->p_s.ip = 0;
new->p_s.sp = 0;
new->p_s.lr = 0;
new->p_s.pc = 0;
new->p_s.cpsr = 0;
new->p_s.CP15_Control = 0;
new->p_s.CP15_EntryHi = 0;
new->p_s.CP15_Cause = 0;
new->p_s.TOD_Hi = 0;
new->p_s.TOD_Low = 0;
#endif
}
}

/* PCB QUEUE HANDLING */

/*
Expand Down
59 changes: 59 additions & 0 deletions src/pcb/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,62 @@ void pcb_SetChildrenParent( pcb_t* old_parent, pcb_t* new_parent ) {
}
}
}

void pcb_init( pcb_t *new, int b_shouldInitState ){
if(new != NULL) {
//inizializzazione pcb
INIT_LIST_HEAD(&(new->p_child));
INIT_LIST_HEAD(&(new->p_sib));
INIT_LIST_HEAD(&(new->p_next));
new->p_parent = NULL;
new->p_semkey = NULL;
new->priority = 0;
new->original_priority = 0;
new->first_activation_tod = 0;
new->chrono_start_tod = 0;
new->kernel_timelapse = 0;
new->user_timelapse = 0;
int i, j;
for( i = 0; i < 3; i++ )
for( j = 0; j < 2; j++ )
new->specPassup[ i ][ j ] = NULL;

if( !b_shouldInitState ) return;

#ifdef TARGET_UMPS
new->p_s.entry_hi = 0;
new->p_s.cause = 0;
new->p_s.status = 0;
new->p_s.pc_epc = 0;
new->p_s.hi = 0;
new->p_s.lo = 0;
for( i = 0; i < STATE_GPR_LEN; i++ ){
new->p_s.gpr[ i ] = 0;
}
#endif
#ifdef TARGET_UARM
new->p_s.a1 = 0;
new->p_s.a2 = 0;
new->p_s.a3 = 0;
new->p_s.a4 = 0;
new->p_s.v1 = 0;
new->p_s.v2 = 0;
new->p_s.v3 = 0;
new->p_s.v4 = 0;
new->p_s.v5 = 0;
new->p_s.v6 = 0;
new->p_s.sl = 0;
new->p_s.fp = 0;
new->p_s.ip = 0;
new->p_s.sp = 0;
new->p_s.lr = 0;
new->p_s.pc = 0;
new->p_s.cpsr = 0;
new->p_s.CP15_Control = 0;
new->p_s.CP15_EntryHi = 0;
new->p_s.CP15_Cause = 0;
new->p_s.TOD_Hi = 0;
new->p_s.TOD_Low = 0;
#endif
}
}
6 changes: 1 addition & 5 deletions src/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void scheduler_init() {

scheduler_struct.b_has_idle = FALSE;
pcb_t *idlePcb = &scheduler_struct.idlePcb;
pcb_init( idlePcb );
pcb_init( idlePcb, TRUE );
idlePcb->original_priority = DEFAULT_PRIORITY;
idlePcb->priority = idlePcb->original_priority;
SetStatus( &idlePcb->p_s, STATUS_NULL);
Expand Down Expand Up @@ -264,10 +264,6 @@ pcb_t *scheduler_GetRunningProcess() {
return scheduler->running_p;
}

scheduler_t *scheduler_Get() {
return scheduler;
}

void scheduler_AddProcess( pcb_t *p ) {
insertProcQ( &scheduler->ready_queue, p );
}
Expand Down

0 comments on commit 2e8681e

Please sign in to comment.