|
|
@ -6,6 +6,7 @@
|
|
|
|
#include "local_runqueue_minheap.h"
|
|
|
|
#include "local_runqueue_minheap.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "priority_queue.h"
|
|
|
|
#include "priority_queue.h"
|
|
|
|
|
|
|
|
#include "software_interrupt.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__thread static struct priority_queue local_runqueue_minheap;
|
|
|
|
__thread static struct priority_queue local_runqueue_minheap;
|
|
|
@ -70,6 +71,9 @@ local_runqueue_minheap_delete(struct sandbox *sandbox)
|
|
|
|
struct sandbox *
|
|
|
|
struct sandbox *
|
|
|
|
local_runqueue_minheap_get_next()
|
|
|
|
local_runqueue_minheap_get_next()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Assumption: Software Interrupts are disabed by caller */
|
|
|
|
|
|
|
|
assert(!software_interrupt_is_enabled());
|
|
|
|
|
|
|
|
|
|
|
|
struct sandbox * sandbox = NULL;
|
|
|
|
struct sandbox * sandbox = NULL;
|
|
|
|
struct sandbox_request *sandbox_request;
|
|
|
|
struct sandbox_request *sandbox_request;
|
|
|
|
int sandbox_rc = local_runqueue_minheap_remove(&sandbox);
|
|
|
|
int sandbox_rc = local_runqueue_minheap_remove(&sandbox);
|
|
|
@ -97,6 +101,8 @@ local_runqueue_minheap_get_next()
|
|
|
|
done:
|
|
|
|
done:
|
|
|
|
return sandbox;
|
|
|
|
return sandbox;
|
|
|
|
sandbox_allocate_err:
|
|
|
|
sandbox_allocate_err:
|
|
|
|
|
|
|
|
fprintf(stderr, "local_runqueue_minheap_get_next failed to allocating sandbox. Readding request to global "
|
|
|
|
|
|
|
|
"request scheduler\n");
|
|
|
|
global_request_scheduler_add(sandbox_request);
|
|
|
|
global_request_scheduler_add(sandbox_request);
|
|
|
|
err:
|
|
|
|
err:
|
|
|
|
sandbox = NULL;
|
|
|
|
sandbox = NULL;
|
|
|
@ -112,9 +118,8 @@ err:
|
|
|
|
void
|
|
|
|
void
|
|
|
|
local_runqueue_minheap_preempt(ucontext_t *user_context)
|
|
|
|
local_runqueue_minheap_preempt(ucontext_t *user_context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(user_context != NULL);
|
|
|
|
/* Assumption: Software Interrupts are disabed by caller */
|
|
|
|
|
|
|
|
assert(!software_interrupt_is_enabled());
|
|
|
|
software_interrupt_disable(); /* no nesting! */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct sandbox *current_sandbox = current_sandbox_get();
|
|
|
|
struct sandbox *current_sandbox = current_sandbox_get();
|
|
|
|
|
|
|
|
|
|
|
@ -147,13 +152,11 @@ local_runqueue_minheap_preempt(ucontext_t *user_context)
|
|
|
|
/* Allocate the request */
|
|
|
|
/* Allocate the request */
|
|
|
|
struct sandbox *next_sandbox;
|
|
|
|
struct sandbox *next_sandbox;
|
|
|
|
/* If sandbox allocation fails, add the request back and exit*/
|
|
|
|
/* If sandbox allocation fails, add the request back and exit*/
|
|
|
|
assert(software_interrupt_is_disabled);
|
|
|
|
|
|
|
|
if (sandbox_allocate(&next_sandbox, sandbox_request) == -1) goto err_sandbox_allocate;
|
|
|
|
if (sandbox_allocate(&next_sandbox, sandbox_request) == -1) goto err_sandbox_allocate;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set as runnable and add it to the runqueue */
|
|
|
|
/* Set as runnable and add it to the runqueue */
|
|
|
|
next_sandbox->state = SANDBOX_RUNNABLE;
|
|
|
|
next_sandbox->state = SANDBOX_RUNNABLE;
|
|
|
|
local_runqueue_add(next_sandbox);
|
|
|
|
local_runqueue_add(next_sandbox);
|
|
|
|
assert(software_interrupt_is_disabled);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Save the context of the currently executing sandbox before switching from it */
|
|
|
|
/* Save the context of the currently executing sandbox before switching from it */
|
|
|
|
arch_mcontext_save(¤t_sandbox->ctxt, &user_context->uc_mcontext);
|
|
|
|
arch_mcontext_save(¤t_sandbox->ctxt, &user_context->uc_mcontext);
|
|
|
@ -173,7 +176,10 @@ done:
|
|
|
|
if (should_enable_software_interrupt) software_interrupt_enable();
|
|
|
|
if (should_enable_software_interrupt) software_interrupt_enable();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
err_sandbox_allocate:
|
|
|
|
err_sandbox_allocate:
|
|
|
|
assert(sandbox_request != NULL);
|
|
|
|
assert(sandbox_request);
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
|
|
|
"local_runqueue_minheap_preempt failed to allocate sandbox, returning request to global request "
|
|
|
|
|
|
|
|
"scheduler\n");
|
|
|
|
global_request_scheduler_add(sandbox_request);
|
|
|
|
global_request_scheduler_add(sandbox_request);
|
|
|
|
err:
|
|
|
|
err:
|
|
|
|
goto done;
|
|
|
|
goto done;
|
|
|
|