Changeset 0db0df2 in mainline for kernel


Ignore:
Timestamp:
2025-04-07T17:53:53Z (3 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
45226285, 93de384
Parents:
8f8818ac
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-07 16:41:57)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-07 17:53:53)
Message:

Hash table improvements

Implement hash_table_foreach macro, analogous to list_foreach.

Remove superfluous argument to hash_table_find_next().
(If the user needs to recheck the part of the list already
checked by hash_table_find(), they can just rerun that function.)

Add hash argument to hash_table_ops_t::key_equal.
The big change here is that users with big keys can store the hash
value alongside key in their entries, and for the low low cost of
sizeof(size_t) bytes eliminate a bunch of expensive key comparisons.

Also added a hash function for strings and arbitrary data.
Found this one by asking ChatGPT, because the latency of accesses
to my book collection is currently a couple of hours.

+ Some drive-by unused #include removal.

Location:
kernel
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/page_ht.c

    r8f8818ac r0db0df2  
    5555static size_t ht_hash(const ht_link_t *);
    5656static size_t ht_key_hash(const void *);
    57 static bool ht_key_equal(const void *, const ht_link_t *);
     57static bool ht_key_equal(const void *, size_t, const ht_link_t *);
    5858static void ht_remove_callback(ht_link_t *);
    5959
     
    119119
    120120/** Return true if the key is equal to the item's lookup key. */
    121 bool ht_key_equal(const void *arg, const ht_link_t *item)
     121bool ht_key_equal(const void *arg, size_t hash, const ht_link_t *item)
    122122{
    123123        const uintptr_t *key = arg;
  • kernel/generic/src/cap/cap.c

    r8f8818ac r0db0df2  
    118118}
    119119
    120 static bool caps_key_equal(const void *key, const ht_link_t *item)
     120static bool caps_key_equal(const void *key, size_t hash, const ht_link_t *item)
    121121{
    122122        const cap_handle_t *handle = key;
  • kernel/generic/src/ddi/irq.c

    r8f8818ac r0db0df2  
    7575static size_t irq_ht_key_hash(const void *);
    7676static bool irq_ht_equal(const ht_link_t *, const ht_link_t *);
    77 static bool irq_ht_key_equal(const void *, const ht_link_t *);
     77static bool irq_ht_key_equal(const void *, size_t, const ht_link_t *);
    7878
    7979static const hash_table_ops_t irq_ht_ops = {
     
    141141{
    142142        irq_spinlock_lock(l, false);
    143         ht_link_t *first = hash_table_find(h, &inr);
    144         for (ht_link_t *lnk = first; lnk;
    145             lnk = hash_table_find_next(h, first, lnk)) {
    146                 irq_t *irq = hash_table_get_inst(lnk, irq_t, link);
     143
     144        hash_table_foreach(h, &inr, link, irq_t, irq) {
    147145                irq_spinlock_lock(&irq->lock, false);
    148146                if (irq->claim(irq) == IRQ_ACCEPT) {
     
    153151                irq_spinlock_unlock(&irq->lock, false);
    154152        }
     153
    155154        irq_spinlock_unlock(l, false);
    156155
     
    223222
    224223/** Return true if the key is equal to the item's lookup key. */
    225 bool irq_ht_key_equal(const void *key, const ht_link_t *item)
     224bool irq_ht_key_equal(const void *key, size_t hash, const ht_link_t *item)
    226225{
    227226        const inr_t *inr = key;
  • kernel/generic/src/lib/ra.c

    r8f8818ac r0db0df2  
    7474
    7575/** Return true if the key is equal to the item's lookup key */
    76 static bool used_key_equal(const void *key, const ht_link_t *item)
     76static bool used_key_equal(const void *key, size_t, const ht_link_t *item)
    7777{
    7878        const uintptr_t *base = key;
Note: See TracChangeset for help on using the changeset viewer.