Changeset 42f5860 in mainline


Ignore:
Timestamp:
2018-07-18T19:56:49Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9d8307a
Parents:
9bde0d5
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-13 23:13:27)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-18 19:56:49)
Message:

Clean up userspace RCU.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/rcu.c

    r9bde0d5 r42f5860  
    105105        size_t cur_gp;
    106106        size_t reader_group;
    107         futex_t list_futex;
     107        fibril_rmutex_t list_mutex;
    108108        list_t fibrils_list;
    109109        struct {
    110                 futex_t futex;
     110                fibril_rmutex_t mutex;
    111111                bool locked;
    112112                list_t blocked_fibrils;
    113                 size_t blocked_thread_cnt;
    114                 futex_t futex_blocking_threads;
    115113        } sync_lock;
    116114} rcu_data_t;
     
    137135        .cur_gp = 0,
    138136        .reader_group = RCU_GROUP_A,
    139         .list_futex = FUTEX_INITIALIZER,
     137        .list_mutex = FIBRIL_RMUTEX_INITIALIZER(rcu.list_mutex),
    140138        .fibrils_list = LIST_INITIALIZER(rcu.fibrils_list),
    141139        .sync_lock = {
    142                 .futex = FUTEX_INITIALIZER,
     140                .mutex = FIBRIL_RMUTEX_INITIALIZER(rcu.sync_lock.mutex),
    143141                .locked = false,
    144142                .blocked_fibrils = LIST_INITIALIZER(rcu.sync_lock.blocked_fibrils),
    145                 .blocked_thread_cnt = 0,
    146                 .futex_blocking_threads = FUTEX_INITIALIZE(0),
    147143        },
    148144};
     
    171167        assert(!fibril_rcu.registered);
    172168
    173         futex_lock(&rcu.list_futex);
     169        fibril_rmutex_lock(&rcu.list_mutex);
    174170        list_append(&fibril_rcu.link, &rcu.fibrils_list);
    175         futex_unlock(&rcu.list_futex);
     171        fibril_rmutex_unlock(&rcu.list_mutex);
    176172
    177173        fibril_rcu.registered = true;
     
    196192        fibril_rcu.nesting_cnt = 0;
    197193
    198         futex_lock(&rcu.list_futex);
     194        fibril_rmutex_lock(&rcu.list_mutex);
    199195        list_remove(&fibril_rcu.link);
    200         futex_unlock(&rcu.list_futex);
     196        fibril_rmutex_unlock(&rcu.list_mutex);
    201197
    202198        fibril_rcu.registered = false;
     
    333329static void wait_for_readers(size_t reader_group)
    334330{
    335         futex_lock(&rcu.list_futex);
     331        fibril_rmutex_lock(&rcu.list_mutex);
    336332
    337333        list_t quiescent_fibrils;
     
    344340
    345341                        if (is_preexisting_reader(fib, reader_group)) {
    346                                 futex_unlock(&rcu.list_futex);
     342                                fibril_rmutex_unlock(&rcu.list_mutex);
    347343                                sync_sleep();
    348                                 futex_lock(&rcu.list_futex);
     344                                fibril_rmutex_lock(&rcu.list_mutex);
    349345                                /* Break to while loop. */
    350346                                break;
     
    357353
    358354        list_concat(&rcu.fibrils_list, &quiescent_fibrils);
    359         futex_unlock(&rcu.list_futex);
     355        fibril_rmutex_unlock(&rcu.list_mutex);
    360356}
    361357
    362358static void lock_sync(void)
    363359{
    364         futex_lock(&rcu.sync_lock.futex);
     360        fibril_rmutex_lock(&rcu.sync_lock.mutex);
    365361        if (rcu.sync_lock.locked) {
    366362                blocked_fibril_t blocked_fib;
     
    371367                do {
    372368                        blocked_fib.is_ready = false;
    373                         futex_unlock(&rcu.sync_lock.futex);
     369                        fibril_rmutex_unlock(&rcu.sync_lock.mutex);
    374370                        futex_lock(&async_futex);
    375371                        fibril_switch(FIBRIL_FROM_BLOCKED);
    376372                        futex_unlock(&async_futex);
    377                         futex_lock(&rcu.sync_lock.futex);
     373                        fibril_rmutex_lock(&rcu.sync_lock.mutex);
    378374                } while (rcu.sync_lock.locked);
    379375
     
    389385        assert(rcu.sync_lock.locked);
    390386
    391         /*
    392          * Blocked threads have a priority over fibrils when accessing sync().
    393          * Pass the lock onto a waiting thread.
    394          */
    395         if (0 < rcu.sync_lock.blocked_thread_cnt) {
    396                 --rcu.sync_lock.blocked_thread_cnt;
    397                 futex_unlock(&rcu.sync_lock.futex_blocking_threads);
    398         } else {
    399                 /* Unlock but wake up any fibrils waiting for the lock. */
    400 
    401                 if (!list_empty(&rcu.sync_lock.blocked_fibrils)) {
    402                         blocked_fibril_t *blocked_fib = member_to_inst(
    403                             list_first(&rcu.sync_lock.blocked_fibrils), blocked_fibril_t, link);
    404 
    405                         if (!blocked_fib->is_ready) {
    406                                 blocked_fib->is_ready = true;
    407                                 fibril_add_ready(blocked_fib->id);
    408                         }
     387        /* Unlock but wake up any fibrils waiting for the lock. */
     388
     389        if (!list_empty(&rcu.sync_lock.blocked_fibrils)) {
     390                blocked_fibril_t *blocked_fib = member_to_inst(
     391                    list_first(&rcu.sync_lock.blocked_fibrils), blocked_fibril_t, link);
     392
     393                if (!blocked_fib->is_ready) {
     394                        blocked_fib->is_ready = true;
     395                        fibril_add_ready(blocked_fib->id);
    409396                }
    410 
    411                 rcu.sync_lock.locked = false;
    412                 futex_unlock(&rcu.sync_lock.futex);
    413397        }
     398
     399        rcu.sync_lock.locked = false;
     400        fibril_rmutex_unlock(&rcu.sync_lock.mutex);
    414401}
    415402
     
    421408         * but keep sync locked.
    422409         */
    423         futex_unlock(&rcu.sync_lock.futex);
     410        fibril_rmutex_unlock(&rcu.sync_lock.mutex);
    424411        fibril_usleep(RCU_SLEEP_MS * 1000);
    425         futex_lock(&rcu.sync_lock.futex);
     412        fibril_rmutex_lock(&rcu.sync_lock.mutex);
    426413}
    427414
Note: See TracChangeset for help on using the changeset viewer.