How is the average Miss Miss Ratio (ACMR) calculated?

I am studying Tom Forsyth Linear-Speed ​​Vertex Cache Optimization, and I do not understand how it calculates ACMR. From what I read, I already know that ACMR = the number of misses in the cache / the number of triangles, but I do not understand what type of cache is used (i.e. FIFO or LRU?).

I wrote a test program that calculates and prints the ACMR of a given 3d model using the FIFO cache, can you tell me if this code is ok? or should I use LRU cache instead?

/* the number of entries in a FIFO cache */
#define FIFO_CACHE_SIZE     32

struct fifo_cache {
    long entries[FIFO_CACHE_SIZE];
};

/**
 * init_cache - initializes a FIFO cache
 * @cache: A pointer to the FIFO cache structure to be initialized.
 *
 * Before a FIFO cache can be used, it must be initialized by calling this
 * function.
 */
static void init_cache(struct fifo_cache *cache)
{
    int i = 0;

    /* initialize cache entries to an invalid value */
    for (i = 0;i < FIFO_CACHE_SIZE;i++)
        cache->entries[i] = -1;
}

/**
 * check_entry - checks if the same entry is already added to the cache
 * @cache: A pointer to the FIFO cache structure to be searched.
 * @entry: An entry to be searched for.
 *
 * Return: If the same entry was found, the return value is nonzero. Otherwise,
 *         the return value is zero.
 */
static int check_entry(const struct fifo_cache *cache, u16 entry)
{
    int i = 0;

    for (i = 0;i < FIFO_CACHE_SIZE;i++) {
        if (cache->entries[i] == (long)entry)
            return 1;
    }

    return 0;
}

/**
 * add_entry - adds a new entry to the FIFO cache
 * @cache: A pointer to the FIFO cache structure the entry will be added to.
 * @entry: An entry to add.
 */
static void add_entry(struct fifo_cache *cache, u16 entry)
{
    long aux = 0;
    long aux2 = 0;
    int i = 0;

    aux = cache->entries[0];
    cache->entries[0] = (long)entry;

    for (i = 1;i < FIFO_CACHE_SIZE;i++) {
        aux2 = cache->entries[i];
        cache->entries[i] = aux;
        aux = aux2;
    }
}

/**
 * calculate_acmr - calculates the average cache miss ratio (aka. ACMR)
 * @indices: The list of vertex indices.
 * @count: The number of vertex indices in the @indices list.
 */
float calculate_acmr(const u16 *indices, size_t count)
{
    struct fifo_cache cache = {0};
    long total = 0; /* the total number of cache misses */
    long i = 0;

    /* initialize the cache */
    init_cache(&cache);

    for (i = 0;i < count;i++) {
        if (!check_entry(&cache, indices[i])) {
            /* an entry doesn't exist in the cache, so add it */
            add_entry(&cache, indices[i]);

            total++;
        }
    }

    return ((float)total / (count / 3));
}
+4
source share
2 answers

. FIFO , ACMR FIFO. , , , .

+2

Source: https://habr.com/ru/post/1543739/


All Articles