Fixing broken stuff
This commit is contained in:
parent
98c2dd8502
commit
52648a9907
|
@ -13,7 +13,7 @@
|
|||
CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc"
|
||||
CC2NAME=gcc
|
||||
COPTIM=-O2
|
||||
CWARNS=-Wall -Wextra -Wshadow -Wpedantic
|
||||
CWARNS=-Wall -Wextra -Wshadow // -Wpedantic
|
||||
CINCLUDES=-isystem./kaleid/include
|
||||
|
||||
CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
//
|
||||
// Digits table for bases <=36 (unused)
|
||||
//
|
||||
#if 0
|
||||
static const char digits[] =
|
||||
"0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
#endif
|
||||
|
||||
//
|
||||
// Integer to string in any base between 2 and 36 (included)
|
||||
|
@ -21,29 +23,35 @@ static const char digits[] =
|
|||
|
||||
#if defined(_NEED_ITOA)
|
||||
|
||||
char *itoa(int i, char *str, int base)
|
||||
#define _IL_MIN INT_MIN
|
||||
#define _IL_MIN_STRING "-2147483648"
|
||||
char *itoa(int i, char *str, int base)
|
||||
{
|
||||
int rem;
|
||||
|
||||
#elif defined(_NEED_LTOA)
|
||||
|
||||
char *ltoa(long i, char *str, int base)
|
||||
#define _IL_MIN LONG_MIN
|
||||
#define _IL_MIN_STRING "-9223372036854775808"
|
||||
char *ltoa(long i, char *str, int base)
|
||||
{
|
||||
long rem;
|
||||
|
||||
#elif defined(_NEED_UTOA)
|
||||
|
||||
char *utoa(uint i, char *str, int base)
|
||||
{
|
||||
uint rem;
|
||||
|
||||
#elif defined(_NEED_ULTOA)
|
||||
|
||||
char *ultoa(ulong i, char *str, int base)
|
||||
{
|
||||
ulong rem;
|
||||
|
||||
#else
|
||||
#error "What am I supposed to declare?"
|
||||
#endif
|
||||
|
||||
{
|
||||
char *orig = str;
|
||||
|
||||
#if defined(_NEED_ITOA) || defined(_NEED_LTOA)
|
||||
|
@ -72,7 +80,7 @@ char *ultoa(ulong i, char *str, int base)
|
|||
//
|
||||
if (base < 2 || base > 36) {
|
||||
__set_errno(EINVAL);
|
||||
*orig = '\0;
|
||||
*orig = '\0';
|
||||
goto leave;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ static ulong next = 7756;
|
|||
//
|
||||
int rand(void)
|
||||
{
|
||||
next = next * 1103515245 + 12345;
|
||||
return (uint)(next / 65536) % INT_MAX;
|
||||
next = next * 1103515245 + 12347;
|
||||
return (uint)(next / 65536);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
//
|
||||
// Format str according to fmt using ellipsed arguments
|
||||
//
|
||||
// BE CAREFUL when using this
|
||||
// you need to know for sure an overflow won't happen
|
||||
//
|
||||
int sprintf(char *str, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
|
@ -31,6 +34,7 @@ int vsprintf(char *str, const char *fmt, va_list ap)
|
|||
|
||||
//
|
||||
// (v)sprintf() but with a size limit: no more than n bytes are written in str
|
||||
// Always null-terminate str
|
||||
//
|
||||
int snprintf(char *str, size_t n, const char *fmt, ...)
|
||||
{
|
||||
|
|
|
@ -292,7 +292,7 @@ char *strncat(char *restrict dest, const char *restrict src, size_t n)
|
|||
// Always null-terminates, and returne TRUE or FALSE depending on whether
|
||||
// regular strcat() would have null-terminated this string, or not
|
||||
//
|
||||
int *strnzcat(char *restrict dest, const char *restrict src, size_t n)
|
||||
int strnzcat(char *restrict dest, const char *restrict src, size_t n)
|
||||
{
|
||||
size_t it, off = 0;
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ int strnzcpy(char *restrict, const char *restrict, size_t);
|
|||
|
||||
char *strcat (char *restrict, const char *restrict);
|
||||
char *strncat (char *restrict, const char *restrict, size_t);
|
||||
int *strnzcat(char *restrict, const char *restrict, size_t);
|
||||
int strnzcat(char *restrict, const char *restrict, size_t);
|
||||
|
||||
char *strrev(char *restrict, const char *restrict);
|
||||
char *strrev2(char *);
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
#define NULL 0L
|
||||
#endif
|
||||
|
||||
#ifndef INITOK
|
||||
#define INITOK ((unsigned int)0xCAFEBABE)
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// Keywords //
|
||||
//------------------------------------------//
|
||||
|
|
|
@ -38,6 +38,13 @@
|
|||
#include <kernel/kernterm.h>
|
||||
#endif
|
||||
|
||||
// not ready for kernel compilation
|
||||
#ifndef _KALEID_KERNEL
|
||||
#ifndef _KALKERN_SCHED_H
|
||||
#include <kernel/kernsched.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//------------------------------------------//
|
||||
// End of header //
|
||||
//------------------------------------------//
|
||||
|
|
|
@ -59,7 +59,6 @@ typedef enum {
|
|||
// Multiprocessor misc. //
|
||||
//------------------------------------------//
|
||||
|
||||
|
||||
#ifndef INITOK
|
||||
#define INITOK ((unsigned int)0xCAFEBABE)
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
sched-test:
|
||||
gcc -O2 -masm=intel -I../../include ./sched.c
|
||||
gcc -O2 -Wall -Wextra -Wshadow -std=gnu11 -masm=intel -I../../include ./sched.c
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// Desc: Scheduling algorithm //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
#include <kernel/kernsched.h>
|
||||
#include <kalkern.h>
|
||||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
||||
|
@ -17,17 +17,18 @@ CREATE_PER_CPU(CurProc, Process_t *);
|
|||
//
|
||||
// For test purpose only
|
||||
//
|
||||
int procslen = 9;
|
||||
int procslen = 10;
|
||||
Process_t procs[] = {
|
||||
{ 0, 0, 0, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 1, 2, 2, 16, 16, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 2, 3, 3, 31, 31, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 3, 2, 2, 1, 1, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 4, 0, 0, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 4, 3, 3, 5, 5, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 5, 0, 0, 30, 30, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 6, 1, 1, 19, 19, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 7, 1, 1, 0, 0, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 8, 3, 3, 12, 12, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
{ 9, 2, 2, 21, 21, STATE_RUNNABLE, DEF_PROC_TSLICE, DEF_PROC_TSLICE, NULL },
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -67,22 +68,22 @@ void SchedUnlock(void) {
|
|||
// The four priority classes of OS/2
|
||||
//
|
||||
|
||||
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ServPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(TimeCritProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ServPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(ReglPrioProcs, ListHead_t *);
|
||||
CREATE_PER_CPU(IdlePrioProcs, ListHead_t *);
|
||||
|
||||
const char *PrioClassesNames[] = {
|
||||
"Idle priority class",
|
||||
"Regular priority class",
|
||||
"Server priority class",
|
||||
"Time-critical class",
|
||||
"Server priority class",
|
||||
"Regular priority class",
|
||||
"Idle priority class",
|
||||
};
|
||||
|
||||
enum { IDLE_PRIO_PROC = 0,
|
||||
REGL_PRIO_PROC = 1,
|
||||
SERV_PRIO_PROC = 2,
|
||||
TIME_CRIT_PROC = 3,
|
||||
enum { TIME_CRIT_PROC = 0,
|
||||
SERV_PRIO_PROC = 1,
|
||||
REGL_PRIO_PROC = 2,
|
||||
IDLE_PRIO_PROC = 3,
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -111,8 +112,8 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
|
|||
{
|
||||
KalAssert(proc1 && proc2);
|
||||
|
||||
if (proc1->prioClass > proc2->prioClass) return proc1;
|
||||
if (proc1->prioClass < proc2->prioClass) return proc2;
|
||||
if (proc1->prioClass < proc2->prioClass) return proc1;
|
||||
if (proc1->prioClass > proc2->prioClass) return proc2;
|
||||
|
||||
if (proc1->prioLevel > proc2->prioLevel) return proc1;
|
||||
if (proc1->prioLevel < proc2->prioLevel) return proc2;
|
||||
|
@ -126,7 +127,7 @@ Process_t *CompareProcs(Process_t *proc1, Process_t *proc2)
|
|||
static inline
|
||||
void SchedThisProcUnlocked(Process_t *proc)
|
||||
{
|
||||
KalAssert(proc && proc->procState == STATE_RUNNABLE);
|
||||
KalAssert(proc && proc->procState == STATE_RUNNABLE && !proc->schedNode);
|
||||
|
||||
bool found = false;
|
||||
ListNode_t *iterNode = NULL;
|
||||
|
@ -137,13 +138,15 @@ void SchedThisProcUnlocked(Process_t *proc)
|
|||
|
||||
proc->schedNode = procNode;
|
||||
|
||||
//printdbg("Adding process %d to '%s'\n", proc->pid, PrioClassesNames[proc->prioClass]);
|
||||
|
||||
//
|
||||
// Find a process with lesser priority
|
||||
//
|
||||
for (iterNode = head->first; iterNode; iterNode = iterNode->next) {
|
||||
if (proc->prioLevel > GetNodeData(iterNode, Process_t *)->prioLevel) {
|
||||
// Detect double insertions
|
||||
KalAssert(proc->pid != GetNodeData(iterNode, Process_t *)->pid);
|
||||
|
||||
// Add process to schedule
|
||||
AddNodeBefore(head, iterNode, procNode);
|
||||
found = true;
|
||||
break;
|
||||
|
@ -198,9 +201,12 @@ void BlockCurProc(void)
|
|||
|
||||
ListNode_t *procNode = GetCurProc()->schedNode;
|
||||
|
||||
KalAssert(procNode && "Blocking non-scheduled process");
|
||||
|
||||
GetCurProc()->procState = STATE_BLOCKED;
|
||||
RemoveNode(procNode->head, procNode);
|
||||
|
||||
GetCurProc()->schedNode = NULL;
|
||||
SetCurProc(SelectSchedNext());
|
||||
}
|
||||
|
||||
|
@ -208,6 +214,7 @@ static inline
|
|||
void ReSchedCurProc(void)
|
||||
{
|
||||
KalAssert(GetCurProc() && GetCurProc()->procState == STATE_RUNNING);
|
||||
KalAssert(GetCurProc()->schedNode);
|
||||
|
||||
// Restore default attributes, cancelling boosts
|
||||
GetCurProc()->prioClass = GetCurProc()->defPrioClass;
|
||||
|
@ -301,7 +308,6 @@ leave:
|
|||
void InitSched(void)
|
||||
{
|
||||
int pid;
|
||||
Process_t *proc;
|
||||
|
||||
SchedLock();
|
||||
|
||||
|
@ -345,7 +351,7 @@ void FiniSched(void)
|
|||
|
||||
#ifndef _KALEID_KERNEL
|
||||
|
||||
#define PrintProc(proc) printdbg("{ %d, '%s', %d , %d}\n", (proc)->pid, \
|
||||
#define PrintProc(proc) printdbg("{ %d, '%s', %d , %lu}\n", (proc)->pid, \
|
||||
PrioClassesNames[(proc)->prioClass], (proc)->prioLevel, (proc)->timeSlice);
|
||||
|
||||
//
|
||||
|
@ -358,7 +364,7 @@ void PrintList(ListHead_t *head)
|
|||
Process_t *proc;
|
||||
ListNode_t *node = head->first;
|
||||
|
||||
printdbg("len: %d\n", head->length);
|
||||
printdbg("len: %lu\n", head->length);
|
||||
|
||||
while (node) {
|
||||
proc = GetNodeData(node, Process_t *);
|
||||
|
@ -402,8 +408,8 @@ int main(void)
|
|||
}
|
||||
|
||||
if (tick == 50) {
|
||||
procs[2].procState = STATE_RUNNABLE;
|
||||
SchedThisProc(&procs[2]);
|
||||
procs[0].procState = STATE_RUNNABLE;
|
||||
SchedThisProc(&procs[0]);
|
||||
}
|
||||
|
||||
printf("Tick %d - Running: ", tick);
|
||||
|
@ -418,6 +424,9 @@ int main(void)
|
|||
|
||||
SchedOnTick();
|
||||
|
||||
if (tick == 50) // already done
|
||||
puts("Re-scheduling process 0");
|
||||
|
||||
tick++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue