Finish scheduler implementation

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2021-10-24 18:30:09 -03:00
parent f5eda8639a
commit a2b410fca3
11 changed files with 137 additions and 89 deletions

View File

@ -11,38 +11,38 @@ static int currentY = 0;
int limitX[2] = {0, 80};
int limitY[2] = {0, 25};
char windowVideo = 1;
void changeWindow() {
windowVideo = 1 - windowVideo;
moveToWindowVideo(windowVideo);
}
void moveToWindowVideo(char window) {
if (window == -1) {
windowVideo = -1;
limitX[0] = 0;
limitX[1] = 80;
limitY[0] = 0;
limitY[1] = 25;
}
if (window == 1) {
windowVideo = 1;
limitX[0] = 40;
limitX[1] = 80;
limitY[0] = 0;
limitY[1] = 25;
}
if (window == 0) {
windowVideo = 0;
limitX[0] = 0;
limitX[1] = 40;
limitY[0] = 0;
limitY[1] = 25;
}
currentX = limitX[0];
currentY = limitY[0];
}
// char windowVideo = 1;
//
// void changeWindow() {
// windowVideo = 1 - windowVideo;
// moveToWindowVideo(windowVideo);
// }
//
// void moveToWindowVideo(char window) {
// if (window == -1) {
// windowVideo = -1;
// limitX[0] = 0;
// limitX[1] = 80;
// limitY[0] = 0;
// limitY[1] = 25;
// }
// if (window == 1) {
// windowVideo = 1;
// limitX[0] = 40;
// limitX[1] = 80;
// limitY[0] = 0;
// limitY[1] = 25;
// }
// if (window == 0) {
// windowVideo = 0;
// limitX[0] = 0;
// limitX[1] = 40;
// limitY[0] = 0;
// limitY[1] = 25;
// }
// currentX = limitX[0];
// currentY = limitY[0];
// }
void increment() {
currentX++;

View File

@ -11,7 +11,7 @@
void forceTimer();
void haltcpu();
#define STACK_SIZE 1024
#define STACK_SIZE 1024 * 512
#define MAX_PRIORITY 40 // Maximum number for a priority
#define MIN_PRIORITY 0 // Minimum number for a priority (yet maximum level of priority) // me gusta
#define DEF_PRIORITY 0

View File

@ -84,12 +84,12 @@ static void startOver() {
clear();
// cleanProcesses();
moveToWindowVideo(1);
// moveToWindowVideo(1);
//((fn)sampleCodeAddress)();
}
static void genericException(char * string, int len) {
moveToWindowVideo(-1);
// moveToWindowVideo(-1);
clear();
printStringLen(15, string, len);
printRegs();

View File

@ -178,6 +178,7 @@ int main() {
// ((EntryPoint)sampleCodeModuleAddress)();
char * argv[] = {"SampleCode"};
enqueueProcess(sampleCodeModuleAddress, 1, 1, argv);
clear();
// haltcpu();
_sti();
// forceTimer();

View File

@ -22,7 +22,7 @@ typedef unsigned long UBaseType_t;
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 1024 * 1024
#define configTOTAL_HEAP_SIZE 1024 * 1024 * 100
#define configAPPLICATION_ALLOCATED_HEAP 0
#define portBYTE_ALIGNMENT 8
#define portBYTE_ALIGNMENT_MASK ( 0x0007 ) // 8

View File

@ -1,4 +1,6 @@
#include "scheduler.h"
#define INIT_PID 1
void _initialize_stack_frame(void *, void *, int, char**);
enum states {READY = 0, BLOCKED};
@ -25,33 +27,46 @@ int readyLen = 0;
int blockedLen = 0;
static processCDT * currentProcess = NULL;
int pids = 0;
static int pids = INIT_PID;
static char update = 1;
#include "naiveConsole.h"
#include "time.h"
uint64_t nextProcess() {
update = 1;
if (currentProcess == NULL) {
ncClear();
ncPrint("Una cubana para el socio biza");
ncPrint(firstReady->name);
// ncPrintDec(firstReady->pid);
ncPrintHex(firstReady->rsp);
ncPrintHex(firstReady->rbp);
// ncClear();
// ncPrint("Una cubana para el socio biza");
// ncPrint(firstReady->name);
// // ncPrintDec(firstReady->pid);
// ncPrintHex(firstReady->rsp);
// ncPrintHex(firstReady->rbp);
// wait(4);
if (firstReady == NULL)
unblock(INIT_PID);
currentProcess = firstReady;
return firstReady->rsp;
}
if (currentProcess->executions < MAX_PRIORITY - currentProcess->priority + 1) {
currentProcess->executions++;
ncClear();
ncPrint("Hola");
// ncClear();
// ncPrint("Hola");
// ncPrintDec(firstReady->pid);
// wait(4);
return currentProcess->rsp;
}
ncPrint("Chau");
// ncPrint("Chau");
currentProcess->executions = 0;
currentProcess = currentProcess->next;
if (currentProcess->next != NULL)
currentProcess = currentProcess->next;
else {
// ncPrint("Una venezolana para el socio biza");
// wait(4);
currentProcess = firstReady;
}
return currentProcess->rsp;
}
@ -67,8 +82,12 @@ void initScheduler() {
}
void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[]) {
if (firstReady != NULL && firstReady->pid == INIT_PID)
block(INIT_PID);
processADT process = pvPortMalloc(sizeof(processCDT));
uint64_t * rbp = STACK_SIZE + pvPortMalloc(STACK_SIZE);
uint64_t * auxi = pvPortMalloc(STACK_SIZE);
uint64_t * rbp = STACK_SIZE + auxi;
uint64_t * rsp = rbp - 20; //22
char priority = (foreground == 1) ? DEF_PRIORITY : MAX_PRIORITY/2;
@ -94,41 +113,40 @@ void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *
_initialize_stack_frame(fn, rbp, argc, argv);
if (firstReady == NULL) {
if (firstReady == NULL)
firstReady = process;
lastReady = firstReady;
}
else
else
lastReady->next = process;
lastReady = process;
ncClear();
ncPrint(argv[0]);
// proc->name = argv[0];
ncPrint(process->name);
ncPrintDec(process->pid);
ncPrintHex(process->rsp);
ncPrintHex(process->rbp);
// ncClear();
// ncPrint(argv[0]);
// // proc->name = argv[0];
// ncPrint(process->name);
// ncPrintDec(process->pid);
// ncPrintHex(process->rsp);
// ncPrintHex(process->rbp);
// wait(3);
return;
}
void newProcess(processADT process, char * name, char priority, char foreground, uint64_t rsp, uint64_t rbp) {
char aux[MAX_NAME_SIZE];
int j;
for (j = 0; j < MAX_NAME_SIZE - 1 && name[j] != 0; j++) {
aux[j] = name[j];
}
aux[j] = '\0';
// char aux[MAX_NAME_SIZE];
// int j;
// for (j = 0; j < MAX_NAME_SIZE - 1 && name[j] != 0; j++) {
// aux[j] = name[j];
// }
// aux[j] = '\0';
process->name = aux;
process->pid = pids++;
process->ppid = currentProcess->pid;
process->priority = priority;
process->rsp = rsp;
process->rbp = rbp;
process->executions = 0;
process->foreground = foreground;
process->state = READY;
// process->name = aux;
// process->pid = pids++;
// process->ppid = currentProcess->pid;
// process->priority = priority;
// process->rsp = rsp;
// process->rbp = rbp;
// process->executions = 0;
// process->foreground = foreground;
// process->state = READY;
}
// void loader(int argc, char * argv[], void (*fn) (int, char **)) {
@ -169,11 +187,20 @@ char block(int pid) {
firstReady = del->next;
}
lastBlocked->next = del;
processCDT * next = del->next;
del->next = NULL;
if (lastBlocked != NULL)
lastBlocked->next = del;
else
firstBlocked = del;
lastBlocked = del;
forceTimer();
if (pid == currentProcess->pid) {
update = 0;
currentProcess = next;
forceTimer();
}
return EXIT_SUCCESS;
}
@ -188,10 +215,13 @@ char unblock(int pid) {
prev->next = del->next;
else
firstBlocked = del->next;
del->next = NULL;
if (lastReady != NULL)
lastReady->next = del;
else
firstReady = del;
lastReady = del;
}
if (pid == del->pid)
forceTimer();
return EXIT_SUCCESS;
}
@ -217,12 +247,17 @@ char kill(int pid) {
firstReady = del->next;
}
if (pid == del->pid)
forceTimer();
vPortFree((void *) del->rsp);
processCDT * next = del->next;
vPortFree((void *) del->rbp - STACK_SIZE);
vPortFree((void *) del);
if (pid == currentProcess->pid) {
update = 0;
currentProcess = next;
forceTimer();
}
return EXIT_SUCCESS;
}
@ -239,12 +274,13 @@ char nice(char offset) {
void updateRSP(uint64_t newRsp) {
if (currentProcess == NULL) {
ncClear();
ncPrint("ES NULL");
// ncClear();
// ncPrint("ES NULL");
// wait(4);
return;
}
currentProcess->rsp = newRsp;
if (update)
currentProcess->rsp = newRsp;
}
int getPid() {

View File

@ -31,11 +31,13 @@ int semPost(char semaphore) {}
// o pasando la estructura de sem. esta es la q hace posix
sem_t * semOpen(char * name, unsigned int value) {
enter_region(&semLock);
//
leave_region(&semLock);
}
int semClose(sem_t * semaphore) {
enter_region(&semLock);
//
leave_region(&semLock);
}
@ -60,5 +62,6 @@ int semWait(sem_t * semaphore) {
int semPost(sem_t * semaphore) {
enter_region(&semLock);
//
leave_region(&semLock);
}

View File

@ -6,6 +6,7 @@
void winClear();
void printString(char * string);
void printStringError(char * string);
void printStringLen(char * string, int len);
void new_line();
char getChar();
int abs();

View File

@ -5,6 +5,10 @@ void printString(char * string) {
sys_write(1, string, len);
}
void printStringLen(char * string, int len) {
sys_write(1, string, len);
}
void printStringError(char * string) {
int len = strlen(string);
sys_write(2, string, len);

View File

@ -15,5 +15,5 @@ int main(int argc, char *argv[]) {
// sys_switchContext();
sys_exit();
return 1;
return 1;
}

View File

@ -14,7 +14,7 @@
#define SIZE 100
#define MAX_ARGS 5
#define COLS 40
#define COLS 80
#define ROWS 25
const int len = 8;
@ -42,7 +42,7 @@ void addText(char * buffer, char * window, int * offset) {
}
void printWindow(char * window) {
printString(window);
printStringLen(window, ROWS * COLS);
}
void scanfNoPrint(char * buffer, int maxSize, char * window, int * offset) {
@ -80,6 +80,9 @@ void clearWindow(char * window, int * offset) {
printWindow(window);
}
// static char window[ROWS * COLS + 1] = {[0 ... ROWS * COLS - 1] = ' ', 0};
// static char buffer[SIZE] = {0};
// static char *tokens[SIZE] = {0};
void shell(int argc, char *argv[]) {
char window[ROWS * COLS + 1] = {[0 ... ROWS * COLS - 1] = ' ', 0};
int offset = (ROWS - 1) * COLS;