Changeset 9119

Show
Ignore:
Timestamp:
11/03/11 15:13:36 (20 months ago)
Author:
jdenton
Message:

Added #include of usrint.h to the beginning of ucache.c to include the top
level includes.

Changed ucache_close_file to call an internal remove_file routine.

Location:
branches/Orange-Branch/src/client/usrint
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/Orange-Branch/src/client/usrint/iocommon.c

    r9116 r9119  
    10601060    int i; /* index used for 'for loops' */ 
    10611061    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 */ 
    10631063    uint32_t blk_size = CACHE_BLOCK_SIZE_K * 1024; 
    10641064    uint64_t remainder = 0; /* used to determine if offset is byte alligned */ 
  • branches/Orange-Branch/src/client/usrint/ucache.c

    r9116 r9119  
    88 * Currently under development... 
    99 */ 
    10  
     10#include <usrint.h> /* to get PVFS_UCACHE_ENABLE */ 
    1111#if PVFS_UCACHE_ENABLE 
    1212#include <ucache.h> 
    13 //#define LOCATE_MAX_ENABLED 1 
    14 //#define FILE_SYSTEM_ENABLED 1 
     13 
     14//#define FILE_SYSTEM_ENABLED  
    1515 
    1616/* Global Variables */ 
     
    1818 
    1919union user_cache_u *ucache = 0; 
    20 //static uint32_t ucache_blk_cnt = 0; 
     20/* static uint32_t ucache_blk_cnt = 0; */ 
    2121 
    2222ucache_lock_t *ucache_locks = 0; /* will refer to the shmem of all ucache locks */ 
     
    9090 
    9191/* File and Memory Entry Removal */ 
    92 /* static int remove_file(struct file_ent_s *fent); */ 
     92static int remove_file(struct file_ent_s *fent); 
    9393static int wipe_mtbl(struct mem_table_s *mtbl); 
    9494static int remove_mem(struct file_ent_s *fent, uint64_t offset); 
     
    171171struct mem_table_s *get_mtbl(uint16_t mtbl_blk, uint16_t mtbl_ent) 
    172172{ 
    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    } 
    174184} 
    175185 
     
    479489    int rc = 0; 
    480490    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); 
    522492    lock_unlock(ucache_lock); 
    523493    return rc; 
     
    642612                        current_fent = ftbl->file[current_fent].next) 
    643613    { 
    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); 
    645615    } 
    646616    fprintf(out, "End of Free File Entry List\n\n"); 
     
    671641 
    672642                fprintf(out, "\tMTBL LRU List ****************\n"); 
    673                 //print_LRU(mtbl); 
    674                 //print_Dirty(mtbl); 
     643                /* print_LRU(mtbl); */ 
     644                /* print_Dirty(mtbl); */ 
    675645 
    676646                fprintf(out, "\tMTBL INFO ********************\n"); 
     
    790760    return sem_post(lock); 
    791761    #elif LOCK_TYPE == 1 
    792     //printf("lock size = %d\n", sizeof(*lock)); 
     762    /* printf("lock size = %d\n", sizeof(*lock)); */ 
    793763    return pthread_mutex_unlock(lock); 
    794764    #elif LOCK_TYPE == 2 
     
    818788    #elif (LOCK_TYPE == 1) 
    819789    rc = pthread_mutex_destroy(lock); 
    820     //printf("rc = %d\terrno = %d\n", rc, errno); 
    821790    #elif (LOCK_TYPE == 2) 
    822791    rc = pthread_spin_destroy(lock); 
     
    844813    #elif (LOCK_TYPE == 1) 
    845814    rc = pthread_mutex_trylock(lock); 
    846     //printf("rc = %d\n", rc); 
    847815    if( rc != 0) 
    848816    { 
     
    860828        /* Unlock before leaving if lock wasn't already set */ 
    861829        rc = lock_unlock(lock); 
    862         //printf("OK - UNLOCKED!\n"); 
    863     } 
    864     else 
    865     { 
    866         //printf("BLOCK WAS LOCKED!\n"); 
    867830    } 
    868831    return rc; 
     
    13771340 * Returns NIL if file is referenced or if the file could not be located. 
    13781341 */ 
    1379 /* 
    13801342static int remove_file(struct file_ent_s *fent) 
    13811343{ 
    13821344    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 
    14141383    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} 
    14211393 
    14221394/** Lookup the memory location of a block of data in cache that is identified  
     
    15811553        mtbl->lru_first = index; 
    15821554    } 
    1583     //print_LRU(mtbl); 
     1555    /* print_LRU(mtbl); */ 
    15841556}     
    15851557 
     
    16001572    for(i = 0; i < FILE_TABLE_HASH_MAX; i++) 
    16011573    { 
    1602 //        if(DBG)fprintf(out, "\texamining ftbl index %hu\n", i); 
     1574        /* if(DBG)fprintf(out, "\texamining ftbl index %hu\n", i); */ 
    16031575        /* Iterate over hash table chain */ 
    16041576        uint16_t j; 
     
    16061578        { 
    16071579            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             */ 
    16111584            if((current_fent->mtbl_blk == NIL16) ||  
    16121585                    (current_fent->mtbl_ent == NIL16)) 
     
    16221595            if(current_mtbl->num_blocks >= value_of_max) 
    16231596            { 
    1624 //                if(DBG)fprintf(out, "\tmax updated @ %d\n", j); 
     1597                /* if(DBG)fprintf(out, "\tmax updated @ %d\n", j); */ 
    16251598                *fent = current_fent; /* Set the parameter to this mtbl */ 
    16261599                index_of_max_blk = current_fent->mtbl_blk; 
     
    17111684            if(DBG)fprintf(out, "\tget_free_blk returned NIL, evicting a block " 
    17121685                  "from max mtbl which has %hu entries\n", max_mtbl->num_blocks); 
    1713             //print_LRU(max_mtbl); 
     1686            /* print_LRU(max_mtbl); */ 
    17141687            evict_LRU(max_fent); 
    17151688            free_blk = get_free_blk(); 
     
    17251698            mtbl->num_blocks++; 
    17261699            update_LRU(mtbl, index); 
    1727             //print_LRU(mtbl); 
     1700            /* print_LRU(mtbl); */ 
    17281701            if(DBG)fprintf(out, "\tsuccessfully inserted memory entry @ blk: " 
    17291702                                                  "%hu\n", free_blk); 
     
    17831756            if(DBG)fprintf(out, "\tno ment\n"); 
    17841757            evict_rc = evict_LRU(fent); 
    1785             //print_LRU(mtbl); 
     1758            /* print_LRU(mtbl); */ 
    17861759            assert(evict_rc != 0); 
    17871760            mentIndex = get_free_ment(mtbl); 
  • branches/Orange-Branch/src/client/usrint/ucache.h

    r9116 r9119  
    66 
    77#ifndef UCACHE_H 
    8 #define UCACHE_H 
    9  
    10 //#define UCACHE_ENABLED 
    11 #define UCACHE_LOCKING_ENABLED 
     8#define UCACHE_H 1 
    129 
    1310#include <stdio.h> 
     
    1613#include <pthread.h> 
    1714#include <sys/shm.h> 
    18 #include <usrint.h> 
    1915 
    2016#define MEM_TABLE_ENTRY_COUNT 818 
     
    4541#define NIL32 0XFFFFFFFF 
    4642#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 
    4749 
    4850#ifndef DBG