refactor: rename state transitions

master
Sean McBride 3 years ago
parent 3a60134d44
commit 9ec668ec3e

@ -1,8 +1,13 @@
digraph { digraph {
Uninitialized -> Initialized Uninitialized -> Initialized
Initialized -> {Runnable Error} Initialized -> {Runnable Error}
{Runnable Running_User Preempted} -> Running_Kernel Runnable -> Running_Sys
Running_Kernel -> {Blocked Error Preempted Returned Running_User} Running_User -> Running_Sys [label="interrupt"]
Returned -> Complete Running_Sys -> Asleep [label="sleep"]
Blocked -> Runnable Running_Sys -> {Error Returned}
Running_Sys -> Running_User [label="return"]
Running_Sys -> Preempted [label="preempt"]
Preempted -> Running_User
Returned -> Complete [label="exit_success"]
Asleep -> Runnable [label="wakeup"]
} }

@ -4,148 +4,154 @@
<!-- Generated by graphviz version 2.43.0 (0) <!-- Generated by graphviz version 2.43.0 (0)
--> -->
<!-- Title: %3 Pages: 1 --> <!-- Title: %3 Pages: 1 -->
<svg width="632pt" height="404pt" <svg width="650pt" height="437pt"
viewBox="0.00 0.00 631.84 404.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> viewBox="0.00 0.00 649.79 437.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 400)"> <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 433)">
<title>%3</title> <title>%3</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-400 627.84,-400 627.84,4 -4,4"/> <polygon fill="white" stroke="transparent" points="-4,4 -4,-433 645.79,-433 645.79,4 -4,4"/>
<!-- Uninitialized --> <!-- Uninitialized -->
<g id="node1" class="node"> <g id="node1" class="node">
<title>Uninitialized</title> <title>Uninitialized</title>
<ellipse fill="none" stroke="black" cx="371.45" cy="-378" rx="70.39" ry="18"/> <ellipse fill="none" stroke="black" cx="70.19" cy="-411" rx="70.39" ry="18"/>
<text text-anchor="middle" x="371.45" y="-374.3" font-family="Times,serif" font-size="14.00">Uninitialized</text> <text text-anchor="middle" x="70.19" y="-407.3" font-family="Times,serif" font-size="14.00">Uninitialized</text>
</g> </g>
<!-- Initialized --> <!-- Initialized -->
<g id="node2" class="node"> <g id="node2" class="node">
<title>Initialized</title> <title>Initialized</title>
<ellipse fill="none" stroke="black" cx="371.45" cy="-306" rx="57.39" ry="18"/> <ellipse fill="none" stroke="black" cx="70.19" cy="-338" rx="57.39" ry="18"/>
<text text-anchor="middle" x="371.45" y="-302.3" font-family="Times,serif" font-size="14.00">Initialized</text> <text text-anchor="middle" x="70.19" y="-334.3" font-family="Times,serif" font-size="14.00">Initialized</text>
</g> </g>
<!-- Uninitialized&#45;&gt;Initialized --> <!-- Uninitialized&#45;&gt;Initialized -->
<g id="edge1" class="edge"> <g id="edge1" class="edge">
<title>Uninitialized&#45;&gt;Initialized</title> <title>Uninitialized&#45;&gt;Initialized</title>
<path fill="none" stroke="black" d="M371.45,-359.7C371.45,-351.98 371.45,-342.71 371.45,-334.11"/> <path fill="none" stroke="black" d="M70.19,-392.81C70.19,-384.79 70.19,-375.05 70.19,-366.07"/>
<polygon fill="black" stroke="black" points="374.95,-334.1 371.45,-324.1 367.95,-334.1 374.95,-334.1"/> <polygon fill="black" stroke="black" points="73.69,-366.03 70.19,-356.03 66.69,-366.03 73.69,-366.03"/>
</g> </g>
<!-- Runnable --> <!-- Runnable -->
<g id="node3" class="node"> <g id="node3" class="node">
<title>Runnable</title> <title>Runnable</title>
<ellipse fill="none" stroke="black" cx="315.45" cy="-234" rx="54.69" ry="18"/> <ellipse fill="none" stroke="black" cx="266.19" cy="-265" rx="54.69" ry="18"/>
<text text-anchor="middle" x="315.45" y="-230.3" font-family="Times,serif" font-size="14.00">Runnable</text> <text text-anchor="middle" x="266.19" y="-261.3" font-family="Times,serif" font-size="14.00">Runnable</text>
</g> </g>
<!-- Initialized&#45;&gt;Runnable --> <!-- Initialized&#45;&gt;Runnable -->
<g id="edge2" class="edge"> <g id="edge2" class="edge">
<title>Initialized&#45;&gt;Runnable</title> <title>Initialized&#45;&gt;Runnable</title>
<path fill="none" stroke="black" d="M358.17,-288.41C351.27,-279.78 342.7,-269.06 335.04,-259.5"/> <path fill="none" stroke="black" d="M106.14,-323.98C138.57,-312.23 186.39,-294.91 221.32,-282.26"/>
<polygon fill="black" stroke="black" points="337.6,-257.09 328.62,-251.47 332.14,-261.47 337.6,-257.09"/> <polygon fill="black" stroke="black" points="222.59,-285.52 230.8,-278.82 220.21,-278.94 222.59,-285.52"/>
</g> </g>
<!-- Error --> <!-- Error -->
<g id="node4" class="node"> <g id="node4" class="node">
<title>Error</title> <title>Error</title>
<ellipse fill="none" stroke="black" cx="587.45" cy="-90" rx="36.29" ry="18"/> <ellipse fill="none" stroke="black" cx="52.19" cy="-105" rx="36.29" ry="18"/>
<text text-anchor="middle" x="587.45" y="-86.3" font-family="Times,serif" font-size="14.00">Error</text> <text text-anchor="middle" x="52.19" y="-101.3" font-family="Times,serif" font-size="14.00">Error</text>
</g> </g>
<!-- Initialized&#45;&gt;Error --> <!-- Initialized&#45;&gt;Error -->
<g id="edge3" class="edge"> <g id="edge3" class="edge">
<title>Initialized&#45;&gt;Error</title> <title>Initialized&#45;&gt;Error</title>
<path fill="none" stroke="black" d="M388.04,-288.56C426.34,-250.62 520.98,-156.85 564.67,-113.56"/> <path fill="none" stroke="black" d="M68.84,-319.64C65.73,-279.74 58.06,-181.27 54.32,-133.24"/>
<polygon fill="black" stroke="black" points="567.33,-115.86 571.97,-106.33 562.4,-110.89 567.33,-115.86"/> <polygon fill="black" stroke="black" points="57.8,-132.95 53.54,-123.25 50.83,-133.49 57.8,-132.95"/>
</g> </g>
<!-- Running_Kernel --> <!-- Running_Sys -->
<g id="node7" class="node"> <g id="node5" class="node">
<title>Running_Kernel</title> <title>Running_Sys</title>
<ellipse fill="none" stroke="black" cx="315.45" cy="-162" rx="84.49" ry="18"/> <ellipse fill="none" stroke="black" cx="266.19" cy="-192" rx="70.69" ry="18"/>
<text text-anchor="middle" x="315.45" y="-158.3" font-family="Times,serif" font-size="14.00">Running_Kernel</text> <text text-anchor="middle" x="266.19" y="-188.3" font-family="Times,serif" font-size="14.00">Running_Sys</text>
</g> </g>
<!-- Runnable&#45;&gt;Running_Kernel --> <!-- Runnable&#45;&gt;Running_Sys -->
<g id="edge4" class="edge"> <g id="edge4" class="edge">
<title>Runnable&#45;&gt;Running_Kernel</title> <title>Runnable&#45;&gt;Running_Sys</title>
<path fill="none" stroke="black" d="M315.45,-215.7C315.45,-207.98 315.45,-198.71 315.45,-190.11"/> <path fill="none" stroke="black" d="M266.19,-246.81C266.19,-238.79 266.19,-229.05 266.19,-220.07"/>
<polygon fill="black" stroke="black" points="318.95,-190.1 315.45,-180.1 311.95,-190.1 318.95,-190.1"/> <polygon fill="black" stroke="black" points="269.69,-220.03 266.19,-210.03 262.69,-220.03 269.69,-220.03"/>
</g>
<!-- Running_Sys&#45;&gt;Error -->
<g id="edge7" class="edge">
<title>Running_Sys&#45;&gt;Error</title>
<path fill="none" stroke="black" d="M202.68,-183.96C173.38,-178.94 138.83,-170.41 110.19,-156 96.75,-149.24 83.86,-138.69 73.66,-129.01"/>
<polygon fill="black" stroke="black" points="76,-126.4 66.42,-121.87 71.08,-131.38 76,-126.4"/>
</g> </g>
<!-- Running_User --> <!-- Running_User -->
<g id="node5" class="node"> <g id="node6" class="node">
<title>Running_User</title> <title>Running_User</title>
<ellipse fill="none" stroke="black" cx="315.45" cy="-90" rx="76.89" ry="18"/> <ellipse fill="none" stroke="black" cx="226.19" cy="-18" rx="76.89" ry="18"/>
<text text-anchor="middle" x="315.45" y="-86.3" font-family="Times,serif" font-size="14.00">Running_User</text> <text text-anchor="middle" x="226.19" y="-14.3" font-family="Times,serif" font-size="14.00">Running_User</text>
</g> </g>
<!-- Running_User&#45;&gt;Running_Kernel --> <!-- Running_Sys&#45;&gt;Running_User -->
<g id="edge5" class="edge"> <g id="edge9" class="edge">
<title>Running_User&#45;&gt;Running_Kernel</title> <title>Running_Sys&#45;&gt;Running_User</title>
<path fill="none" stroke="black" d="M321.34,-108.1C322.15,-115.79 322.38,-125.05 322.05,-133.67"/> <path fill="none" stroke="black" d="M256.46,-174C249.29,-160.59 239.98,-141.19 235.19,-123 228.52,-97.63 226.52,-67.69 226.04,-46.47"/>
<polygon fill="black" stroke="black" points="318.55,-133.48 321.36,-143.7 325.54,-133.96 318.55,-133.48"/> <polygon fill="black" stroke="black" points="229.53,-46.19 225.91,-36.24 222.53,-46.28 229.53,-46.19"/>
<text text-anchor="middle" x="258.19" y="-101.3" font-family="Times,serif" font-size="14.00">return</text>
</g> </g>
<!-- Preempted --> <!-- Asleep -->
<g id="node6" class="node"> <g id="node7" class="node">
<title>Preempted</title> <title>Asleep</title>
<ellipse fill="none" stroke="black" cx="471.45" cy="-90" rx="61.99" ry="18"/> <ellipse fill="none" stroke="black" cx="600.19" cy="-105" rx="41.69" ry="18"/>
<text text-anchor="middle" x="471.45" y="-86.3" font-family="Times,serif" font-size="14.00">Preempted</text> <text text-anchor="middle" x="600.19" y="-101.3" font-family="Times,serif" font-size="14.00">Asleep</text>
</g> </g>
<!-- Preempted&#45;&gt;Running_Kernel --> <!-- Running_Sys&#45;&gt;Asleep -->
<g id="edge6" class="edge"> <g id="edge6" class="edge">
<title>Preempted&#45;&gt;Running_Kernel</title> <title>Running_Sys&#45;&gt;Asleep</title>
<path fill="none" stroke="black" d="M443.44,-106.11C421.31,-116.62 390.07,-130.7 363.94,-141.97"/> <path fill="none" stroke="black" d="M318.7,-179.8C375.79,-167.3 469.52,-145.8 549.19,-123 552.38,-122.09 555.66,-121.1 558.95,-120.08"/>
<polygon fill="black" stroke="black" points="362.38,-138.83 354.57,-145.98 365.14,-145.26 362.38,-138.83"/> <polygon fill="black" stroke="black" points="560.31,-123.32 568.77,-116.95 558.18,-116.65 560.31,-123.32"/>
<text text-anchor="middle" x="499.19" y="-144.8" font-family="Times,serif" font-size="14.00">sleep</text>
</g> </g>
<!-- Running_Kernel&#45;&gt;Error --> <!-- Returned -->
<g id="edge7" class="edge"> <g id="node8" class="node">
<title>Running_Kernel&#45;&gt;Error</title> <title>Returned</title>
<path fill="none" stroke="black" d="M375.28,-149.28C421.39,-139.71 486.5,-125.02 542.45,-108 545.05,-107.21 547.73,-106.34 550.41,-105.43"/> <ellipse fill="none" stroke="black" cx="486.19" cy="-105" rx="53.89" ry="18"/>
<polygon fill="black" stroke="black" points="551.79,-108.66 560.04,-102.01 549.44,-102.06 551.79,-108.66"/> <text text-anchor="middle" x="486.19" y="-101.3" font-family="Times,serif" font-size="14.00">Returned</text>
</g> </g>
<!-- Running_Kernel&#45;&gt;Running_User --> <!-- Running_Sys&#45;&gt;Returned -->
<g id="edge8" class="edge"> <g id="edge8" class="edge">
<title>Running_Kernel&#45;&gt;Running_User</title> <title>Running_Sys&#45;&gt;Returned</title>
<path fill="none" stroke="black" d="M309.53,-143.7C308.73,-135.98 308.51,-126.71 308.85,-118.11"/> <path fill="none" stroke="black" d="M312.74,-178.34C333.61,-172.25 358.38,-164.45 380.19,-156 403.62,-146.93 429.1,-134.98 449.21,-125.04"/>
<polygon fill="black" stroke="black" points="312.34,-118.32 309.55,-108.1 305.36,-117.84 312.34,-118.32"/> <polygon fill="black" stroke="black" points="450.95,-128.09 458.33,-120.49 447.82,-121.82 450.95,-128.09"/>
</g>
<!-- Running_Kernel&#45;&gt;Preempted -->
<g id="edge9" class="edge">
<title>Running_Kernel&#45;&gt;Preempted</title>
<path fill="none" stroke="black" d="M345.08,-145.12C368.01,-134.27 400,-119.88 426.11,-108.67"/>
<polygon fill="black" stroke="black" points="427.61,-111.84 435.44,-104.7 424.87,-105.4 427.61,-111.84"/>
</g> </g>
<!-- Blocked --> <!-- Preempted -->
<g id="node8" class="node"> <g id="node9" class="node">
<title>Blocked</title> <title>Preempted</title>
<ellipse fill="none" stroke="black" cx="47.45" cy="-90" rx="47.39" ry="18"/> <ellipse fill="none" stroke="black" cx="352.19" cy="-105" rx="61.99" ry="18"/>
<text text-anchor="middle" x="47.45" y="-86.3" font-family="Times,serif" font-size="14.00">Blocked</text> <text text-anchor="middle" x="352.19" y="-101.3" font-family="Times,serif" font-size="14.00">Preempted</text>
</g> </g>
<!-- Running_Kernel&#45;&gt;Blocked --> <!-- Running_Sys&#45;&gt;Preempted -->
<g id="edge10" class="edge"> <g id="edge10" class="edge">
<title>Running_Kernel&#45;&gt;Blocked</title> <title>Running_Sys&#45;&gt;Preempted</title>
<path fill="none" stroke="black" d="M260.79,-148.13C217.86,-137.82 156.65,-122.72 103.45,-108 99.91,-107.02 96.25,-105.98 92.59,-104.91"/> <path fill="none" stroke="black" d="M283.18,-174.21C296.11,-161.43 314.05,-143.7 328.4,-129.52"/>
<polygon fill="black" stroke="black" points="93.5,-101.53 82.92,-102.06 91.52,-108.25 93.5,-101.53"/> <polygon fill="black" stroke="black" points="330.88,-131.99 335.53,-122.47 325.96,-127.01 330.88,-131.99"/>
<text text-anchor="middle" x="345.69" y="-144.8" font-family="Times,serif" font-size="14.00">preempt</text>
</g> </g>
<!-- Returned --> <!-- Running_User&#45;&gt;Running_Sys -->
<g id="node9" class="node"> <g id="edge5" class="edge">
<title>Returned</title> <title>Running_User&#45;&gt;Running_Sys</title>
<ellipse fill="none" stroke="black" cx="166.45" cy="-90" rx="53.89" ry="18"/> <path fill="none" stroke="black" d="M196.06,-34.66C163.08,-53.98 117.48,-88.54 138.19,-123 153.49,-148.45 181.89,-164.89 208.05,-175.21"/>
<text text-anchor="middle" x="166.45" y="-86.3" font-family="Times,serif" font-size="14.00">Returned</text> <polygon fill="black" stroke="black" points="206.97,-178.54 217.56,-178.74 209.4,-171.98 206.97,-178.54"/>
</g> <text text-anchor="middle" x="171.19" y="-101.3" font-family="Times,serif" font-size="14.00">interrupt</text>
<!-- Running_Kernel&#45;&gt;Returned -->
<g id="edge11" class="edge">
<title>Running_Kernel&#45;&gt;Returned</title>
<path fill="none" stroke="black" d="M282.01,-145.29C259.43,-134.69 229.55,-120.65 205.82,-109.5"/>
<polygon fill="black" stroke="black" points="207.27,-106.31 196.73,-105.23 204.3,-112.65 207.27,-106.31"/>
</g> </g>
<!-- Blocked&#45;&gt;Runnable --> <!-- Asleep&#45;&gt;Runnable -->
<g id="edge13" class="edge"> <g id="edge13" class="edge">
<title>Blocked&#45;&gt;Runnable</title> <title>Asleep&#45;&gt;Runnable</title>
<path fill="none" stroke="black" d="M74.17,-105.16C122.41,-130.72 224.08,-184.59 278.77,-213.57"/> <path fill="none" stroke="black" d="M579.26,-120.81C563.89,-131.34 542.26,-145.43 522.19,-156 450.82,-193.58 363.46,-228.15 311.45,-247.6"/>
<polygon fill="black" stroke="black" points="277.3,-216.75 287.77,-218.34 280.58,-210.56 277.3,-216.75"/> <polygon fill="black" stroke="black" points="310,-244.41 301.85,-251.17 312.44,-250.97 310,-244.41"/>
<text text-anchor="middle" x="512.69" y="-188.3" font-family="Times,serif" font-size="14.00">wakeup</text>
</g> </g>
<!-- Complete --> <!-- Complete -->
<g id="node10" class="node"> <g id="node10" class="node">
<title>Complete</title> <title>Complete</title>
<ellipse fill="none" stroke="black" cx="166.45" cy="-18" rx="55.49" ry="18"/> <ellipse fill="none" stroke="black" cx="486.19" cy="-18" rx="55.49" ry="18"/>
<text text-anchor="middle" x="166.45" y="-14.3" font-family="Times,serif" font-size="14.00">Complete</text> <text text-anchor="middle" x="486.19" y="-14.3" font-family="Times,serif" font-size="14.00">Complete</text>
</g> </g>
<!-- Returned&#45;&gt;Complete --> <!-- Returned&#45;&gt;Complete -->
<g id="edge12" class="edge"> <g id="edge12" class="edge">
<title>Returned&#45;&gt;Complete</title> <title>Returned&#45;&gt;Complete</title>
<path fill="none" stroke="black" d="M166.45,-71.7C166.45,-63.98 166.45,-54.71 166.45,-46.11"/> <path fill="none" stroke="black" d="M486.19,-86.8C486.19,-75.16 486.19,-59.55 486.19,-46.24"/>
<polygon fill="black" stroke="black" points="169.95,-46.1 166.45,-36.1 162.95,-46.1 169.95,-46.1"/> <polygon fill="black" stroke="black" points="489.69,-46.18 486.19,-36.18 482.69,-46.18 489.69,-46.18"/>
<text text-anchor="middle" x="530.69" y="-57.8" font-family="Times,serif" font-size="14.00">exit_success</text>
</g>
<!-- Preempted&#45;&gt;Running_User -->
<g id="edge11" class="edge">
<title>Preempted&#45;&gt;Running_User</title>
<path fill="none" stroke="black" d="M328.79,-88.21C309.06,-74.9 280.62,-55.72 258.69,-40.92"/>
<polygon fill="black" stroke="black" points="260.58,-37.97 250.33,-35.28 256.66,-43.78 260.58,-37.97"/>
</g> </g>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

@ -27,7 +27,7 @@ sandbox_print_perf(struct sandbox *sandbox)
sandbox->module->relative_deadline, sandbox->total_time, queued_duration, sandbox->module->relative_deadline, sandbox->total_time, queued_duration,
sandbox->duration_of_state[SANDBOX_UNINITIALIZED], sandbox->duration_of_state[SANDBOX_ALLOCATED], sandbox->duration_of_state[SANDBOX_UNINITIALIZED], sandbox->duration_of_state[SANDBOX_ALLOCATED],
sandbox->duration_of_state[SANDBOX_INITIALIZED], sandbox->duration_of_state[SANDBOX_RUNNABLE], sandbox->duration_of_state[SANDBOX_INITIALIZED], sandbox->duration_of_state[SANDBOX_RUNNABLE],
sandbox->duration_of_state[SANDBOX_PREEMPTED], sandbox->duration_of_state[SANDBOX_RUNNING_KERNEL], sandbox->duration_of_state[SANDBOX_PREEMPTED], sandbox->duration_of_state[SANDBOX_RUNNING_SYS],
sandbox->duration_of_state[SANDBOX_RUNNING_USER], sandbox->duration_of_state[SANDBOX_ASLEEP], sandbox->duration_of_state[SANDBOX_RUNNING_USER], sandbox->duration_of_state[SANDBOX_ASLEEP],
sandbox->duration_of_state[SANDBOX_RETURNED], sandbox->duration_of_state[SANDBOX_COMPLETE], sandbox->duration_of_state[SANDBOX_RETURNED], sandbox->duration_of_state[SANDBOX_COMPLETE],
sandbox->duration_of_state[SANDBOX_ERROR], runtime_processor_speed_MHz, sandbox->memory.size); sandbox->duration_of_state[SANDBOX_ERROR], runtime_processor_speed_MHz, sandbox->memory.size);

@ -25,7 +25,7 @@ sandbox_set_as_asleep(struct sandbox *sandbox, sandbox_state_t last_state)
uint64_t now = __getcycles(); uint64_t now = __getcycles();
switch (last_state) { switch (last_state) {
case SANDBOX_RUNNING_KERNEL: { case SANDBOX_RUNNING_SYS: {
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
break; break;
} }
@ -46,6 +46,6 @@ sandbox_set_as_asleep(struct sandbox *sandbox, sandbox_state_t last_state)
static inline void static inline void
sandbox_sleep(struct sandbox *sandbox) sandbox_sleep(struct sandbox *sandbox)
{ {
assert(sandbox->state == SANDBOX_RUNNING_KERNEL); assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_set_as_asleep(sandbox, SANDBOX_RUNNING_KERNEL); sandbox_set_as_asleep(sandbox, SANDBOX_RUNNING_SYS);
} }

@ -46,9 +46,8 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
runtime_sandbox_total_decrement(last_state); runtime_sandbox_total_decrement(last_state);
/* Admissions Control Post Processing */ /* Admissions Control Post Processing */
admissions_info_update(&sandbox->module->admissions_info, admissions_info_update(&sandbox->module->admissions_info, sandbox->duration_of_state[SANDBOX_RUNNING_USER]
sandbox->duration_of_state[SANDBOX_RUNNING_USER] + sandbox->duration_of_state[SANDBOX_RUNNING_SYS]);
+ sandbox->duration_of_state[SANDBOX_RUNNING_KERNEL]);
admissions_control_subtract(sandbox->admissions_estimate); admissions_control_subtract(sandbox->admissions_estimate);
/* Terminal State Logging */ /* Terminal State Logging */
@ -58,3 +57,10 @@ sandbox_set_as_complete(struct sandbox *sandbox, sandbox_state_t last_state)
/* Do not touch sandbox state after adding to completion queue to avoid use-after-free bugs */ /* Do not touch sandbox state after adding to completion queue to avoid use-after-free bugs */
local_completion_queue_add(sandbox); local_completion_queue_add(sandbox);
} }
static inline void
sandbox_exit_success(struct sandbox *sandbox)
{
assert(sandbox->state == SANDBOX_RETURNED);
sandbox_set_as_complete(sandbox, SANDBOX_RETURNED);
}

@ -36,8 +36,9 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
case SANDBOX_UNINITIALIZED: case SANDBOX_UNINITIALIZED:
/* Technically, this is a degenerate sandbox that we generate by hand */ /* Technically, this is a degenerate sandbox that we generate by hand */
break; break;
case SANDBOX_RUNNING_KERNEL: { case SANDBOX_RUNNING_SYS: {
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
sandbox_free_linear_memory(sandbox);
break; break;
} }
default: { default: {
@ -53,10 +54,20 @@ sandbox_set_as_error(struct sandbox *sandbox, sandbox_state_t last_state)
runtime_sandbox_total_increment(SANDBOX_ERROR); runtime_sandbox_total_increment(SANDBOX_ERROR);
runtime_sandbox_total_decrement(last_state); runtime_sandbox_total_decrement(last_state);
/* Admissions Control Post Processing */
admissions_control_subtract(sandbox->admissions_estimate);
/* Terminal State Logging */
sandbox_print_perf(sandbox); sandbox_print_perf(sandbox);
sandbox_summarize_page_allocations(sandbox); sandbox_summarize_page_allocations(sandbox);
sandbox_free_linear_memory(sandbox);
admissions_control_subtract(sandbox->admissions_estimate);
/* Do not touch sandbox after adding to completion queue to avoid use-after-free bugs */ /* Do not touch sandbox after adding to completion queue to avoid use-after-free bugs */
local_completion_queue_add(sandbox); local_completion_queue_add(sandbox);
} }
static inline void
sandbox_exit_error(struct sandbox *sandbox)
{
assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_set_as_error(sandbox, SANDBOX_RUNNING_SYS);
}

@ -26,7 +26,7 @@ sandbox_set_as_preempted(struct sandbox *sandbox, sandbox_state_t last_state)
uint64_t now = __getcycles(); uint64_t now = __getcycles();
switch (last_state) { switch (last_state) {
case SANDBOX_RUNNING_USER: { case SANDBOX_RUNNING_SYS: {
current_sandbox_set(NULL); current_sandbox_set(NULL);
break; break;
} }
@ -43,3 +43,10 @@ sandbox_set_as_preempted(struct sandbox *sandbox, sandbox_state_t last_state)
runtime_sandbox_total_increment(SANDBOX_PREEMPTED); runtime_sandbox_total_increment(SANDBOX_PREEMPTED);
runtime_sandbox_total_decrement(last_state); runtime_sandbox_total_decrement(last_state);
} }
static inline void
sandbox_preempt(struct sandbox *sandbox)
{
assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_set_as_preempted(sandbox, SANDBOX_RUNNING_SYS);
}

@ -28,7 +28,7 @@ sandbox_set_as_returned(struct sandbox *sandbox, sandbox_state_t last_state)
uint64_t now = __getcycles(); uint64_t now = __getcycles();
switch (last_state) { switch (last_state) {
case SANDBOX_RUNNING_KERNEL: { case SANDBOX_RUNNING_SYS: {
sandbox->timestamp_of.response = now; sandbox->timestamp_of.response = now;
sandbox->total_time = now - sandbox->timestamp_of.request_arrival; sandbox->total_time = now - sandbox->timestamp_of.request_arrival;
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);

@ -11,10 +11,10 @@
#include "sandbox_types.h" #include "sandbox_types.h"
static inline void static inline void
sandbox_set_as_running_kernel(struct sandbox *sandbox, sandbox_state_t last_state) sandbox_set_as_running_sys(struct sandbox *sandbox, sandbox_state_t last_state)
{ {
assert(sandbox); assert(sandbox);
sandbox->state = SANDBOX_RUNNING_KERNEL; sandbox->state = SANDBOX_RUNNING_SYS;
uint64_t now = __getcycles(); uint64_t now = __getcycles();
switch (last_state) { switch (last_state) {
@ -39,7 +39,14 @@ sandbox_set_as_running_kernel(struct sandbox *sandbox, sandbox_state_t last_stat
/* State Change Bookkeeping */ /* State Change Bookkeeping */
sandbox->duration_of_state[last_state] += (now - sandbox->timestamp_of.last_state_change); sandbox->duration_of_state[last_state] += (now - sandbox->timestamp_of.last_state_change);
sandbox->timestamp_of.last_state_change = now; sandbox->timestamp_of.last_state_change = now;
sandbox_state_history_append(sandbox, SANDBOX_RUNNING_KERNEL); sandbox_state_history_append(sandbox, SANDBOX_RUNNING_SYS);
runtime_sandbox_total_increment(SANDBOX_RUNNING_KERNEL); runtime_sandbox_total_increment(SANDBOX_RUNNING_SYS);
runtime_sandbox_total_decrement(last_state); runtime_sandbox_total_decrement(last_state);
} }
static inline void
sandbox_interrupt(struct sandbox *sandbox)
{
assert(sandbox->state == SANDBOX_RUNNING_USER);
sandbox_set_as_running_sys(sandbox, SANDBOX_RUNNING_USER);
}

@ -18,7 +18,7 @@ sandbox_set_as_running_user(struct sandbox *sandbox, sandbox_state_t last_state)
uint64_t now = __getcycles(); uint64_t now = __getcycles();
switch (last_state) { switch (last_state) {
case SANDBOX_RUNNING_KERNEL: { case SANDBOX_RUNNING_SYS: {
assert(sandbox == current_sandbox_get()); assert(sandbox == current_sandbox_get());
assert(runtime_worker_threads_deadline[worker_thread_idx] == sandbox->absolute_deadline); assert(runtime_worker_threads_deadline[worker_thread_idx] == sandbox->absolute_deadline);
break; break;
@ -46,3 +46,10 @@ sandbox_set_as_running_user(struct sandbox *sandbox, sandbox_state_t last_state)
* is preemptable */ * is preemptable */
sandbox->state = SANDBOX_RUNNING_USER; sandbox->state = SANDBOX_RUNNING_USER;
} }
static inline void
sandbox_return(struct sandbox *sandbox)
{
assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_set_as_running_user(sandbox, SANDBOX_RUNNING_SYS);
}

@ -13,7 +13,7 @@ typedef enum
SANDBOX_INITIALIZED, SANDBOX_INITIALIZED,
SANDBOX_RUNNABLE, SANDBOX_RUNNABLE,
SANDBOX_PREEMPTED, SANDBOX_PREEMPTED,
SANDBOX_RUNNING_KERNEL, SANDBOX_RUNNING_SYS,
SANDBOX_RUNNING_USER, SANDBOX_RUNNING_USER,
SANDBOX_ASLEEP, SANDBOX_ASLEEP,
SANDBOX_RETURNED, SANDBOX_RETURNED,

@ -18,7 +18,7 @@
#include "sandbox_types.h" #include "sandbox_types.h"
#include "sandbox_set_as_preempted.h" #include "sandbox_set_as_preempted.h"
#include "sandbox_set_as_runnable.h" #include "sandbox_set_as_runnable.h"
#include "sandbox_set_as_running_kernel.h" #include "sandbox_set_as_running_sys.h"
#include "sandbox_set_as_running_user.h" #include "sandbox_set_as_running_user.h"
#include "scheduler_execute_epoll_loop.h" #include "scheduler_execute_epoll_loop.h"
@ -188,7 +188,7 @@ scheduler_preemptive_switch_to(ucontext_t *interrupted_context, struct sandbox *
case ARCH_CONTEXT_VARIANT_FAST: { case ARCH_CONTEXT_VARIANT_FAST: {
assert(next->state == SANDBOX_RUNNABLE); assert(next->state == SANDBOX_RUNNABLE);
arch_context_restore_fast(&interrupted_context->uc_mcontext, &next->ctxt); arch_context_restore_fast(&interrupted_context->uc_mcontext, &next->ctxt);
sandbox_set_as_running_kernel(next, SANDBOX_RUNNABLE); sandbox_set_as_running_sys(next, SANDBOX_RUNNABLE);
break; break;
} }
case ARCH_CONTEXT_VARIANT_SLOW: { case ARCH_CONTEXT_VARIANT_SLOW: {
@ -222,12 +222,17 @@ scheduler_preemptive_sched(ucontext_t *interrupted_context)
assert(current != NULL); assert(current != NULL);
assert(current->state == SANDBOX_RUNNING_USER); assert(current->state == SANDBOX_RUNNING_USER);
sandbox_interrupt(current);
struct sandbox *next = scheduler_get_next(); struct sandbox *next = scheduler_get_next();
/* Assumption: the current sandbox is on the runqueue, so the scheduler should always return something */ /* Assumption: the current sandbox is on the runqueue, so the scheduler should always return something */
assert(next != NULL); assert(next != NULL);
/* If current equals next, no switch is necessary, so resume execution */ /* If current equals next, no switch is necessary, so resume execution */
if (current == next) return; if (current == next) {
sandbox_return(current);
return;
}
#ifdef LOG_PREEMPTION #ifdef LOG_PREEMPTION
debuglog("Preempting sandbox %lu to run sandbox %lu\n", current->id, next->id); debuglog("Preempting sandbox %lu to run sandbox %lu\n", current->id, next->id);
@ -236,7 +241,7 @@ scheduler_preemptive_sched(ucontext_t *interrupted_context)
scheduler_log_sandbox_switch(current, next); scheduler_log_sandbox_switch(current, next);
/* Preempt executing sandbox */ /* Preempt executing sandbox */
sandbox_set_as_preempted(current, SANDBOX_RUNNING_USER); sandbox_preempt(current);
arch_context_save_slow(&current->ctxt, &interrupted_context->uc_mcontext); arch_context_save_slow(&current->ctxt, &interrupted_context->uc_mcontext);
scheduler_preemptive_switch_to(interrupted_context, next); scheduler_preemptive_switch_to(interrupted_context, next);
@ -260,7 +265,7 @@ scheduler_cooperative_switch_to(struct sandbox *next_sandbox)
switch (next_sandbox->state) { switch (next_sandbox->state) {
case SANDBOX_RUNNABLE: { case SANDBOX_RUNNABLE: {
assert(next_context->variant == ARCH_CONTEXT_VARIANT_FAST); assert(next_context->variant == ARCH_CONTEXT_VARIANT_FAST);
sandbox_set_as_running_kernel(next_sandbox, SANDBOX_RUNNABLE); sandbox_set_as_running_sys(next_sandbox, SANDBOX_RUNNABLE);
break; break;
} }
case SANDBOX_PREEMPTED: { case SANDBOX_PREEMPTED: {

@ -9,7 +9,7 @@
#include "sandbox_set_as_returned.h" #include "sandbox_set_as_returned.h"
#include "sandbox_set_as_complete.h" #include "sandbox_set_as_complete.h"
#include "sandbox_set_as_running_user.h" #include "sandbox_set_as_running_user.h"
#include "sandbox_set_as_running_kernel.h" #include "sandbox_set_as_running_sys.h"
#include "sandbox_setup_arguments.h" #include "sandbox_setup_arguments.h"
#include "scheduler.h" #include "scheduler.h"
#include "software_interrupt.h" #include "software_interrupt.h"
@ -43,7 +43,7 @@ current_sandbox_sleep()
assert(sandbox != NULL); assert(sandbox != NULL);
switch (sandbox->state) { switch (sandbox->state) {
case SANDBOX_RUNNING_KERNEL: { case SANDBOX_RUNNING_SYS: {
sandbox_sleep(sandbox); sandbox_sleep(sandbox);
break; break;
} }
@ -68,6 +68,8 @@ void
current_sandbox_exit() current_sandbox_exit()
{ {
struct sandbox *sandbox = current_sandbox_get(); struct sandbox *sandbox = current_sandbox_get();
current_sandbox_set(NULL);
assert(sandbox != NULL); assert(sandbox != NULL);
struct arch_context *current_context = &sandbox->ctxt; struct arch_context *current_context = &sandbox->ctxt;
@ -78,43 +80,33 @@ current_sandbox_exit()
switch (sandbox->state) { switch (sandbox->state) {
case SANDBOX_RETURNED: case SANDBOX_RETURNED:
/* sandbox_exit_success(sandbox);
* We draw a distinction between RETURNED and COMPLETED because a sandbox cannot add itself to the
* completion queue
* TODO: I think this executes when running inside the sandbox, as it hasn't yet yielded
* See Issue #224 at https://github.com/gwsystems/sledge-serverless-framework/issues/224
*/
sandbox_set_as_complete(sandbox, SANDBOX_RETURNED);
break; break;
case SANDBOX_ERROR: case SANDBOX_ERROR:
sandbox_exit_error(sandbox);
break; break;
default: default:
panic("Cooperatively switching from a sandbox in a non-terminal %s state\n", panic("Cooperatively switching from a sandbox in a non-terminal %s state\n",
sandbox_state_stringify(sandbox->state)); sandbox_state_stringify(sandbox->state));
} }
/* Do not access sandbox after this, as it is on the completion queue! */
current_sandbox_set(NULL);
/* Assumption: Base Worker context should never be preempted */ /* Assumption: Base Worker context should never be preempted */
assert(worker_thread_base_context.variant == ARCH_CONTEXT_VARIANT_FAST); assert(worker_thread_base_context.variant == ARCH_CONTEXT_VARIANT_FAST);
arch_context_switch(current_context, &worker_thread_base_context); arch_context_switch(current_context, &worker_thread_base_context);
}
/* The schduler should never switch back to completed sandboxes */
assert(0);
}
/** static inline struct sandbox *
* Sandbox execution logic current_sandbox_init()
* Handles setup, request parsing, WebAssembly initialization, function execution, response building and
* sending, and cleanup
*/
void
current_sandbox_start(void)
{ {
struct sandbox *sandbox = current_sandbox_get(); struct sandbox *sandbox = current_sandbox_get();
assert(sandbox != NULL); assert(sandbox != NULL);
assert(sandbox->state == SANDBOX_RUNNING_KERNEL); assert(sandbox->state == SANDBOX_RUNNING_SYS);
char *error_message = ""; int rc = 0;
int rc = 0;
sandbox_open_http(sandbox); sandbox_open_http(sandbox);
@ -133,14 +125,26 @@ current_sandbox_start(void)
module_initialize_globals(current_module); module_initialize_globals(current_module);
module_initialize_memory(current_module); module_initialize_memory(current_module);
sandbox_setup_arguments(sandbox); sandbox_setup_arguments(sandbox);
sandbox_return(sandbox);
return sandbox;
err:
sandbox_close_http(sandbox);
generic_thread_dump_lock_overhead();
current_sandbox_exit();
assert(0);
}
static inline void
current_sandbox_fini()
{
struct sandbox *sandbox = current_sandbox_get();
assert(sandbox != NULL);
char *error_message = "";
sandbox_interrupt(sandbox);
/* Executing the function */
int32_t argument_count = 0;
assert(sandbox->state == SANDBOX_RUNNING_KERNEL);
sandbox_set_as_running_user(sandbox, SANDBOX_RUNNING_KERNEL);
sandbox->return_value = module_entrypoint(current_module, argument_count, sandbox->arguments_offset);
assert(sandbox->state == SANDBOX_RUNNING_USER);
sandbox_set_as_running_kernel(sandbox, SANDBOX_RUNNING_USER);
sandbox->timestamp_of.completion = __getcycles(); sandbox->timestamp_of.completion = __getcycles();
/* Retrieve the result, construct the HTTP response, and send to client */ /* Retrieve the result, construct the HTTP response, and send to client */
@ -153,24 +157,34 @@ current_sandbox_start(void)
sandbox->timestamp_of.response = __getcycles(); sandbox->timestamp_of.response = __getcycles();
assert(sandbox->state == SANDBOX_RUNNING_KERNEL); assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_close_http(sandbox); sandbox_close_http(sandbox);
sandbox_set_as_returned(sandbox, SANDBOX_RUNNING_KERNEL); sandbox_set_as_returned(sandbox, SANDBOX_RUNNING_SYS);
done: done:
/* Cleanup connection and exit sandbox */ /* Cleanup connection and exit sandbox */
generic_thread_dump_lock_overhead(); generic_thread_dump_lock_overhead();
current_sandbox_exit(); current_sandbox_exit();
/* This assert prevents a segfault discussed in
* https://github.com/phanikishoreg/awsm-Serverless-Framework/issues/66
*/
assert(0); assert(0);
err: err:
debuglog("%s", error_message); debuglog("%s", error_message);
assert(sandbox->state == SANDBOX_RUNNING_KERNEL); assert(sandbox->state == SANDBOX_RUNNING_SYS);
sandbox_close_http(sandbox); sandbox_close_http(sandbox);
sandbox_set_as_error(sandbox, SANDBOX_RUNNING_KERNEL);
goto done; goto done;
} }
/**
* Sandbox execution logic
* Handles setup, request parsing, WebAssembly initialization, function execution, response building and
* sending, and cleanup
*/
void
current_sandbox_start(void)
{
struct sandbox *sandbox = current_sandbox_init();
struct module * current_module = sandbox_get_module(sandbox);
int32_t argument_count = 0;
sandbox->return_value = module_entrypoint(current_module, argument_count, sandbox->arguments_offset);
current_sandbox_fini();
}

@ -60,7 +60,7 @@ local_runqueue_list_rotate()
if (ps_list_head_one_node(&local_runqueue_list)) return; if (ps_list_head_one_node(&local_runqueue_list)) return;
struct sandbox *sandbox_at_head = local_runqueue_list_remove_and_return(); struct sandbox *sandbox_at_head = local_runqueue_list_remove_and_return();
assert(sandbox_at_head->state == SANDBOX_RUNNING_KERNEL || sandbox_at_head->state == SANDBOX_RUNNABLE assert(sandbox_at_head->state == SANDBOX_RUNNING_SYS || sandbox_at_head->state == SANDBOX_RUNNABLE
|| sandbox_at_head->state == SANDBOX_PREEMPTED); || sandbox_at_head->state == SANDBOX_PREEMPTED);
local_runqueue_list_append(sandbox_at_head); local_runqueue_list_append(sandbox_at_head);
} }

@ -16,7 +16,7 @@ expand_memory(void)
{ {
struct sandbox *sandbox = current_sandbox_get(); struct sandbox *sandbox = current_sandbox_get();
assert(sandbox->state == SANDBOX_RUNNING_USER || sandbox->state == SANDBOX_RUNNING_KERNEL); assert(sandbox->state == SANDBOX_RUNNING_USER || sandbox->state == SANDBOX_RUNNING_SYS);
assert(local_sandbox_context_cache.memory.size % WASM_PAGE_SIZE == 0); assert(local_sandbox_context_cache.memory.size % WASM_PAGE_SIZE == 0);
/* Return -1 if we've hit the linear memory max */ /* Return -1 if we've hit the linear memory max */

@ -9,17 +9,17 @@
const char *sandbox_state_labels[SANDBOX_STATE_COUNT] = { const char *sandbox_state_labels[SANDBOX_STATE_COUNT] = {
[SANDBOX_UNINITIALIZED] = "Uninitialized", [SANDBOX_UNINITIALIZED] = "Uninitialized",
[SANDBOX_ALLOCATED] = "Allocated", [SANDBOX_ALLOCATED] = "Allocated",
[SANDBOX_INITIALIZED] = "Initialized", [SANDBOX_INITIALIZED] = "Initialized",
[SANDBOX_RUNNABLE] = "Runnable", [SANDBOX_RUNNABLE] = "Runnable",
[SANDBOX_PREEMPTED] = "Preempted", [SANDBOX_PREEMPTED] = "Preempted",
[SANDBOX_RUNNING_KERNEL] = "Running Kernel", [SANDBOX_RUNNING_SYS] = "Running Kernel",
[SANDBOX_RUNNING_USER] = "Running User", [SANDBOX_RUNNING_USER] = "Running User",
[SANDBOX_ASLEEP] = "Asleep", [SANDBOX_ASLEEP] = "Asleep",
[SANDBOX_RETURNED] = "Returned", [SANDBOX_RETURNED] = "Returned",
[SANDBOX_COMPLETE] = "Complete", [SANDBOX_COMPLETE] = "Complete",
[SANDBOX_ERROR] = "Error" [SANDBOX_ERROR] = "Error"
}; };
#ifdef LOG_SANDBOX_COUNT #ifdef LOG_SANDBOX_COUNT

@ -18,7 +18,6 @@
#include "module.h" #include "module.h"
#include "panic.h" #include "panic.h"
#include "runtime.h" #include "runtime.h"
#include "sandbox_set_as_running_kernel.h"
#include "sandbox_set_as_running_user.h" #include "sandbox_set_as_running_user.h"
#include "sandbox_types.h" #include "sandbox_types.h"
#include "scheduler.h" #include "scheduler.h"

Loading…
Cancel
Save