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; 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 * @param self - the priority queue we want to add to
* @returns The head of the priority queue or NULL when empty * @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 != NULL);
assert(self->get_priority != NULL); assert(self->get_priority != NULL);
// If first_free is 1, we're empty if (priority_queue_is_empty(self)) return NULL;
if (self->first_free == 1) return NULL;
if (ck_spinlock_fas_trylock(&self->lock) == false) return NULL; if (ck_spinlock_fas_trylock(&self->lock) == false) return NULL;
// Start of Critical Section // Start of Critical Section
void *min = self->items[1]; void *min = NULL;
self->items[1] = self->items[self->first_free - 1]; if (!priority_queue_is_empty(self)) {
self->items[self->first_free - 1] = NULL; min = self->items[1];
self->first_free--; self->items[1] = self->items[self->first_free - 1];
assert(self->first_free == 1 || self->items[self->first_free - 1] != NULL); self->items[self->first_free - 1] = NULL;
// Because of 1-based indices, first_free is 2 when there is only one element self->first_free--;
if (self->first_free > 2) priority_queue_percolate_down(self); // 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]); // Update the highest priority
} else { self->highest_priority = !priority_queue_is_empty(self) ? self->get_priority(self->items[1])
self->highest_priority = ULONG_MAX; : ULONG_MAX;
} }
ck_spinlock_fas_unlock(&self->lock); ck_spinlock_fas_unlock(&self->lock);
// End of Critical Section // End of Critical Section

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

@ -12,8 +12,9 @@ static struct priority_queue sandbox_request_scheduler_ps;
static sandbox_request_t * static sandbox_request_t *
sandbox_request_scheduler_ps_add(void *sandbox_request_raw) sandbox_request_scheduler_ps_add(void *sandbox_request_raw)
{ {
// TODO int return_code = priority_queue_enqueue(&sandbox_request_scheduler_ps, sandbox_request_raw);
return NULL;
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 * static sandbox_request_t *
sandbox_request_scheduler_ps_remove(void) sandbox_request_scheduler_ps_remove(void)
{ {
// TODO return (sandbox_request_t *)priority_queue_dequeue(&sandbox_request_scheduler_ps);
return NULL;
} }
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() sandbox_request_scheduler_ps_initialize()
{ {
// Initialize local state // Initialize local state
priority_queue_initialize(&sandbox_request_scheduler_ps, sandbox_request_get_priority);
// TODO // TODO

Loading…
Cancel
Save