[BACK]Return to kern_sched.h CVS log [TXT][DIR] Up to [local] / funnyos / sys

File: [local] / funnyos / sys / kern_sched.h (download)

Revision 1.4, Fri Nov 23 13:37:43 2007 UTC (16 years, 4 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +5 -17 lines

basic roundrobin multitasking support in FunnyOS!
_vector_irq saves Sys_mode context (which is treated as struct pcb) in stack and
passes sp to irq_trampoline() which then sets global iframep pointer to point to pcb of interrupted task.

"task" given by u_task (set by user at compile-time) and k_task which is dynamically allocated by the kernel.
scheduler uses list of k_task (circularly linked list) with one constant task "idle".
idle discarded in sched_init() with status TASK_NOSCHED and will not be scheduled after first sched_tick().

tasks created in task/ directory and should implement void ttt_enter(void) to start execution from.
tasks added by inserting new elements in config_tasklist[].

please note that current *ugly* design causes strange behavior if tasks printf something w/out delays..
also, we do not save task's CPSR yet..

/*
 * $Id: kern_sched.h,v 1.4 2007/11/23 13:37:43 nbrk Exp $
 */
#ifndef _SYS_KERN_SCHED_H
#define _SYS_KERN_SCHED_H
#include <sys/types.h>
#include <sys/pcb.h>

/*
 * u_task is used by user to describe task in config.c.
 * "user task".
 */
struct u_task {
	const char *ut_name; 			/* task name */
	uint8_t 	ut_priority; 		/* priority, bigger the value = higher priority */
	void 		(*ut_enter)(void); 	/* entry point */
};


/*
 * Kernel sees each system task as struct k_task;
 * it is used for scheduling and context switches.
 * "kernel task".
 */
struct k_task {
	struct u_task 	*kt_utask; 	/* points to user-described data */
	uint8_t 		kt_tid; 	/* task id (TID) */

	uint8_t 		kt_state; 	/* task state (running, blocked, etc.) */
//	uint32_t 		kt_timeo; 	/* timeout (in HZ) if task is blocked */ 
	struct pcb 		kt_pcb;		/* hardware context (15 ARM registers) */


	struct k_task 	*kt_next;
};

/*
 * Tasks states.
 */
#define TASK_NOSCHED 	0x00 	/* task not ready or halted; will not schedule this */
#define TASK_READY 		0x01 	/* ready for schedule */
#define TASK_RUNNING 	0x02 	/* running now */
#define TASK_SLEEPING 	0x04 	/* task waits for (planned) timeout */


/*
 * Functions.
 */
void 	sched_init(void);
void 	sched_tick(void);

#endif /* not _SYS_KERN_SCHED_H */