1+ //
2+ // Created by Zhelong Zhao on 2023.08.16.
3+ //
4+ #include "../libCacheSim/utils/include/mymath.h"
5+ #include "common.h"
6+
7+ // static const uint64_t req_cnt_true = 113872, req_byte_true = 4205978112;
8+ static const uint64_t req_cnt_true = 113872 , req_byte_true = 4368040448 ;
9+
10+ static void _verify_profiler_results (const cache_stat_t * res ,
11+ uint64_t num_of_sizes ,
12+ uint64_t req_cnt_true ,
13+ const uint64_t * miss_cnt_true ,
14+ uint64_t req_byte_true ,
15+ const uint64_t * miss_byte_true ) {
16+ for (uint64_t i = 0 ; i < num_of_sizes ; i ++ ) {
17+ g_assert_cmpuint (req_cnt_true , = = , res [i ].n_req );
18+ g_assert_cmpuint (miss_cnt_true [i ], = = , res [i ].n_miss );
19+ g_assert_cmpuint (req_byte_true , = = , res [i ].n_req_byte );
20+ g_assert_cmpuint (miss_byte_true [i ], = = , res [i ].n_miss_byte );
21+ }
22+ }
23+
24+ static void print_results (const cache_t * cache , const cache_stat_t * res ) {
25+ printf ("%s uint64_t cache_size[] = {" , cache -> cache_name );
26+ printf ("%ld" , res [0 ].cache_size );
27+ for (uint64_t i = 1 ; i < CACHE_SIZE / STEP_SIZE ; i ++ ) {
28+ printf (", %ld" , res [i ].cache_size );
29+ }
30+ printf ("};\n" );
31+
32+ printf ("uint64_t miss_cnt_true[] = {" );
33+ printf ("%ld" , res [0 ].n_miss );
34+ for (uint64_t i = 1 ; i < CACHE_SIZE / STEP_SIZE ; i ++ ) {
35+ printf (", %ld" , res [i ].n_miss );
36+ }
37+ printf ("};\n" );
38+
39+ printf ("uint64_t miss_byte_true[] = {" );
40+ printf ("%ld" , res [0 ].n_miss_byte );
41+ for (uint64_t i = 1 ; i < CACHE_SIZE / STEP_SIZE ; i ++ ) {
42+ printf (", %ld" , res [i ].n_miss_byte );
43+ }
44+ printf ("};\n" );
45+ }
46+
47+ static void test_Mithril (gconstpointer user_data ) {
48+ uint64_t miss_cnt_true [] = {79796 , 78480 , 76126 , 75256 ,
49+ 72336 , 72062 , 71936 , 71667 };
50+ uint64_t miss_byte_true [] = {3471357440 , 3399726080 , 3285093888 , 3245231616 ,
51+ 3092759040 , 3077801472 , 3075234816 , 3061489664 };
52+
53+ reader_t * reader = (reader_t * )user_data ;
54+ common_cache_params_t cc_params = {
55+ .cache_size = CACHE_SIZE , .hashpower = 20 , .default_ttl = DEFAULT_TTL };
56+ cache_t * cache = create_test_cache ("Mithril" , cc_params , reader , NULL );
57+ g_assert_true (cache != NULL );
58+ cache_stat_t * res = simulate_at_multi_sizes_with_step_size (
59+ reader , cache , STEP_SIZE , NULL , 0 , 0 , _n_cores ());
60+
61+ print_results (cache , res );
62+ _verify_profiler_results (res , CACHE_SIZE / STEP_SIZE , req_cnt_true ,
63+ miss_cnt_true , req_byte_true , miss_byte_true );
64+ cache -> cache_free (cache );
65+ my_free (sizeof (cache_stat_t ), res );
66+ }
67+
68+ int main (int argc , char * argv []) {
69+ g_test_init (& argc , & argv , NULL );
70+ srand (0 ); // for reproducibility
71+ set_rand_seed (rand ());
72+
73+ reader_t * reader ;
74+
75+ // do not use these two because object size change over time and
76+ // not all algorithms can handle the object size change correctly
77+ // reader = setup_csv_reader_obj_num();
78+ // reader = setup_vscsi_reader();
79+
80+ reader = setup_oracleGeneralBin_reader ();
81+ // reader = setup_vscsi_reader_with_ignored_obj_size();
82+ g_test_add_data_func ("/libCacheSim/cacheAlgo_Mithril" , reader , test_Mithril );
83+
84+ return g_test_run ();
85+ }
0 commit comments