Changeset 2031

Show
Ignore:
Timestamp:
04/02/09 21:32:43 (3 years ago)
Author:
mwhitworth
Message:

Fix KE_OBJECT_TYPE, use new bit functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/memory/slab.c

    r1794 r2031  
    1717 */ 
    1818 
     19#define DEBUG_ASSERTS 
     20 
     21#include <assert.h> 
    1922#include <bitmap.h> 
    2023#include <module.h> 
     
    2427#include <slab.h> 
    2528#include <keobject.h> 
     29#include <locks.h> 
    2630 
    2731/*  
     
    5256}; 
    5357 
    54 KE_OBJECT_TYPE(cacheType, NULL, cacheAttributes, OffsetOf(struct Cache, object)); 
     58KE_OBJECT_TYPE(cacheType, NULL); 
    5559 
    5660static int slabInfoSetup = 0; 
    5761 
    5862/* General slab limits */ 
    59 #define SLAB_START 0xC0000000 
     63#define SLAB_START 0xC2000000 
    6064#define SLAB_END   0xD0000000 
    6165 
     
    7882        DWORD size; 
    7983        struct Cache* cache; 
     84        char* name; 
    8085}; 
    8186 
     
    8388 
    8489static struct CacheSize cacheSizes[]={ 
    85         {16,NULL}, 
    86         {32,NULL}, 
    87         {64,NULL}, 
    88         {128,NULL}, 
    89         {256,NULL}, 
    90         {512,NULL}, 
    91         {1024,NULL}, 
    92         {2048,NULL}, 
    93         {4096,NULL}, 
    94         {8192,NULL}, 
    95         {16384,NULL}, 
    96         {32768,NULL}, 
    97         {65536,NULL}, 
    98         {131072,NULL}, /* 128k */ 
    99 }; 
    100  
    101 const char* mallocNames[]= 
    102 { 
    103         "Malloc16", 
    104         "Malloc32", 
    105         "Malloc64", 
    106         "Malloc128", 
    107         "Malloc256", 
    108         "Malloc512", 
    109         "Malloc1024", 
    110         "Malloc2048", 
    111         "Malloc4096", 
    112         "Malloc8192", 
    113         "Malloc16384", 
    114         "Malloc32768", 
    115         "Malloc65536", 
    116         "Malloc131072", 
     90        {16,NULL, "Malloc16"}, 
     91        {32,NULL, "Malloc32"}, 
     92        {64,NULL, "Malloc64"}, 
     93        {128,NULL, "Malloc128"}, 
     94        {256,NULL, "Malloc256"}, 
     95        {512,NULL, "Malloc512"}, 
     96        {1024,NULL, "Malloc1024"}, 
     97        {2048,NULL, "Malloc2048"}, 
     98        {4096,NULL, "Malloc4096"}, 
     99        {8192,NULL, "Malloc8192"}, 
     100        {16384,NULL, "Malloc16384"}, 
     101        {32768,NULL, "Malloc32768"}, 
     102        {65536,NULL, "Malloc65536"}, 
     103        {131072,NULL, "Malloc131072"}, /* 128k */ 
    117104}; 
    118105 
     
    169156 
    170157        /* And zero out the memory concerned */ 
    171         BmapSetBit(slab->bitmap, i, false); 
     158        BitClear(slab->bitmap, i); 
     159         
    172160        slab->isFull=0; /* At least 1 piece is free now */ 
    173161 
     
    234222                return NULL; 
    235223 
     224        /* Allocate from a slab cache (which does keep its info on slab). */ 
    236225        if (cache->options & SLAB_OFFSLAB) 
    237226        { 
    238                 /* Allocate from a slab cache, which does keep it's info on slab */ 
    239227                slab=(struct Slab*)MemCacheAlloc(slabCache); 
    240228        }else 
     
    242230 
    243231        /* Slab setup is performed here. ZeroMemory call also zeros the bitmap. */ 
    244         ZeroMemory(slab,sizeof(struct Slab)); 
     232        ZeroMemory(slab, sizeof(struct Slab)); 
    245233        slab->page=virtAddr; 
    246234 
     
    340328                if (!currSlab->isFull) 
    341329                { 
    342                         /* Search the bitmap */ 
    343                         for (i=0; i<cache->numObjs; i++) 
     330                        i = BitFindFirstZero(currSlab->bitmap, cache->numObjs); 
     331                         
     332                        if (i < cache->numObjs) 
    344333                        { 
    345                                 if (!BmapGetBit(currSlab->bitmap,i)) 
    346                                 { 
    347                                         BmapSetBit(currSlab->bitmap,i,true); 
    348                                         if (i == cache->numObjs-1) 
    349                                                 currSlab->isFull=1; 
    350                                          
    351                                         if (!cache->ctor)        
    352                                                 ZeroMemory(currSlab->page+cache->offset+(i*cache->size), cache->size); 
    353  
    354                                         IrqRestoreFlags(flags); 
    355                                         return (void*)(currSlab->page+cache->offset+(i*cache->size)); 
    356                                 } 
     334                                BitSet(currSlab->bitmap, i); 
     335                         
     336                                if (i == cache->numObjs-1) 
     337                                        currSlab->isFull=1; 
     338 
     339                                IrqRestoreFlags(flags); 
     340                                return (void*)(currSlab->page+cache->offset+(i*cache->size)); 
    357341                        } 
    358342                } 
     
    417401{ 
    418402        struct Cache* retVal; 
     403        DWORD flags; 
    419404 
    420405        if (!size) 
     
    437422                retVal->numPages=1; 
    438423 
    439         retVal->ctor=ctor; 
    440         retVal->dtor=dtor; 
     424        retVal->ctor = ctor; 
     425        retVal->dtor = dtor; 
    441426        retVal->name = name; 
    442427 
     
    452437                KeObjectCreate(&retVal->object, &cacheSet, name); 
    453438 
     439        IrqSaveFlags(flags); 
    454440        ListAddTail(&retVal->list, &cacheList); 
     441        IrqRestoreFlags(flags); 
    455442 
    456443        return retVal; 
     
    461448int SlabInfoInit() 
    462449{ 
    463         KeSetCreate(&cacheSet, NULL, &cacheType, "Memory"); 
    464          
    465450        /* Register all the caches created so far. */ 
    466451        struct Cache* cache; 
    467452         
     453        KeSetCreate(&cacheSet, NULL, &cacheType, "Memory"); 
     454 
     455        PreemptDisable(); 
     456         
    468457        ListForEachEntry(cache, &cacheList, list) 
    469         { 
    470458                KeObjectCreate(&cache->object, &cacheSet, cache->name); 
    471         } 
    472459         
    473460        slabInfoSetup = 1; 
     461         
     462        PreemptEnable(); 
    474463         
    475464        return 0; 
     
    490479        for (i=0; i<count(cacheSizes); i++) 
    491480        { 
    492                 cacheSizes[i].cache=MemCacheCreate(mallocNames[i], cacheSizes[i].size, NULL, NULL, 0); 
     481                cacheSizes[i].cache=MemCacheCreate(cacheSizes[i].name, cacheSizes[i].size, NULL, NULL, 0); 
    493482                 
    494483                if (!cacheSizes[i].cache)