Changeset 0ca7286 in mainline for uspace/app/trace/ipcp.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (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:
2732c94
Parents:
1c1da4b
Message:

Added resizing to user space (single-threaded) hash_table. Resizes in a way to mitigate effects of bad hash functions. Change of interface affected many files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/trace/ipcp.c

    r1c1da4b r0ca7286  
    3838#include <sys/typefmt.h>
    3939#include <abi/ipc/methods.h>
     40#include <macros.h>
    4041#include "ipc_desc.h"
    4142#include "proto.h"
     
    6465int have_conn[MAX_PHONE];
    6566
    66 #define PCALL_TABLE_CHAINS 32
    67 hash_table_t pending_calls;
     67static hash_table_t pending_calls;
    6868
    6969/*
     
    7373proto_t *proto_unknown;         /**< Protocol with no known methods. */
    7474
    75 static hash_index_t pending_call_hash(unsigned long key[]);
    76 static int pending_call_compare(unsigned long key[], hash_count_t keys,
    77     link_t *item);
    78 static void pending_call_remove_callback(link_t *item);
    79 
    80 hash_table_operations_t pending_call_ops = {
     75static size_t pending_call_key_hash(unsigned long key[]);
     76static size_t pending_call_hash(const link_t *item);
     77static bool pending_call_match(unsigned long key[], size_t keys,
     78    const link_t *item);
     79
     80static hash_table_ops_t pending_call_ops = {
    8181        .hash = pending_call_hash,
    82         .compare = pending_call_compare,
    83         .remove_callback = pending_call_remove_callback
     82        .key_hash = pending_call_key_hash,
     83        .match = pending_call_match,
     84        .equal = 0,
     85        .remove_callback = 0
    8486};
    8587
    8688
    87 static hash_index_t pending_call_hash(unsigned long key[])
    88 {
    89 //      printf("pending_call_hash\n");
    90         return key[0] % PCALL_TABLE_CHAINS;
    91 }
    92 
    93 static int pending_call_compare(unsigned long key[], hash_count_t keys,
    94     link_t *item)
    95 {
    96         pending_call_t *hs;
    97 
    98 //      printf("pending_call_compare\n");
    99         hs = hash_table_get_instance(item, pending_call_t, link);
    100 
    101         // FIXME: this will fail if sizeof(long) < sizeof(void *).
    102         return key[0] == hs->call_hash;
    103 }
    104 
    105 static void pending_call_remove_callback(link_t *item)
    106 {
    107 //      printf("pending_call_remove_callback\n");
    108 }
     89static size_t pending_call_key_hash(unsigned long key[])
     90{
     91        size_t hash = 17;
     92        hash = 31 * hash + key[1];
     93        hash = 31 * hash + key[0];
     94        return hash;
     95}
     96
     97static size_t pending_call_hash(const link_t *item)
     98{
     99        pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
     100        unsigned long key[] = {
     101                LOWER32(hs->call_hash),
     102                UPPER32(hs->call_hash)
     103        };
     104        return pending_call_key_hash(key);
     105}
     106
     107static bool pending_call_match(unsigned long key[], size_t keys,
     108        const link_t *item)
     109{
     110        assert(keys == 2);
     111        pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
     112
     113        return MERGE_LOUP32(key[0], key[1]) == hs->call_hash;
     114}
     115
    109116
    110117
     
    177184        }
    178185
    179         hash_table_create(&pending_calls, PCALL_TABLE_CHAINS, 1, &pending_call_ops);
     186        hash_table_create(&pending_calls, 0, 2, &pending_call_ops);
    180187}
    181188
     
    190197        pending_call_t *pcall;
    191198        proto_t *proto;
    192         unsigned long key[1];
    193199        oper_t *oper;
    194200        sysarg_t *args;
     
    254260        pcall->oper = oper;
    255261
    256         key[0] = hash;
    257 
    258         hash_table_insert(&pending_calls, key, &pcall->link);
     262        hash_table_insert(&pending_calls, &pcall->link);
    259263}
    260264
     
    336340        link_t *item;
    337341        pending_call_t *pcall;
    338         unsigned long key[1];
    339342       
    340343        if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) {
     
    347350       
    348351        hash = hash & ~IPC_CALLID_ANSWERED;
    349         key[0] = hash;
     352        unsigned long key[] = {
     353                LOWER32(hash),
     354                UPPER32(hash)
     355        };
    350356       
    351357        item = hash_table_find(&pending_calls, key);
     
    358364       
    359365        pcall = hash_table_get_instance(item, pending_call_t, link);
    360         hash_table_remove(&pending_calls, key, 1);
     366        hash_table_remove(&pending_calls, key, 2);
    361367       
    362368        parse_answer(hash, pcall, call);
Note: See TracChangeset for help on using the changeset viewer.