Exemplo n.º 1
0
void ProcessorInfo::getLevelInfo(int level)
{
	if(level == 1)
	{
		if(HasCacheLevel(1, ctData))
		{
			this->cache_levels[ctCacheInfo] = 1;
			this->cache_types[ctCacheInfo] = ctData;
			this->cache_sizes[ctCacheInfo] = GetCacheSize(1, ctData);
			ctCacheInfo++;
		}

		if(HasCacheLevel(1, ctInstruction))
		{
			this->cache_levels[ctCacheInfo] = 1;
			this->cache_types[ctCacheInfo] = ctInstruction;
			this->cache_sizes[ctCacheInfo] = GetCacheSize(1, ctInstruction);
			ctCacheInfo++;
		}
	}
	else
	{
		if(HasCacheLevel(level, ctUnified))
		{
			this->cache_levels[ctCacheInfo] = level;
			this->cache_types[ctCacheInfo] = ctUnified;
			this->cache_sizes[ctCacheInfo] = GetCacheSize(level, ctUnified);
			ctCacheInfo++;
		}
	}
}
Exemplo n.º 2
0
void findNBs(char prec, char *NBnam, int MaxL1Size)
{
   FILE *NBf;
   char ln[80];
   int i, L1Size, tmp, tsize, tL1Size, CL, nNB;
   int NB[100];

   fprintf(stderr, "NB setting not supplied; calculating:\n");

   L1Size = GetCacheSize(MaxL1Size);
   tsize = GetTypeSize(prec);

   tL1Size = L1Size * (1024 / tsize);
   tmp = CL = ATL_Cachelen / tsize;
   if (!tmp) tmp=1;
   nNB = 0;
   fprintf(stderr, "tmp=%d, tL1size=%d\n",tmp, tL1Size);
   while (tmp*tmp <= tL1Size)
   {
      if (tmp >= 16)        /* no block sizes smaller than 16 */
         NB[nNB++] = tmp;
      if (tmp >= 80) break;  /* no block sizes bigger than 80 */
      tmp += CL;
   }
   if (!nNB)  /* this should never happen */
   {
      nNB = 3;
      NB[0] = 8;
      NB[1] = 4;
      NB[2] = 16;
   }
   else if (nNB > 2)  /* put second biggest blocking factor first in list */
   {
      tmp = NB[nNB-2];
      NB[nNB-2] = NB[0];
      NB[0] = tmp;
   }

   NBf = fopen(NBnam, "w");
   fprintf(NBf, "%d\n", nNB);
   for (i=0; i != nNB; i++) fprintf(NBf, "%d\n", NB[i]);
   fclose(NBf);
}
Exemplo n.º 3
0
int GetSafeNB(char pre, int MaxL1)
{
   int i, L1, tsize, inc;

   tsize = GetTypeSize(pre);
   inc = ATL_MinMMAlign / tsize;
   if (inc < 4) inc = 4;
   L1 = (GetCacheSize(MaxL1) * 1024) / tsize;
   for (i=inc; i*i < L1; i += inc);
   if (i*i > L1) i -= inc;
   if (pre == 'd' || pre == 's')
   {
      if (i*i == L1) i -= inc;
   }
   else
   {
      if (i*i == L1) i -= 2*inc;
      else i -= inc;
   }
   if (i < 16) i = 16;
   if (i > 80) i = 80;
   return(i);
}
Exemplo n.º 4
0
void CCache::ClearExtraEntries()
{
	static const int estimatedCacheEntrySize = 1024*300;
	size_t availableMem = GetFreeSysMemory() + GetCacheSize();
	int estimatedMaxPossibleEntries = availableMem / estimatedCacheEntrySize;
	if(estimatedMaxPossibleEntries < tLXOptions->iMaxCachedEntries) {
		warnings << "The estimated possible max entry count in cache (" << estimatedMaxPossibleEntries << ") ";
		warnings << "is lower than the current set maximum (" << tLXOptions->iMaxCachedEntries << ")" << endl;
		hints << "Free system memory: " << (GetFreeSysMemory() / 1024) << " KB" << endl; 
		notes << "Lowering cache limit now" << endl;
		tLXOptions->iMaxCachedEntries = estimatedMaxPossibleEntries;
	}

	ScopedLock lock(mutex);
	
	if( (int)MapCache.size() >= tLXOptions->iMaxCachedEntries / 50 )
	{	// Sorted by last-access time, iterators are not invalidated in a map when element is erased
		typedef std::multimap< AbsTime, MapCache_t :: iterator > TimeSorted_t;
		TimeSorted_t TimeSorted;
		int count = 0;
		for( MapCache_t :: iterator it = MapCache.begin(); it != MapCache.end(); it++  )
		{
			TimeSorted.insert( std::make_pair( it->second.fSaveTime, it ) );
			if( it->second.tMap.getRefCount() <= 1 )
				count ++;
		}
		{
			int clearCount = MIN( count, MapCache.size() - tLXOptions->iMaxCachedEntries / 50 );
			for( TimeSorted_t :: iterator it1 = TimeSorted.begin();
					it1 != TimeSorted.end() && clearCount > 0; it1++, clearCount-- )
			{
				if( it1->second->second.tMap.tryDeleteData() )
				{
					clearCount --;
					MapCache.erase( it1->second );
				}
			}
		}
	}
	
	// Delete mods first, and images/sounds after, 'cause they are used by mods mainly
	if( (int)ModCache.size() >= tLXOptions->iMaxCachedEntries / 50 )
	{	// Sorted by last-access time, iterators are not invalidated in a map when element is erased
		typedef std::multimap< AbsTime, ModCache_t :: iterator > TimeSorted_t;
		TimeSorted_t TimeSorted;
		int count = 0;
		for( ModCache_t :: iterator it = ModCache.begin(); it != ModCache.end(); it++  )
		{
			TimeSorted.insert( std::make_pair( it->second.fSaveTime, it ) );
			if( it->second.tMod.getRefCount() <= 1 )
				count ++;
		}
		{
			int clearCount = MIN( count, ModCache.size() - tLXOptions->iMaxCachedEntries / 50 );
			for( TimeSorted_t :: iterator it1 = TimeSorted.begin();
					it1 != TimeSorted.end() && clearCount > 0; it1++, clearCount-- )
			{
				if( it1->second->second.tMod.tryDeleteData() )
				{
					clearCount --;
					ModCache.erase( it1->second );
				}
			}
		}
	}

	if( (int)ImageCache.size() >= tLXOptions->iMaxCachedEntries )
	{	// Sorted by last-access time, iterators are not invalidated in a map when element is erased
		typedef std::multimap< AbsTime, ImageCache_t :: iterator > TimeSorted_t;
		TimeSorted_t TimeSorted;
		int count = 0;
		for( ImageCache_t :: iterator it = ImageCache.begin(); it != ImageCache.end(); it++  )
		{
			TimeSorted.insert( std::make_pair( it->second.fSaveTime, it ) );
			if( it->second.bmpSurf.getRefCount() <= 1 )
				count ++;
		}
		{
			int clearCount = MIN( count, ImageCache.size() - tLXOptions->iMaxCachedEntries );
			for( TimeSorted_t :: iterator it1 = TimeSorted.begin();
					it1 != TimeSorted.end() && clearCount > 0; it1++ )
			{
				if( it1->second->second.bmpSurf.tryDeleteData() )
				{
					clearCount --;
					ImageCache.erase( it1->second );
				};
			};
		};
	};

	if( (int)SoundCache.size() >= tLXOptions->iMaxCachedEntries )
	{	// Sorted by last-access time, iterators are not invalidated in a map when element is erased
		typedef std::multimap< AbsTime, SoundCache_t :: iterator > TimeSorted_t;
		TimeSorted_t TimeSorted;
		int count = 0;
		for( SoundCache_t :: iterator it = SoundCache.begin(); it != SoundCache.end(); it++  )
		{
			TimeSorted.insert( std::make_pair( it->second.fSaveTime, it ) );
			if( it->second.sndSample.getRefCount() <= 1 )
				count ++;
		}
		{
			int clearCount = MIN( count, SoundCache.size() - tLXOptions->iMaxCachedEntries );
			for( TimeSorted_t :: iterator it1 = TimeSorted.begin();
					it1 != TimeSorted.end() && clearCount > 0; it1++, clearCount-- )
			{
				if( it1->second->second.sndSample.tryDeleteData() )
				{
					clearCount --;
					SoundCache.erase( it1->second );
				}
			}
		}
	}
}