Changeset 9119
- Timestamp:
- 11/03/11 15:13:36 (20 months ago)
- Location:
- branches/Orange-Branch/src/client/usrint
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/Orange-Branch/src/client/usrint/iocommon.c
r9116 r9119 1060 1060 int i; /* index used for 'for loops' */ 1061 1061 int req_blk_cnt = 0; /* how many blocks request encompasses */ 1062 int req_size ; /* how many bytes request spans */1062 int req_size = 0; /* how many bytes request spans */ 1063 1063 uint32_t blk_size = CACHE_BLOCK_SIZE_K * 1024; 1064 1064 uint64_t remainder = 0; /* used to determine if offset is byte alligned */ -
branches/Orange-Branch/src/client/usrint/ucache.c
r9116 r9119 8 8 * Currently under development... 9 9 */ 10 10 #include <usrint.h> /* to get PVFS_UCACHE_ENABLE */ 11 11 #if PVFS_UCACHE_ENABLE 12 12 #include <ucache.h> 13 //#define LOCATE_MAX_ENABLED 1 14 //#define FILE_SYSTEM_ENABLED 113 14 //#define FILE_SYSTEM_ENABLED 15 15 16 16 /* Global Variables */ … … 18 18 19 19 union user_cache_u *ucache = 0; 20 / /static uint32_t ucache_blk_cnt = 0;20 /* static uint32_t ucache_blk_cnt = 0; */ 21 21 22 22 ucache_lock_t *ucache_locks = 0; /* will refer to the shmem of all ucache locks */ … … 90 90 91 91 /* File and Memory Entry Removal */ 92 /* static int remove_file(struct file_ent_s *fent); */ 92 static int remove_file(struct file_ent_s *fent); 93 93 static int wipe_mtbl(struct mem_table_s *mtbl); 94 94 static int remove_mem(struct file_ent_s *fent, uint64_t offset); … … 171 171 struct mem_table_s *get_mtbl(uint16_t mtbl_blk, uint16_t mtbl_ent) 172 172 { 173 return &(ucache->b[mtbl_blk].mtbl[mtbl_ent]); 173 if( mtbl_blk >= 0 && 174 mtbl_blk < BLOCKS_IN_CACHE && 175 mtbl_ent >= 0 && 176 mtbl_ent < MEM_TABLE_ENTRY_COUNT) 177 { 178 return &(ucache->b[mtbl_blk].mtbl[mtbl_ent]); 179 } 180 else 181 { 182 return (struct mem_table_s *)NILP; 183 } 174 184 } 175 185 … … 479 489 int rc = 0; 480 490 lock_lock(ucache_lock); 481 482 struct mem_table_s *mtbl = get_mtbl(fent->mtbl_blk, 483 fent->mtbl_ent); 484 485 /* Flush file blocks before file removal */ 486 mtbl->ref_cnt--; 487 if(mtbl->ref_cnt == 0) 488 { 489 /* Flush dirty blocks before file removal from cache */ 490 rc = flush_file(fent); 491 if(rc == -1) 492 { 493 goto done; 494 } 495 } 496 497 /* Instead of removing individually, since memory entries are already 498 * flushed, just wipe the mtbl 499 */ 500 rc = wipe_mtbl(mtbl); 501 if(rc == -1) 502 { 503 /* Couldn't remove entries */ 504 goto done; 505 } 506 507 rc = put_free_mtbl(mtbl, fent); 508 if(rc == -1) 509 { 510 goto done; 511 } 512 513 put_free_fent(fent); 514 if(rc == -1) 515 { 516 goto done; 517 } 518 519 rc = 0; 520 521 done: 491 rc = remove_file(fent); 522 492 lock_unlock(ucache_lock); 523 493 return rc; … … 642 612 current_fent = ftbl->file[current_fent].next) 643 613 { 644 //fprintf(out, "free file entry: index = %d\n", (int16_t)current_fent);614 fprintf(out, "free file entry: index = %d\n", (int16_t)current_fent); 645 615 } 646 616 fprintf(out, "End of Free File Entry List\n\n"); … … 671 641 672 642 fprintf(out, "\tMTBL LRU List ****************\n"); 673 / /print_LRU(mtbl);674 / /print_Dirty(mtbl);643 /* print_LRU(mtbl); */ 644 /* print_Dirty(mtbl); */ 675 645 676 646 fprintf(out, "\tMTBL INFO ********************\n"); … … 790 760 return sem_post(lock); 791 761 #elif LOCK_TYPE == 1 792 / /printf("lock size = %d\n", sizeof(*lock));762 /* printf("lock size = %d\n", sizeof(*lock)); */ 793 763 return pthread_mutex_unlock(lock); 794 764 #elif LOCK_TYPE == 2 … … 818 788 #elif (LOCK_TYPE == 1) 819 789 rc = pthread_mutex_destroy(lock); 820 //printf("rc = %d\terrno = %d\n", rc, errno);821 790 #elif (LOCK_TYPE == 2) 822 791 rc = pthread_spin_destroy(lock); … … 844 813 #elif (LOCK_TYPE == 1) 845 814 rc = pthread_mutex_trylock(lock); 846 //printf("rc = %d\n", rc);847 815 if( rc != 0) 848 816 { … … 860 828 /* Unlock before leaving if lock wasn't already set */ 861 829 rc = lock_unlock(lock); 862 //printf("OK - UNLOCKED!\n");863 }864 else865 {866 //printf("BLOCK WAS LOCKED!\n");867 830 } 868 831 return rc; … … 1377 1340 * Returns NIL if file is referenced or if the file could not be located. 1378 1341 */ 1379 /*1380 1342 static int remove_file(struct file_ent_s *fent) 1381 1343 { 1382 1344 if(DBG)fprintf(out, "trying to remove file...\n"); 1383 1384 1385 uint16_t file_mtbl_blk = NIL16; 1386 uint16_t file_mtbl_ent = NIL16; 1387 uint16_t file_ent_index = NIL16; 1388 uint16_t file_ent_prev_index = NIL16; 1389 1390 struct file_table_s *ftbl = &(ucache->ftbl); 1391 1392 //Lookup File 1393 struct mem_table_s *mtbl = lookup_file( 1394 fent->tag_id, 1395 fent->tag_handle, 1396 &file_mtbl_blk, //The rest can be NULL if not desired 1397 &file_mtbl_ent, 1398 &file_ent_index, 1399 &file_ent_prev_index 1400 ); 1401 1402 //Remove the file completely 1403 //Verify we've recieved the necessary info 1404 if((fent->mtbl_blk == NIL16) || (fent->mtbl_ent == NIL16)) 1405 { 1406 if(DBG)fprintf(out, "\tremoval failure: no mtbl matching file\n"); 1407 return NIL; 1408 } 1409 //Free the mtbl 1410 put_free_mtbl(mtbl, fent); 1411 1412 //Free the file entry 1413 ftbl->file[file_ent_prev_index].next = fent->next; 1345 1346 int rc = 0; 1347 struct mem_table_s *mtbl = get_mtbl(fent->mtbl_blk, 1348 fent->mtbl_ent); 1349 1350 if(mtbl == (struct mem_table_s *)NILP) 1351 { 1352 return -1; 1353 } 1354 1355 /* Flush file blocks before file removal */ 1356 mtbl->ref_cnt--; 1357 if(mtbl->ref_cnt == 0) 1358 { 1359 /* Flush dirty blocks before file removal from cache */ 1360 rc = flush_file(fent); 1361 if(rc == -1) 1362 { 1363 return rc; 1364 } 1365 } 1366 1367 /* Instead of removing individually, since memory entries are already 1368 * flushed, just wipe the mtbl 1369 */ 1370 rc = wipe_mtbl(mtbl); 1371 if(rc == -1) 1372 { 1373 /* Couldn't remove entries */ 1374 return rc; 1375 } 1376 1377 rc = put_free_mtbl(mtbl, fent); 1378 if(rc == -1) 1379 { 1380 return rc; 1381 } 1382 1414 1383 put_free_fent(fent); 1415 1416 if(DBG)fprintf(out, "\tremoval sucessful\n"); 1417 1418 return(1); 1419 } 1420 */ 1384 if(rc == -1) 1385 { 1386 return rc; 1387 } 1388 1389 /* Success */ 1390 rc = 0; 1391 return rc; 1392 } 1421 1393 1422 1394 /** Lookup the memory location of a block of data in cache that is identified … … 1581 1553 mtbl->lru_first = index; 1582 1554 } 1583 / /print_LRU(mtbl);1555 /* print_LRU(mtbl); */ 1584 1556 } 1585 1557 … … 1600 1572 for(i = 0; i < FILE_TABLE_HASH_MAX; i++) 1601 1573 { 1602 // if(DBG)fprintf(out, "\texamining ftbl index %hu\n", i); 1574 /* if(DBG)fprintf(out, "\texamining ftbl index %hu\n", i); */ 1603 1575 /* Iterate over hash table chain */ 1604 1576 uint16_t j; … … 1606 1578 { 1607 1579 struct file_ent_s *current_fent = &(ftbl->file[j]); 1608 // if(DBG)fprintf(out, "\t(blk, ent)=(%hu, %hu)\n", current_fent->mtbl_blk, 1609 // current_fent->mtbl_ent); 1610 //TODO: this might can be removed: test it 1580 /* 1581 if(DBG)fprintf(out, "\t(blk, ent)=(%hu, %hu)\n", current_fent->mtbl_blk, 1582 current_fent->mtbl_ent); 1583 */ 1611 1584 if((current_fent->mtbl_blk == NIL16) || 1612 1585 (current_fent->mtbl_ent == NIL16)) … … 1622 1595 if(current_mtbl->num_blocks >= value_of_max) 1623 1596 { 1624 // if(DBG)fprintf(out, "\tmax updated @ %d\n", j); 1597 /* if(DBG)fprintf(out, "\tmax updated @ %d\n", j); */ 1625 1598 *fent = current_fent; /* Set the parameter to this mtbl */ 1626 1599 index_of_max_blk = current_fent->mtbl_blk; … … 1711 1684 if(DBG)fprintf(out, "\tget_free_blk returned NIL, evicting a block " 1712 1685 "from max mtbl which has %hu entries\n", max_mtbl->num_blocks); 1713 / /print_LRU(max_mtbl);1686 /* print_LRU(max_mtbl); */ 1714 1687 evict_LRU(max_fent); 1715 1688 free_blk = get_free_blk(); … … 1725 1698 mtbl->num_blocks++; 1726 1699 update_LRU(mtbl, index); 1727 / /print_LRU(mtbl);1700 /* print_LRU(mtbl); */ 1728 1701 if(DBG)fprintf(out, "\tsuccessfully inserted memory entry @ blk: " 1729 1702 "%hu\n", free_blk); … … 1783 1756 if(DBG)fprintf(out, "\tno ment\n"); 1784 1757 evict_rc = evict_LRU(fent); 1785 / /print_LRU(mtbl);1758 /* print_LRU(mtbl); */ 1786 1759 assert(evict_rc != 0); 1787 1760 mentIndex = get_free_ment(mtbl); -
branches/Orange-Branch/src/client/usrint/ucache.h
r9116 r9119 6 6 7 7 #ifndef UCACHE_H 8 #define UCACHE_H 9 10 //#define UCACHE_ENABLED 11 #define UCACHE_LOCKING_ENABLED 8 #define UCACHE_H 1 12 9 13 10 #include <stdio.h> … … 16 13 #include <pthread.h> 17 14 #include <sys/shm.h> 18 #include <usrint.h>19 15 20 16 #define MEM_TABLE_ENTRY_COUNT 818 … … 45 41 #define NIL32 0XFFFFFFFF 46 42 #define NIL64 0XFFFFFFFFFFFFFFFF 43 #if (PVFS2_SIZEOF_VOIDP == 32) 44 #define NILP NIL32 45 #elif (PVFS2_SIZEOF_VOIDP == 64) 46 #define NILP NIL64 47 #endif 48 47 49 48 50 #ifndef DBG
