summaryrefslogtreecommitdiff
path: root/cpu
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2005-11-20 17:44:58 -0500
committerNathan Binkert <binkertn@umich.edu>2005-11-20 17:44:58 -0500
commit0dcb288365931b5b6c1048302c23656473fea1af (patch)
tree6c7b5369fe283b61ad6c10fc5764bfd4a8af9ccb /cpu
parentf66ba9064090296563dc3f7712f2c0459fca3c5d (diff)
downloadgem5-0dcb288365931b5b6c1048302c23656473fea1af.tar.xz
Cleanup the StackTrace interfaces and profile interfaces so they
are more efficient and reduce the number of new/delete calls arch/alpha/stacktrace.cc: - Change the StackTrace code so that the class can more easily be cleaned out and reused to avoid extra allocations. - Allow trace() to accept a static instruction pointer so it can determine if the instruction is worth tracing. This is moved from the CPU. - provide constants for special meaning PCs (user, console, unknown), instead of magic numbers - switch to using kernelSymtab instead of allSymtab which will be going away - if the stack adjustment doesn't make any sense, exit and push unknown so we don't get into an infinite loop or record garbage. - check to see if we've made too many iterations through the stack and panic to avoid an infinite loop arch/alpha/stacktrace.hh: - Change the StackTrace code so that the class can more easily be cleaned out and reused to avoid extra allocations. - Allow trace() to accept a static instruction pointer so it can determine if the instruction is worth tracing. This is moved from the CPU. - provide constants for special meaning PCs (user, console, unknown), instead of magic numbers cpu/base.cc: only clear the profile if we have one include profile.hh here since base.hh doesn't do it anymore cpu/base.hh: no need to include cpu/profile.hh here cpu/profile.cc: use ProfileNode pointers instead of objects in the ChildList Consume a vector of addresses since that's really all we care about. cpu/profile.hh: Keep pointers to ProfileNodes to reduce the size of these structures keep a StackTrace around so that we may reuse it. provide consume functions that use the new StackTrace trace interface one consume function is inline and tries to fastpath the no trace condition, it calls the outlined consume function if a trace is generated. cpu/simple/cpu.cc: include cpu/profile.hh here since base.hh no longer does use the new FunctionProfile::consume interface (which contains the tracing functions) --HG-- extra : convert_revision : 5a1d9265289a75f67a497b322926be1f8c2d8eb3
Diffstat (limited to 'cpu')
-rw-r--r--cpu/base.cc4
-rw-r--r--cpu/base.hh1
-rw-r--r--cpu/profile.cc27
-rw-r--r--cpu/profile.hh15
-rw-r--r--cpu/simple/cpu.cc8
5 files changed, 32 insertions, 23 deletions
diff --git a/cpu/base.cc b/cpu/base.cc
index a6e71c808..8b94b8533 100644
--- a/cpu/base.cc
+++ b/cpu/base.cc
@@ -36,6 +36,7 @@
#include "base/output.hh"
#include "cpu/base.hh"
#include "cpu/exec_context.hh"
+#include "cpu/profile.hh"
#include "cpu/sampler/sampler.hh"
#include "sim/param.hh"
#include "sim/sim_events.hh"
@@ -254,7 +255,8 @@ BaseCPU::takeOverFrom(BaseCPU *oldCPU)
intstatus = oldCPU->intstatus;
for (int i = 0; i < execContexts.size(); ++i)
- execContexts[i]->profile->clear();
+ if (execContexts[i]->profile)
+ execContexts[i]->profile->clear();
if (profileEvent)
profileEvent->schedule(curTick);
diff --git a/cpu/base.hh b/cpu/base.hh
index 914d06982..4a44ab804 100644
--- a/cpu/base.hh
+++ b/cpu/base.hh
@@ -33,7 +33,6 @@
#include "base/statistics.hh"
#include "config/full_system.hh"
-#include "cpu/profile.hh"
#include "cpu/sampler/sampler.hh"
#include "sim/eventq.hh"
#include "sim/sim_object.hh"
diff --git a/cpu/profile.cc b/cpu/profile.cc
index b17a3c74e..f4aa81c2b 100644
--- a/cpu/profile.cc
+++ b/cpu/profile.cc
@@ -47,8 +47,8 @@ ProfileNode::dump(const string &symbol, uint64_t id, const SymbolTable *symtab,
ccprintf(os, "%#x %s %d ", id, symbol, count);
ChildList::const_iterator i, end = children.end();
for (i = children.begin(); i != end; ++i) {
- const ProfileNode &node = i->second;
- ccprintf(os, "%#x ", (intptr_t)&node);
+ const ProfileNode *node = i->second;
+ ccprintf(os, "%#x ", (intptr_t)node);
}
ccprintf(os, "\n");
@@ -65,8 +65,8 @@ ProfileNode::dump(const string &symbol, uint64_t id, const SymbolTable *symtab,
else if (!symtab->findSymbol(addr, symbol))
panic("could not find symbol for address %#x\n", addr);
- const ProfileNode &node = i->second;
- node.dump(symbol, (intptr_t)&node, symtab, os);
+ const ProfileNode *node = i->second;
+ node->dump(symbol, (intptr_t)node, symtab, os);
}
}
@@ -75,11 +75,8 @@ ProfileNode::clear()
{
count = 0;
ChildList::iterator i, end = children.end();
- for (i = children.begin(); i != end; ++i) {
- ProfileNode &node = i->second;
- node.clear();
- }
-
+ for (i = children.begin(); i != end; ++i)
+ i->second->clear();
}
FunctionProfile::FunctionProfile(const SymbolTable *_symtab)
@@ -92,12 +89,16 @@ FunctionProfile::~FunctionProfile()
}
ProfileNode *
-FunctionProfile::consume(const StackTrace *trace)
+FunctionProfile::consume(const vector<Addr> &stack)
{
- const vector<Addr> &stack = trace->getstack();
ProfileNode *current = &top;
- for (int i = 0, size = stack.size(); i < size; ++i)
- current = &current->children[stack[size - i - 1]];
+ for (int i = 0, size = stack.size(); i < size; ++i) {
+ ProfileNode *&ptr = current->children[stack[size - i - 1]];
+ if (ptr == NULL)
+ ptr = new ProfileNode;
+
+ current = ptr;
+ }
return current;
}
diff --git a/cpu/profile.hh b/cpu/profile.hh
index 9da170eb4..c795b8f41 100644
--- a/cpu/profile.hh
+++ b/cpu/profile.hh
@@ -40,7 +40,7 @@ class ProfileNode
private:
friend class FunctionProfile;
- typedef std::map<Addr, ProfileNode> ChildList;
+ typedef std::map<Addr, ProfileNode *> ChildList;
ChildList children;
public:
@@ -60,15 +60,26 @@ class FunctionProfile
const SymbolTable *symtab;
ProfileNode top;
std::map<Addr, Counter> pc_count;
+ StackTrace trace;
public:
FunctionProfile(const SymbolTable *symtab);
~FunctionProfile();
- ProfileNode *consume(const StackTrace *trace);
+ ProfileNode *consume(ExecContext *xc, StaticInstPtr<TheISA> inst);
+ ProfileNode *consume(const std::vector<Addr> &stack);
void clear();
void dump(ExecContext *xc, std::ostream &out) const;
void sample(ProfileNode *node, Addr pc);
};
+inline ProfileNode *
+FunctionProfile::consume(ExecContext *xc, StaticInstPtr<TheISA> inst)
+{
+ if (!trace.trace(xc, inst))
+ return NULL;
+ trace.dprintf();
+ return consume(trace.getstack());
+}
+
#endif // __CPU_PROFILE_HH__
diff --git a/cpu/simple/cpu.cc b/cpu/simple/cpu.cc
index 8f7534e16..862fe5b2c 100644
--- a/cpu/simple/cpu.cc
+++ b/cpu/simple/cpu.cc
@@ -46,6 +46,7 @@
#include "cpu/base.hh"
#include "cpu/exec_context.hh"
#include "cpu/exetrace.hh"
+#include "cpu/profile.hh"
#include "cpu/sampler/sampler.hh"
#include "cpu/simple/cpu.hh"
#include "cpu/smt.hh"
@@ -763,12 +764,7 @@ SimpleCPU::tick()
if (xc->profile) {
bool usermode = (xc->regs.ipr[AlphaISA::IPR_DTB_CM] & 0x18) != 0;
xc->profilePC = usermode ? 1 : xc->regs.pc;
- StackTrace *trace = StackTrace::create(xc, inst);
- if (trace) {
- xc->profileNode = xc->profile->consume(trace);
- trace->dprintf();
- delete trace;
- }
+ xc->profileNode = xc->profile->consume(xc, inst);
}
#endif