• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/FE/mallocSysCall.h

00001 // Copyright 2007 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2007, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef MALLOC_SYS_CALL_H
00014 #define MALLOC_SYS_CALL_H
00015 
00016 #include "global.h"
00017 #include <map>
00018 #include <string>
00019 
00020 using namespace std;
00021 
00022 class addrRegion {
00023  protected:
00024   simAddress baseAddr;
00025   simAddress maxAddr;
00026 
00027   map<simAddress, unsigned int> objectSizeInPages;
00028 
00029   unsigned char* pages;
00030   unsigned int pageSize;
00031   unsigned int pageShift;
00032   unsigned int pageMask;
00033   unsigned int totalPages;
00034 
00035   unsigned int makePageMask ();
00036 
00037   unsigned int numPages (unsigned int size) {
00038     unsigned int count = size >> pageShift;
00039     if ((size & pageMask) != 0)
00040       count++;
00041     return count;
00042   }
00043 
00044  public:
00045   string regionName;
00046 
00047  addrRegion(simAddress base, simAddress max, const char *name) :
00048      baseAddr(base), maxAddr(max),
00049      pages(NULL), pageSize(4096), pageShift(12), totalPages((max-base)/4096),
00050      regionName(name)
00051     {}
00052 
00053   unsigned int free (simAddress sa, unsigned int size, unsigned int& nextPage);
00054 };
00055 
00056 class processor;
00057 
00058 class localRegionAlloc : public addrRegion {
00059   unsigned int numLocs;
00060   unsigned int *nextPage;
00061 
00062   map<simAddress, unsigned int> objectLoc;
00063 
00064   map<processor*, unsigned int> procLoc;
00065 
00066  public:
00067   unsigned int free (simAddress sa) { return free (sa, 0);}
00068   unsigned int free (simAddress sa, unsigned int size);
00069 
00070   void setup (unsigned int shift, unsigned int locs);
00071 
00072   void addLoc (processor *p, unsigned int loc) {
00073     procLoc[p] = loc;
00074   }
00075 
00076   int getLoc (processor *p) {
00077     if (procLoc.count(p) == 0) {
00078       printf ("Error, could not find loc for proc %p\n",p);
00079       return -1;
00080     }
00081     return procLoc[p];
00082   }
00083 
00084   simAddress addrOnLoc(unsigned int locID) {
00085     return ((locID << pageShift) + baseAddr);
00086   }
00087   unsigned int whichLoc(simAddress sa);
00088   unsigned int stride() { return (1 << pageShift); }
00089   unsigned int locs() {return numLocs;}
00090   simAddress allocate (unsigned int size, unsigned int locID);
00091 
00092   localRegionAlloc (simAddress base, simAddress max, const char* name) :
00093       addrRegion(base, max, name)
00094     { }
00095 
00096 };
00097 
00098 class vmRegionAlloc : public addrRegion {
00099 
00100  public:
00101   unsigned int nextPage;
00102 
00103  vmRegionAlloc (simAddress base, simAddress max, const char* name) :
00104   addrRegion(base, max, name), nextPage(0) {
00105     pageSize = 4096;
00106     pageShift = 12;
00107     totalPages = (max - base) / pageSize;
00108     pages = new unsigned char[totalPages];
00109     for (unsigned int i = 0; i < totalPages; i++)
00110       pages[i] = 'f';
00111     makePageMask();
00112   }
00113   
00114   unsigned int free (simAddress sa) { return free (sa, 0);}
00115   unsigned int free (simAddress sa, unsigned int size);
00116 
00117   simAddress allocate(unsigned int size);
00118 };
00119 
00120 #endif

Generated on Fri Oct 22 2010 11:02:21 for SST by  doxygen 1.7.1