Skip to content

Commit

Permalink
feat: add conditional compilation variables for schedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
PatricioIribarneCatella committed Apr 24, 2024
1 parent 1125e1a commit 96c0da9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
11 changes: 11 additions & 0 deletions sched/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions sched/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target> USE_RR=1
```

- **priorities**:

```bash
make <target> USE_PR=1
```

## Pruebas

```bash
Expand Down
23 changes: 18 additions & 5 deletions sched/kern/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 96c0da9

Please sign in to comment.