Beispiel #1
0
void
memsweep_domain(int domainId)
{
    char* ptr = NULL;
    size_t size = numa_info.nodes[domainId].totalMemory * 1024ULL * memoryFraction / 100ULL;
    printf("Sweeping domain %d: Using %g MB of %g MB\n",
            domainId,
            size / (1024.0 * 1024.0),
            numa_info.nodes[domainId].totalMemory/ 1024.0);
    ptr = (char*) allocateOnNode(size, domainId);
    initMemory(size, ptr, domainId);
    cleanupCache(ptr);
    munmap(ptr, size);
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    int opt = 0;
    int setBitCount = 1, blockBitCount = 1, associativity = 1;
    while ((opt = getopt(argc, argv, "hvs:E:b:t:")) != -1) {
        switch(opt) {
            case 'h':
                printf(
                        "Usage: %s [-hv] -s <num> -E <num> -b <num> -t <file>\n"
                        "Options:\n"
                        "-h         Print this help message.\n"
                        "-v         Optional verbose flag.\n"
                        "-s <num>   Number of set index bits.\n"
                        "-E <num>   Number of lines per set.\n"
                        "-b <num>   Number of block offset bits.\n"
                        "-t <file>  Trace file.\n"
                        "\n"
                        "Examples:\n"
                        "linux>  %s -s 4 -E 1 -b 4 -t traces/yi.trace\n"
                        "linux>  %s -v -s 8 -E 2 -b 4 -t traces/yi.trace\n", argv[0], argv[0], argv[0]);
                break;
            case 'v':
                g_isVerbose = 1;
                break;
            case 's':
                setBitCount = atoi(optarg);
                break;
            case 'E':
                associativity = atoi(optarg);
                break;
            case 'b':
                blockBitCount = atoi(optarg);
                break;
            case 't': {
                FILE *traceFile = fopen(optarg, "r");
                dup2(fileno(traceFile), fileno(stdin));
                fclose(traceFile);
              } break;
            default:
                break;
        }
    }

    Cache* cache = setupCache(setBitCount, associativity, blockBitCount, &onCacheHit, &onCacheMiss, &onCacheEviction);
    {
        char buf[32] = "";
        long long addr;
        int size;
        while (scanf("%s %llx,%d", buf, &addr, &size) == 3) {
            printf("%s %llx,%d", buf, addr, size);
            switch (buf[0]) {
                case 'I':
                    break;
                case 'L':
                    accessCache(cache, addr, size);
                    break;
                case 'S':
                    accessCache(cache, addr, size);
                    break;
                case 'M':
                    accessCache(cache, addr, size);
                    accessCache(cache, addr, size);
                    break;
            }
            puts("");
        }
    }
    cleanupCache(cache);

    printSummary(g_hitCount, g_missCount, g_evictionCount);
    return 0;
}
void MeshUpdateQueue::addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
{
	MutexAutoLock lock(m_mutex);

	cleanupCache();

	/*
		Cache the block data (force-update the center block, don't update the
		neighbors but get them if they aren't already cached)
	*/
	std::vector<CachedMapBlockData*> cached_blocks;
	size_t cache_hit_counter = 0;
	cached_blocks.reserve(3*3*3);
	v3s16 dp;
	for (dp.X = -1; dp.X <= 1; dp.X++)
	for (dp.Y = -1; dp.Y <= 1; dp.Y++)
	for (dp.Z = -1; dp.Z <= 1; dp.Z++) {
		v3s16 p1 = p + dp;
		CachedMapBlockData *cached_block;
		if (dp == v3s16(0, 0, 0))
			cached_block = cacheBlock(map, p1, FORCE_UPDATE);
		else
			cached_block = cacheBlock(map, p1, SKIP_UPDATE_IF_ALREADY_CACHED,
					&cache_hit_counter);
		cached_blocks.push_back(cached_block);
	}
	g_profiler->avg("MeshUpdateQueue MapBlock cache hit %",
			100.0f * cache_hit_counter / cached_blocks.size());

	/*
		Mark the block as urgent if requested
	*/
	if (urgent)
		m_urgents.insert(p);

	/*
		Find if block is already in queue.
		If it is, update the data and quit.
	*/
	for (QueuedMeshUpdate *q : m_queue) {
		if (q->p == p) {
			// NOTE: We are not adding a new position to the queue, thus
			//       refcount_from_queue stays the same.
			if(ack_block_to_server)
				q->ack_block_to_server = true;
			q->crack_level = m_client->getCrackLevel();
			q->crack_pos = m_client->getCrackPos();
			return;
		}
	}

	/*
		Add the block
	*/
	QueuedMeshUpdate *q = new QueuedMeshUpdate;
	q->p = p;
	q->ack_block_to_server = ack_block_to_server;
	q->crack_level = m_client->getCrackLevel();
	q->crack_pos = m_client->getCrackPos();
	m_queue.push_back(q);

	// This queue entry is a new reference to the cached blocks
	for (CachedMapBlockData *cached_block : cached_blocks) {
		cached_block->refcount_from_queue++;
	}
}