BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / bb0cb7718204df7c0cbaf87484b1def3c4b2880f / task / time.c

// Related

Nucleus

Barry Per-CPU Scheduler bb0cb77 (3 years, 2 months ago)
/*
 * This file controls the system clock and contains the functions related to
 * getting and setting the time from various sources.  It keeps a monotonic
 * clock internally, but can also make use of the tasks' clocks, and the RTC.
 */

#include <stdint.h>
#include <nucleus/cpu.h>
#include <nucleus/task.h>

void balance_scheduler(void);

uint32_t monotonic = 0;

/* Timer interrupt */
void
timer_handler(struct InterruptFrame *frame)
{
	if (cpu->id == 0)
		monotonic++;
	if (!current)
		return;

	/* Book-keep the scheduler */
	Scheduler *s = cpu->scheduler;
	if (monotonic % 300000 == 0)
		balance_scheduler();
	s->timeslice++;

	/* Call scheduler */
	if (s->timeslice < (current->priority * 10))
		return;
	schedule();
}