source: trunk/modules/vci_cc_xcache_wrapper_v4/caba/source/include/vci_cc_xcache_wrapper_v4.h @ 147

Last change on this file since 147 was 147, checked in by alain, 13 years ago

Return to version 134 :
The multi-processor version of the L1 cache must be renamed as a new component...

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Rev URL Revision"
  • Property svn:mime-type set to text/plain
File size: 16.0 KB
RevLine 
[2]1/* -*- c++ -*-
2 *
3 * SOCLIB_LGPL_HEADER_BEGIN
4 *
5 * This file is part of SoCLib, GNU LGPLv2.1.
6 *
7 * SoCLib is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; version 2.1 of the License.
10 *
11 * SoCLib is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with SoCLib; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 * SOCLIB_LGPL_HEADER_END
22 *
23 * Copyright (c) UPMC, Lip6, SoC
24 *         Alain Greiner <alain.greiner@lip6.fr>, 2008
25 *
26 * Maintainers: alain
27 */
28 
29#ifndef SOCLIB_CABA_VCI_CC_XCACHE_WRAPPER_V4_H
30#define SOCLIB_CABA_VCI_CC_XCACHE_WRAPPER_V4_H
31
32#include <inttypes.h>
33#include <systemc>
[134]34#include <queue>
[2]35#include "caba_base_module.h"
[134]36#include "multi_write_buffer.h"
[2]37#include "generic_cache.h"
38#include "vci_initiator.h"
39#include "vci_target.h"
40#include "mapping_table.h"
41#include "static_assert.h"
42
[134]43/*
[147]44 * CC_XCACHE_WRAPPER_SELECT_VICTIM :
45 *   The selection and the update of cache (after a read miss)
46 *   are separated in two step
47 *   Also, the cleanup can be send in parallel at the read miss.
48 *
[134]49 * CC_XCACHE_WRAPPER_FIFO_RSP
50 *   Two simple fifo (each 2x32 depth) receive the cache line from
51 *   RAM. Instead of two buffers (m_icache_words and m_dcache_words)
52 *   
53 * CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE
54 *   Update cache in "2*cache_words" cycles (read+mask, write)
55 *   
56 * CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE_OPT
57 *   Update cache with only modified data (be != 0)
58 *   
59 * CC_XCACHE_WRAPPER_WBUF_UPDATE_SCHEME
60 *   Write buffer scheme for update step :
61 *     1    - multi_scan
62 *     2    - round_robin_scan
63 *     3    - one_scan
64 *     else - default scheme
65 *
66 * CC_XCACHE_WRAPPER_VCI_CMD_PRIORITY
67 *   Write buffer access is conditionnal with dcache_miss_req and icache_miss_req
[147]68 *     1    - two access authorized
69 *     2    - one access with static priority (dcache prior)
70 *     3    - one access with static priority (icache prior)
71 *     4    - one access with round robin priority
[134]72 *
73 * CC_XCACHE_WRAPPER_STOP_SIMULATION :
74 *   stop simulation if processor is stall after a long time
75 *   (configurable with "stop_simulation" function)
76 *
77 * CC_XCACHE_WRAPPER_DEBUG :
78 *   Add log to help the debugging
79 *
80 * CC_XCACHE_WRAPPER_DEBUG_CYCLE_MIN :
81 *   Number of cycle before to prinf debug message
82 *
[147]83 * CC_XCACHE_WRAPPER_DEBUG_DCACHE_TRANSACTION
84 *   Print transaction between the cpu and the cache
[134]85 */
[2]86
[134]87// implementation
[147]88#ifndef CC_XCACHE_WRAPPER_SELECT_VICTIM
89#define CC_XCACHE_WRAPPER_SELECT_VICTIM             0
90#endif
[134]91#ifndef CC_XCACHE_WRAPPER_FIFO_RSP
[147]92#define CC_XCACHE_WRAPPER_FIFO_RSP                  0
[134]93#endif
94#ifndef CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE
[147]95#define CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE     1
[134]96#endif
97#ifndef CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE_OPT
[147]98#define CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE_OPT 1
[134]99#endif
100#ifndef CC_XCACHE_WRAPPER_WBUF_UPDATE_SCHEME
[147]101#define CC_XCACHE_WRAPPER_WBUF_UPDATE_SCHEME        0
[134]102#endif
103#ifndef CC_XCACHE_WRAPPER_VCI_CMD_PRIORITY
[147]104#define CC_XCACHE_WRAPPER_VCI_CMD_PRIORITY          2
105#endif 
[134]106// debugging
107#ifndef CC_XCACHE_WRAPPER_STOP_SIMULATION
[147]108#define CC_XCACHE_WRAPPER_STOP_SIMULATION           1
[134]109#endif
110#ifndef CC_XCACHE_WRAPPER_DEBUG
[147]111#define CC_XCACHE_WRAPPER_DEBUG                     0
[134]112#endif
113#ifndef CC_XCACHE_WRAPPER_DEBUG_CYCLE_MIN
[147]114#define CC_XCACHE_WRAPPER_DEBUG_CYCLE_MIN           200000
[134]115#endif
[147]116#ifndef CC_XCACHE_WRAPPER_DEBUG_DCACHE_TRANSACTION
117#define CC_XCACHE_WRAPPER_DEBUG_DCACHE_TRANSACTION  0
[134]118#endif
119
[2]120namespace soclib {
121namespace caba {
122
123using namespace sc_core;
124
125////////////////////////////////////////////
126template<typename vci_param, typename iss_t>
127class VciCcXCacheWrapperV4
128///////////////////////////////////////////
129    : public soclib::caba::BaseModule
130{
[90]131    typedef sc_dt::sc_uint<40>  addr_40;
[110]132    typedef sc_dt::sc_uint<64>  data_64;
[90]133    typedef uint32_t            data_t;
134    typedef uint32_t            tag_t;
135    typedef uint32_t            be_t;
[2]136    typedef typename vci_param::fast_addr_t vci_addr_t;
[134]137
[2]138    enum dcache_fsm_state_e {
139        DCACHE_IDLE,
140        DCACHE_WRITE_UPDT,
[147]141#if CC_XCACHE_WRAPPER_SELECT_VICTIM
[134]142        DCACHE_MISS_VICTIM,
[147]143#endif
[2]144        DCACHE_MISS_WAIT,
145        DCACHE_MISS_UPDT,
146        DCACHE_UNC_WAIT,
147        DCACHE_SC_WAIT,
148        DCACHE_INVAL,
[134]149        DCACHE_SYNC,
[2]150        DCACHE_ERROR,
151        DCACHE_CC_CHECK,
152        DCACHE_CC_INVAL,
153        DCACHE_CC_UPDT,
154        DCACHE_CC_CLEANUP,
155    };
156
157    enum icache_fsm_state_e {
158        ICACHE_IDLE,
[147]159#if CC_XCACHE_WRAPPER_SELECT_VICTIM
[134]160        ICACHE_MISS_VICTIM,
[147]161#endif
[2]162        ICACHE_MISS_WAIT,
163        ICACHE_MISS_UPDT,
164        ICACHE_UNC_WAIT,
165        ICACHE_ERROR,
166        ICACHE_CC_CLEANUP,
167        ICACHE_CC_CHECK,
168        ICACHE_CC_INVAL,
169        ICACHE_CC_UPDT,
170    };
171
172    enum cmd_fsm_state_e {
173        CMD_IDLE,
174        CMD_INS_MISS,
175        CMD_INS_UNC,
176        CMD_DATA_MISS,
177        CMD_DATA_UNC,
178        CMD_DATA_WRITE,
179        CMD_DATA_SC,
180    };
181
182    enum rsp_fsm_state_e {
183        RSP_IDLE,
184        RSP_INS_MISS,
185        RSP_INS_UNC,
186        RSP_DATA_MISS,
187        RSP_DATA_UNC,
188        RSP_DATA_WRITE,
189        RSP_DATA_SC,
190    };
191
192    enum tgt_fsm_state_e {
193        TGT_IDLE,
194        TGT_UPDT_WORD,
195        TGT_UPDT_DATA,
196        TGT_REQ_BROADCAST,
197        TGT_REQ_ICACHE,
198        TGT_REQ_DCACHE,
199        TGT_RSP_BROADCAST,
200        TGT_RSP_ICACHE,
201        TGT_RSP_DCACHE,
202    };
203
[134]204    enum cleanup_fsm_state_e {
205        CLEANUP_IDLE,
[147]206        CLEANUP_DCACHE,
207        CLEANUP_ICACHE,
[134]208    };
209
210    enum transaction_type_c_e {
211        // convention with memcache
212        TYPE_DATA_CLEANUP = 0x0,
213        TYPE_INS_CLEANUP  = 0x1
214    };
215
216    enum transaction_type_rw_e {
217        // convention with memcache
218        // b0 : 1 if cached
219        // b1 : 1 if instruction
220        // b2 : 1 if sc
221        TYPE_DATA_UNC     = 0x0,
222        TYPE_DATA_MISS    = 0x1,
223        TYPE_INS_UNC      = 0x2,
224        TYPE_INS_MISS     = 0x3,
225        TYPE_DATA_SC      = 0x4, // sc is data and no cached
226    };
227
[2]228public:
229
230    // PORTS
231    sc_in<bool>                             p_clk;
232    sc_in<bool>                             p_resetn;
[147]233    sc_in<bool>                             p_irq[iss_t::n_irq];
[2]234    soclib::caba::VciInitiator<vci_param>   p_vci_ini_rw;
235    soclib::caba::VciInitiator<vci_param>   p_vci_ini_c;
236    soclib::caba::VciTarget<vci_param>      p_vci_tgt;
237
238private:
239
240    // STRUCTURAL PARAMETERS
241    const soclib::common::AddressDecodingTable<vci_addr_t, bool>    m_cacheability_table;
242    const soclib::common::Segment                                   m_segment;
[147]243    iss_t               m_iss;
[2]244    const uint32_t      m_srcid_rw;   
245    const uint32_t      m_srcid_c;   
246   
247    const size_t        m_dcache_ways;
248    const size_t        m_dcache_words;
[134]249    const uint32_t      m_dcache_words_shift;
[2]250    const size_t        m_dcache_yzmask;
251    const size_t        m_icache_ways;
252    const size_t        m_icache_words;
[134]253    const uint32_t      m_icache_words_shift;
[2]254    const size_t        m_icache_yzmask;
[134]255    const size_t        m_cache_words; // max between m_dcache_words and m_icache_words
[2]256
[134]257#if CC_XCACHE_WRAPPER_STOP_SIMULATION
258    bool                m_stop_simulation;
259    uint32_t            m_stop_simulation_nb_frz_cycles_max;
[147]260    uint32_t            m_stop_simulation_nb_frz_cycles;
[134]261#endif // CC_XCACHE_WRAPPER_STOP_SIMULATION
262
[2]263    // REGISTERS
[147]264    sc_signal<int>          r_dcache_fsm;
265    sc_signal<int>          r_dcache_fsm_save;
266    sc_signal<addr_40>      r_dcache_addr_save;
267    sc_signal<data_t>       r_dcache_wdata_save;
268    sc_signal<data_t>       r_dcache_rdata_save;
269    sc_signal<int>          r_dcache_type_save;
270    sc_signal<be_t>         r_dcache_be_save;
271    sc_signal<bool>         r_dcache_cached_save;
272    sc_signal<bool>         r_dcache_cleanup_req;
273    sc_signal<addr_40>      r_dcache_cleanup_line;
274    sc_signal<bool>         r_dcache_miss_req;
275    sc_signal<size_t>       r_dcache_miss_way;
276    sc_signal<size_t>       r_dcache_miss_set;
277    sc_signal<bool>         r_dcache_unc_req;
278    sc_signal<bool>         r_dcache_sc_req;
279    sc_signal<bool>         r_dcache_inval_rsp;
280    sc_signal<size_t>       r_dcache_update_addr;
281    sc_signal<data_64>      r_dcache_ll_data;
282    sc_signal<addr_40>      r_dcache_ll_addr;
283    sc_signal<bool>         r_dcache_ll_valid;
284    sc_signal<bool>         r_dcache_previous_unc;
[2]285
[147]286    sc_signal<int>          r_icache_fsm;
287    sc_signal<int>          r_icache_fsm_save;
288    sc_signal<addr_40>      r_icache_addr_save;
289    sc_signal<bool>         r_icache_miss_req;
290    sc_signal<size_t>       r_icache_miss_way;
291    sc_signal<size_t>       r_icache_miss_set;
292    sc_signal<bool>         r_icache_unc_req;
293    sc_signal<bool>         r_icache_cleanup_req;
294    sc_signal<addr_40>      r_icache_cleanup_line;
295    sc_signal<bool>         r_icache_inval_rsp;
296    sc_signal<size_t>       r_icache_update_addr;
[2]297
298    sc_signal<int>          r_vci_cmd_fsm;
299    sc_signal<size_t>       r_vci_cmd_min;       
300    sc_signal<size_t>       r_vci_cmd_max;       
301    sc_signal<size_t>       r_vci_cmd_cpt;       
[134]302    sc_signal<bool>         r_vci_cmd_dcache_prior;
[147]303     
[2]304    sc_signal<int>          r_vci_rsp_fsm;
[147]305    sc_signal<bool>         r_vci_rsp_ins_error;   
306    sc_signal<bool>         r_vci_rsp_data_error;   
[2]307    sc_signal<size_t>       r_vci_rsp_cpt; 
[147]308    sc_signal<bool>         r_vci_rsp_ack;
[2]309
[147]310#if CC_XCACHE_WRAPPER_FIFO_RSP
311    std::queue<data_t>      r_icache_miss_buf;
312    std::queue<data_t>      r_dcache_miss_buf;
[134]313#else
[147]314    bool                   *r_icache_miss_val;    //[m_icache_words]
315    data_t                 *r_icache_miss_buf;    //[m_icache_words]
316    bool                   *r_dcache_miss_val;    //[m_dcache_words]
317    data_t                 *r_dcache_miss_buf;    //[m_dcache_words]
[134]318#endif
[147]319    sc_signal<bool>         r_icache_buf_unc_valid;
320
321    data_t                 *r_tgt_buf;            //[m_cache_words]
322    be_t                   *r_tgt_be;             //[m_cache_words]
[134]323#if CC_XCACHE_WRAPPER_CC_UPDATE_MULTI_CYCLE
324    sc_signal<uint32_t>     r_cache_word;
325#endif
[2]326
327    sc_signal<int>          r_vci_tgt_fsm;
[147]328    sc_signal<addr_40>      r_tgt_addr;
[2]329    sc_signal<size_t>       r_tgt_word;
330    sc_signal<bool>         r_tgt_update;
331    sc_signal<bool>         r_tgt_update_data;
[134]332  //sc_signal<bool>         r_tgt_brdcast;
[2]333    sc_signal<size_t>       r_tgt_srcid;
334    sc_signal<size_t>       r_tgt_pktid;
335    sc_signal<size_t>       r_tgt_trdid;
[134]336  //sc_signal<size_t>       r_tgt_plen;
[147]337    sc_signal<bool>         r_tgt_icache_req;
338    sc_signal<bool>         r_tgt_dcache_req;
339    sc_signal<bool>         r_tgt_icache_rsp;
340    sc_signal<bool>         r_tgt_dcache_rsp;
[2]341
[134]342    sc_signal<int>          r_cleanup_fsm;              // controls initiator port of the coherence network
343
[147]344    MultiWriteBuffer<addr_40>   r_wbuf;
345    GenericCache<vci_addr_t>    r_icache;
346    GenericCache<vci_addr_t>    r_dcache;
[2]347
[147]348#if CC_XCACHE_WRAPPER_DEBUG_DCACHE_TRANSACTION
349    std::ofstream               log_dcache_transaction_file;
[134]350#endif
351
[2]352    // Activity counters
[147]353    uint32_t m_cpt_dcache_data_read;             // * DCACHE DATA READ
354    uint32_t m_cpt_dcache_data_write;            // * DCACHE DATA WRITE
355    uint32_t m_cpt_dcache_dir_read;              // * DCACHE DIR READ
356    uint32_t m_cpt_dcache_dir_write;             // * DCACHE DIR WRITE
357                                                 
358    uint32_t m_cpt_icache_data_read;             // * ICACHE DATA READ
359    uint32_t m_cpt_icache_data_write;            // * ICACHE DATA WRITE
360    uint32_t m_cpt_icache_dir_read;              // * ICACHE DIR READ
361    uint32_t m_cpt_icache_dir_write;             // * ICACHE DIR WRITE
[2]362
[147]363    uint32_t m_cpt_cc_update_icache;             // number of coherence update packets (for icache)
364    uint32_t m_cpt_cc_update_dcache;             // number of coherence update packets (for dcache)
365    uint32_t m_cpt_cc_inval_broadcast;           // number of coherence inval packets
366    uint32_t m_cpt_cc_inval_icache;              // number of coherence inval packets
367    uint32_t m_cpt_cc_inval_dcache;              // number of coherence inval packets
368    uint32_t m_cpt_cc_update_icache_word_useful; // number of valid word in coherence update packets
369    uint32_t m_cpt_cc_update_dcache_word_useful; // number of valid word in coherence update packets
[2]370
[147]371    uint32_t m_cpt_frz_cycles;                   // * number of cycles where the cpu is frozen
372    uint32_t m_cpt_total_cycles;                     // total number of cycles
[2]373
[147]374    uint32_t m_cpt_data_read;                    //   number of data read
375    uint32_t m_cpt_data_read_miss;               //   number of data read miss
376    uint32_t m_cpt_data_read_uncached;           //   number of data read uncached
377    uint32_t m_cpt_data_write;                   //   number of data write
378    uint32_t m_cpt_data_write_miss;              //   number of data write miss
379    uint32_t m_cpt_data_write_uncached;          //   number of data write uncached
380    uint32_t m_cpt_ins_miss;                     // * number of instruction miss
[2]381
[147]382    uint32_t m_cost_write_frz;                   // * number of frozen cycles related to write buffer         
383    uint32_t m_cost_data_miss_frz;               // * number of frozen cycles related to data miss
384    uint32_t m_cost_unc_read_frz;                // * number of frozen cycles related to uncached read
385    uint32_t m_cost_ins_miss_frz;                // * number of frozen cycles related to ins miss
[2]386
[147]387    uint32_t m_cpt_imiss_transaction;            // * number of VCI instruction miss transactions
388    uint32_t m_cpt_dmiss_transaction;            // * number of VCI data miss transactions
389    uint32_t m_cpt_unc_transaction;              // * number of VCI uncached read transactions
390    uint32_t m_cpt_data_write_transaction;       // * number of VCI write transactions
391
392    uint32_t m_cost_imiss_transaction;           // * cumulated duration for VCI IMISS transactions
393    uint32_t m_cost_dmiss_transaction;           // * cumulated duration for VCI DMISS transactions
394    uint32_t m_cost_unc_transaction;             // * cumulated duration for VCI UNC transactions
395    uint32_t m_cost_write_transaction;           // * cumulated duration for VCI WRITE transactions
396    uint32_t m_length_write_transaction;         // * cumulated length for VCI WRITE transactions
397
[2]398protected:
399    SC_HAS_PROCESS(VciCcXCacheWrapperV4);
400
401public:
402
403    VciCcXCacheWrapperV4(
404                       sc_module_name insname,
405                       int proc_id,
406                       const soclib::common::MappingTable &mtp,
407                       const soclib::common::MappingTable &mtc,
408                       const soclib::common::IntTab &initiator_index_rw,
409                       const soclib::common::IntTab &initiator_index_c,
410                       const soclib::common::IntTab &target_index,
411                       size_t icache_ways,
412                       size_t icache_sets,
413                       size_t icache_words,
414                       size_t dcache_ways,
415                       size_t dcache_sets,
[134]416                       size_t dcache_words,
417                       size_t wbuf_nwords,
418                       size_t wbuf_nlines,
419                       size_t wbuf_timeout
420                         );
[2]421
422    ~VciCcXCacheWrapperV4();
423
[147]424    void print_trace(size_t mode = 0);
425    void print_cpi();
426    void print_stats();
[2]427
[134]428// #if CC_XCACHE_WRAPPER_STOP_SIMULATION
429    void stop_simulation (uint32_t);
430// #endif // CC_XCACHE_WRAPPER_STOP_SIMULATION
431
[2]432private:
433
434    void transition();
435    void genMoore();
436
[147]437    soclib_static_assert((int)iss_t::SC_ATOMIC == (int)vci_param::STORE_COND_ATOMIC);
[2]438    soclib_static_assert((int)iss_t::SC_NOT_ATOMIC == (int)vci_param::STORE_COND_NOT_ATOMIC);
439};
440
441}}
442
443#endif /* SOCLIB_CABA_VCI_CC_XCACHE_WRAPPER_V4_H */
444
445// Local Variables:
446// tab-width: 4
447// c-basic-offset: 4
448// c-file-offsets:((innamespace . 0)(inline-open . 0))
449// indent-tabs-mode: nil
450// End:
451
452// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracBrowser for help on using the repository browser.