simply allows setting up and execution of a handler in the context of a specified CPU, the handler is defined staticly in compile time, and is invoked when the worker_item is signaled for a specied CPU.
doesn't use locks to avoid unnecessary contention.
needed for the per-cpu memory allocator, instead of creating additional n threads (per each cpu), the plan is to define and register a simple handler (lambda function).
example of usage:
void say_hello() { debug("Hello, world!"); }
// define hello_tester as a worker_item PCPU_WORKERITEM(hello_tester, [] { say_hello(); });
. . .
// anywhere in the code: hello_tester.signal(sched::cpus[1]);
// will invoke say_hello() in the context of cpu 1
Thanks to Avi for adding code that I was able to copy & paste :)
45e4042 pcpu-worker: add a per cpu worker thread that can execute work items
arch/x64/loader.ld | 5 ++
build.mk | 1 +
core/percpu-worker.cc | 120 ++++++++++++++++++++++++++++++++++++++++++
include/osv/percpu-worker.hh | 43 +++++++++++++++
4 files changed, 169 insertions(+)
Upstream: github.com