-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathcache.h
68 lines (57 loc) · 1.95 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* rv32emu is freely redistributable under the MIT License. See the file
* "LICENSE" for information on usage and redistribution of this file.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/* Currently, THRESHOLD is set to identify hot spots. Once the using frequency
* for a block exceeds the THRESHOLD, the tier-1 JIT compiler process is
* triggered.
*/
#define THRESHOLD 4096
struct cache;
/** cache_create - create a new cache
* @size_bits: cache size is 2^size_bits
* @return: a pointer points to new cache
*/
struct cache *cache_create(uint32_t size_bits);
/**
* cache_get - retrieve the specified entry from the cache
* @cache: a pointer points to target cache
* @key: the key of the specified entry
* @update: update frequency or not
* @return: the specified entry or NULL
*/
void *cache_get(const struct cache *cache, uint32_t key, bool update);
/**
* cache_put - insert a new entry into the cache
* @cache: a pointer points to target cache
* @key: the key of the inserted entry
* @value: the value of the inserted entry
* @return: the replaced entry or NULL
*/
void *cache_put(struct cache *cache, uint32_t key, void *value);
/**
* cache_free - free a cache
* @cache: a pointer points to target cache
* @callback: a function for freeing cache entry completely
*/
void cache_free(struct cache *cache);
#if RV32_HAS(JIT)
/**
* cache_hot - check whether the frequency of the cache entry exceeds the
* threshold or not
* @cache: a pointer points to target cache
* @key: the key of the specified entry
*/
bool cache_hot(const struct cache *cache, uint32_t key);
typedef void (*prof_func_t)(void *, uint32_t, FILE *);
void cache_profile(const struct cache *cache,
FILE *output_file,
prof_func_t func);
typedef void (*clear_func_t)(void *);
void clear_cache_hot(const struct cache *cache, clear_func_t func);
#endif
uint32_t cache_freq(const struct cache *cache, uint32_t key);