cp_annotate.cc revision 11320
15952Ssaidi@eecs.umich.edu/*
25952Ssaidi@eecs.umich.edu * Copyright (c) 2006-2009 The Regents of The University of Michigan
35952Ssaidi@eecs.umich.edu * All rights reserved.
45952Ssaidi@eecs.umich.edu *
55952Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
65952Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
75952Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
85952Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
95952Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
105952Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
115952Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
125952Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
135952Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
145952Ssaidi@eecs.umich.edu * this software without specific prior written permission.
155952Ssaidi@eecs.umich.edu *
165952Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175952Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185952Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195952Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205952Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215952Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225952Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235952Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245952Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255952Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265952Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275952Ssaidi@eecs.umich.edu *
285952Ssaidi@eecs.umich.edu * Authors: Ali Saidi
295952Ssaidi@eecs.umich.edu */
305952Ssaidi@eecs.umich.edu
3110377Sandreas.hansson@arm.com#include "arch/generic/linux/threadinfo.hh"
325952Ssaidi@eecs.umich.edu#include "arch/utility.hh"
338229Snate@binkert.org#include "base/loader/object_file.hh"
348229Snate@binkert.org#include "base/callback.hh"
355952Ssaidi@eecs.umich.edu#include "base/cp_annotate.hh"
365952Ssaidi@eecs.umich.edu#include "base/output.hh"
375952Ssaidi@eecs.umich.edu#include "base/trace.hh"
386658Snate@binkert.org#include "config/the_isa.hh"
395952Ssaidi@eecs.umich.edu#include "cpu/thread_context.hh"
4010377Sandreas.hansson@arm.com#include "debug/Annotate.hh"
4110377Sandreas.hansson@arm.com#include "debug/AnnotateVerbose.hh"
425952Ssaidi@eecs.umich.edu#include "sim/arguments.hh"
435952Ssaidi@eecs.umich.edu#include "sim/core.hh"
445952Ssaidi@eecs.umich.edu#include "sim/sim_exit.hh"
455952Ssaidi@eecs.umich.edu#include "sim/system.hh"
465952Ssaidi@eecs.umich.edu
475952Ssaidi@eecs.umich.edustruct CPAIgnoreSymbol
485952Ssaidi@eecs.umich.edu{
495952Ssaidi@eecs.umich.edu    const char *symbol;
505952Ssaidi@eecs.umich.edu    size_t len;
515952Ssaidi@eecs.umich.edu};
525952Ssaidi@eecs.umich.edu#define CPA_IGNORE_SYMBOL(sym) { #sym, sizeof(#sym) }
535952Ssaidi@eecs.umich.edu
545952Ssaidi@eecs.umich.eduCPAIgnoreSymbol ignoreSymbols[] = {
555952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("m5a_"),
565952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("ret_from_sys_call"),
575952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("ret_from_reschedule"),
585952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("_spin_"),
595952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("local_bh_"),
605952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("restore_all"),
615952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("Call_Pal_"),
625952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("pal_post_interrupt"),
635952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("rti_to_"),
645952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("sys_int_2"),
655952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("sys_interrupt"),
665952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("normal_int"),
675952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("TRAP_INTERRUPT_10_"),
685952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("Trap_Interrupt"),
695952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("do_entInt"),
705952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("__do_softirq"),
715952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("_end"),
725952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("entInt"),
735952Ssaidi@eecs.umich.edu    CPA_IGNORE_SYMBOL("entSys"),
745952Ssaidi@eecs.umich.edu    {0,0}
755952Ssaidi@eecs.umich.edu};
765952Ssaidi@eecs.umich.edu#undef CPA_IGNORE_SYMBOL
775952Ssaidi@eecs.umich.edu
785952Ssaidi@eecs.umich.eduusing namespace std;
795952Ssaidi@eecs.umich.eduusing namespace TheISA;
805952Ssaidi@eecs.umich.edu
815952Ssaidi@eecs.umich.edubool CPA::exists;
825952Ssaidi@eecs.umich.eduCPA *CPA::_cpa;
835952Ssaidi@eecs.umich.edu
845952Ssaidi@eecs.umich.educlass AnnotateDumpCallback : public Callback
855952Ssaidi@eecs.umich.edu{
865952Ssaidi@eecs.umich.edu
875952Ssaidi@eecs.umich.edu  private:
885952Ssaidi@eecs.umich.edu    CPA *cpa;
895952Ssaidi@eecs.umich.edu  public:
905952Ssaidi@eecs.umich.edu    virtual void process();
915952Ssaidi@eecs.umich.edu    AnnotateDumpCallback(CPA *_cpa)
925952Ssaidi@eecs.umich.edu        : cpa(_cpa)
935952Ssaidi@eecs.umich.edu    {}
945952Ssaidi@eecs.umich.edu};
955952Ssaidi@eecs.umich.edu
965952Ssaidi@eecs.umich.eduvoid
975952Ssaidi@eecs.umich.eduAnnotateDumpCallback::process()
985952Ssaidi@eecs.umich.edu{
995952Ssaidi@eecs.umich.edu    cpa->dump(true);
1005952Ssaidi@eecs.umich.edu    cpa->dumpKey();
1015952Ssaidi@eecs.umich.edu}
1025952Ssaidi@eecs.umich.edu
1035952Ssaidi@eecs.umich.edu
1045952Ssaidi@eecs.umich.eduCPA::CPA(Params *p)
1055952Ssaidi@eecs.umich.edu    : SimObject(p), numSm(0), numSmt(0), numSys(0), numQs(0), conId(0)
1065952Ssaidi@eecs.umich.edu{
1075952Ssaidi@eecs.umich.edu    if (exists)
1085952Ssaidi@eecs.umich.edu        fatal("Multiple annotation objects found in system");
1095952Ssaidi@eecs.umich.edu    exists = true;
1105952Ssaidi@eecs.umich.edu
1115952Ssaidi@eecs.umich.edu    _enabled = p->enabled;
1125952Ssaidi@eecs.umich.edu    _cpa = this;
1135952Ssaidi@eecs.umich.edu
1145952Ssaidi@eecs.umich.edu    vector<string>::iterator i;
1155952Ssaidi@eecs.umich.edu    i = p->user_apps.begin();
1165952Ssaidi@eecs.umich.edu
1175952Ssaidi@eecs.umich.edu    while (i != p->user_apps.end()) {
1185952Ssaidi@eecs.umich.edu        ObjectFile *of = createObjectFile(*i);
1195952Ssaidi@eecs.umich.edu        string sf;
1205952Ssaidi@eecs.umich.edu        if (!of)
1215952Ssaidi@eecs.umich.edu            fatal("Couldn't load symbols from file: %s\n", *i);
1225952Ssaidi@eecs.umich.edu        sf = *i;
1235952Ssaidi@eecs.umich.edu        sf.erase(0, sf.rfind('/') + 1);;
1245952Ssaidi@eecs.umich.edu        DPRINTFN("file %s short: %s\n", *i, sf);
1255952Ssaidi@eecs.umich.edu        userApp[sf] = new SymbolTable;
1265952Ssaidi@eecs.umich.edu        bool result1 = of->loadGlobalSymbols(userApp[sf]);
1275952Ssaidi@eecs.umich.edu        bool result2 = of->loadLocalSymbols(userApp[sf]);
1285952Ssaidi@eecs.umich.edu        if (!result1 || !result2)
1295952Ssaidi@eecs.umich.edu            panic("blah");
1305952Ssaidi@eecs.umich.edu        assert(result1 && result2);
1315952Ssaidi@eecs.umich.edu        i++;
1325952Ssaidi@eecs.umich.edu    }
1335952Ssaidi@eecs.umich.edu}
1345952Ssaidi@eecs.umich.edu
1355952Ssaidi@eecs.umich.eduvoid
1365952Ssaidi@eecs.umich.eduCPA::startup()
1375952Ssaidi@eecs.umich.edu{
1385952Ssaidi@eecs.umich.edu    osbin = simout.create("annotate.bin", true);
1395952Ssaidi@eecs.umich.edu    // MAGIC version number 'M''5''A'N' + version/capabilities
1405952Ssaidi@eecs.umich.edu    ah.version = 0x4D35414E00000101ULL;
1415952Ssaidi@eecs.umich.edu    ah.num_recs = 0;
1425952Ssaidi@eecs.umich.edu    ah.key_off = 0;
1435952Ssaidi@eecs.umich.edu    osbin->write((char*)&ah, sizeof(AnnotateHeader));
1445952Ssaidi@eecs.umich.edu
1455952Ssaidi@eecs.umich.edu    registerExitCallback(new AnnotateDumpCallback(this));
1465952Ssaidi@eecs.umich.edu}
14710377Sandreas.hansson@arm.com
14810377Sandreas.hansson@arm.comuint64_t
14910377Sandreas.hansson@arm.comCPA::getFrame(ThreadContext *tc)
15010377Sandreas.hansson@arm.com{
15110377Sandreas.hansson@arm.com    // This code is ISA specific and will need to be changed
15210377Sandreas.hansson@arm.com    // if the annotation code is used for something other than Alpha
15310377Sandreas.hansson@arm.com    return (tc->readMiscRegNoEffect(TheISA::IPR_PALtemp23) &
15410377Sandreas.hansson@arm.com            ~ULL(0x3FFF));
15510377Sandreas.hansson@arm.com
15610377Sandreas.hansson@arm.com}
15710377Sandreas.hansson@arm.com
1585952Ssaidi@eecs.umich.eduvoid
1595952Ssaidi@eecs.umich.eduCPA::swSmBegin(ThreadContext *tc)
1605952Ssaidi@eecs.umich.edu{
1615952Ssaidi@eecs.umich.edu    if (!enabled())
1625952Ssaidi@eecs.umich.edu        return;
1635952Ssaidi@eecs.umich.edu
1645952Ssaidi@eecs.umich.edu    Arguments args(tc);
1655952Ssaidi@eecs.umich.edu    std::string st;
1665952Ssaidi@eecs.umich.edu    Addr junk;
1675952Ssaidi@eecs.umich.edu    char sm[50];
1685952Ssaidi@eecs.umich.edu    if (!TheISA::inUserMode(tc))
1695952Ssaidi@eecs.umich.edu        debugSymbolTable->findNearestSymbol(
1705952Ssaidi@eecs.umich.edu            tc->readIntReg(ReturnAddressReg), st, junk);
1715952Ssaidi@eecs.umich.edu
1725952Ssaidi@eecs.umich.edu    CopyStringOut(tc, sm, args[0], 50);
1735952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
1745952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
1755952Ssaidi@eecs.umich.edu
1765952Ssaidi@eecs.umich.edu    if (!sm[0])
1777823Ssteve.reinhardt@amd.com        warn("Got null SM at tick %d\n", curTick());
1785952Ssaidi@eecs.umich.edu
1795952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
1805952Ssaidi@eecs.umich.edu    int smi = getSm(sysi, sm, args[1]);
1815952Ssaidi@eecs.umich.edu    DPRINTF(Annotate,  "Starting machine: %s(%d) sysi: %d id: %#x\n", sm,
1825952Ssaidi@eecs.umich.edu            smi, sysi, args[1]);
18311320Ssteve.reinhardt@amd.com    DPRINTF(Annotate, "smMap[%d] = %d, %s, %#x\n", smi,
18411320Ssteve.reinhardt@amd.com            smMap[smi-1].first, smMap[smi-1].second.first,
1855952Ssaidi@eecs.umich.edu            smMap[smi-1].second.second);
1865952Ssaidi@eecs.umich.edu
1875952Ssaidi@eecs.umich.edu    uint64_t frame = getFrame(tc);
1885952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, frame);
1895952Ssaidi@eecs.umich.edu
1905952Ssaidi@eecs.umich.edu    // check if we need to link to the previous state machine
1915952Ssaidi@eecs.umich.edu    int flags = args[2];
1925952Ssaidi@eecs.umich.edu    if (flags & FL_LINK) {
1935952Ssaidi@eecs.umich.edu        if (smStack[sid].size()) {
1945952Ssaidi@eecs.umich.edu            int prev_smi = smStack[sid].back();
1955952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "Linking from %d to state machine %s(%d) [%#x]\n",
1965952Ssaidi@eecs.umich.edu                    prev_smi, sm, smi, args[1]);
1975952Ssaidi@eecs.umich.edu
1985952Ssaidi@eecs.umich.edu            if (lnMap[smi])
1995952Ssaidi@eecs.umich.edu                DPRINTF(Annotate, "LnMap already contains entry for %d of %d\n",
2005952Ssaidi@eecs.umich.edu                        smi, lnMap[smi]);
2015952Ssaidi@eecs.umich.edu            assert(lnMap[smi] == 0);
2025952Ssaidi@eecs.umich.edu            lnMap[smi] =  prev_smi;
2035952Ssaidi@eecs.umich.edu
2045952Ssaidi@eecs.umich.edu            add(OP_LINK, FL_NONE, tc->contextId(), prev_smi, smi);
2055952Ssaidi@eecs.umich.edu        } else {
2065952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "Not Linking to state machine %s(%d) [%#x]\n",
2075952Ssaidi@eecs.umich.edu                    sm, smi, args[1]);
2085952Ssaidi@eecs.umich.edu        }
2095952Ssaidi@eecs.umich.edu    }
2105952Ssaidi@eecs.umich.edu
2115952Ssaidi@eecs.umich.edu
2125952Ssaidi@eecs.umich.edu    smStack[sid].push_back(smi);
2135952Ssaidi@eecs.umich.edu
2145952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Stack Now (%#X):\n", frame);
2155952Ssaidi@eecs.umich.edu    for (int x = smStack[sid].size()-1; x >= 0; x--)
2165952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "-- %d\n", smStack[sid][x]);
2175952Ssaidi@eecs.umich.edu
2185952Ssaidi@eecs.umich.edu    // reset the sw state exculsion to false
2195952Ssaidi@eecs.umich.edu    if (swExpl[sid])
2205952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
2215952Ssaidi@eecs.umich.edu
2225952Ssaidi@eecs.umich.edu
2235952Ssaidi@eecs.umich.edu    Id id = Id(sm, frame);
2245952Ssaidi@eecs.umich.edu    if (scLinks[sysi-1][id]) {
2255952Ssaidi@eecs.umich.edu        AnnDataPtr an = scLinks[sysi-1][id];
2265952Ssaidi@eecs.umich.edu        scLinks[sysi-1].erase(id);
2275952Ssaidi@eecs.umich.edu        an->stq = smi;
2285952Ssaidi@eecs.umich.edu        an->dump = true;
22911320Ssteve.reinhardt@amd.com        DPRINTF(Annotate,
2305952Ssaidi@eecs.umich.edu                "Found prev unknown linking from %d to state machine %s(%d)\n",
2315952Ssaidi@eecs.umich.edu                an->sm, sm, smi);
2325952Ssaidi@eecs.umich.edu
2335952Ssaidi@eecs.umich.edu        if (lnMap[smi])
2345952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "LnMap already contains entry for %d of %d\n",
2355952Ssaidi@eecs.umich.edu                    smi, lnMap[smi]);
2365952Ssaidi@eecs.umich.edu        assert(lnMap[smi] == 0);
2375952Ssaidi@eecs.umich.edu        lnMap[smi] =  an->sm;
2385952Ssaidi@eecs.umich.edu    }
2395952Ssaidi@eecs.umich.edu
2405952Ssaidi@eecs.umich.edu    // add a new begin ifwe have that info
2415952Ssaidi@eecs.umich.edu    if (st != "") {
2425952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "st: %s smi: %d stCache.size %d\n", st,
2435952Ssaidi@eecs.umich.edu                smi, stCache.size());
2445952Ssaidi@eecs.umich.edu        int sti = getSt(sm, st);
2455952Ssaidi@eecs.umich.edu        lastState[smi] = sti;
2465952Ssaidi@eecs.umich.edu        add(OP_BEGIN, FL_NONE, tc->contextId(), smi, sti);
2475952Ssaidi@eecs.umich.edu    }
2485952Ssaidi@eecs.umich.edu}
2495952Ssaidi@eecs.umich.edu
2505952Ssaidi@eecs.umich.eduvoid
2515952Ssaidi@eecs.umich.eduCPA::swSmEnd(ThreadContext *tc)
2525952Ssaidi@eecs.umich.edu{
2535952Ssaidi@eecs.umich.edu    if (!enabled())
2545952Ssaidi@eecs.umich.edu        return;
2555952Ssaidi@eecs.umich.edu
2565952Ssaidi@eecs.umich.edu    Arguments args(tc);
2575952Ssaidi@eecs.umich.edu    char sm[50];
2585952Ssaidi@eecs.umich.edu    CopyStringOut(tc, sm, args[0], 50);
2595952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
2605952Ssaidi@eecs.umich.edu    doSwSmEnd(sys, tc->contextId(), sm, getFrame(tc));
2615952Ssaidi@eecs.umich.edu}
2625952Ssaidi@eecs.umich.edu
2635952Ssaidi@eecs.umich.eduvoid
2645952Ssaidi@eecs.umich.eduCPA::doSwSmEnd(System *sys, int cpuid, string sm, uint64_t frame)
2655952Ssaidi@eecs.umich.edu{
2665952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
2675952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, frame);
2685952Ssaidi@eecs.umich.edu
2695952Ssaidi@eecs.umich.edu
2705952Ssaidi@eecs.umich.edu    // reset the sw state exculsion to false
2715952Ssaidi@eecs.umich.edu    if (swExpl[sid])
2725952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
2735952Ssaidi@eecs.umich.edu
2745952Ssaidi@eecs.umich.edu
2755952Ssaidi@eecs.umich.edu    int smib = smStack[sid].back();
2765952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
2775952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Ending machine: %s[%d, %#x] (%d?)\n", sm, sysi,
2785952Ssaidi@eecs.umich.edu            frame, smib);
2795952Ssaidi@eecs.umich.edu
2805952Ssaidi@eecs.umich.edu    if (!smStack[sid].size() || smMap[smib-1].second.first != sm) {
2815952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "State Machine not unwinding correctly. sid: %d, %#x"
2825952Ssaidi@eecs.umich.edu                " top of stack: %s Current Stack:\n",
2835952Ssaidi@eecs.umich.edu                sysi, frame, smMap[smib-1].second.first);
2845952Ssaidi@eecs.umich.edu        for (int x = smStack[sid].size()-1; x >= 0; x--)
2855952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "-- %d\n", smStack[sid][x]);
2865952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "Ending machine: %s; end stack: %s\n", sm,
2875952Ssaidi@eecs.umich.edu                smMap[smib-1].second.first);
2885952Ssaidi@eecs.umich.edu
2897823Ssteve.reinhardt@amd.com        warn("State machine stack not unwinding correctly at %d\n", curTick());
2905952Ssaidi@eecs.umich.edu    } else {
29111320Ssteve.reinhardt@amd.com        DPRINTF(Annotate,
2925952Ssaidi@eecs.umich.edu                "State machine ending:%s sysi:%d id:%#x back:%d getSm:%d\n",
2935952Ssaidi@eecs.umich.edu                sm, sysi, smMap[smib-1].second.second, smStack[sid].back(),
2945952Ssaidi@eecs.umich.edu                getSm(sysi, sm, smMap[smib-1].second.second));
29511320Ssteve.reinhardt@amd.com        assert(getSm(sysi, sm, smMap[smib-1].second.second) ==
2965952Ssaidi@eecs.umich.edu                smStack[sid].back());
2975952Ssaidi@eecs.umich.edu
2985952Ssaidi@eecs.umich.edu        int smi = smStack[sid].back();
2995952Ssaidi@eecs.umich.edu        smStack[sid].pop_back();
3005952Ssaidi@eecs.umich.edu
3015952Ssaidi@eecs.umich.edu        if (lnMap[smi]) {
3025952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "Linking %d back to %d\n", smi, lnMap[smi]);
3035952Ssaidi@eecs.umich.edu            add(OP_LINK, FL_NONE, cpuid, smi, lnMap[smi]);
3045952Ssaidi@eecs.umich.edu            lnMap.erase(smi);
3055952Ssaidi@eecs.umich.edu        }
3065952Ssaidi@eecs.umich.edu
3075952Ssaidi@eecs.umich.edu        if (smStack[sid].size()) {
3085952Ssaidi@eecs.umich.edu            add(OP_BEGIN, FL_NONE, cpuid, smi, lastState[smi]);
3095952Ssaidi@eecs.umich.edu        }
3105952Ssaidi@eecs.umich.edu
3115952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "Stack Now:\n");
3125952Ssaidi@eecs.umich.edu        for (int x = smStack[sid].size()-1; x >= 0; x--)
3135952Ssaidi@eecs.umich.edu            DPRINTF(Annotate, "-- %d\n", smStack[sid][x]);
3145952Ssaidi@eecs.umich.edu    }
3155952Ssaidi@eecs.umich.edu}
3165952Ssaidi@eecs.umich.edu
3175952Ssaidi@eecs.umich.edu
3185952Ssaidi@eecs.umich.eduvoid
3195952Ssaidi@eecs.umich.eduCPA::swExplictBegin(ThreadContext *tc)
3205952Ssaidi@eecs.umich.edu{
3215952Ssaidi@eecs.umich.edu    if (!enabled())
3225952Ssaidi@eecs.umich.edu        return;
3235952Ssaidi@eecs.umich.edu
3245952Ssaidi@eecs.umich.edu    Arguments args(tc);
3255952Ssaidi@eecs.umich.edu    char st[50];
3265952Ssaidi@eecs.umich.edu    CopyStringOut(tc, st, args[1], 50);
3275952Ssaidi@eecs.umich.edu
3285952Ssaidi@eecs.umich.edu    StringWrap name(tc->getSystemPtr()->name());
3295952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Explict begin of state %s\n", st);
3305952Ssaidi@eecs.umich.edu    uint32_t flags = args[0];
3315952Ssaidi@eecs.umich.edu    if (flags & FL_BAD)
3327823Ssteve.reinhardt@amd.com        warn("BAD state encountered: at cycle %d: %s\n", curTick(), st);
3335952Ssaidi@eecs.umich.edu    swBegin(tc->getSystemPtr(), tc->contextId(), st, getFrame(tc), true, args[0]);
3345952Ssaidi@eecs.umich.edu}
3355952Ssaidi@eecs.umich.edu
3365952Ssaidi@eecs.umich.eduvoid
3375952Ssaidi@eecs.umich.eduCPA::swAutoBegin(ThreadContext *tc, Addr next_pc)
3385952Ssaidi@eecs.umich.edu{
3395952Ssaidi@eecs.umich.edu    if (!enabled())
3405952Ssaidi@eecs.umich.edu        return;
3415952Ssaidi@eecs.umich.edu
3425952Ssaidi@eecs.umich.edu    string sym;
3435952Ssaidi@eecs.umich.edu    Addr sym_addr = 0;
3445952Ssaidi@eecs.umich.edu
3455952Ssaidi@eecs.umich.edu    if (!TheISA::inUserMode(tc)) {
3465952Ssaidi@eecs.umich.edu        debugSymbolTable->findNearestSymbol(next_pc, sym, sym_addr);
3475952Ssaidi@eecs.umich.edu    } else {
3485952Ssaidi@eecs.umich.edu        Linux::ThreadInfo ti(tc);
3495952Ssaidi@eecs.umich.edu        string app = ti.curTaskName();
3505952Ssaidi@eecs.umich.edu        if (userApp.count(app))
3515952Ssaidi@eecs.umich.edu            userApp[app]->findNearestSymbol(next_pc, sym, sym_addr);
3525952Ssaidi@eecs.umich.edu    }
3535952Ssaidi@eecs.umich.edu
3545952Ssaidi@eecs.umich.edu    if (sym_addr)
3555952Ssaidi@eecs.umich.edu        swBegin(tc->getSystemPtr(), tc->contextId(), sym, getFrame(tc));
3565952Ssaidi@eecs.umich.edu}
3575952Ssaidi@eecs.umich.edu
3585952Ssaidi@eecs.umich.eduvoid
3595952Ssaidi@eecs.umich.eduCPA::swBegin(System *sys, int cpuid, std::string st, uint64_t frame, bool expl,
3605952Ssaidi@eecs.umich.edu        int flags)
3615952Ssaidi@eecs.umich.edu{
3625952Ssaidi@eecs.umich.edu    int x = 0;
3635952Ssaidi@eecs.umich.edu    int len;
3645952Ssaidi@eecs.umich.edu    while (ignoreSymbols[x].len)
3655952Ssaidi@eecs.umich.edu    {
3665952Ssaidi@eecs.umich.edu        len = ignoreSymbols[x].len;
3675952Ssaidi@eecs.umich.edu        if (!st.compare(0,len, ignoreSymbols[x].symbol, len))
3685952Ssaidi@eecs.umich.edu            return;
3695952Ssaidi@eecs.umich.edu        x++;
3705952Ssaidi@eecs.umich.edu    }
3715952Ssaidi@eecs.umich.edu
3725952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
3735952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, frame);
3745952Ssaidi@eecs.umich.edu    // if expl is true suspend symbol table based states
3755952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
3765952Ssaidi@eecs.umich.edu        return;
3775952Ssaidi@eecs.umich.edu    if (!expl && swExpl[sid])
3785952Ssaidi@eecs.umich.edu        return;
3795952Ssaidi@eecs.umich.edu    if (expl)
3805952Ssaidi@eecs.umich.edu        swExpl[sid] = true;
3815952Ssaidi@eecs.umich.edu    DPRINTFS(AnnotateVerbose, sys, "SwBegin: %s sysi: %d\n", st, sysi);
3825952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
3835952Ssaidi@eecs.umich.edu    int sti = getSt(smMap[smi-1].second.first, st);
3845952Ssaidi@eecs.umich.edu    if (lastState[smi] != sti) {
3855952Ssaidi@eecs.umich.edu        lastState[smi] = sti;
3865952Ssaidi@eecs.umich.edu        add(OP_BEGIN, flags, cpuid, smi, sti);
3875952Ssaidi@eecs.umich.edu    }
3885952Ssaidi@eecs.umich.edu}
3895952Ssaidi@eecs.umich.edu
3905952Ssaidi@eecs.umich.eduvoid
3915952Ssaidi@eecs.umich.eduCPA::swEnd(ThreadContext *tc)
3925952Ssaidi@eecs.umich.edu{
3935952Ssaidi@eecs.umich.edu    if (!enabled())
3945952Ssaidi@eecs.umich.edu        return;
3955952Ssaidi@eecs.umich.edu
3965952Ssaidi@eecs.umich.edu    std::string st;
3975952Ssaidi@eecs.umich.edu    Addr junk;
3985952Ssaidi@eecs.umich.edu    if (!TheISA::inUserMode(tc))
3995952Ssaidi@eecs.umich.edu        debugSymbolTable->findNearestSymbol(
4005952Ssaidi@eecs.umich.edu            tc->readIntReg(ReturnAddressReg), st, junk);
4015952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
4025952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
40311320Ssteve.reinhardt@amd.com
4045952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
4055952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
4065952Ssaidi@eecs.umich.edu    if (!smStack[sid].size()) {
4075952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "Explict end of State: %s IGNORED\n",  st);
4085952Ssaidi@eecs.umich.edu        return;
4095952Ssaidi@eecs.umich.edu    }
4105952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Explict end of State: %s\n",  st);
4115952Ssaidi@eecs.umich.edu    // return back to symbol table based states
4125952Ssaidi@eecs.umich.edu    swExpl[sid] = false;
4135952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
4145952Ssaidi@eecs.umich.edu    if (st != "") {
4155952Ssaidi@eecs.umich.edu        int sti = getSt(smMap[smi-1].second.first, st);
4165952Ssaidi@eecs.umich.edu        lastState[smi] = sti;
4175952Ssaidi@eecs.umich.edu        add(OP_BEGIN, FL_NONE, tc->contextId(), smi, sti);
4185952Ssaidi@eecs.umich.edu    }
4195952Ssaidi@eecs.umich.edu}
4205952Ssaidi@eecs.umich.edu
4215952Ssaidi@eecs.umich.eduvoid
4225952Ssaidi@eecs.umich.eduCPA::swQ(ThreadContext *tc)
4235952Ssaidi@eecs.umich.edu{
4245952Ssaidi@eecs.umich.edu    if (!enabled())
4255952Ssaidi@eecs.umich.edu        return;
4265952Ssaidi@eecs.umich.edu
4275952Ssaidi@eecs.umich.edu    char q[50];
4285952Ssaidi@eecs.umich.edu    Arguments args(tc);
4295952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
4305952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
4315952Ssaidi@eecs.umich.edu    int32_t count = args[2];
4325952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
4335952Ssaidi@eecs.umich.edu
4345952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
4355952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
4365952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
4375952Ssaidi@eecs.umich.edu        return;
4385952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
4395952Ssaidi@eecs.umich.edu    if (swExpl[sid])
4405952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
4415952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
4425952Ssaidi@eecs.umich.edu    if (count == 0) {
4435952Ssaidi@eecs.umich.edu        //warn("Tried to queue 0 bytes in %s, ignoring\n", q);
4445952Ssaidi@eecs.umich.edu        return;
4455952Ssaidi@eecs.umich.edu    }
44611320Ssteve.reinhardt@amd.com    DPRINTFS(AnnotateQ, sys,
4475952Ssaidi@eecs.umich.edu            "swQ: %s[%#x] cur size %d %d bytes: %d adding: %d\n",
4485952Ssaidi@eecs.umich.edu            q, id, qSize[qi-1], qData[qi-1].size(), qBytes[qi-1], count);
4495952Ssaidi@eecs.umich.edu    doQ(sys, FL_NONE, tc->contextId(), smi, q, qi, count);
4505952Ssaidi@eecs.umich.edu}
4515952Ssaidi@eecs.umich.edu
4525952Ssaidi@eecs.umich.eduvoid
4535952Ssaidi@eecs.umich.eduCPA::swDq(ThreadContext *tc)
4545952Ssaidi@eecs.umich.edu{
4555952Ssaidi@eecs.umich.edu    if (!enabled())
4565952Ssaidi@eecs.umich.edu        return;
4575952Ssaidi@eecs.umich.edu
4585952Ssaidi@eecs.umich.edu    char q[50];
4595952Ssaidi@eecs.umich.edu    Arguments args(tc);
4605952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
4615952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
4625952Ssaidi@eecs.umich.edu    int32_t count = args[2];
4635952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
4645952Ssaidi@eecs.umich.edu
4655952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
4665952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
4675952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
4685952Ssaidi@eecs.umich.edu        return;
4695952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
4705952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
4715952Ssaidi@eecs.umich.edu    if (swExpl[sid])
4725952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
47311320Ssteve.reinhardt@amd.com    DPRINTFS(AnnotateQ, sys,
4745952Ssaidi@eecs.umich.edu            "swDq: %s[%#x] cur size %d %d bytes: %d removing: %d\n",
4755952Ssaidi@eecs.umich.edu            q, id, qSize[qi-1], qData[qi-1].size(), qBytes[qi-1], count);
4765952Ssaidi@eecs.umich.edu    assert(count != 0);
4775952Ssaidi@eecs.umich.edu
4785952Ssaidi@eecs.umich.edu    doDq(sys, FL_NONE, tc->contextId(), smi, q, qi, count);
4795952Ssaidi@eecs.umich.edu}
4805952Ssaidi@eecs.umich.edu
4815952Ssaidi@eecs.umich.eduvoid
4825952Ssaidi@eecs.umich.eduCPA::swPq(ThreadContext *tc)
4835952Ssaidi@eecs.umich.edu{
4845952Ssaidi@eecs.umich.edu    if (!enabled())
4855952Ssaidi@eecs.umich.edu        return;
4865952Ssaidi@eecs.umich.edu
4875952Ssaidi@eecs.umich.edu    char q[50];
4885952Ssaidi@eecs.umich.edu    Arguments args(tc);
4895952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
4905952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
4915952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
4925952Ssaidi@eecs.umich.edu    int32_t count = args[2];
4935952Ssaidi@eecs.umich.edu
4945952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
4955952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
4965952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
4975952Ssaidi@eecs.umich.edu        return;
4985952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
4995952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
5005952Ssaidi@eecs.umich.edu    if (swExpl[sid])
5015952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
50211320Ssteve.reinhardt@amd.com    DPRINTFS(AnnotateQ, sys,
5035952Ssaidi@eecs.umich.edu            "swPq: %s [%#x] cur size %d %d bytes: %d peeking: %d\n",
5045952Ssaidi@eecs.umich.edu            q, id, qSize[qi-1], qData[qi-1].size(), qBytes[qi-1], count);
5055952Ssaidi@eecs.umich.edu
5065952Ssaidi@eecs.umich.edu    assert(count != 0);
5075952Ssaidi@eecs.umich.edu    if (qBytes[qi-1] < count) {
5085952Ssaidi@eecs.umich.edu        dump(true);
5095952Ssaidi@eecs.umich.edu        dumpKey();
5105952Ssaidi@eecs.umich.edu        fatal("Queue %s peeking with not enough bytes available in queue!\n", q);
5115952Ssaidi@eecs.umich.edu    }
5125952Ssaidi@eecs.umich.edu
5135952Ssaidi@eecs.umich.edu    add(OP_PEEK, FL_NONE, tc->contextId(), smi, qi, count);
5145952Ssaidi@eecs.umich.edu}
5155952Ssaidi@eecs.umich.edu
5165952Ssaidi@eecs.umich.eduvoid
5175952Ssaidi@eecs.umich.eduCPA::swRq(ThreadContext *tc)
5185952Ssaidi@eecs.umich.edu{
5195952Ssaidi@eecs.umich.edu    if (!enabled())
5205952Ssaidi@eecs.umich.edu        return;
5215952Ssaidi@eecs.umich.edu
5225952Ssaidi@eecs.umich.edu    char q[50];
5235952Ssaidi@eecs.umich.edu    Arguments args(tc);
5245952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
5255952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
5265952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
5275952Ssaidi@eecs.umich.edu    int32_t count = args[2];
5285952Ssaidi@eecs.umich.edu
5295952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
5305952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
5315952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
5325952Ssaidi@eecs.umich.edu        return;
5335952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
5345952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
5355952Ssaidi@eecs.umich.edu    if (swExpl[sid])
5365952Ssaidi@eecs.umich.edu        swExpl[sid] = false;
53711320Ssteve.reinhardt@amd.com    DPRINTFS(AnnotateQ, sys,
5385952Ssaidi@eecs.umich.edu            "swRq: %s [%#x] cur size %d %d bytes: %d reserve: %d\n",
5395952Ssaidi@eecs.umich.edu            q, id, qSize[qi-1], qData[qi-1].size(), qBytes[qi-1], count);
5405952Ssaidi@eecs.umich.edu
5415952Ssaidi@eecs.umich.edu    assert(count != 0);
5425952Ssaidi@eecs.umich.edu
5435952Ssaidi@eecs.umich.edu    add(OP_RESERVE, FL_NONE, tc->contextId(), smi, qi, count);
5445952Ssaidi@eecs.umich.edu}
5455952Ssaidi@eecs.umich.edu
5465952Ssaidi@eecs.umich.edu
5475952Ssaidi@eecs.umich.eduvoid
5485952Ssaidi@eecs.umich.eduCPA::swWf(ThreadContext *tc)
5495952Ssaidi@eecs.umich.edu{
5505952Ssaidi@eecs.umich.edu    if (!enabled())
5515952Ssaidi@eecs.umich.edu        return;
5525952Ssaidi@eecs.umich.edu
5535952Ssaidi@eecs.umich.edu    char q[50];
5545952Ssaidi@eecs.umich.edu    Arguments args(tc);
5555952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
5565952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
5575952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
5585952Ssaidi@eecs.umich.edu    int32_t count = args[3];
5595952Ssaidi@eecs.umich.edu
5605952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
5615952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
5625952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
5635952Ssaidi@eecs.umich.edu        return;
5645952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
5655952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
5665952Ssaidi@eecs.umich.edu    add(OP_WAIT_FULL, FL_NONE, tc->contextId(), smi, qi, count);
5675952Ssaidi@eecs.umich.edu
5685952Ssaidi@eecs.umich.edu    if (!!args[2]) {
5695952Ssaidi@eecs.umich.edu        char sm[50];
5705952Ssaidi@eecs.umich.edu        CopyStringOut(tc, sm, args[2], 50);
5715952Ssaidi@eecs.umich.edu        doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
5725952Ssaidi@eecs.umich.edu    }
5735952Ssaidi@eecs.umich.edu}
5745952Ssaidi@eecs.umich.edu
5755952Ssaidi@eecs.umich.eduvoid
5765952Ssaidi@eecs.umich.eduCPA::swWe(ThreadContext *tc)
5775952Ssaidi@eecs.umich.edu{
5785952Ssaidi@eecs.umich.edu    if (!enabled())
5795952Ssaidi@eecs.umich.edu        return;
5805952Ssaidi@eecs.umich.edu
5815952Ssaidi@eecs.umich.edu    char q[50];
5825952Ssaidi@eecs.umich.edu    Arguments args(tc);
5835952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
5845952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
5855952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
5865952Ssaidi@eecs.umich.edu    int32_t count = args[3];
5875952Ssaidi@eecs.umich.edu
5885952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
5895952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
5905952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
5915952Ssaidi@eecs.umich.edu        return;
5925952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
5935952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
5945952Ssaidi@eecs.umich.edu    add(OP_WAIT_EMPTY, FL_NONE, tc->contextId(), smi, qi, count);
5955952Ssaidi@eecs.umich.edu
5965952Ssaidi@eecs.umich.edu    if (!!args[2]) {
5975952Ssaidi@eecs.umich.edu        char sm[50];
5985952Ssaidi@eecs.umich.edu        CopyStringOut(tc, sm, args[2], 50);
5995952Ssaidi@eecs.umich.edu        doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
6005952Ssaidi@eecs.umich.edu    }
6015952Ssaidi@eecs.umich.edu}
6025952Ssaidi@eecs.umich.edu
6035952Ssaidi@eecs.umich.eduvoid
6045952Ssaidi@eecs.umich.eduCPA::swSq(ThreadContext *tc)
6055952Ssaidi@eecs.umich.edu{
6065952Ssaidi@eecs.umich.edu    if (!enabled())
6075952Ssaidi@eecs.umich.edu        return;
6085952Ssaidi@eecs.umich.edu
6095952Ssaidi@eecs.umich.edu    char q[50];
6105952Ssaidi@eecs.umich.edu    Arguments args(tc);
6115952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
6125952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
6135952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
6145952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
6155952Ssaidi@eecs.umich.edu    int32_t size = args[2];
6165952Ssaidi@eecs.umich.edu    int flags = args[3];
6175952Ssaidi@eecs.umich.edu
6185952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
6195952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
6205952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
6215952Ssaidi@eecs.umich.edu        return;
6225952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
6235952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
6245952Ssaidi@eecs.umich.edu    DPRINTF(AnnotateQ, "swSq: %s [%#x] cur size: %d bytes: %d, new size: %d\n",
6255952Ssaidi@eecs.umich.edu             q, id, qSize[qi-1], qBytes[qi-1], size);
6265952Ssaidi@eecs.umich.edu
6275952Ssaidi@eecs.umich.edu    if (FL_RESET & flags) {
6285952Ssaidi@eecs.umich.edu        DPRINTF(AnnotateQ, "Resetting Queue %s\n", q);
6295952Ssaidi@eecs.umich.edu        add(OP_SIZE_QUEUE, FL_NONE, tc->contextId(), smi, qi, 0);
6305952Ssaidi@eecs.umich.edu        qData[qi-1].clear();
6315952Ssaidi@eecs.umich.edu        qSize[qi-1] = 0;
6325952Ssaidi@eecs.umich.edu        qBytes[qi-1] = 0;
6335952Ssaidi@eecs.umich.edu    }
6345952Ssaidi@eecs.umich.edu
6355952Ssaidi@eecs.umich.edu    if (qBytes[qi-1] < size)
6365952Ssaidi@eecs.umich.edu        doQ(sys, FL_NONE, tc->contextId(), smi, q, qi, size - qBytes[qi-1]);
6375952Ssaidi@eecs.umich.edu    else if (qBytes[qi-1] > size) {
6385952Ssaidi@eecs.umich.edu        DPRINTF(AnnotateQ, "removing for resize of queue %s\n", q);
6395952Ssaidi@eecs.umich.edu        add(OP_SIZE_QUEUE, FL_NONE, tc->contextId(), smi, qi, size);
6405952Ssaidi@eecs.umich.edu        if (size <= 0) {
6415952Ssaidi@eecs.umich.edu            qData[qi-1].clear();
6425952Ssaidi@eecs.umich.edu            qSize[qi-1] = 0;
6435952Ssaidi@eecs.umich.edu            qBytes[qi-1] = 0;
6445952Ssaidi@eecs.umich.edu            return;
6455952Ssaidi@eecs.umich.edu        }
6465952Ssaidi@eecs.umich.edu        int need = qBytes[qi-1] - size;
6475952Ssaidi@eecs.umich.edu        qBytes[qi-1] = size;
6485952Ssaidi@eecs.umich.edu        while (need > 0) {
6495952Ssaidi@eecs.umich.edu            int32_t tail_bytes = qData[qi-1].back()->data;
6505952Ssaidi@eecs.umich.edu            if (qSize[qi-1] <= 0 || qBytes[qi-1] < 0) {
6515952Ssaidi@eecs.umich.edu                dump(true);
6525952Ssaidi@eecs.umich.edu                dumpKey();
6535952Ssaidi@eecs.umich.edu                fatal("Queue %s had inconsistancy when doing size queue!\n", q);
6545952Ssaidi@eecs.umich.edu            }
6555952Ssaidi@eecs.umich.edu            if (tail_bytes > need) {
6565952Ssaidi@eecs.umich.edu                qData[qi-1].back()->data -= need;
6575952Ssaidi@eecs.umich.edu                need = 0;
6585952Ssaidi@eecs.umich.edu            } else if (tail_bytes == need) {
6595952Ssaidi@eecs.umich.edu                qData[qi-1].pop_back();
6605952Ssaidi@eecs.umich.edu                qSize[qi-1]--;
6615952Ssaidi@eecs.umich.edu                need = 0;
6625952Ssaidi@eecs.umich.edu            } else {
6635952Ssaidi@eecs.umich.edu                qData[qi-1].pop_back();
6645952Ssaidi@eecs.umich.edu                qSize[qi-1]--;
6655952Ssaidi@eecs.umich.edu                need -= tail_bytes;
6665952Ssaidi@eecs.umich.edu            }
6675952Ssaidi@eecs.umich.edu        }
6685952Ssaidi@eecs.umich.edu    }
6695952Ssaidi@eecs.umich.edu}
6705952Ssaidi@eecs.umich.edu
6715952Ssaidi@eecs.umich.eduvoid
6725952Ssaidi@eecs.umich.eduCPA::swAq(ThreadContext *tc)
6735952Ssaidi@eecs.umich.edu{
6745952Ssaidi@eecs.umich.edu    if (!enabled())
6755952Ssaidi@eecs.umich.edu        return;
6765952Ssaidi@eecs.umich.edu
6775952Ssaidi@eecs.umich.edu    char q[50];
6785952Ssaidi@eecs.umich.edu    Arguments args(tc);
6795952Ssaidi@eecs.umich.edu    uint64_t id = args[0];
6805952Ssaidi@eecs.umich.edu    CopyStringOut(tc, q, args[1], 50);
6815952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
6825952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
6835952Ssaidi@eecs.umich.edu    int32_t size = args[2];
6845952Ssaidi@eecs.umich.edu
6855952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
6865952Ssaidi@eecs.umich.edu    int qi = getQ(sysi, q, id);
6875952Ssaidi@eecs.umich.edu    if (qBytes[qi-1] != size) {
6885952Ssaidi@eecs.umich.edu        DPRINTF(AnnotateQ, "Queue %s [%#x] has inconsintant size\n", q, id);
6895952Ssaidi@eecs.umich.edu        //dump(true);
6905952Ssaidi@eecs.umich.edu        //dumpKey();
6915952Ssaidi@eecs.umich.edu        std::list<AnnDataPtr>::iterator ai = qData[qi-1].begin();
6925952Ssaidi@eecs.umich.edu        int x = 0;
6935952Ssaidi@eecs.umich.edu        while (ai != qData[qi-1].end()) {
6945952Ssaidi@eecs.umich.edu            DPRINTF(AnnotateQ, "--Element %d size %d\n", x, (*ai)->data);
6955952Ssaidi@eecs.umich.edu            ai++;
6965952Ssaidi@eecs.umich.edu            x++;
6975952Ssaidi@eecs.umich.edu        }
6985952Ssaidi@eecs.umich.edu
69911320Ssteve.reinhardt@amd.com        warn("%d: Queue Assert: SW said there should be %d byte(s) in %s,"
7005952Ssaidi@eecs.umich.edu                "however there are %d byte(s)\n",
7017823Ssteve.reinhardt@amd.com            curTick(), size, q, qBytes[qi-1]);
7025952Ssaidi@eecs.umich.edu        DPRINTF(AnnotateQ, "%d: Queue Assert: SW said there should be %d"
7035952Ssaidi@eecs.umich.edu                " byte(s) in %s, however there are %d byte(s)\n",
7047823Ssteve.reinhardt@amd.com            curTick(), size, q, qBytes[qi-1]);
7055952Ssaidi@eecs.umich.edu    }
7065952Ssaidi@eecs.umich.edu}
7075952Ssaidi@eecs.umich.edu
7085952Ssaidi@eecs.umich.eduvoid
7095952Ssaidi@eecs.umich.eduCPA::swLink(ThreadContext *tc)
7105952Ssaidi@eecs.umich.edu{
7115952Ssaidi@eecs.umich.edu    if (!enabled())
7125952Ssaidi@eecs.umich.edu        return;
7135952Ssaidi@eecs.umich.edu
7145952Ssaidi@eecs.umich.edu    char lsm[50];
7155952Ssaidi@eecs.umich.edu    Arguments args(tc);
7165952Ssaidi@eecs.umich.edu    CopyStringOut(tc, lsm, args[0], 50);
7175952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
7185952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
7195952Ssaidi@eecs.umich.edu
7205952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
7215952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
7225952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
7235952Ssaidi@eecs.umich.edu        return;
7245952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
7255952Ssaidi@eecs.umich.edu    int lsmi = getSm(sysi, lsm, args[1]);
7265952Ssaidi@eecs.umich.edu
7275952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Linking from %d to state machine %s(%d) [%#x]\n",
7285952Ssaidi@eecs.umich.edu            smi, lsm, lsmi, args[1]);
7295952Ssaidi@eecs.umich.edu
7305952Ssaidi@eecs.umich.edu    if (lnMap[lsmi])
7315952Ssaidi@eecs.umich.edu        DPRINTF(Annotate, "LnMap already contains entry for %d of %d\n",
7325952Ssaidi@eecs.umich.edu                lsmi, lnMap[lsmi]);
7335952Ssaidi@eecs.umich.edu    assert(lnMap[lsmi] == 0);
7345952Ssaidi@eecs.umich.edu    lnMap[lsmi] =  smi;
7355952Ssaidi@eecs.umich.edu
7365952Ssaidi@eecs.umich.edu    add(OP_LINK, FL_NONE, tc->contextId(), smi, lsmi);
7375952Ssaidi@eecs.umich.edu
7385952Ssaidi@eecs.umich.edu    if (!!args[2]) {
7395952Ssaidi@eecs.umich.edu        char sm[50];
7405952Ssaidi@eecs.umich.edu        CopyStringOut(tc, sm, args[2], 50);
7415952Ssaidi@eecs.umich.edu        doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
7425952Ssaidi@eecs.umich.edu    }
7435952Ssaidi@eecs.umich.edu}
7445952Ssaidi@eecs.umich.edu
7455952Ssaidi@eecs.umich.eduvoid
7465952Ssaidi@eecs.umich.eduCPA::swIdentify(ThreadContext *tc)
7475952Ssaidi@eecs.umich.edu{
7485952Ssaidi@eecs.umich.edu    if (!enabled())
7495952Ssaidi@eecs.umich.edu        return;
7505952Ssaidi@eecs.umich.edu
7515952Ssaidi@eecs.umich.edu    Arguments args(tc);
7525952Ssaidi@eecs.umich.edu    int sysi = getSys(tc->getSystemPtr());
7535952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
7545952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
7555952Ssaidi@eecs.umich.edu        return;
7565952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
7575952Ssaidi@eecs.umich.edu
7585952Ssaidi@eecs.umich.edu    DPRINTFS(Annotate, tc->getSystemPtr(), "swIdentify: id %#X\n", args[0]);
7595952Ssaidi@eecs.umich.edu
7605952Ssaidi@eecs.umich.edu    add(OP_IDENT, FL_NONE, tc->contextId(), smi, 0, args[0]);
7615952Ssaidi@eecs.umich.edu}
7625952Ssaidi@eecs.umich.edu
7635952Ssaidi@eecs.umich.eduuint64_t
7645952Ssaidi@eecs.umich.eduCPA::swGetId(ThreadContext *tc)
7655952Ssaidi@eecs.umich.edu{
7665952Ssaidi@eecs.umich.edu    if (!enabled())
7675952Ssaidi@eecs.umich.edu        return 0;
7685952Ssaidi@eecs.umich.edu
7695952Ssaidi@eecs.umich.edu    uint64_t id = ++conId;
7705952Ssaidi@eecs.umich.edu    int sysi = getSys(tc->getSystemPtr());
7715952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
7725952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
7735952Ssaidi@eecs.umich.edu        panic("swGetId called without a state machine stack!");
7745952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
7755952Ssaidi@eecs.umich.edu
7765952Ssaidi@eecs.umich.edu    DPRINTFS(Annotate, tc->getSystemPtr(), "swGetId: id %#X\n", id);
7775952Ssaidi@eecs.umich.edu
7785952Ssaidi@eecs.umich.edu    add(OP_IDENT, FL_NONE, tc->contextId(), smi, 0, id);
7795952Ssaidi@eecs.umich.edu    return id;
7805952Ssaidi@eecs.umich.edu}
7815952Ssaidi@eecs.umich.edu
7825952Ssaidi@eecs.umich.edu
7835952Ssaidi@eecs.umich.eduvoid
7845952Ssaidi@eecs.umich.eduCPA::swSyscallLink(ThreadContext  *tc)
7855952Ssaidi@eecs.umich.edu{
7865952Ssaidi@eecs.umich.edu    if (!enabled())
7875952Ssaidi@eecs.umich.edu        return;
7885952Ssaidi@eecs.umich.edu
7895952Ssaidi@eecs.umich.edu    char lsm[50];
7905952Ssaidi@eecs.umich.edu    Arguments args(tc);
7915952Ssaidi@eecs.umich.edu    CopyStringOut(tc, lsm, args[0], 50);
7925952Ssaidi@eecs.umich.edu    System *sys = tc->getSystemPtr();
7935952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
7945952Ssaidi@eecs.umich.edu    int sysi = getSys(sys);
7955952Ssaidi@eecs.umich.edu
7965952Ssaidi@eecs.umich.edu    Id id = Id(lsm, getFrame(tc));
7975952Ssaidi@eecs.umich.edu    StackId sid = StackId(sysi, getFrame(tc));
7985952Ssaidi@eecs.umich.edu
7995952Ssaidi@eecs.umich.edu    if (!smStack[sid].size())
8005952Ssaidi@eecs.umich.edu        return;
8015952Ssaidi@eecs.umich.edu
8025952Ssaidi@eecs.umich.edu    int smi = smStack[sid].back();
8035952Ssaidi@eecs.umich.edu
8045952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Linking from %d to state machine %s(UNKNOWN)\n",
8055952Ssaidi@eecs.umich.edu            smi, lsm);
8065952Ssaidi@eecs.umich.edu
8075952Ssaidi@eecs.umich.edu    if (scLinks[sysi-1][id])
80811320Ssteve.reinhardt@amd.com        DPRINTF(Annotate,
8095952Ssaidi@eecs.umich.edu                "scLinks already contains entry for system %d %s[%x] of %d\n",
8105952Ssaidi@eecs.umich.edu                sysi, lsm, getFrame(tc), scLinks[sysi-1][id]);
8115952Ssaidi@eecs.umich.edu    assert(scLinks[sysi-1][id] == 0);
8125952Ssaidi@eecs.umich.edu    scLinks[sysi-1][id] = add(OP_LINK, FL_NONE, tc->contextId(), smi, 0xFFFF);
8135952Ssaidi@eecs.umich.edu    scLinks[sysi-1][id]->dump = false;
8145952Ssaidi@eecs.umich.edu
8155952Ssaidi@eecs.umich.edu    if (!!args[1]) {
8165952Ssaidi@eecs.umich.edu        char sm[50];
8175952Ssaidi@eecs.umich.edu        CopyStringOut(tc, sm, args[1], 50);
8185952Ssaidi@eecs.umich.edu        doSwSmEnd(tc->getSystemPtr(), tc->contextId(), sm, getFrame(tc));
8195952Ssaidi@eecs.umich.edu    }
8205952Ssaidi@eecs.umich.edu}
8215952Ssaidi@eecs.umich.edu
8225952Ssaidi@eecs.umich.eduCPA::AnnDataPtr
8235952Ssaidi@eecs.umich.eduCPA::add(int t, int f, int c, int sm, int stq, int32_t d)
8245952Ssaidi@eecs.umich.edu{
82510470Sandreas.hansson@arm.com    AnnDataPtr an = std::make_shared<AnnotateData>();
8267823Ssteve.reinhardt@amd.com    an->time = curTick();
8275952Ssaidi@eecs.umich.edu    an->data = d;
8285952Ssaidi@eecs.umich.edu    an->orig_data = d;
8295952Ssaidi@eecs.umich.edu    an->op = t;
8305952Ssaidi@eecs.umich.edu    an->flag = f;
8315952Ssaidi@eecs.umich.edu    an->sm = sm;
8325952Ssaidi@eecs.umich.edu    an->stq = stq;
8335952Ssaidi@eecs.umich.edu    an->cpu = c;
8345952Ssaidi@eecs.umich.edu    an->dump = true;
8355952Ssaidi@eecs.umich.edu
8365952Ssaidi@eecs.umich.edu    data.push_back(an);
8375952Ssaidi@eecs.umich.edu
8385952Ssaidi@eecs.umich.edu    DPRINTF(AnnotateVerbose, "Annotate: op: %d flags: 0x%x sm: %d state: %d time: %d, data: %d\n",
8395952Ssaidi@eecs.umich.edu            an->op, an->flag, an->sm, an->stq, an->time, an->data);
84011320Ssteve.reinhardt@amd.com
8415952Ssaidi@eecs.umich.edu    // Don't dump Links because we might be setting no-dump on it
8425952Ssaidi@eecs.umich.edu    if (an->op != OP_LINK)
8435952Ssaidi@eecs.umich.edu        dump(false);
8445952Ssaidi@eecs.umich.edu
8455952Ssaidi@eecs.umich.edu    return an;
8465952Ssaidi@eecs.umich.edu}
8475952Ssaidi@eecs.umich.edu
8485952Ssaidi@eecs.umich.eduvoid
8495952Ssaidi@eecs.umich.eduCPA::dumpKey()
8505952Ssaidi@eecs.umich.edu{
8515952Ssaidi@eecs.umich.edu    std::streampos curpos = osbin->tellp();
8525952Ssaidi@eecs.umich.edu    ah.key_off = curpos;
8535952Ssaidi@eecs.umich.edu
8545952Ssaidi@eecs.umich.edu    // Output the various state machines and their corresponding states
8555952Ssaidi@eecs.umich.edu    *osbin << "# Automatically generated state machine descriptor file" << endl;
8565952Ssaidi@eecs.umich.edu
8575952Ssaidi@eecs.umich.edu    *osbin << "sms = {}" << endl << endl;
8585952Ssaidi@eecs.umich.edu    vector<string> state_machines;
8595952Ssaidi@eecs.umich.edu    state_machines.resize(numSmt+1);
8605952Ssaidi@eecs.umich.edu
8615952Ssaidi@eecs.umich.edu    // State machines, id -> states
8625952Ssaidi@eecs.umich.edu    SCache::iterator i = smtCache.begin();
8635952Ssaidi@eecs.umich.edu    while (i != smtCache.end()) {
8645952Ssaidi@eecs.umich.edu        state_machines[i->second] = i->first;
8655952Ssaidi@eecs.umich.edu        i++;
8665952Ssaidi@eecs.umich.edu    }
8675952Ssaidi@eecs.umich.edu
8685952Ssaidi@eecs.umich.edu    for (int x = 1; x < state_machines.size(); x++) {
8695952Ssaidi@eecs.umich.edu        vector<string> states;
8705952Ssaidi@eecs.umich.edu        states.resize(numSt[x-1]+1);
8715952Ssaidi@eecs.umich.edu        assert(x-1 < stCache.size());
8725952Ssaidi@eecs.umich.edu        SCache::iterator i = stCache[x-1].begin();
8735952Ssaidi@eecs.umich.edu        while (i != stCache[x-1].end()) {
8745952Ssaidi@eecs.umich.edu            states[i->second] = i->first;
8755952Ssaidi@eecs.umich.edu            i++;
8765952Ssaidi@eecs.umich.edu        }
8775952Ssaidi@eecs.umich.edu        *osbin << "sms[\"" << state_machines[x] << "\"] = [\"NULL\"";
8785952Ssaidi@eecs.umich.edu        for (int y = 1; y < states.size(); y++)
8795952Ssaidi@eecs.umich.edu            *osbin << ", \"" << states[y] << "\"";
8805952Ssaidi@eecs.umich.edu        *osbin << "]" << endl;
8815952Ssaidi@eecs.umich.edu    }
8825952Ssaidi@eecs.umich.edu
8835952Ssaidi@eecs.umich.edu    *osbin << endl << endl << endl;
8845952Ssaidi@eecs.umich.edu
8855952Ssaidi@eecs.umich.edu    // state machine number -> system, name, id
8865952Ssaidi@eecs.umich.edu    *osbin << "smNum = [\"NULL\"";
8875952Ssaidi@eecs.umich.edu    for (int x = 0; x < smMap.size(); x++)
8885952Ssaidi@eecs.umich.edu        *osbin << ", (" << smMap[x].first << ", \"" << smMap[x].second.first <<
8895952Ssaidi@eecs.umich.edu            "\", " << smMap[x].second.second << ")";
8905952Ssaidi@eecs.umich.edu    *osbin << "]" << endl;
8915952Ssaidi@eecs.umich.edu
8925952Ssaidi@eecs.umich.edu    *osbin << endl << endl << endl;
8935952Ssaidi@eecs.umich.edu
8945952Ssaidi@eecs.umich.edu    // Output the systems
8955952Ssaidi@eecs.umich.edu    vector<string> systems;
8965952Ssaidi@eecs.umich.edu    systems.resize(numSys+1);
8975952Ssaidi@eecs.umich.edu    NameCache::iterator i2 = nameCache.begin();
8985952Ssaidi@eecs.umich.edu    while (i2 != nameCache.end()) {
8995952Ssaidi@eecs.umich.edu        systems[i2->second.second] = i2->second.first;
9005952Ssaidi@eecs.umich.edu        i2++;
9015952Ssaidi@eecs.umich.edu    }
9025952Ssaidi@eecs.umich.edu
9035952Ssaidi@eecs.umich.edu    *osbin << "sysNum = [\"NULL\"";
9045952Ssaidi@eecs.umich.edu    for (int x = 1; x < systems.size(); x++) {
9055952Ssaidi@eecs.umich.edu        *osbin << ", \"" << systems[x] << "\"";
9065952Ssaidi@eecs.umich.edu    }
9075952Ssaidi@eecs.umich.edu    *osbin << "]" << endl;
9085952Ssaidi@eecs.umich.edu
9095952Ssaidi@eecs.umich.edu    // queue number -> system, qname, qid
9105952Ssaidi@eecs.umich.edu    *osbin << "queues = [\"NULL\"";
9115952Ssaidi@eecs.umich.edu    for (int x = 0; x < qMap.size(); x++)
9125952Ssaidi@eecs.umich.edu        *osbin << ", (" << qMap[x].first << ", \"" << qMap[x].second.first <<
9135952Ssaidi@eecs.umich.edu            "\", " << qMap[x].second.second << ")";
9145952Ssaidi@eecs.umich.edu    *osbin << "]" << endl;
9155952Ssaidi@eecs.umich.edu
9165952Ssaidi@eecs.umich.edu    *osbin << "smComb = [s for s in [(i,r) for i in xrange(1,len(sysNum)) "
9175952Ssaidi@eecs.umich.edu           << "for r in xrange (1,len(smNum))]]" << endl;
9185952Ssaidi@eecs.umich.edu    ah.key_len = osbin->tellp() - curpos;
9195952Ssaidi@eecs.umich.edu
9205952Ssaidi@eecs.umich.edu    // output index
9215952Ssaidi@eecs.umich.edu    curpos = osbin->tellp();
9225952Ssaidi@eecs.umich.edu    ah.idx_off = curpos;
9235952Ssaidi@eecs.umich.edu
9245952Ssaidi@eecs.umich.edu    for (int x = 0; x < annotateIdx.size(); x++)
9255952Ssaidi@eecs.umich.edu        osbin->write((char*)&annotateIdx[x], sizeof(uint64_t));
9265952Ssaidi@eecs.umich.edu    ah.idx_len = osbin->tellp() - curpos;
9275952Ssaidi@eecs.umich.edu
9285952Ssaidi@eecs.umich.edu    osbin->seekp(0);
9295952Ssaidi@eecs.umich.edu    osbin->write((char*)&ah, sizeof(AnnotateHeader));
9305952Ssaidi@eecs.umich.edu    osbin->flush();
9315952Ssaidi@eecs.umich.edu
9325952Ssaidi@eecs.umich.edu}
9335952Ssaidi@eecs.umich.edu
9345952Ssaidi@eecs.umich.eduvoid
9355952Ssaidi@eecs.umich.eduCPA::dump(bool all)
9365952Ssaidi@eecs.umich.edu{
9375952Ssaidi@eecs.umich.edu
9385952Ssaidi@eecs.umich.edu    list<AnnDataPtr>::iterator i;
9395952Ssaidi@eecs.umich.edu
9405952Ssaidi@eecs.umich.edu    i = data.begin();
9415952Ssaidi@eecs.umich.edu
9425952Ssaidi@eecs.umich.edu    if (i == data.end())
9435952Ssaidi@eecs.umich.edu        return;
9445952Ssaidi@eecs.umich.edu
9455952Ssaidi@eecs.umich.edu    // Dump the data every
9465952Ssaidi@eecs.umich.edu    if (!all && data.size() < 10000)
9475952Ssaidi@eecs.umich.edu        return;
9485952Ssaidi@eecs.umich.edu
9495952Ssaidi@eecs.umich.edu    DPRINTF(Annotate, "Writing %d\n", data.size());
9505952Ssaidi@eecs.umich.edu    while (i != data.end()) {
9515952Ssaidi@eecs.umich.edu        AnnDataPtr an = *i;
9525952Ssaidi@eecs.umich.edu
9535952Ssaidi@eecs.umich.edu        // If we can't dump this record, hold here
9545952Ssaidi@eecs.umich.edu        if (!an->dump && !all)
9555952Ssaidi@eecs.umich.edu            break;
9565952Ssaidi@eecs.umich.edu
9575952Ssaidi@eecs.umich.edu        ah.num_recs++;
9585952Ssaidi@eecs.umich.edu        if (ah.num_recs % 100000 == 0)
9595952Ssaidi@eecs.umich.edu            annotateIdx.push_back(osbin->tellp());
9605952Ssaidi@eecs.umich.edu
9615952Ssaidi@eecs.umich.edu
9625952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->time), sizeof(an->time));
9635952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->orig_data), sizeof(an->orig_data));
9645952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->sm), sizeof(an->sm));
9655952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->stq), sizeof(an->stq));
9665952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->op), sizeof(an->op));
9675952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->flag), sizeof(an->flag));
9685952Ssaidi@eecs.umich.edu        osbin->write((char*)&(an->cpu), sizeof(an->cpu));
9695952Ssaidi@eecs.umich.edu        i++;
9705952Ssaidi@eecs.umich.edu    }
9715952Ssaidi@eecs.umich.edu    if (data.begin() != i)
9725952Ssaidi@eecs.umich.edu        data.erase(data.begin(), i);
9735952Ssaidi@eecs.umich.edu
9745952Ssaidi@eecs.umich.edu    if (all)
9755952Ssaidi@eecs.umich.edu        osbin->flush();
9765952Ssaidi@eecs.umich.edu}
9775952Ssaidi@eecs.umich.edu
9785952Ssaidi@eecs.umich.eduvoid
9795952Ssaidi@eecs.umich.eduCPA::doQ(System *sys, int flags, int cpuid, int sm,
9805952Ssaidi@eecs.umich.edu              string q, int qi, int count)
9815952Ssaidi@eecs.umich.edu{
9825952Ssaidi@eecs.umich.edu    qSize[qi-1]++;
9835952Ssaidi@eecs.umich.edu    qBytes[qi-1] += count;
9845952Ssaidi@eecs.umich.edu    if (qSize[qi-1] > 2501 || qBytes[qi-1] > 2000000000)
9855952Ssaidi@eecs.umich.edu        warn("Queue %s is %d elements/%d bytes, "
9865952Ssaidi@eecs.umich.edu                "maybe things aren't being removed?\n",
9875952Ssaidi@eecs.umich.edu                q, qSize[qi-1], qBytes[qi-1]);
9885952Ssaidi@eecs.umich.edu    if (flags & FL_QOPP)
9895952Ssaidi@eecs.umich.edu        qData[qi-1].push_front(add(OP_QUEUE, flags, cpuid, sm, qi, count));
9905952Ssaidi@eecs.umich.edu    else
9915952Ssaidi@eecs.umich.edu        qData[qi-1].push_back(add(OP_QUEUE, flags, cpuid, sm, qi, count));
9925952Ssaidi@eecs.umich.edu    DPRINTFS(AnnotateQ, sys, "Queing in queue %s size now %d/%d\n",
9935952Ssaidi@eecs.umich.edu            q, qSize[qi-1], qBytes[qi-1]);
9945952Ssaidi@eecs.umich.edu    assert(qSize[qi-1] >= 0);
9955952Ssaidi@eecs.umich.edu    assert(qBytes[qi-1] >= 0);
9965952Ssaidi@eecs.umich.edu}
9975952Ssaidi@eecs.umich.edu
9985952Ssaidi@eecs.umich.edu
9995952Ssaidi@eecs.umich.eduvoid
10005952Ssaidi@eecs.umich.eduCPA::doDq(System *sys, int flags, int cpuid, int sm,
10015952Ssaidi@eecs.umich.edu               string q, int qi, int count)
10025952Ssaidi@eecs.umich.edu{
10035952Ssaidi@eecs.umich.edu
10045952Ssaidi@eecs.umich.edu    StringWrap name(sys->name());
10055952Ssaidi@eecs.umich.edu    if (count == -1) {
10065952Ssaidi@eecs.umich.edu        add(OP_DEQUEUE, flags, cpuid, sm, qi, count);
10075952Ssaidi@eecs.umich.edu        qData[qi-1].clear();
10085952Ssaidi@eecs.umich.edu        qSize[qi-1] = 0;
10095952Ssaidi@eecs.umich.edu        qBytes[qi-1] = 0;
10105952Ssaidi@eecs.umich.edu        DPRINTF(AnnotateQ, "Dequeing all data in queue %s size now %d/%d\n",
10115952Ssaidi@eecs.umich.edu                q, qSize[qi-1], qBytes[qi-1]);
10125952Ssaidi@eecs.umich.edu        return;
10135952Ssaidi@eecs.umich.edu    }
10145952Ssaidi@eecs.umich.edu
10155952Ssaidi@eecs.umich.edu    assert(count > 0);
10165952Ssaidi@eecs.umich.edu    if (qSize[qi-1] <= 0 || qBytes[qi-1] <= 0 || !qData[qi-1].size()) {
10175952Ssaidi@eecs.umich.edu        dump(true);
10185952Ssaidi@eecs.umich.edu        dumpKey();
10195952Ssaidi@eecs.umich.edu        fatal("Queue %s dequing with no data available in queue!\n",
10205952Ssaidi@eecs.umich.edu                q);
10215952Ssaidi@eecs.umich.edu    }
10225952Ssaidi@eecs.umich.edu    assert(qSize[qi-1] >= 0);
10235952Ssaidi@eecs.umich.edu    assert(qBytes[qi-1] >= 0);
10245952Ssaidi@eecs.umich.edu    assert(qData[qi-1].size());
10255952Ssaidi@eecs.umich.edu
10265952Ssaidi@eecs.umich.edu    int32_t need = count;
10275952Ssaidi@eecs.umich.edu    qBytes[qi-1] -= count;
10285952Ssaidi@eecs.umich.edu    if (qBytes[qi-1] < 0) {
10295952Ssaidi@eecs.umich.edu        dump(true);
10305952Ssaidi@eecs.umich.edu        dumpKey();
10315952Ssaidi@eecs.umich.edu        fatal("Queue %s dequing with no bytes available in queue!\n",
10325952Ssaidi@eecs.umich.edu                q);
10335952Ssaidi@eecs.umich.edu    }
10345952Ssaidi@eecs.umich.edu
10355952Ssaidi@eecs.umich.edu    while (need > 0) {
10365952Ssaidi@eecs.umich.edu        int32_t head_bytes = qData[qi-1].front()->data;
10375952Ssaidi@eecs.umich.edu        if (qSize[qi-1] <= 0 || qBytes[qi-1] < 0) {
10385952Ssaidi@eecs.umich.edu            dump(true);
10395952Ssaidi@eecs.umich.edu            dumpKey();
10405952Ssaidi@eecs.umich.edu            fatal("Queue %s dequing with nothing in queue!\n",
10415952Ssaidi@eecs.umich.edu                q);
10425952Ssaidi@eecs.umich.edu        }
10435952Ssaidi@eecs.umich.edu
10445952Ssaidi@eecs.umich.edu        if (head_bytes > need) {
10455952Ssaidi@eecs.umich.edu            qData[qi-1].front()->data -= need;
10465952Ssaidi@eecs.umich.edu            need = 0;
10475952Ssaidi@eecs.umich.edu        } else if (head_bytes == need) {
10485952Ssaidi@eecs.umich.edu            qData[qi-1].pop_front();
10495952Ssaidi@eecs.umich.edu            qSize[qi-1]--;
10505952Ssaidi@eecs.umich.edu            need = 0;
10515952Ssaidi@eecs.umich.edu        } else {
10525952Ssaidi@eecs.umich.edu            qData[qi-1].pop_front();
10535952Ssaidi@eecs.umich.edu            qSize[qi-1]--;
10545952Ssaidi@eecs.umich.edu            need -= head_bytes;
10555952Ssaidi@eecs.umich.edu        }
10565952Ssaidi@eecs.umich.edu    }
10575952Ssaidi@eecs.umich.edu
10585952Ssaidi@eecs.umich.edu    add(OP_DEQUEUE, flags, cpuid, sm, qi, count);
10595952Ssaidi@eecs.umich.edu    DPRINTF(AnnotateQ, "Dequeing in queue %s size now %d/%d\n",
10605952Ssaidi@eecs.umich.edu            q, qSize[qi-1], qBytes[qi-1]);
10615952Ssaidi@eecs.umich.edu}
10625952Ssaidi@eecs.umich.edu
10635952Ssaidi@eecs.umich.edu
10645952Ssaidi@eecs.umich.edu
10655952Ssaidi@eecs.umich.eduvoid
106610905Sandreas.sandberg@arm.comCPA::serialize(CheckpointOut &cp) const
10675952Ssaidi@eecs.umich.edu{
10685952Ssaidi@eecs.umich.edu
10695952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(numSm);
10705952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(numSmt);
10715952Ssaidi@eecs.umich.edu    arrayParamOut(os, "numSt", numSt);
10725952Ssaidi@eecs.umich.edu    arrayParamOut(os, "numQ", numQ);
10735952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(numSys);
10745952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(numQs);
10755952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(conId);
10765952Ssaidi@eecs.umich.edu    arrayParamOut(os, "qSize", qSize);
10775952Ssaidi@eecs.umich.edu    arrayParamOut(os, "qSize", qSize);
10785952Ssaidi@eecs.umich.edu    arrayParamOut(os, "qBytes", qBytes);
10795952Ssaidi@eecs.umich.edu
10805952Ssaidi@eecs.umich.edu    SCache::iterator i;
10815952Ssaidi@eecs.umich.edu    int x = 0, y = 0;
10825952Ssaidi@eecs.umich.edu
10835952Ssaidi@eecs.umich.edu    // smtCache (SCache)
10845952Ssaidi@eecs.umich.edu    x = 0;
10855952Ssaidi@eecs.umich.edu    y = 0;
10865952Ssaidi@eecs.umich.edu    i = smtCache.begin();
10875952Ssaidi@eecs.umich.edu    while (i != smtCache.end()) {
10885952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smtCache%d.str", x), i->first);
10895952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smtCache%d.int", x), i->second);
10905952Ssaidi@eecs.umich.edu        x++; i++;
10915952Ssaidi@eecs.umich.edu    }
10925952Ssaidi@eecs.umich.edu
10935952Ssaidi@eecs.umich.edu    // stCache  (StCache)
10945952Ssaidi@eecs.umich.edu    for (x = 0; x < stCache.size(); x++) {
10955952Ssaidi@eecs.umich.edu        i = stCache[x].begin();
10965952Ssaidi@eecs.umich.edu        y = 0;
10975952Ssaidi@eecs.umich.edu        while (i != stCache[x].end()) {
10985952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("stCache%d_%d.str", x, y), i->first);
10995952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("stCache%d_%d.int", x, y), i->second);
11005952Ssaidi@eecs.umich.edu            y++; i++;
11015952Ssaidi@eecs.umich.edu        }
11025952Ssaidi@eecs.umich.edu    }
11035952Ssaidi@eecs.umich.edu
11045952Ssaidi@eecs.umich.edu    // qCache (IdCache)
11055952Ssaidi@eecs.umich.edu    IdHCache::iterator idi;
11065952Ssaidi@eecs.umich.edu    for (x = 0; x < qCache.size(); x++) {
11075952Ssaidi@eecs.umich.edu        idi = qCache[x].begin();
11085952Ssaidi@eecs.umich.edu        y = 0;
11095952Ssaidi@eecs.umich.edu        while (idi != qCache[x].end()) {
11105952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("qCache%d_%d.str", x, y), idi->first.first);
11115952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("qCache%d_%d.id", x, y), idi->first.second);
11125952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("qCache%d_%d.int", x, y), idi->second);
11135952Ssaidi@eecs.umich.edu            y++; idi++;
11145952Ssaidi@eecs.umich.edu        }
11155952Ssaidi@eecs.umich.edu    }
11165952Ssaidi@eecs.umich.edu
11175952Ssaidi@eecs.umich.edu    // smCache (IdCache)
11185952Ssaidi@eecs.umich.edu    for (x = 0; x < smCache.size(); x++) {
11195952Ssaidi@eecs.umich.edu        idi = smCache[x].begin();
11205952Ssaidi@eecs.umich.edu        y = 0;
11215952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smCache%d", x), smCache[x].size());
11225952Ssaidi@eecs.umich.edu        while (idi != smCache[x].end()) {
11235952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("smCache%d_%d.str", x, y), idi->first.first);
11245952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("smCache%d_%d.id", x, y), idi->first.second);
11255952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("smCache%d_%d.int", x, y), idi->second);
11265952Ssaidi@eecs.umich.edu            y++; idi++;
11275952Ssaidi@eecs.umich.edu        }
11285952Ssaidi@eecs.umich.edu    }
11295952Ssaidi@eecs.umich.edu
11305952Ssaidi@eecs.umich.edu    // scLinks (ScCache) -- data not serialize
11315952Ssaidi@eecs.umich.edu
11325952Ssaidi@eecs.umich.edu
11335952Ssaidi@eecs.umich.edu    // namecache (NameCache)
11345952Ssaidi@eecs.umich.edu    NameCache::iterator ni;
11355952Ssaidi@eecs.umich.edu
11365952Ssaidi@eecs.umich.edu    ni = nameCache.begin();
11375952Ssaidi@eecs.umich.edu    x = 0;
11385952Ssaidi@eecs.umich.edu    while (ni != nameCache.end()) {
11395952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("nameCache%d.name", x), ni->first->name());
11405952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("nameCache%d.str", x), ni->second.first);
11415952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("nameCache%d.int", x), ni->second.second);
11425952Ssaidi@eecs.umich.edu        x++; ni++;
11435952Ssaidi@eecs.umich.edu    }
11445952Ssaidi@eecs.umich.edu
11455952Ssaidi@eecs.umich.edu    // smStack (SmStack)
11465952Ssaidi@eecs.umich.edu    SmStack::iterator si;
11475952Ssaidi@eecs.umich.edu    si = smStack.begin();
11485952Ssaidi@eecs.umich.edu    x = 0;
11495952Ssaidi@eecs.umich.edu    paramOut(os, "smStackIdCount", smStack.size());
11505952Ssaidi@eecs.umich.edu    while (si != smStack.end()) {
11515952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smStackId%d.sys", x), si->first.first);
11525952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smStackId%d.frame", x), si->first.second);
11535952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smStackId%d.count", x), si->second.size());
11545952Ssaidi@eecs.umich.edu        for (y = 0; y < si->second.size(); y++)
11555952Ssaidi@eecs.umich.edu            paramOut(os, csprintf("smStackId%d_%d", x, y), si->second[y]);
11565952Ssaidi@eecs.umich.edu        x++; si++;
11575952Ssaidi@eecs.umich.edu    }
11585952Ssaidi@eecs.umich.edu
11595952Ssaidi@eecs.umich.edu    // lnMap (LinkMap)
11605952Ssaidi@eecs.umich.edu    x = 0;
11615952Ssaidi@eecs.umich.edu    LinkMap::iterator li;
11625952Ssaidi@eecs.umich.edu    li = lnMap.begin();
11635952Ssaidi@eecs.umich.edu    paramOut(os, "lnMapSize", lnMap.size());
11645952Ssaidi@eecs.umich.edu    while (li != lnMap.end()) {
11655952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("lnMap%d.smi", x), li->first);
11665952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("lnMap%d.lsmi", x), li->second);
11675952Ssaidi@eecs.umich.edu        x++; li++;
11685952Ssaidi@eecs.umich.edu    }
11695952Ssaidi@eecs.umich.edu
11705952Ssaidi@eecs.umich.edu    // swExpl (vector)
11715952Ssaidi@eecs.umich.edu    SwExpl::iterator swexpli;
11725952Ssaidi@eecs.umich.edu    swexpli = swExpl.begin();
11735952Ssaidi@eecs.umich.edu    x = 0;
11745952Ssaidi@eecs.umich.edu    paramOut(os, "swExplCount", swExpl.size());
11755952Ssaidi@eecs.umich.edu    while (swexpli != swExpl.end()) {
11765952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("swExpl%d.sys", x), swexpli->first.first);
11775952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("swExpl%d.frame", x), swexpli->first.second);
11785952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("swExpl%d.swexpl", x), swexpli->second);
11795952Ssaidi@eecs.umich.edu        x++; swexpli++;
11805952Ssaidi@eecs.umich.edu    }
11815952Ssaidi@eecs.umich.edu
11825952Ssaidi@eecs.umich.edu    // lastState (IMap)
11835952Ssaidi@eecs.umich.edu    x = 0;
11845952Ssaidi@eecs.umich.edu    IMap::iterator ii;
11855952Ssaidi@eecs.umich.edu    ii = lastState.begin();
11865952Ssaidi@eecs.umich.edu    paramOut(os, "lastStateSize", lastState.size());
11875952Ssaidi@eecs.umich.edu    while (ii != lastState.end()) {
11885952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("lastState%d.smi", x), ii->first);
11895952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("lastState%d.sti", x), ii->second);
11905952Ssaidi@eecs.umich.edu        x++; ii++;
11915952Ssaidi@eecs.umich.edu    }
11925952Ssaidi@eecs.umich.edu
11935952Ssaidi@eecs.umich.edu    // smMap (IdMap)
11945952Ssaidi@eecs.umich.edu    for (x = 0; x < smMap.size(); x++) {
11955952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smMap%d.sys", x), smMap[x].first);
11965952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smMap%d.smname", x), smMap[x].second.first);
11975952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("smMap%d.id", x), smMap[x].second.second);
11985952Ssaidi@eecs.umich.edu    }
11995952Ssaidi@eecs.umich.edu
12005952Ssaidi@eecs.umich.edu    // qMap (IdMap)
12015952Ssaidi@eecs.umich.edu    for (x = 0; x < qMap.size(); x++) {
12025952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("qMap%d.sys", x), qMap[x].first);
12035952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("qMap%d.qname", x), qMap[x].second.first);
12045952Ssaidi@eecs.umich.edu        paramOut(os, csprintf("qMap%d.id", x), qMap[x].second.second);
12055952Ssaidi@eecs.umich.edu    }
12065952Ssaidi@eecs.umich.edu
12075952Ssaidi@eecs.umich.edu    // qData (vector<AnnotateList>)
12085952Ssaidi@eecs.umich.edu    for(x = 0; x < qData.size(); x++) {
12095952Ssaidi@eecs.umich.edu        if (!qData[x].size())
12105952Ssaidi@eecs.umich.edu            continue;
12115952Ssaidi@eecs.umich.edu        y = 0;
121210905Sandreas.sandberg@arm.com        for (auto &ann : qData[x]) {
121310905Sandreas.sandberg@arm.com            ann->serializeSection(os, csprintf("Q%d_%d", x, y));
12145952Ssaidi@eecs.umich.edu            y++;
12155952Ssaidi@eecs.umich.edu        }
12165952Ssaidi@eecs.umich.edu    }
12175952Ssaidi@eecs.umich.edu}
12185952Ssaidi@eecs.umich.edu
12195952Ssaidi@eecs.umich.eduvoid
122010905Sandreas.sandberg@arm.comCPA::unserialize(CheckpointIn &cp)
12215952Ssaidi@eecs.umich.edu{
12225952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(numSm);
12235952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(numSmt);
122410905Sandreas.sandberg@arm.com    UNSERIALIZE_CONTAINER(numSt);
122510905Sandreas.sandberg@arm.com    UNSERIALIZE_CONTAINER(numQ);
12265952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(numSys);
12275952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(numQs);
12285952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(conId);
122910905Sandreas.sandberg@arm.com    UNSERIALIZE_CONTAINER(qSize);
123010905Sandreas.sandberg@arm.com    UNSERIALIZE_CONTAINER(qBytes);
12315952Ssaidi@eecs.umich.edu
12325952Ssaidi@eecs.umich.edu
12335952Ssaidi@eecs.umich.edu    // smtCache (SCache
12345952Ssaidi@eecs.umich.edu    string str;
12355952Ssaidi@eecs.umich.edu    int smi;
12365952Ssaidi@eecs.umich.edu    for (int x = 0;  x < numSmt; x++) {
123710905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smtCache%d.str", x), str);
123810905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smtCache%d.int", x), smi);
12395952Ssaidi@eecs.umich.edu        smtCache[str] = smi;
12405952Ssaidi@eecs.umich.edu    }
12415952Ssaidi@eecs.umich.edu
12425952Ssaidi@eecs.umich.edu    // stCache  (StCache)
12435952Ssaidi@eecs.umich.edu    stCache.resize(numSmt);
12445952Ssaidi@eecs.umich.edu    for (int x = 0;  x < numSmt; x++) {
12455952Ssaidi@eecs.umich.edu        for (int y = 0; y < numSt[x]; y++) {
124610905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("stCache%d_%d.str", x,y), str);
124710905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("stCache%d_%d.int", x,y), smi);
12485952Ssaidi@eecs.umich.edu            stCache[x][str] = smi;
12495952Ssaidi@eecs.umich.edu        }
12505952Ssaidi@eecs.umich.edu    }
12515952Ssaidi@eecs.umich.edu
12525952Ssaidi@eecs.umich.edu    // qCache (IdCache)
12535952Ssaidi@eecs.umich.edu    uint64_t id;
12545952Ssaidi@eecs.umich.edu    qCache.resize(numSys);
12555952Ssaidi@eecs.umich.edu    for (int x = 0;  x < numSys; x++) {
12565952Ssaidi@eecs.umich.edu        for (int y = 0; y < numQ[x]; y++) {
125710905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("qCache%d_%d.str", x,y), str);
125810905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("qCache%d_%d.id", x,y), id);
125910905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("qCache%d_%d.int", x,y), smi);
12605952Ssaidi@eecs.umich.edu            qCache[x][Id(str,id)] = smi;
12615952Ssaidi@eecs.umich.edu        }
12625952Ssaidi@eecs.umich.edu    }
12635952Ssaidi@eecs.umich.edu
12645952Ssaidi@eecs.umich.edu    // smCache (IdCache)
12655952Ssaidi@eecs.umich.edu    smCache.resize(numSys);
12665952Ssaidi@eecs.umich.edu    for (int x = 0;  x < numSys; x++) {
12675952Ssaidi@eecs.umich.edu        int size;
126810905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smCache%d", x), size);
12695952Ssaidi@eecs.umich.edu        for (int y = 0; y < size; y++) {
127010905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("smCache%d_%d.str", x,y), str);
127110905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("smCache%d_%d.id", x,y), id);
127210905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("smCache%d_%d.int", x,y), smi);
12735952Ssaidi@eecs.umich.edu            smCache[x][Id(str,id)] = smi;
12745952Ssaidi@eecs.umich.edu        }
12755952Ssaidi@eecs.umich.edu    }
12765952Ssaidi@eecs.umich.edu
12775952Ssaidi@eecs.umich.edu    // scLinks (ScCache) -- data not serialized, just creating one per sys
12785952Ssaidi@eecs.umich.edu    for (int x = 0; x < numSys; x++)
12795952Ssaidi@eecs.umich.edu        scLinks.push_back(ScHCache());
12805952Ssaidi@eecs.umich.edu
12815952Ssaidi@eecs.umich.edu    // nameCache (NameCache)
12825952Ssaidi@eecs.umich.edu    for (int x = 0; x < numSys; x++) {
12835952Ssaidi@eecs.umich.edu        System *sys;
12845952Ssaidi@eecs.umich.edu        SimObject *sptr;
12855952Ssaidi@eecs.umich.edu        string str;
12865952Ssaidi@eecs.umich.edu        int sysi;
12875952Ssaidi@eecs.umich.edu
128810905Sandreas.sandberg@arm.com        objParamIn(cp, csprintf("nameCache%d.name", x), sptr);
12895952Ssaidi@eecs.umich.edu        sys = dynamic_cast<System*>(sptr);
12905952Ssaidi@eecs.umich.edu
129110905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("nameCache%d.str", x), str);
129210905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("nameCache%d.int", x), sysi);
129310377Sandreas.hansson@arm.com        nameCache[sys] = std::make_pair(str, sysi);
12945952Ssaidi@eecs.umich.edu    }
12955952Ssaidi@eecs.umich.edu
12965952Ssaidi@eecs.umich.edu    //smStack (SmStack)
12975952Ssaidi@eecs.umich.edu    int smStack_size;
129810905Sandreas.sandberg@arm.com    paramIn(cp, "smStackIdCount", smStack_size);
12995952Ssaidi@eecs.umich.edu    for (int x = 0; x < smStack_size; x++) {
13005952Ssaidi@eecs.umich.edu        int sysi;
13015952Ssaidi@eecs.umich.edu        uint64_t frame;
13025952Ssaidi@eecs.umich.edu        int count;
130310905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smStackId%d.sys", x), sysi);
130410905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smStackId%d.frame", x), frame);
130510905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smStackId%d.count", x), count);
13065952Ssaidi@eecs.umich.edu        StackId sid = StackId(sysi, frame);
13075952Ssaidi@eecs.umich.edu        for (int y = 0; y < count; y++) {
130810905Sandreas.sandberg@arm.com            paramIn(cp, csprintf("smStackId%d_%d", x, y), smi);
13095952Ssaidi@eecs.umich.edu            smStack[sid].push_back(smi);
13105952Ssaidi@eecs.umich.edu        }
13115952Ssaidi@eecs.umich.edu    }
13125952Ssaidi@eecs.umich.edu
13135952Ssaidi@eecs.umich.edu    // lnMap (LinkMap)
13145952Ssaidi@eecs.umich.edu    int lsmi;
13155952Ssaidi@eecs.umich.edu    int lnMap_size;
131610905Sandreas.sandberg@arm.com    paramIn(cp, "lnMapSize", lnMap_size);
13175952Ssaidi@eecs.umich.edu    for (int x = 0;  x < lnMap_size; x++) {
131810905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("lnMap%d.smi", x), smi);
131910905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("lnMap%d.lsmi", x), lsmi);
13205952Ssaidi@eecs.umich.edu        lnMap[smi] = lsmi;
13215952Ssaidi@eecs.umich.edu    }
13225952Ssaidi@eecs.umich.edu
13235952Ssaidi@eecs.umich.edu    // swExpl (vector)
13245952Ssaidi@eecs.umich.edu    int swExpl_size;
132510905Sandreas.sandberg@arm.com    paramIn(cp, "swExplCount", swExpl_size);
13265952Ssaidi@eecs.umich.edu    for (int x = 0; x < swExpl_size; x++) {
13275952Ssaidi@eecs.umich.edu        int sysi;
13285952Ssaidi@eecs.umich.edu        uint64_t frame;
13295952Ssaidi@eecs.umich.edu        bool b;
133010905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("swExpl%d.sys", x), sysi);
133110905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("swExpl%d.frame", x), frame);
133210905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("swExpl%d.swexpl", x), b);
13335952Ssaidi@eecs.umich.edu        StackId sid = StackId(sysi, frame);
13345952Ssaidi@eecs.umich.edu        swExpl[sid] = b;
13355952Ssaidi@eecs.umich.edu    }
13365952Ssaidi@eecs.umich.edu
13375952Ssaidi@eecs.umich.edu    // lastState (IMap)
13385952Ssaidi@eecs.umich.edu    int sti;
13395952Ssaidi@eecs.umich.edu    int lastState_size;
134010905Sandreas.sandberg@arm.com    paramIn(cp, "lastStateSize", lastState_size);
13415952Ssaidi@eecs.umich.edu    for (int x = 0;  x < lastState_size; x++) {
134210905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("lastState%d.smi", x), smi);
134310905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("lastState%d.sti", x), sti);
13445952Ssaidi@eecs.umich.edu        lastState[smi] = sti;
13455952Ssaidi@eecs.umich.edu    }
13465952Ssaidi@eecs.umich.edu
13475952Ssaidi@eecs.umich.edu
13485952Ssaidi@eecs.umich.edu    //smMap (IdMap)
13495952Ssaidi@eecs.umich.edu    smMap.resize(numSm);
13505952Ssaidi@eecs.umich.edu    for (int x = 0; x < smMap.size(); x++) {
135110905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smMap%d.sys", x), smMap[x].first);
135210905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smMap%d.smname", x), smMap[x].second.first);
135310905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("smMap%d.id", x), smMap[x].second.second);
13545952Ssaidi@eecs.umich.edu    }
13555952Ssaidi@eecs.umich.edu
13565952Ssaidi@eecs.umich.edu    //qMap (IdMap)
13575952Ssaidi@eecs.umich.edu    qMap.resize(numQs);
13585952Ssaidi@eecs.umich.edu    for (int x = 0; x < qMap.size(); x++) {
135910905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("qMap%d.sys", x), qMap[x].first);
136010905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("qMap%d.qname", x), qMap[x].second.first);
136110905Sandreas.sandberg@arm.com        paramIn(cp, csprintf("qMap%d.id", x), qMap[x].second.second);
13625952Ssaidi@eecs.umich.edu    }
13635952Ssaidi@eecs.umich.edu
13645952Ssaidi@eecs.umich.edu
13655952Ssaidi@eecs.umich.edu    // qData (vector<AnnotateList>)
13665952Ssaidi@eecs.umich.edu    qData.resize(qSize.size());
13675952Ssaidi@eecs.umich.edu    for (int x = 0; x < qSize.size(); x++) {
13685952Ssaidi@eecs.umich.edu        if (!qSize[x])
13695952Ssaidi@eecs.umich.edu            continue;
13705952Ssaidi@eecs.umich.edu        for (int y = 0; y < qSize[x]; y++) {
137110470Sandreas.hansson@arm.com            AnnDataPtr a = std::make_shared<AnnotateData>();
137210905Sandreas.sandberg@arm.com            a->unserializeSection(cp, csprintf("Q%d_%d", x, y));
13735952Ssaidi@eecs.umich.edu            data.push_back(a);
13745952Ssaidi@eecs.umich.edu            qData[x].push_back(a);
13755952Ssaidi@eecs.umich.edu        }
13765952Ssaidi@eecs.umich.edu    }
13775952Ssaidi@eecs.umich.edu}
13785952Ssaidi@eecs.umich.edu
13795952Ssaidi@eecs.umich.eduvoid
138010905Sandreas.sandberg@arm.comCPA::AnnotateData::serialize(CheckpointOut &cp) const
13815952Ssaidi@eecs.umich.edu{
13825952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(time);
13835952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(data);
13845952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(sm);
13855952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stq);
13865952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(op);
13875952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(flag);
13885952Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(cpu);
13895952Ssaidi@eecs.umich.edu}
13905952Ssaidi@eecs.umich.edu
13915952Ssaidi@eecs.umich.eduvoid
139210905Sandreas.sandberg@arm.comCPA::AnnotateData::unserialize(CheckpointIn &cp)
13935952Ssaidi@eecs.umich.edu{
13945952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(time);
13955952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(data);
13965952Ssaidi@eecs.umich.edu    orig_data = data;
13975952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(sm);
13985952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stq);
13995952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(op);
14005952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(flag);
14015952Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(cpu);
14025952Ssaidi@eecs.umich.edu    dump = true;
14035952Ssaidi@eecs.umich.edu}
14045952Ssaidi@eecs.umich.edu
14055952Ssaidi@eecs.umich.eduCPA*
14065952Ssaidi@eecs.umich.eduCPAParams::create()
14075952Ssaidi@eecs.umich.edu{
14085952Ssaidi@eecs.umich.edu    return new CPA(this);
14095952Ssaidi@eecs.umich.edu}
14105952Ssaidi@eecs.umich.edu
1411