Changeset 3679f51a in mainline


Ignore:
Timestamp:
2018-06-25T20:41:09Z (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:
95838f1
Parents:
d73d992
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-25 20:30:35)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-25 20:41:09)
Message:

Remove the option of RCU-upgradable futexes for now.
They complicate threading design too much.

Location:
uspace/lib/c
Files:
7 edited

Legend:

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

    rd73d992 r3679f51a  
    5151#include "private/fibril.h"
    5252
    53 #ifdef FUTEX_UPGRADABLE
    54 #include <rcu.h>
    55 #endif
    5653
    5754/**
     
    7875
    7976        fibril_t *fibril = fibril_self();
    80 
    81 #ifdef FUTEX_UPGRADABLE
    82         rcu_register_fibril();
    83 #endif
    8477
    8578        /* Call the implementing function. */
     
    203196                break;
    204197        }
    205 
    206 #ifdef FUTEX_UPGRADABLE
    207         if (stype == FIBRIL_FROM_DEAD) {
    208                 rcu_deregister_fibril();
    209         }
    210 #endif
    211198
    212199        /* Swap to the next fibril. */
  • uspace/lib/c/generic/futex.c

    rd73d992 r3679f51a  
    4747}
    4848
    49 
    50 #ifdef FUTEX_UPGRADABLE
    51 
    52 int _upgrade_futexes = 0;
    53 static futex_t upg_and_wait_futex = FUTEX_INITIALIZER;
    54 
    55 void futex_upgrade_all_and_wait(void)
    56 {
    57         futex_down(&upg_and_wait_futex);
    58 
    59         if (!_upgrade_futexes) {
    60                 rcu_assign(_upgrade_futexes, 1);
    61                 _rcu_synchronize(BM_BLOCK_THREAD);
    62         }
    63 
    64         futex_up(&upg_and_wait_futex);
    65 }
    66 
    67 #endif
    68 
    6949/** @}
    7050 */
  • uspace/lib/c/generic/libc.c

    rd73d992 r3679f51a  
    5757#include "private/fibril.h"
    5858
    59 #ifdef FUTEX_UPGRADABLE
    60 #include <rcu.h>
    61 #endif
    62 
    6359#ifdef CONFIG_RTLD
    6460#include <rtld/rtld.h>
     
    9086
    9187        __tcb_set(fibril->tcb);
    92 
    93 
    94 #ifdef FUTEX_UPGRADABLE
    95         rcu_register_fibril();
    96 #endif
    9788
    9889        __async_server_init();
  • uspace/lib/c/generic/rcu.c

    rd73d992 r3679f51a  
    150150
    151151
    152 static void wait_for_readers(size_t reader_group, blocking_mode_t blocking_mode);
     152static void wait_for_readers(size_t reader_group);
    153153static void force_mb_in_all_threads(void);
    154154static bool is_preexisting_reader(const fibril_rcu_data_t *fib, size_t group);
    155155
    156 static void lock_sync(blocking_mode_t blocking_mode);
     156static void lock_sync(void);
    157157static void unlock_sync(void);
    158 static void sync_sleep(blocking_mode_t blocking_mode);
     158static void sync_sleep(void);
    159159
    160160static bool is_in_group(size_t nesting_cnt, size_t group);
     
    242242
    243243/** Blocks until all preexisting readers exit their critical sections. */
    244 void _rcu_synchronize(blocking_mode_t blocking_mode)
     244void rcu_synchronize(void)
    245245{
    246246        assert(!rcu_read_locked());
     
    252252        size_t gp_in_progress = ACCESS_ONCE(rcu.cur_gp);
    253253
    254         lock_sync(blocking_mode);
     254        lock_sync();
    255255
    256256        /*
     
    300300
    301301        size_t new_reader_group = get_other_group(rcu.reader_group);
    302         wait_for_readers(new_reader_group, blocking_mode);
     302        wait_for_readers(new_reader_group);
    303303
    304304        /* Separates waiting for readers in new_reader_group from group flip. */
     
    312312        memory_barrier();
    313313
    314         wait_for_readers(old_reader_group, blocking_mode);
     314        wait_for_readers(old_reader_group);
    315315
    316316        /* MB_FORCE_U  */
     
    332332
    333333/** Waits for readers of reader_group to exit their readers sections. */
    334 static void wait_for_readers(size_t reader_group, blocking_mode_t blocking_mode)
     334static void wait_for_readers(size_t reader_group)
    335335{
    336336        futex_down(&rcu.list_futex);
     
    346346                        if (is_preexisting_reader(fib, reader_group)) {
    347347                                futex_up(&rcu.list_futex);
    348                                 sync_sleep(blocking_mode);
     348                                sync_sleep();
    349349                                futex_down(&rcu.list_futex);
    350350                                /* Break to while loop. */
     
    361361}
    362362
    363 static void lock_sync(blocking_mode_t blocking_mode)
     363static void lock_sync(void)
    364364{
    365365        futex_down(&rcu.sync_lock.futex);
    366366        if (rcu.sync_lock.locked) {
    367                 if (blocking_mode == BM_BLOCK_FIBRIL) {
    368                         blocked_fibril_t blocked_fib;
    369                         blocked_fib.id = fibril_get_id();
    370 
    371                         list_append(&blocked_fib.link, &rcu.sync_lock.blocked_fibrils);
    372 
    373                         do {
    374                                 blocked_fib.is_ready = false;
    375                                 futex_up(&rcu.sync_lock.futex);
    376                                 fibril_switch(FIBRIL_TO_MANAGER);
    377                                 futex_down(&rcu.sync_lock.futex);
    378                         } while (rcu.sync_lock.locked);
    379 
    380                         list_remove(&blocked_fib.link);
    381                         rcu.sync_lock.locked = true;
    382                 } else {
    383                         assert(blocking_mode == BM_BLOCK_THREAD);
    384                         rcu.sync_lock.blocked_thread_cnt++;
     367                blocked_fibril_t blocked_fib;
     368                blocked_fib.id = fibril_get_id();
     369
     370                list_append(&blocked_fib.link, &rcu.sync_lock.blocked_fibrils);
     371
     372                do {
     373                        blocked_fib.is_ready = false;
    385374                        futex_up(&rcu.sync_lock.futex);
    386                         futex_down(&rcu.sync_lock.futex_blocking_threads);
    387                 }
     375                        fibril_switch(FIBRIL_TO_MANAGER);
     376                        futex_down(&rcu.sync_lock.futex);
     377                } while (rcu.sync_lock.locked);
     378
     379                list_remove(&blocked_fib.link);
     380                rcu.sync_lock.locked = true;
    388381        } else {
    389382                rcu.sync_lock.locked = true;
     
    420413}
    421414
    422 static void sync_sleep(blocking_mode_t blocking_mode)
     415static void sync_sleep(void)
    423416{
    424417        assert(rcu.sync_lock.locked);
     
    428421         */
    429422        futex_up(&rcu.sync_lock.futex);
    430 
    431         if (blocking_mode == BM_BLOCK_FIBRIL) {
    432                 async_usleep(RCU_SLEEP_MS * 1000);
    433         } else {
    434                 thread_usleep(RCU_SLEEP_MS * 1000);
    435         }
    436 
     423        async_usleep(RCU_SLEEP_MS * 1000);
    437424        futex_down(&rcu.sync_lock.futex);
    438425}
  • uspace/lib/c/generic/thread.c

    rd73d992 r3679f51a  
    4848#include "private/fibril.h"
    4949
    50 #ifdef FUTEX_UPGRADABLE
    51 #include <rcu.h>
    52 #endif
    53 
    54 
    5550/** Main thread function.
    5651 *
     
    6964
    7065        __tcb_set(fibril->tcb);
    71 
    72 #ifdef FUTEX_UPGRADABLE
    73         rcu_register_fibril();
    74         futex_upgrade_all_and_wait();
    75 #endif
    7666
    7767        uarg->uspace_thread_function(uarg->uspace_thread_arg);
     
    8575        /* If there is a manager, destroy it */
    8676        async_destroy_manager();
    87 
    88 #ifdef FUTEX_UPGRADABLE
    89         rcu_deregister_fibril();
    90 #endif
    9177
    9278        fibril_teardown(fibril, false);
  • uspace/lib/c/include/futex.h

    rd73d992 r3679f51a  
    4242typedef struct futex {
    4343        atomic_t val;
    44 #ifdef FUTEX_UPGRADABLE
    45         int upgraded;
    46 #endif
    4744} futex_t;
    48 
    4945
    5046extern void futex_initialize(futex_t *futex, int value);
    5147
    52 #ifdef FUTEX_UPGRADABLE
    53 #include <rcu.h>
    54 
    55 #define FUTEX_INITIALIZE(val) {{ (val) }, 0}
    56 
    57 #define futex_lock(fut) \
    58 ({ \
    59         rcu_read_lock(); \
    60         (fut)->upgraded = rcu_access(_upgrade_futexes); \
    61         if ((fut)->upgraded) \
    62                 (void) futex_down((fut)); \
    63 })
    64 
    65 #define futex_trylock(fut) \
    66 ({ \
    67         rcu_read_lock(); \
    68         int _upgraded = rcu_access(_upgrade_futexes); \
    69         if (_upgraded) { \
    70                 int _acquired = futex_trydown((fut)); \
    71                 if (!_acquired) { \
    72                         rcu_read_unlock(); \
    73                 } else { \
    74                         (fut)->upgraded = true; \
    75                 } \
    76                 _acquired; \
    77         } else { \
    78                 (fut)->upgraded = false; \
    79                 1; \
    80         } \
    81 })
    82 
    83 #define futex_unlock(fut) \
    84 ({ \
    85         if ((fut)->upgraded) \
    86                 (void) futex_up((fut)); \
    87         rcu_read_unlock(); \
    88 })
    89 
    90 extern int _upgrade_futexes;
    91 
    92 extern void futex_upgrade_all_and_wait(void);
    93 
    94 #else
    95 
    9648#define FUTEX_INITIALIZE(val) {{ (val) }}
     49#define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    9750
    9851#define futex_lock(fut)     (void) futex_down((fut))
    9952#define futex_trylock(fut)  futex_trydown((fut))
    10053#define futex_unlock(fut)   (void) futex_up((fut))
    101 
    102 #endif
    103 
    104 #define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    10554
    10655/** Try to down the futex.
  • uspace/lib/c/include/rcu.h

    rd73d992 r3679f51a  
    9292#define rcu_access(ptr) ACCESS_ONCE(ptr)
    9393
    94 typedef enum blocking_mode {
    95         BM_BLOCK_FIBRIL,
    96         BM_BLOCK_THREAD
    97 } blocking_mode_t;
    98 
    9994extern void rcu_register_fibril(void);
    10095extern void rcu_deregister_fibril(void);
     
    105100extern bool rcu_read_locked(void);
    106101
    107 #define rcu_synchronize() _rcu_synchronize(BM_BLOCK_FIBRIL)
    108 
    109 extern void _rcu_synchronize(blocking_mode_t);
     102extern void rcu_synchronize(void);
    110103
    111104#endif
Note: See TracChangeset for help on using the changeset viewer.