Changeset 9262 for branches/stable/src/client/usrint/ucache.c
- Timestamp:
- 03/15/12 14:00:52 (14 months ago)
- Files:
-
- 1 modified
-
branches/stable/src/client/usrint/ucache.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/src/client/usrint/ucache.c
r9234 r9262 811 811 uint16_t k; 812 812 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) 815 818 { 816 819 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)) 818 821 { 819 822 struct mem_ent_s * ment = &(mtbl->mem[l]); … … 841 844 { 842 845 fprintf(out, "\tvacant memory entry @ index = %d\n", 843 k);846 mtbl->bucket[k]); 844 847 } 845 848 } … … 1139 1142 mtbl->dirty_list = NIL16; 1140 1143 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++) 1149 1154 { 1150 1155 rc = init_memory_entry(mtbl, i); … … 1152 1157 1153 1158 } 1159 /* NIL Terminate the last entries next index */ 1154 1160 rc = init_memory_entry(mtbl, MEM_TABLE_ENTRY_COUNT - 1); 1155 1161 mtbl->mem[MEM_TABLE_ENTRY_COUNT - 1].next = NIL16; 1156 1162 } 1157 1158 1163 1159 1164 /** … … 1252 1257 * Puts the memory entry corresponding to the provided mtbl and entry index 1253 1258 * 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 this1256 * index must remain the head of the linked list. Otherwise, set next to the1257 * current head of ment free list and set the free list head to the provided1258 * index.1259 1259 */ 1260 1260 static void put_free_ment(struct mem_table_s *mtbl, uint16_t ent) … … 1266 1266 mtbl->mem[ent].lru_prev = NIL16; 1267 1267 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; 1275 1272 } 1276 1273 … … 1384 1381 { 1385 1382 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)) 1387 1384 { 1388 1385 /* Current Memory Entry */ … … 1603 1600 /* index into mem hash table */ 1604 1601 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]); 1608 1611 1609 1612 /* previous, current, next memory entry index in mtbl */ 1610 1613 int16_t p = NIL16; 1611 int16_t c = index;1614 int16_t c = bucket_index; 1612 1615 int16_t n = current->next; 1613 1616 … … 1871 1874 { 1872 1875 void* rc = 0; 1873 1874 1876 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);1878 1877 1879 1878 /* Lookup first */ … … 1885 1884 } 1886 1885 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 1890 1890 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); 1894 1895 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); 1926 1911 if(rc != (void *)NIL) 1927 1912 { 1928 *block_ndx = mtbl->mem[index].item; 1913 mtbl->mem[mentIndex].next = next_ment; 1914 *block_ndx = mtbl->mem[mentIndex].item; 1929 1915 return rc; 1930 1916 } 1931 1917 else 1932 1918 { 1919 /* Restore the previous head back to head of the chain */ 1920 mtbl->bucket[index] = next_ment; 1933 1921 return (void *)NIL; 1934 1922 }
