~maelkum/viuavm

38432debfc48c37eb51977427dd81b7f9bed42b1 — Marek Marecki 5 months ago 74fe9b8 master
Set thread names

This makes it easier to see which thread is which when inspecting the VM
in GDB.
3 files changed, 10 insertions(+), 0 deletions(-)

M src/kernel/kernel.cpp
M src/scheduler/io/scheduler.cpp
M src/scheduler/process.cpp
M src/kernel/kernel.cpp => src/kernel/kernel.cpp +3 -0
@@ 789,6 789,9 @@ viua::kernel::Kernel::Kernel()
            &foreign_functions_mutex,
            &foreign_call_queue_mutex,
            &foreign_call_queue_condition));
        pthread_setname_np(
              foreign_call_workers.back()->native_handle()
            , ("ffi." + std::to_string(ffi_schedulers_limit - i)).c_str());
    }

    auto const io_schedulers_limit = no_of_io_schedulers();

M src/scheduler/io/scheduler.cpp => src/scheduler/io/scheduler.cpp +3 -0
@@ 17,6 17,7 @@
 *  along with Viua VM.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <pthread.h>
#include <chrono>
#include <condition_variable>
#include <iostream>


@@ 43,6 44,8 @@ void viua::scheduler::io::io_scheduler(
    std::mutex& io_request_mutex,
    std::condition_variable& io_request_cv)
{
    pthread_setname_np(pthread_self(), ("io." + std::to_string(scheduler_id)).c_str());

    auto local_interactions = std::deque<std::unique_ptr<IO_interaction>>{};

    while (true) {

M src/scheduler/process.cpp => src/scheduler/process.cpp +4 -0
@@ 17,6 17,7 @@
 *  along with Viua VM.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <pthread.h>
#include <iomanip>
#include <mutex>
#include <viua/kernel/kernel.h>


@@ 393,6 394,9 @@ template<typename T> struct deferred {
auto Process_scheduler::launch() -> void
{
    scheduler_thread = std::thread([this] { (*this)(); });
    pthread_setname_np(
        scheduler_thread.native_handle()
        , ("proc." + std::to_string(assigned_id)).c_str());
}
auto Process_scheduler::operator()() -> void
{