Changeset 82cbf8c6 in mainline for kernel/generic/src/synch/futex.c


Ignore:
Timestamp:
2017-10-08T19:37:24Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2fd26bb
Parents:
81b9d3e
Message:

Replace the old hash table implementation in the kernel with the newer one

This replaces the original hash table implementation with the resizable one
already used in uspace. Along the way, the IRQ hash table code was streamlined
and cleaned up.

File:
1 edited

Legend:

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

    r81b9d3e r82cbf8c6  
    7474#include <genarch/mm/page_ht.h>
    7575#include <adt/cht.h>
     76#include <adt/hash.h>
    7677#include <adt/hash_table.h>
    7778#include <adt/list.h>
     
    8081#include <panic.h>
    8182#include <errno.h>
    82 
    83 #define FUTEX_HT_SIZE   1024    /* keep it a power of 2 */
    8483
    8584/** Task specific pointer to a global kernel futex object. */
     
    108107static bool find_futex_paddr(uintptr_t uaddr, uintptr_t *phys_addr);
    109108
    110 static size_t futex_ht_hash(sysarg_t *key);
    111 static bool futex_ht_compare(sysarg_t *key, size_t keys, link_t *item);
    112 static void futex_ht_remove_callback(link_t *item);
     109static size_t futex_ht_hash(const ht_link_t *item);
     110static size_t futex_ht_key_hash(void *key);
     111static bool futex_ht_key_equal(void *key, const ht_link_t *item);
     112static void futex_ht_remove_callback(ht_link_t *item);
    113113
    114114static size_t task_fut_ht_hash(const cht_link_t *link);
     
    131131
    132132/** Global kernel futex hash table operations. */
    133 static hash_table_operations_t futex_ht_ops = {
     133static hash_table_ops_t futex_ht_ops = {
    134134        .hash = futex_ht_hash,
    135         .compare = futex_ht_compare,
     135        .key_hash = futex_ht_key_hash,
     136        .key_equal = futex_ht_key_equal,
    136137        .remove_callback = futex_ht_remove_callback
    137138};
     
    149150void futex_init(void)
    150151{
    151         hash_table_create(&futex_ht, FUTEX_HT_SIZE, 1, &futex_ht_ops);
     152        hash_table_create(&futex_ht, 0, 0, &futex_ht_ops);
    152153}
    153154
     
    234235{
    235236        waitq_initialize(&futex->wq);
    236         link_initialize(&futex->ht_link);
    237237        futex->paddr = paddr;
    238238        futex->refcount = 1;
     
    256256       
    257257        if (0 == futex->refcount) {
    258                 hash_table_remove(&futex_ht, &futex->paddr, 1);
     258                hash_table_remove(&futex_ht, &futex->paddr);
    259259        }
    260260}
     
    347347        spinlock_lock(&futex_ht_lock);
    348348       
    349         link_t *fut_link = hash_table_find(&futex_ht, &phys_addr);
     349        ht_link_t *fut_link = hash_table_find(&futex_ht, &phys_addr);
    350350       
    351351        if (fut_link) {
     
    355355        } else {
    356356                futex_initialize(futex, phys_addr);
    357                 hash_table_insert(&futex_ht, &phys_addr, &futex->ht_link);
     357                hash_table_insert(&futex_ht, &futex->ht_link);
    358358        }
    359359       
     
    437437
    438438
    439 /** Compute hash index into futex hash table.
    440  *
    441  * @param key           Address where the key (i.e. physical address of futex
    442  *                      counter) is stored.
    443  *
    444  * @return              Index into futex hash table.
    445  */
    446 size_t futex_ht_hash(sysarg_t *key)
    447 {
    448         return (*key & (FUTEX_HT_SIZE - 1));
    449 }
    450 
    451 /** Compare futex hash table item with a key.
    452  *
    453  * @param key           Address where the key (i.e. physical address of futex
    454  *                      counter) is stored.
    455  *
    456  * @return              True if the item matches the key. False otherwise.
    457  */
    458 bool futex_ht_compare(sysarg_t *key, size_t keys, link_t *item)
     439/** Return the hash of the key stored in the item */
     440size_t futex_ht_hash(const ht_link_t *item)
     441{
     442        futex_t *futex = hash_table_get_inst(item, futex_t, ht_link);
     443        return hash_mix(futex->paddr);
     444}
     445
     446/** Return the hash of the key */
     447size_t futex_ht_key_hash(void *key)
     448{
     449        uintptr_t *paddr = (uintptr_t *) key;
     450        return hash_mix(*paddr);
     451}
     452
     453/** Return true if the key is equal to the item's lookup key. */
     454bool futex_ht_key_equal(void *key, const ht_link_t *item)
     455{
     456        uintptr_t *paddr = (uintptr_t *) key;
     457        futex_t *futex = hash_table_get_inst(item, futex_t, ht_link);
     458        return *paddr == futex->paddr;
     459}
     460
     461/** Callback for removal items from futex hash table.
     462 *
     463 * @param item          Item removed from the hash table.
     464 */
     465void futex_ht_remove_callback(ht_link_t *item)
    459466{
    460467        futex_t *futex;
    461468
    462         assert(keys == 1);
    463 
    464         futex = hash_table_get_instance(item, futex_t, ht_link);
    465         return *key == futex->paddr;
    466 }
    467 
    468 /** Callback for removal items from futex hash table.
    469  *
    470  * @param item          Item removed from the hash table.
    471  */
    472 void futex_ht_remove_callback(link_t *item)
    473 {
    474         futex_t *futex;
    475 
    476         futex = hash_table_get_instance(item, futex_t, ht_link);
     469        futex = hash_table_get_inst(item, futex_t, ht_link);
    477470        free(futex);
    478471}
Note: See TracChangeset for help on using the changeset viewer.