(moving this over to m5-dev) M5 has a multi-phase startup process too for dealing with these dependencies. I don't see it documented explicitly anywhere unfortunately. Here's the gist of it though (based on a combination of memory and quick code browsing, so it may not be authoritative):
- As you note, the SimObject's parameter values are passed in through the param pointer in the constructor. In general you probably do want to consume those in the constructor if you can, but you're not required to; the _params member (accessible via params()) keeps this pointer around forever so you can ignore them in the constructor and wait to look at them until later if you want. - In addition to the constructor, there are also optional init() and startup() virtual methods you can declare to do things at different phases of initialization (in addition to regStats() which is similar but obviously has a specific purpose). Basically in instantiate(), all SimObjects are constructed in the first pass, then the ports are connected, then init() is called on all the objects, then regStats(). At this point, the top-level script may (or may not) call restoreCheckpoint(), which will call unserialize() on all the objects. Then just before you enter the event loop for the first time, startup() is called on all the objects. - You're guaranteed that any SimObject that is passed to you as a parameter has been constructed before your constructor is called, so that the pointer in the params struct is valid. Since init() hasn't been called yet you can't assume too much about what that other object is prepared to do though. If you need to do something that relies on the other object having been through init(), you need to do it in startup(). Note that this means you can't have circular parameter dependencies. Basically if you have two objects A and B that need to know about each other (other than being connected via a port), there's a special relationship, and one of them will have a "register" method. So for example A will get a pointer to B, but then in A's constructor or init() method it will call B->registerA() to say "hey B, I'm your A". As always, the source is the ultimate guide; since Nate moved a lot of this into python I had to do some searching to find it myself. See src/python/sim/simulate.py and realize that a number of the functions that get called there are actually C++ functions wrapped via SWIG. If anyone (Nate?) has some more specific guidelines on how things should be split conceptually between the constructor, init(), and startup() please speak up. Steve On Thu, Jul 9, 2009 at 9:24 AM, Somayeh Sardashti <[email protected]>wrote: > Hi, > > For the starting point, I agree with you. Also, I think I should change the > way we pass parameters. In M5, they are passed through constructor, while we > handle it in a similar way by passing through another function (init) which > is called exactly after constructing the object. However , sometimes order > of defining and initiating different objects are important for us, so we > should handle them too. > > Somayeh > > > Steve Reinhardt wrote: > >> Hi Somayeh, >> >> This sounds great. Unfortunately I don't know much about Ruby >> configuration, but my expectation is that the first step in getting Ruby >> configured in M5 style (and really the main step in getting Ruby and M5 more >> tightly integrated overall) is to have the various Ruby objects derive from >> the M5 SimObject class. Once that's done, then it's pretty easy to add >> parameters to the Python side of SimObject definitions, which then magically >> show up in C++. I don't think there's much documentation on this on the >> wiki, but our last tutorial (at http://m5sim.org/wiki/index.php/Tutorials) >> had a section on this. The discussion on slides 98-114 (104-120 if you go >> by the pdf page numbers) is the relevant part. If you want to watch the >> video, it would be the "extending" part. >> >> Steve >> >> On Wed, Jul 8, 2009 at 10:01 AM, nathan binkert <[email protected]<mailto: >> [email protected]>> wrote: >> >> > I am working in Multifacet group on Gem5. As I have handled Ruby >> language >> > configurations for different components, I pretty much know Ruby >> > configuration. Also, I have studied M5 configuration. Therefore, >> we thought >> > I can handle changing Ruby configuration to M5 style. In this >> way, we can >> > speed up completing Gem5. >> > >> > Where do you think I should start from? >> >> Hi Somayeh, >> >> The taxi is here and I'm off for Vacation. Steve will be answering >> your questions. In the future, please use [email protected] >> <mailto:[email protected]> for your >> questions. That forum goes to all of the contributors and the answers >> to your questions will benefit others. (And the correct person will >> always get your message). >> >> Nate >> >> >> >
_______________________________________________ m5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/m5-dev
