Skip to content

Commit

Permalink
sched: changed thread time slices
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 7, 2024
1 parent aa9f649 commit f5e408a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/include/kernel/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
#include <kernel/syscalls.h>
#include <kernel/io.h>

// ideal number of context switches per second
// still not sure of how to decide on this value so it'll probably change
#define SCHED_SWITCH_RATE 200
#define SCHED_TIME_SLICE 1 // ms

#define MAX_PID 99999

Expand All @@ -26,9 +25,9 @@
#define THREAD_ZOMBIE 3
#define THREAD_SLEEP 4

#define PRIORITY_HIGH 0
#define PRIORITY_NORMAL 1
#define PRIORITY_LOW 2
#define PRIORITY_LOW 1
#define PRIORITY_NORMAL 2
#define PRIORITY_HIGH 3

typedef struct Thread {
int status, cpu, priority;
Expand Down
11 changes: 2 additions & 9 deletions src/sched/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,8 @@ int threadUseContext(pid_t tid) {
*/

uint64_t schedTimeslice(Thread *t, int p) {
/* todo: actually interpret the priority value */
uint64_t schedTime = PLATFORM_TIMER_FREQUENCY / SCHED_SWITCH_RATE;

int cpus = platformCountCPU();
uint64_t time = schedTime / threads;
if(time < 6) time = 6; // minimum threshold
time *= cpus;
if(time < 12) time = 12;

if(!p) p = PRIORITY_NORMAL;
uint64_t time = p * SCHED_TIME_SLICE;
t->priority = p;
return time;
}
Expand Down

0 comments on commit f5e408a

Please sign in to comment.