Liblor / advanced_operating_systems_2020

Advanced Operating System Course at ETHZ
MIT License
19 stars 3 forks source link

Decrease Busy Waiting time when no URPC events are available #139

Closed abertschi closed 4 years ago

abertschi commented 4 years ago

During implementation of the lpuart driver in userspace I run into issues with our current approach to handle urpc events. With event_dispatch_non_block lpuart interrupts seemed to get stuck and not delivered. Debugging showed that the issue only occurs if events in default_waitset are process with event_dispatch_non_block instead of event_dispatch.

I further noticed that we do alot of busy waiting in the main loop as urpc events do not occur so often. This interferes with how interrupts are delivered to my lpuart module and causes keystrokes to be lost and no more interrupts to arrive.

    // Hang around
    struct waitset *default_ws = get_default_waitset();
    while (true) {
        err = initserver_serve_next();
        if (err_is_fail(err)) {
            DEBUG_ERR(err, "in initserver_serve_next");
            abort();
        }

    // ...

        err = event_dispatch_non_block(default_ws);
        if (err != LIB_ERR_NO_EVENT &&  err_is_fail(err)) {
            DEBUG_ERR(err, "in event_dispatch");
            abort();
        }
    }

To reduce busy waiting time, I introduce a periodic event which queries urpc events every N microseconds. Currently set to 1000. This allows us to process events in the main loop in a blocking manner and only process events when there are events due.

I applied the same principle for the thread which busy waits for local tasks in the monitor.

These changes have rather significant impact on performance. rpc-test.c now spawns dispatchers much faster.