Changeset 207e8880 in mainline for kernel/generic/src/synch/futex.c


Ignore:
Timestamp:
2012-12-05T22:36:42Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b1c57a8
Parents:
6a585dd
Message:

futex: Switched from using mutexes to spinlocks in futex subsystem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/futex.c

    r6a585dd r207e8880  
    121121 * Acquire task specific TASK->futex_list_lock before this mutex.
    122122 */
    123 static mutex_t futex_ht_lock;
     123SPINLOCK_STATIC_INITIALIZE_NAME(futex_ht_lock, "futex-ht-lock");
    124124
    125125/** Global kernel futex hash table. Lock futex_ht_lock before accessing.
     
    148148void futex_init(void)
    149149{
    150         mutex_initialize(&futex_ht_lock, MUTEX_PASSIVE);
    151150        hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops);
    152151}
     
    160159       
    161160        list_initialize(&task->futexes->list);
    162         mutex_initialize(&task->futexes->list_lock, MUTEX_PASSIVE);
     161        spinlock_initialize(&task->futexes->list_lock, "futex-list-lock");
    163162}
    164163
     
    206205       
    207206        /* All threads of this task have terminated. This is the last thread. */
    208         mutex_lock(&futexes->list_lock);
     207        spinlock_lock(&futexes->list_lock);
    209208       
    210209        list_foreach_safe(futexes->list, cur_link, next_link) {
     
    222221        }
    223222       
    224         mutex_unlock(&futexes->list_lock);
     223        spinlock_unlock(&futexes->list_lock);
    225224}
    226225
     
    242241static void futex_add_ref(futex_t *futex)
    243242{
    244         ASSERT(mutex_locked(&futex_ht_lock));
     243        ASSERT(spinlock_locked(&futex_ht_lock));
    245244        ASSERT(0 < futex->refcount);
    246245        ++futex->refcount;
     
    250249static void futex_release_ref(futex_t *futex)
    251250{
    252         ASSERT(mutex_locked(&futex_ht_lock));
     251        ASSERT(spinlock_locked(&futex_ht_lock));
    253252        ASSERT(0 < futex->refcount);
    254253       
     
    263262static void futex_release_ref_locked(futex_t *futex)
    264263{
    265         mutex_lock(&futex_ht_lock);
     264        spinlock_lock(&futex_ht_lock);
    266265        futex_release_ref(futex);
    267         mutex_unlock(&futex_ht_lock);
     266        spinlock_unlock(&futex_ht_lock);
    268267}
    269268
     
    278277        uintptr_t paddr;
    279278
    280         if (!find_futex_paddr(uaddr, &paddr))
     279        if (!find_futex_paddr(uaddr, &paddr)) {
    281280                return 0;
     281        }
    282282
    283283        return get_and_cache_futex(paddr, uaddr);
     
    288288static bool find_futex_paddr(uintptr_t uaddr, uintptr_t *paddr)
    289289{
    290         page_table_lock(AS, true);
     290        spinlock_lock(&futex_ht_lock);
     291        page_table_lock(AS, false);
    291292
    292293        bool found = false;
    293         pte_t *t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), false);
     294        pte_t *t = page_mapping_find(AS, ALIGN_DOWN(uaddr, PAGE_SIZE), true);
    294295       
    295296        if (t && PTE_VALID(t) && PTE_PRESENT(t)) {
     
    298299        }
    299300       
    300         page_table_unlock(AS, true);
     301        page_table_unlock(AS, false);
     302        spinlock_unlock(&futex_ht_lock);
    301303       
    302304        return found;
     
    338340         * if it is not present).
    339341         */
    340         mutex_lock(&futex_ht_lock);
     342        spinlock_lock(&futex_ht_lock);
    341343       
    342344        link_t *fut_link = hash_table_find(&futex_ht, &phys_addr);
     
    351353        }
    352354       
    353         mutex_unlock(&futex_ht_lock);
     355        spinlock_unlock(&futex_ht_lock);
    354356       
    355357        /*
     
    366368        /* Cache the mapping from the virtual address to the futex for this task. */
    367369        if (cht_insert_unique(&TASK->futexes->ht, &fut_ptr->cht_link, &dup_link)) {
    368                 mutex_lock(&TASK->futexes->list_lock);
     370                spinlock_lock(&TASK->futexes->list_lock);
    369371                list_append(&fut_ptr->all_link, &TASK->futexes->list);
    370                 mutex_unlock(&TASK->futexes->list_lock);
     372                spinlock_unlock(&TASK->futexes->list_lock);
    371373        } else {
    372374                /* Another thread of this task beat us to it. Use that mapping instead.*/
     
    398400                return (sysarg_t) ENOENT;
    399401
    400 #ifdef CONFIG_UDEBUG
    401         udebug_stoppable_begin();
    402 #endif
    403402        int rc = waitq_sleep_timeout(&futex->wq, 0, SYNCH_FLAGS_INTERRUPTIBLE);
    404 #ifdef CONFIG_UDEBUG
    405         udebug_stoppable_end();
    406 #endif
     403
    407404        return (sysarg_t) rc;
    408405}
Note: See TracChangeset for help on using the changeset viewer.