c - How the Average Cache Miss Ratio (ACMR) is calculated? -
i'm studying tom forsyth's linear-speed vertex cache optimization , don't understand how calculates acmr. have read know acmr = number of cache misses / number of triangles, don't understand kind of cache being used (i.e. fifo or lru?).
i have written test program calculates , prints acmr of given 3d model using fifo cache, can please tell me if code ok? or should use lru cache instead?
/* number of entries in fifo cache */ #define fifo_cache_size 32 struct fifo_cache { long entries[fifo_cache_size]; }; /** * init_cache - initializes fifo cache * @cache: pointer fifo cache structure initialized. * * before fifo cache can used, must initialized calling * function. */ static void init_cache(struct fifo_cache *cache) { int = 0; /* initialize cache entries invalid value */ (i = 0;i < fifo_cache_size;i++) cache->entries[i] = -1; } /** * check_entry - checks if same entry added cache * @cache: pointer fifo cache structure searched. * @entry: entry searched for. * * return: if same entry found, return value nonzero. otherwise, * return value zero. */ static int check_entry(const struct fifo_cache *cache, u16 entry) { int = 0; (i = 0;i < fifo_cache_size;i++) { if (cache->entries[i] == (long)entry) return 1; } return 0; } /** * add_entry - adds new entry fifo cache * @cache: pointer fifo cache structure entry added to. * @entry: entry add. */ static void add_entry(struct fifo_cache *cache, u16 entry) { long aux = 0; long aux2 = 0; int = 0; aux = cache->entries[0]; cache->entries[0] = (long)entry; (i = 1;i < fifo_cache_size;i++) { aux2 = cache->entries[i]; cache->entries[i] = aux; aux = aux2; } } /** * calculate_acmr - calculates average cache miss ratio (aka. acmr) * @indices: list of vertex indices. * @count: number of vertex indices in @indices list. */ float calculate_acmr(const u16 *indices, size_t count) { struct fifo_cache cache = {0}; long total = 0; /* total number of cache misses */ long = 0; /* initialize cache */ init_cache(&cache); (i = 0;i < count;i++) { if (!check_entry(&cache, indices[i])) { /* entry doesn't exist in cache, add */ add_entry(&cache, indices[i]); total++; } } return ((float)total / (count / 3)); }
you correct way hardware it. additionally may want read this: http://www.realtimerendering.com/blog/acmr-and-atvr/
Comments
Post a Comment