Review Board 2.0.15


Faults: Pass the StaticInst involved, if any, to a Fault's invoke method.

Review Request #239 - Created Aug. 31, 2010 and submitted

Information
Gabe Black
gem5
Reviewers
Default
Faults: Pass the StaticInst involved, if any, to a Fault's invoke method.



This review is pretty boring except that I moved the "Fault" type definition into base/types.hh to avoid a header file dependency loop, and the idea that a StaticInstPtr parameter is added to the Fault's invoke method per Steve's suggestion on m5-dev. #includes had to be changed around to avoid circular dependencies among headers and to accommodate "Fault"'s new location.

   
Posted (Sept. 8, 2010, 1:54 p.m.)
This diff doesn't include the fact that base/types.hh now has the definition of Fault.  I would really prefer not to see that go into base/types.hh myself since most things that use base/types.hh could care less about Fault.  Perhaps you could explain the #include loop.
  1. I wasn't very excited about moving it either, but I didn't see any other way to make it work. It's been a little while so I may have mixed up the details a little, but I think it was that StaticInst defines its execute/initiateAcc/completeAcc functions to return a Fault object, so static_inst.hh needs to include whatever defines the Fault type. Fault is really just reference counted pointer, but gcc was very uncooperative when I tried to just declare the type in static_inst.hh, but more on that below. In sim/faults.hh the invoke method now would take a StaticInstPtr parameter, so it needed to include the definition of that. gcc got cranky about just declaring that type too for I presume the same reasons. So if StaticInstPtr is defined in cpu/static_inst.hh and Fault is defined in sim/faults.hh, those two files include each other and things break. I initially tried moving StaticInstPtr out of cpu/static_inst.hh, but that didn't really work. Fortunately, faults don't have quite the same usage pattern so it worked to move the Fault type.
    
    I did a little reading and a little pondering and I think one reasons gcc gets upset about prototyping reference counted pointers is the dereference operator. Everything else deals with a T*, but that dereferences and returns a const reference. The const reference should still be ok, but I guess there may be a subtle issue there since it makes a round trip through the underlying type. Also there are the calls to incref and decref, but those should be available from the base RefCounted class and shouldn't be ambiguous. Although now that I look at it, the template won't know what the base class of T is, so it won't know how to handle those calls. Would it fix things if we explicitly cast down to a RefCounted pointer before the calls to make things more explicit? Or a Base template parameter that was defaulted to RefCounted in case somebody (for whatever reason) wanted to use something else? One other issue I ran into is that gcc won't let you predeclare something that ends up being a typedef with the class keyword. Since many or maybe even all reference counted pointer types are actually typedefs to hide the template argument and I don't know how to declare a typedef without having the underlying type handy, things got tricky there too.
    
    In any case, I wasn't comfortable fiddling with that too much since I could accidentally introduce very subtle bugs and I'd found an imperfect but working solution. If you know of a way to make, say, StaticInstPtr as easy to declare as class StaticInst, that would actually improve things anywhere we use reference counted pointers which would be great.
  2. Perhaps you can do the forward declaration that I proposed in static_inst.hh now?  I'm still not quite clear on where the loop is, do you have an old diff with the problem that I can read?
src/arch/alpha/isa.cc (Diff revision 1)
 
 
<cassert> is the correct include.
  1. fixed
src/arch/mips/utility.cc (Diff revision 1)
 
 
<cmath> is the correct include.
  1. fixed
Posted (Sept. 9, 2010, 6:51 a.m.)
Ok, so part of my problem was that I didn't read the whole diff.  I didn't realize that it was split on three pages, so I only read the first page.  I didn't get what you were doing with StaticInst.  Now that I see what you did to base/types.hh, I like it even less because you suck in ref_cnt.hh.  I'd rather see a sim/fault.hh that has the additions that you put into base/types.hh.  That said, there are some other options which I've noted on types.hh.
src/base/types.hh (Diff revision 1)
 
 
I think you can remove this if you change what's below.  I'd still hesitant to see this in base/types.hh, but if we can get rid of the #include, it's not as bad.  What about putting this stuff in something like sim/fault.hh?
src/base/types.hh (Diff revision 1)
 
 
I think you can forward declare RefCountingPtr like this without the #include:

class FaultBase;
template <class T> class RefCountingPtr;
typedef RefCountingPtr<FaultBase> Fault;