diff --git a/sched/GNUmakefile b/sched/GNUmakefile index 6a657db..ce491e2 100644 --- a/sched/GNUmakefile +++ b/sched/GNUmakefile @@ -100,6 +100,17 @@ CFLAGS += -fno-tree-ch # Add -fno-stack-protector if the option exists. CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector) +USE_RR = +USE_PR = + +ifeq ($(USE_RR), 1) +CFLAGS += -DSCHED_ROUND_ROBIN +else ifeq ($(USE_PR), 1) +CFLAGS += -DSCHED_PRIORITIES +else +CFLAGS += -DSCHED_ROUND_ROBIN +endif + # Common linker flags LDFLAGS := -m elf_i386 diff --git a/sched/README.md b/sched/README.md index c3e202c..fa67560 100644 --- a/sched/README.md +++ b/sched/README.md @@ -8,10 +8,28 @@ Utilizar el archivo `sched.md` provisto en el repositorio ## Compilar +Por _default_ se compilará el _scheduler_ en versión **round-robin**. + ```bash make ``` +## Compilación condicional de _schedulers_ + +Para compilar y probar el kernel y poder probar ambos planificadores, se puede: + +- **round-robin**: + +```bash +make USE_RR=1 +``` + +- **priorities**: + +```bash +make USE_PR=1 +``` + ## Pruebas ```bash diff --git a/sched/kern/sched.c b/sched/kern/sched.c index a2dfacb..079f6a7 100644 --- a/sched/kern/sched.c +++ b/sched/kern/sched.c @@ -11,13 +11,12 @@ void sched_halt(void); void sched_yield(void) { - struct Env *idle; - +#ifdef SCHED_ROUND_ROBIN // Implement simple round-robin scheduling. // // Search through 'envs' for an ENV_RUNNABLE environment in // circular fashion starting just after the env this CPU was - // last running. Switch to the first such environment found. + // last running. Switch to the first such environment found. // // If no envs are runnable, but the environment previously // running on this CPU is still ENV_RUNNING, it's okay to @@ -28,8 +27,22 @@ sched_yield(void) // no runnable environments, simply drop through to the code // below to halt the cpu. - // Your code here - // Wihtout scheduler, keep runing the last environment while it exists + // Your code here - Round robin +#endif + +#ifdef SCHED_PRIORITIES + // Implement simple priorities scheduling. + // + // Environments now have a "priority" so it must be consider + // when the selection is performed. + // + // Be careful to not fall in "starvation" such that only one + // environment is selected and run every time. + + // Your code here - Priorities +#endif + + // Without scheduler, keep runing the last environment while it exists if (curenv) { env_run(curenv); }