CacheRecorder.hh revision 14184
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
312855Sgabeblack@google.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
412855Sgabeblack@google.com * All rights reserved.
512855Sgabeblack@google.com *
612855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
712855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
812855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
912855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1012855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1112855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1212855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1312855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1412855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1512855Sgabeblack@google.com * this software without specific prior written permission.
1612855Sgabeblack@google.com *
1712855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812855Sgabeblack@google.com */
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com/*
3112855Sgabeblack@google.com * Recording cache requests made to a ruby cache at certain ruby
3212855Sgabeblack@google.com * time. Also dump the requests to a gziped file.
3312855Sgabeblack@google.com */
3412855Sgabeblack@google.com
3512855Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_CACHERECORDER_HH__
3612855Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_CACHERECORDER_HH__
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com#include <vector>
3912855Sgabeblack@google.com
4012855Sgabeblack@google.com#include "base/types.hh"
4112855Sgabeblack@google.com#include "mem/ruby/common/Address.hh"
4212855Sgabeblack@google.com#include "mem/ruby/common/DataBlock.hh"
4312855Sgabeblack@google.com#include "mem/ruby/common/TypeDefines.hh"
4412855Sgabeblack@google.com#include "mem/ruby/protocol/RubyRequestType.hh"
4512855Sgabeblack@google.com
4612855Sgabeblack@google.comclass Sequencer;
4712855Sgabeblack@google.com
4812855Sgabeblack@google.com/*!
4912855Sgabeblack@google.com * Class for recording cache contents. Note that the last element of the
5012855Sgabeblack@google.com * class is an array of length zero. It is used for creating variable
5112855Sgabeblack@google.com * length object, so that while writing the data to a file one does not
5212855Sgabeblack@google.com * need to copy the meta data and the actual data separately.
5312855Sgabeblack@google.com */
5412855Sgabeblack@google.comclass TraceRecord {
5512855Sgabeblack@google.com  public:
5612855Sgabeblack@google.com    int m_cntrl_id;
5712855Sgabeblack@google.com    Tick m_time;
5812855Sgabeblack@google.com    Addr m_data_address;
5912855Sgabeblack@google.com    Addr m_pc_address;
6012855Sgabeblack@google.com    RubyRequestType m_type;
6112855Sgabeblack@google.com    uint8_t m_data[0];
6212855Sgabeblack@google.com
6312855Sgabeblack@google.com    void print(std::ostream& out) const;
6412855Sgabeblack@google.com};
6512855Sgabeblack@google.com
66class CacheRecorder
67{
68  public:
69    CacheRecorder();
70    ~CacheRecorder();
71
72    CacheRecorder(uint8_t* uncompressed_trace,
73                  uint64_t uncompressed_trace_size,
74                  std::vector<Sequencer*>& SequencerMap,
75                  uint64_t block_size_bytes);
76    void addRecord(int cntrl, Addr data_addr, Addr pc_addr,
77                   RubyRequestType type, Tick time, DataBlock& data);
78
79    uint64_t aggregateRecords(uint8_t **data, uint64_t size);
80
81    /*!
82     * Function for flushing the memory contents of the caches to the
83     * main memory. It goes through the recorded contents of the caches,
84     * and issues flush requests. Except for the first one, a flush request
85     * is issued only after the previous one has completed. This currently
86     * requires use of MOESI Hammer protocol since only that protocol
87     * supports flush requests.
88     */
89    void enqueueNextFlushRequest();
90
91    /*!
92     * Function for fetching warming up the memory and the caches. It goes
93     * through the recorded contents of the caches, as available in the
94     * checkpoint and issues fetch requests. Except for the first one, a
95     * fetch request is issued only after the previous one has completed.
96     * It should be possible to use this with any protocol.
97     */
98    void enqueueNextFetchRequest();
99
100  private:
101    // Private copy constructor and assignment operator
102    CacheRecorder(const CacheRecorder& obj);
103    CacheRecorder& operator=(const CacheRecorder& obj);
104
105    std::vector<TraceRecord*> m_records;
106    uint8_t* m_uncompressed_trace;
107    uint64_t m_uncompressed_trace_size;
108    std::vector<Sequencer*> m_seq_map;
109    uint64_t m_bytes_read;
110    uint64_t m_records_read;
111    uint64_t m_records_flushed;
112    uint64_t m_block_size_bytes;
113};
114
115inline bool
116compareTraceRecords(const TraceRecord* n1, const TraceRecord* n2)
117{
118    return n1->m_time > n2->m_time;
119}
120
121inline std::ostream&
122operator<<(std::ostream& out, const TraceRecord& obj)
123{
124    obj.print(out);
125    out << std::flush;
126    return out;
127}
128
129#endif //__MEM_RUBY_SYSTEM_CACHERECORDER_HH__
130