Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions benchmarks/stack-usage/callee.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "callee.h"
#include "../timing.h"

int noop_return(size_t s)
{
use_stack(s);
return rdcycle();
}

int noop_call(int start)
{
int end = rdcycle();
check_stack_zeroed();
return end - start;
}
4 changes: 4 additions & 0 deletions benchmarks/stack-usage/callee.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <compartment.h>

int __cheri_compartment("callee") noop_return(size_t s);
int __cheri_compartment("callee") noop_call(int start);
22 changes: 22 additions & 0 deletions benchmarks/stack-usage/caller.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "../timing.h"
#include "callee.h"
#include <compartment.h>
#include <locks.hh>

void __cheri_compartment("caller") run()
{
MessageBuilder<ImplicitUARTOutput> out;
out.format("#board\tstack_use\tcall\treturn\n");
for (size_t s = 1; s < 0x1000; s <<= 1)
{
auto [callPath, returnPath] = CHERI::with_interrupts_disabled([&]() {
use_stack(s);
auto callPath = noop_call(rdcycle());
auto returnPath = noop_return(s);
returnPath = rdcycle() - returnPath;
check_stack_zeroed();
return std::tuple{callPath, returnPath};
});
out.format(__XSTRING(BOARD) "\t{}\t{}\t{}\n", s, callPath, returnPath);
}
}
39 changes: 39 additions & 0 deletions benchmarks/stack-usage/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Copyright Microsoft and CHERIoT Contributors.
-- SPDX-License-Identifier: MIT

set_project("CHERIoT stack-usage benchmark");
sdkdir = "../../sdk"
includes(sdkdir)
set_toolchains("cheriot-clang")

-- Support libraries
includes(path.join(sdkdir, "lib/freestanding"),
path.join(sdkdir, "lib/atomic"),
path.join(sdkdir, "lib/crt"))

option("board")
set_default("sail")

compartment("callee")
add_files("callee.cc")

compartment("caller")
add_defines("BOARD=" .. tostring(get_config("board")))
add_files("caller.cc")

-- Firmware image for the example.
firmware("stack-usage-benchmark")
add_deps("crt", "freestanding", "atomic")
add_deps("caller", "callee")
on_load(function(target)
target:values_set("board", "$(board)")
target:values_set("threads", {
{
compartment = "caller",
priority = 1,
entry_point = "run",
stack_size = 0x1000,
trusted_stack_frames = 3
}
}, {expand = false})
end)
24 changes: 24 additions & 0 deletions benchmarks/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,28 @@ namespace
CHERI::Capability stack{cspRegister};
return stack.length();
}

void use_stack(size_t s)
{
volatile uint8_t stack_array[s];
stack_array[0] = 1;
}

void check_stack_zeroed()
{
register void **cspRegister asm("csp");
asm("" : "=C"(cspRegister));
CHERI::Capability stack{cspRegister};
CHERI::Capability<void*> stackP{stack};
stackP.address() = stack.base();
while(stackP.address() < stack.address())
{
CHERI::Capability<void> value{*stackP};
if (value != NULL)
{
__builtin_trap();
}
stackP += 1;
}
}
} // namespace