CacheRecorder.hh revision 11049:dfb0aa3f0649
113516Sgabeblack@google.com/*
213516Sgabeblack@google.com * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
313516Sgabeblack@google.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
413516Sgabeblack@google.com * All rights reserved.
513516Sgabeblack@google.com *
613516Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
713516Sgabeblack@google.com * modification, are permitted provided that the following conditions are
813516Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
913516Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
1013516Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1113516Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1213516Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1313516Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1413516Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1513516Sgabeblack@google.com * this software without specific prior written permission.
1613516Sgabeblack@google.com *
1713516Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1813516Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1913516Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2013516Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2113516Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2213516Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2313516Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2413516Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2513516Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2613516Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2713516Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2813516Sgabeblack@google.com */
2913516Sgabeblack@google.com
3013516Sgabeblack@google.com/*
3113516Sgabeblack@google.com * Recording cache requests made to a ruby cache at certain ruby
3213516Sgabeblack@google.com * time. Also dump the requests to a gziped file.
3313516Sgabeblack@google.com */
3413516Sgabeblack@google.com
3513516Sgabeblack@google.com#ifndef __MEM_RUBY_RECORDER_CACHERECORDER_HH__
3613516Sgabeblack@google.com#define __MEM_RUBY_RECORDER_CACHERECORDER_HH__
3713516Sgabeblack@google.com
3813516Sgabeblack@google.com#include <vector>
3913516Sgabeblack@google.com
4013516Sgabeblack@google.com#include "base/hashmap.hh"
4113516Sgabeblack@google.com#include "base/types.hh"
4213516Sgabeblack@google.com#include "mem/protocol/RubyRequestType.hh"
4313516Sgabeblack@google.com#include "mem/ruby/common/Address.hh"
4413516Sgabeblack@google.com#include "mem/ruby/common/DataBlock.hh"
4513516Sgabeblack@google.com#include "mem/ruby/common/TypeDefines.hh"
4613516Sgabeblack@google.com
4713516Sgabeblack@google.comclass Sequencer;
4813516Sgabeblack@google.com
4913516Sgabeblack@google.com/*!
5013516Sgabeblack@google.com * Class for recording cache contents. Note that the last element of the
5113516Sgabeblack@google.com * class is an array of length zero. It is used for creating variable
5213516Sgabeblack@google.com * length object, so that while writing the data to a file one does not
5313516Sgabeblack@google.com * need to copy the meta data and the actual data separately.
5413516Sgabeblack@google.com */
5513516Sgabeblack@google.comclass TraceRecord {
5613516Sgabeblack@google.com  public:
5713516Sgabeblack@google.com    int m_cntrl_id;
5813516Sgabeblack@google.com    Tick m_time;
5913516Sgabeblack@google.com    Addr m_data_address;
6013516Sgabeblack@google.com    Addr m_pc_address;
6113516Sgabeblack@google.com    RubyRequestType m_type;
6213516Sgabeblack@google.com    uint8_t m_data[0];
6313516Sgabeblack@google.com
6413516Sgabeblack@google.com    void print(std::ostream& out) const;
6513516Sgabeblack@google.com};
6613516Sgabeblack@google.com
6713516Sgabeblack@google.comclass CacheRecorder
6813516Sgabeblack@google.com{
6913516Sgabeblack@google.com  public:
7013516Sgabeblack@google.com    CacheRecorder();
7113516Sgabeblack@google.com    ~CacheRecorder();
7213516Sgabeblack@google.com
7313516Sgabeblack@google.com    CacheRecorder(uint8_t* uncompressed_trace,
7413516Sgabeblack@google.com                  uint64_t uncompressed_trace_size,
7513516Sgabeblack@google.com                  std::vector<Sequencer*>& SequencerMap,
7613516Sgabeblack@google.com                  uint64_t block_size_bytes);
7713516Sgabeblack@google.com    void addRecord(int cntrl, Addr data_addr, Addr pc_addr,
7813516Sgabeblack@google.com                   RubyRequestType type, Tick time, DataBlock& data);
7913516Sgabeblack@google.com
8013516Sgabeblack@google.com    uint64 aggregateRecords(uint8_t** data, uint64 size);
8113516Sgabeblack@google.com
8213516Sgabeblack@google.com    /*!
8313516Sgabeblack@google.com     * Function for flushing the memory contents of the caches to the
8413516Sgabeblack@google.com     * main memory. It goes through the recorded contents of the caches,
8513516Sgabeblack@google.com     * and issues flush requests. Except for the first one, a flush request
8613516Sgabeblack@google.com     * is issued only after the previous one has completed. This currently
8713516Sgabeblack@google.com     * requires use of MOESI Hammer protocol since only that protocol
8813516Sgabeblack@google.com     * supports flush requests.
8913516Sgabeblack@google.com     */
9013516Sgabeblack@google.com    void enqueueNextFlushRequest();
9113516Sgabeblack@google.com
9213516Sgabeblack@google.com    /*!
9313516Sgabeblack@google.com     * Function for fetching warming up the memory and the caches. It goes
9413516Sgabeblack@google.com     * through the recorded contents of the caches, as available in the
9513516Sgabeblack@google.com     * checkpoint and issues fetch requests. Except for the first one, a
9613516Sgabeblack@google.com     * fetch request is issued only after the previous one has completed.
9713516Sgabeblack@google.com     * It should be possible to use this with any protocol.
9813516Sgabeblack@google.com     */
9913516Sgabeblack@google.com    void enqueueNextFetchRequest();
10013516Sgabeblack@google.com
10113516Sgabeblack@google.com  private:
10213516Sgabeblack@google.com    // Private copy constructor and assignment operator
10313516Sgabeblack@google.com    CacheRecorder(const CacheRecorder& obj);
10413516Sgabeblack@google.com    CacheRecorder& operator=(const CacheRecorder& obj);
10513516Sgabeblack@google.com
10613516Sgabeblack@google.com    std::vector<TraceRecord*> m_records;
10713516Sgabeblack@google.com    uint8_t* m_uncompressed_trace;
10813516Sgabeblack@google.com    uint64_t m_uncompressed_trace_size;
10913516Sgabeblack@google.com    std::vector<Sequencer*> m_seq_map;
11013516Sgabeblack@google.com    uint64_t m_bytes_read;
11113516Sgabeblack@google.com    uint64_t m_records_read;
112    uint64_t m_records_flushed;
113    uint64_t m_block_size_bytes;
114};
115
116inline bool
117compareTraceRecords(const TraceRecord* n1, const TraceRecord* n2)
118{
119    return n1->m_time > n2->m_time;
120}
121
122inline std::ostream&
123operator<<(std::ostream& out, const TraceRecord& obj)
124{
125    obj.print(out);
126    out << std::flush;
127    return out;
128}
129
130#endif // __MEM_RUBY_RECORDER_CACHERECORDER_HH__
131