Show
Ignore:
Timestamp:
03/15/12 14:00:52 (14 months ago)
Author:
walt
Message:

updates to usrint/ucache code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/stable/src/client/usrint/ucache.c

    r9234 r9262  
    811811                    uint16_t k; 
    812812                    for(k = 0; k < MEM_TABLE_HASH_MAX; k++) 
    813                     {    
    814                         if(mtbl->mem[k].tag != NIL64) 
     813                    { 
     814                        if(mtbl->bucket[k] == NIL16) 
     815                            continue; 
     816    
     817                        if(mtbl->mem[mtbl->bucket[k]].tag != NIL64) 
    815818                        { 
    816819                            uint16_t l; 
    817                             for(l = k; !ment_done(l); l = ment_next(mtbl, l)) 
     820                            for(l = mtbl->bucket[k]; !ment_done(l); l = ment_next(mtbl, l)) 
    818821                            { 
    819822                                struct mem_ent_s * ment = &(mtbl->mem[l]); 
     
    841844                            { 
    842845                                fprintf(out, "\tvacant memory entry @ index = %d\n", 
    843                                                                                  k); 
     846                                    mtbl->bucket[k]); 
    844847                            } 
    845848                        } 
     
    11391142    mtbl->dirty_list = NIL16; 
    11401143    mtbl->ref_cnt = 0; 
    1141     /* set up hash table */ 
    1142     for (i = 0; i < MEM_TABLE_HASH_MAX; i++) 
    1143     { 
    1144         rc = init_memory_entry(mtbl, i); 
    1145     } 
    1146     /* set up list of free hash table entries */ 
    1147     mtbl->free_list = MEM_TABLE_HASH_MAX; 
    1148     for (i = MEM_TABLE_HASH_MAX; i < (MEM_TABLE_ENTRY_COUNT - 1); i++) 
     1144 
     1145    /* Initialize Buckets */ 
     1146    for(i = 0; i < MEM_TABLE_HASH_MAX; i++) 
     1147    { 
     1148        mtbl->bucket[i] = NIL16; 
     1149    } 
     1150 
     1151    /* set up free ments */ 
     1152    mtbl->free_list = 0; 
     1153    for(i = 0; i < (MEM_TABLE_ENTRY_COUNT - 1); i++) 
    11491154    { 
    11501155        rc = init_memory_entry(mtbl, i); 
     
    11521157 
    11531158    } 
     1159    /* NIL Terminate the last entries next index */ 
    11541160    rc = init_memory_entry(mtbl, MEM_TABLE_ENTRY_COUNT - 1); 
    11551161    mtbl->mem[MEM_TABLE_ENTRY_COUNT - 1].next = NIL16; 
    11561162} 
    1157  
    11581163 
    11591164/**  
     
    12521257 * Puts the memory entry corresponding to the provided mtbl and entry index  
    12531258 * back on the mtbl's memory entry free list.  
    1254  * 
    1255  * If the entry index is < MEM_TABLE_HASH_MAX, then set next to NIL since this  
    1256  * index must remain the head of the linked list. Otherwise, set next to the  
    1257  * current head of ment free list and set the free list head to the provided  
    1258  * index. 
    12591259 */ 
    12601260static void put_free_ment(struct mem_table_s *mtbl, uint16_t ent) 
     
    12661266    mtbl->mem[ent].lru_prev = NIL16; 
    12671267    mtbl->mem[ent].lru_next = NIL16; 
    1268     if(ent >= MEM_TABLE_HASH_MAX) 
    1269     { 
    1270         /* Set next index to the current head of the free list */ 
    1271         mtbl->mem[ent].next = mtbl->free_list; 
    1272         /* Update free list to include this entry */ 
    1273         mtbl->free_list = ent; 
    1274     } 
     1268    /* Set next index to the current head of the free list */ 
     1269    mtbl->mem[ent].next = mtbl->free_list; 
     1270    /* Update free list to include this entry */ 
     1271    mtbl->free_list = ent; 
    12751272} 
    12761273 
     
    13841381    { 
    13851382        uint16_t j; 
    1386         for(j = i; !ment_done(j); j = ment_next(mtbl, j)) 
     1383        for(j = mtbl->bucket[i]; !ment_done(j); j = ment_next(mtbl, j)) 
    13871384        { 
    13881385            /* Current Memory Entry */ 
     
    16031600    /* index into mem hash table */ 
    16041601    uint16_t index = (uint16_t) ((offset / CACHE_BLOCK_SIZE) % MEM_TABLE_HASH_MAX); 
    1605     //printf("lookup_mem index = %hu\n", index); 
    1606  
    1607     struct mem_ent_s *current = &(mtbl->mem[index]); 
     1602 
     1603    /* If the bucket is empty then go ahead and return */ 
     1604    if(mtbl->bucket[index] == NIL16) 
     1605    { 
     1606        return (struct mem_table_s *)NIL; 
     1607    } 
     1608 
     1609    uint16_t bucket_index = mtbl->bucket[index]; 
     1610    struct mem_ent_s *current = &(mtbl->mem[bucket_index]); 
    16081611 
    16091612    /* previous, current, next memory entry index in mtbl */ 
    16101613    int16_t p = NIL16; 
    1611     int16_t c = index; 
     1614    int16_t c = bucket_index; 
    16121615    int16_t n = current->next;   
    16131616 
     
    18711874{ 
    18721875    void* rc = 0; 
    1873  
    18741876    struct mem_table_s *mtbl = get_mtbl(fent->mtbl_blk, fent->mtbl_ent); 
    1875  
    1876     /* Index into mem hash table */ 
    1877     uint16_t index = (uint16_t) ((offset / CACHE_BLOCK_SIZE) % MEM_TABLE_HASH_MAX); 
    18781877 
    18791878    /* Lookup first */ 
     
    18851884    } 
    18861885 
    1887     /* Entry doesn't exist, insertion required */ 
    1888     struct mem_ent_s *current = &(mtbl->mem[index]); 
    1889     uint16_t mentIndex = 0; 
     1886    /* Index into mem hash table */ 
     1887    /* Hash to a bucket */ 
     1888    uint16_t index = (uint16_t) ((offset / CACHE_BLOCK_SIZE) % MEM_TABLE_HASH_MAX); 
     1889 
    18901890    int evict_rc = 0; 
    1891     if(mtbl->mem[index].tag != NIL64) 
    1892     { 
    1893         /* If head occupied, need to get free ment */ 
     1891    uint16_t mentIndex = get_free_ment(mtbl); 
     1892    if(mentIndex == NIL16) 
     1893    {   /* No free ment available, so attempt eviction, and try again */ 
     1894        evict_rc = evict_LRU(fent); 
    18941895        mentIndex = get_free_ment(mtbl); 
    1895         if(mentIndex == NIL16) 
    1896         {   /* No free ment available, so attempt eviction, and try again */ 
    1897             evict_rc = evict_LRU(fent); 
    1898             mentIndex = get_free_ment(mtbl); 
    1899         } 
    1900         /* Procede with memory insertion if ment aquired */ 
    1901         if(mentIndex != NIL16) 
    1902         {    
    1903             /* Insert directly after head of chain */ 
    1904             uint16_t next_ment = current->next; 
    1905             current->next = mentIndex; 
    1906             mtbl->mem[mentIndex].next = next_ment; 
    1907             rc = set_item(fent, offset, mentIndex);  
    1908             if(rc != (void *)NIL) 
    1909             { 
    1910                 *block_ndx = mtbl->mem[mentIndex].item; 
    1911                 return rc;       
    1912             } 
    1913             else 
    1914             { 
    1915                 return (void *)NIL;    
    1916             }  
    1917         } 
    1918         /* Eviction Failed */ 
    1919         else 
    1920         { 
    1921             return (void *)NULL; 
    1922         } 
    1923     } 
    1924     /* Head vacant. No need to iterate to next in chain, just use head */ 
    1925     rc = set_item(fent, offset, index); 
     1896    } 
     1897 
     1898    /* Eviction Failed */ 
     1899    if(mentIndex == NIL16) 
     1900    { 
     1901        return (void *)NULL; 
     1902    } 
     1903 
     1904    /* Procede with memory insertion if ment aquired */ 
     1905    uint16_t next_ment = NIL16; 
     1906    /* Insert at head, keeping track of the previous head */ 
     1907    next_ment = mtbl->bucket[index]; 
     1908    mtbl->bucket[index] = mentIndex; 
     1909 
     1910    rc = set_item(fent, offset, mentIndex); 
    19261911    if(rc != (void *)NIL) 
    19271912    { 
    1928         *block_ndx = mtbl->mem[index].item; 
     1913        mtbl->mem[mentIndex].next = next_ment; 
     1914        *block_ndx = mtbl->mem[mentIndex].item; 
    19291915        return rc;       
    19301916    } 
    19311917    else 
    19321918    { 
     1919        /* Restore the previous head back to head of the chain */ 
     1920        mtbl->bucket[index] = next_ment; 
    19331921        return (void *)NIL;    
    19341922    }