feat: Implement basic ps for sandbox requests

main
Sean McBride 5 years ago
parent 6a7bbc2e97
commit 1999a97c8f

@ -174,6 +174,14 @@ priority_queue_enqueue(struct priority_queue *self, void *value)
return rc;
}
static bool
priority_queue_is_empty(struct priority_queue *self)
{
assert(self != NULL);
assert(self->first_free != 0);
return self->first_free == 1;
}
/**
* @param self - the priority queue we want to add to
* @returns The head of the priority queue or NULL when empty
@ -183,23 +191,21 @@ priority_queue_dequeue(struct priority_queue *self)
{
assert(self != NULL);
assert(self->get_priority != NULL);
// If first_free is 1, we're empty
if (self->first_free == 1) return NULL;
if (priority_queue_is_empty(self)) return NULL;
if (ck_spinlock_fas_trylock(&self->lock) == false) return NULL;
// Start of Critical Section
void *min = self->items[1];
void *min = NULL;
if (!priority_queue_is_empty(self)) {
min = self->items[1];
self->items[1] = self->items[self->first_free - 1];
self->items[self->first_free - 1] = NULL;
self->first_free--;
assert(self->first_free == 1 || self->items[self->first_free - 1] != NULL);
// Because of 1-based indices, first_free is 2 when there is only one element
if (self->first_free > 2) priority_queue_percolate_down(self);
if (self->first_free > 1) {
self->highest_priority = self->get_priority(self->items[1]);
} else {
self->highest_priority = ULONG_MAX;
// Update the highest priority
self->highest_priority = !priority_queue_is_empty(self) ? self->get_priority(self->items[1])
: ULONG_MAX;
}
ck_spinlock_fas_unlock(&self->lock);
// End of Critical Section

@ -20,7 +20,8 @@
#include <module.h>
#include <sandbox.h>
#include <sandbox_request.h>
#include <sandbox_request_scheduler_fifo.h>
// #include <sandbox_request_scheduler_fifo.h>
#include <sandbox_request_scheduler_ps.h>
#include <software_interrupt.h>
#include <types.h>
@ -45,7 +46,8 @@ runtime_initialize(void)
assert(runtime_epoll_file_descriptor >= 0);
// Allocate and Initialize the global deque
sandbox_request_scheduler_fifo_initialize();
// sandbox_request_scheduler_fifo_initialize();
sandbox_request_scheduler_ps_initialize();
// Mask Signals
software_interrupt_mask_signal(SIGUSR1);

@ -12,8 +12,9 @@ static struct priority_queue sandbox_request_scheduler_ps;
static sandbox_request_t *
sandbox_request_scheduler_ps_add(void *sandbox_request_raw)
{
// TODO
return NULL;
int return_code = priority_queue_enqueue(&sandbox_request_scheduler_ps, sandbox_request_raw);
return return_code == 0 ? sandbox_request_raw : NULL;
}
/**
@ -23,10 +24,17 @@ sandbox_request_scheduler_ps_add(void *sandbox_request_raw)
static sandbox_request_t *
sandbox_request_scheduler_ps_remove(void)
{
// TODO
return NULL;
return (sandbox_request_t *)priority_queue_dequeue(&sandbox_request_scheduler_ps);
}
unsigned long long int
sandbox_request_get_priority(void *element)
{
sandbox_request_t *sandbox_request = (sandbox_request_t *)element;
return sandbox_request->absolute_deadline;
};
/**
*
**/
@ -34,6 +42,7 @@ void
sandbox_request_scheduler_ps_initialize()
{
// Initialize local state
priority_queue_initialize(&sandbox_request_scheduler_ps, sandbox_request_get_priority);
// TODO

Loading…
Cancel
Save