From 248caaf27eb67556aea23c3ceff204237d4df9c3 Mon Sep 17 00:00:00 2001 From: superfunc Date: Fri, 15 Sep 2017 12:49:00 -0700 Subject: [PATCH 1/2] Update docs on assignment operator (#6373) --- doc/manual/types.txt | 3 +-- doc/tut1.rst | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doc/manual/types.txt b/doc/manual/types.txt index e6875f2df..2c4b019ad 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -570,8 +570,7 @@ order. The *names* of the fields also have to be identical. The assignment operator for tuples copies each component. The default assignment operator for objects copies each component. Overloading -of the assignment operator for objects is not possible, but this will change -in future versions of the compiler. +of the assignment operator is described in `type-bound-operations-operator`_. .. code-block:: nim diff --git a/doc/tut1.rst b/doc/tut1.rst index 89893a39a..be5cd8c11 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -185,9 +185,8 @@ to a storage location: var x = "abc" # introduces a new variable `x` and assigns a value to it x = "xyz" # assigns a new value to `x` -``=`` is the *assignment operator*. The assignment operator cannot be -overloaded, overwritten or forbidden, but this might change in a future version -of Nim. You can declare multiple variables with a single assignment +``=`` is the *assignment operator*. The assignment operator can be +overloaded. You can declare multiple variables with a single assignment statement and all the variables will have the same value: .. code-block:: From 9258672cee32ca82fcf1494447cd9020602df567 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 16 Sep 2017 01:02:59 -0500 Subject: [PATCH 2/2] balance Genode CPU pinning, deadlock at Genode exit (#6317) * Genode: balance thread CPU affinities Genode threads are pinned by defaut to the same CPU as the initial component entrypoint thread. Thread affinities are also permanent. This patch pins new threads to CPUs in a round-robin manner. Arbitrary CPU pinning is not exposed and the 'nimPinToCpu' has no effect. * Genode: guarantee that 'quit' will not return On Genode exits are handled by whatever component is acting as parent. The caller has no guarentee that the parent implementation will halt the caller's threads, so explicitly deadlock the 'quit' procedure. --- lib/genode_cpp/threads.h | 12 ++++++++---- lib/system.nim | 3 ++- lib/system/threads.nim | 9 +++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/genode_cpp/threads.h b/lib/genode_cpp/threads.h index 043f808f1..a7cb2f17b 100644 --- a/lib/genode_cpp/threads.h +++ b/lib/genode_cpp/threads.h @@ -31,8 +31,12 @@ struct Nim::SysThread void entry() override { (_func)(_arg); } - Thread(Genode::Env &env, Genode::size_t stack_size, Entry func, void *arg) - : Genode::Thread(env, "nim-thread", stack_size), _func(func), _arg(arg) + Thread(Genode::Env &env, Genode::size_t stack_size, Entry func, void *arg, int affinity) + : Genode::Thread(env, "nim-thread", stack_size, + env.cpu().affinity_space().location_of_index(affinity), + Genode::Cpu_session::Weight(Genode::Cpu_session::Weight::DEFAULT_WEIGHT-1), + env.cpu()), + _func(func), _arg(arg) { Genode::Thread::start(); } @@ -40,8 +44,8 @@ struct Nim::SysThread Genode::Constructible _thread; - void initThread(Genode::Env *env, Genode::size_t stack_size, Entry func, void *arg) { - _thread.construct(*env, stack_size, func, arg); } + void initThread(Genode::Env *env, Genode::size_t stack_size, Entry func, void *arg, int aff) { + _thread.construct(*env, stack_size, func, arg, aff); } void joinThread() { _thread->join(); } diff --git a/lib/system.nim b/lib/system.nim index 157f32387..39f65c5a3 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1435,7 +1435,8 @@ when defined(nimdoc): elif defined(genode): proc quit*(errorcode: int = QuitSuccess) {.magic: "Exit", noreturn, - importcpp: "genodeEnv->parent().exit(@)", header: "".} + importcpp: "genodeEnv->parent().exit(@); Genode::sleep_forever()", + header: "".} else: proc quit*(errorcode: int = QuitSuccess) {. diff --git a/lib/system/threads.nim b/lib/system/threads.nim index a7a811844..96c045e6b 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -127,7 +127,8 @@ elif defined(genode): proc initThread(s: var SysThread, stackSize: culonglong, entry: GenodeThreadProc, - arg: pointer) {. + arg: pointer, + affinity: cuint) {. importcpp: "#.initThread(genodeEnv, @)".} proc threadVarAlloc(): ThreadVarSlot = 0 @@ -567,6 +568,9 @@ when hostOS == "windows": setThreadAffinityMask(t.sys, uint(1 shl cpu)) elif defined(genode): + var affinityOffset: cuint = 1 + # CPU affinity offset for next thread, safe to roll-over + proc createThread*[TArg](t: var Thread[TArg], tp: proc (arg: TArg) {.thread, nimcall.}, param: TArg) = @@ -577,7 +581,8 @@ elif defined(genode): when hasSharedHeap: t.stackSize = ThreadStackSize t.sys.initThread( ThreadStackSize.culonglong, - threadProcWrapper[TArg], addr(t)) + threadProcWrapper[TArg], addr(t), affinityOffset) + inc affinityOffset proc pinToCpu*[Arg](t: var Thread[Arg]; cpu: Natural) = {.hint: "cannot change Genode thread CPU affinity after initialization".}