Moving Ruby to M5's debug print support
Review Request #277 - Created Oct. 17, 2010 and submitted
| Information | |
|---|---|
| Nilay Vaish | |
| gem5 | |
| Reviewers | |
| Default, Ruby | |
Ruby currently uses GEMS debug support with the enum character string map to enable certain debug messages. Meanwhile, M5 has debug print support that works with scons. Compiling the m5.fast binary, the M5 debug statements are removed, but the Ruby ones are not unless RUBY_DEBUG is not defined. This patch moves Ruby to M5's debug print support.
Review request changed
Updated (Oct. 19, 2010, 10:30 a.m.)
Groups: |
|
|---|
Posted (Oct. 21, 2010, 6:35 a.m.)
-
src/cpu/testers/rubytest/CheckTable.cc (Diff revision 1) -
These adjacent DPRINTFs should be consolidated into one. It's more efficient (since it's a single check of the trace flag and a single call to cprintf), and in this case (and many others) we don't really need the function name, file name, and line number printed redundantly. Also you don't need to use c_str(), cprintf() handles std::string just fine (and anything else that supports the '<<' operator, I believe).
-
src/mem/SConscript (Diff revision 1) -
Do we want to define a whole new disjoint set of trace flags just for Ruby? For example, why have RubyCache and Cache both?
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 1) -
This DPRINTF is broken (and several others like it)... it needs a trace flag as the first arg, and "%str" probably isn't the format string you want (basically it's just like printf, so you probably mean "%s").
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 1) -
We should get rid of these commented-out lines, either deleting them if they're not needed or just using a trace flag that keeps them turned off unless wanted. That's the point of the trace flags, is so that you don't have to comment out debug printfs, but can just turn them on and off dynamically at the granularity you want.
-
src/mem/ruby/buffers/MessageBuffer.cc (Diff revision 1) -
Note that DPRINTF automatically prepends the value of name(), so we should make sure that works for Ruby so we don't need to explicitly pass m_name.c_str() (which I assume is the same or similar).
-
src/mem/ruby/common/Address.hh (Diff revision 1) -
Indentation looks funky on this line. Are you using tabs?
-
src/mem/ruby/common/Address.hh (Diff revision 1) -
Nate can correct me if I'm wrong, but the cprintf library eventually uses '<<' at the bottom, so if we need to define a type-specific output (here and with DataBlock below) we should just overload that operator. In this specific case, much of this formatting can be handled in the format string itself as "[0x%x, line 0x%x]" and then calling with addr and blockAlign(addr) as arguments.
-
src/mem/ruby/common/Debug.hh (Diff revision 1) -
We need to decide how valuable it is to automatically include the function name, file, and line number. If there's a consensus that we should keep it, we should add DPRINTF variants to M5 that have this. If not, we should eliminate this info from the Ruby debug messages. But we shouldn't take a bunch of boilerplate that used to be nicely encapsulated in a macro and reproduce it N times all over the code.
-
src/mem/ruby/common/Debug.cc (Diff revision 1) -
Code should never just be commented out... if we don't need it any more, just delete it.
Posted (Oct. 21, 2010, 8:23 a.m.)
I think Steve covered most of the main points. Please see my detailed comment below about when I think line numbers and function names are useful. Brad
-
src/mem/protocol/RubySlicc_MemControl.sm (Diff revision 1) -
I'll beat Nate to this. :) Try to avoid inserting and deleting random lines in files. It cluters the diff and unecessarily makes merging harder.
-
src/mem/ruby/common/DataBlock.hh (Diff revision 1) -
Spacing is off. Are you using mistakingly using tabs?
-
src/mem/ruby/common/Debug.hh (Diff revision 1) -
I agree with Steve's point that adding "__PRETTY_FUNCTION__, __FILE__, __LINE__" to every Ruby DPRINTF call is too cumbersome and we either need to remove it or define a macro that does it automatically. Nilay, I think I might have confused you during our previous email conversations. We definitely want to automatically include the function name, file, and line number for the SLICC/.sm debug statements...I've found that feature very useful in the past. However, I'm not sure we need it for the debug statements on the Ruby side. Nilay, if I understand your changes to SLICC correctly and recall from our previous conversations on this topic, these old ruby DEBUG macros relied on the ostream operator<< overloading, correct? That is why you now have the conditional statements in the SLICC that generate the correct DPRINTF line depending on the type. Am I understanding the issues correctly? If so, I think your solution for the SLICC generation of DPRINTF statements looks good. I just think that we need to clean up the Ruby DPRINTF statements.
-
src/mem/ruby/common/NetDest.hh (Diff revision 1) -
Spacing again.
-
src/mem/slicc/ast/FuncCallExprAST.py (Diff revision 1) -
See long comment above.
Overall, I have two major comments. 1) You should get rid of print_str() (and probably print()) for that matter and implement operator<<. 2) You shouldn't be duplicating so many lines with the __PRETTY_FUNCTION__, __FILE__, __LINE__ stuff. I think it should be buried in a macro. In fact, if people like, we could make those available to *ALL* DPRINTFs and make turning them on and off another trace flag. In all honesty though, they tend not to be necessary if your trace strings are at all descriptive.
-
src/cpu/testers/rubytest/CheckTable.cc (Diff revision 1) -
You don't need __PRETTY_FUNCTION__ and __FILE__/__LINE__. I'd say that one or the other should do. Also if you're going to do this a lot, we should have a new DPRINTF macro for it.
-
src/mem/SConscript (Diff revision 1) -
I would emphatically argue *no*
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 1) -
I agree that we should pass it through unmodified. Also, DPRINTF understands operator<<, and if you use %s, it can use any object with an operator<<, so I'd get rid of print_str() on the objects and just rename it operator<<
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 1) -
I agree with Steve. Commented out code is a no-no.
-
src/mem/protocol/MESI_CMP_directory-L2cache.sm (Diff revision 1) -
Can you consolidate these into a single expression that has some context? I guess that's not the point of this diff though, so I don't think it's required.
-
src/mem/protocol/MESI_CMP_directory-L2cache.sm (Diff revision 1) -
Same here
-
src/mem/protocol/RubySlicc_Exports.sm (Diff revision 1) -
We should probably change this to operator<<, then again, I am not quite clear how ruby uses this.
-
src/mem/ruby/SConsopts (Diff revision 1) -
Good work!
-
src/mem/ruby/buffers/MessageBuffer.cc (Diff revision 1) -
I'd rather see a new DPRINT Macro.
-
src/mem/ruby/buffers/MessageBuffer.cc (Diff revision 1) -
Generally, this is a bad idea.
-
src/mem/ruby/buffers/MessageBuffer.cc (Diff revision 1) -
you don't need to use c_str(), and in fact name() is automatically inserted into all DPRINTF statements.
-
src/mem/ruby/buffers/MessageBuffer.cc (Diff revision 1) -
why is "message" in the argument list? Also, why this very complicated expression to get some message string? I suggest getting rid of print_str() and making operator<< work.
-
src/mem/ruby/common/Address.hh (Diff revision 1) -
I'd honestly get rid of both print and print_str and just simply implement operator<<
-
src/mem/ruby/common/Address.hh (Diff revision 1) -
Yes. That is exactly correct.
-
src/mem/ruby/network/simple/PerfectSwitch.cc (Diff revision 1) -
Pretty strange that you keep having things like "m_switch_id" in the argument list.
-
src/mem/ruby/storebuffer/storebuffer.cc (Diff revision 1) -
Instead of commenting these out, you could add a new Trace flag for these and get rid of the #ifdefs. Not sure if it's useful or not though.
Review request changed
Updated (Oct. 24, 2010, 1:59 a.m.)
Change Summary:
I have made almost all the changes suggested below or on the m5-dev mailing list.
Posted (Oct. 24, 2010, 2:45 p.m.)
Thanks, this is hugely improved. Just a few little things I noticed still; the panic() thing is the only one I consider really necessary to take care of before committing.
-
src/mem/SConscript (Diff revision 2) -
Nate and I agreed that it would be nice not to prefix all of these with "Ruby", though if other people feel this decision needs more discussion that's fine.
-
src/mem/protocol/MI_example-dir.sm (Diff revision 2) -
Can some of these FooBarBazType_to_string() functions, like the one here and several more below, be converted to (or hidden behind) operator<<? That's not strictly necessary but it would make these calls a lot less verbose.
-
src/mem/ruby/storebuffer/storebuffer.cc (Diff revision 2) -
In these cases (and the ones below) where this is really a fatal error, I believe the whole ERROR_OUT/DEBUG_EXPR/ASSERT(0) sequence should be replaced by a single call to panic(), which takes the same arguments as cprintf(). I think if you're dying you don't want to only print relevant info if you had traceflags enabled too.
-
src/mem/slicc/ast/FuncCallExprAST.py (Diff revision 2) -
What is this code doing? It looks like it's inserting the location, but how does this work if the format string isn't changed? Plus it would be nice to have a comment here in the SLICC code too.
Review request changed
Updated (Oct. 25, 2010, 12:54 a.m.)
Change Summary:
I have removed the _to_string() function calls that were appearing in .sm files. Also, I have added a comment for the changes made to the FuncCallExprAST.py.
Diff: |
Revision 3 (+248 -394)
|
|---|
Posted (Oct. 25, 2010, 2:35 a.m.)
-
src/mem/protocol/MESI_CMP_directory-L2cache.sm (Diff revision 3) -
It looks like this call goes over 80 chars on the first line, and then uses up a lot of unnecessary lines by taking up a whole line for each arg. If you want to keep the verbose labels, you should format it like this: DPRINTF(RubySlicc, "Address: %s, L2 Cache State: %s, Sender: %s, " "Response Type: %s, Destination: %s", in_msg.Address, getState(in_msg.Address), in_msg.Sender, in_msg.Type, in_msg.Destination); though my inclination would be to save more space by abbreviating or even eliminating some of the labels in the format string (since most of the fields will be self-evident, and they'll get pretty tiring in the trace output too, I expect).
Posted (Oct. 25, 2010, 3:33 a.m.)
Looking much better. There are two main questions: 1) Do we want Ruby to prefix all trace flag names. (I vote NO) 2) Do we want to have you insert the location into the DPRINTF statements or use #line directives and create DPRINTFL. The latter is more general, but it could certainly be done in the future. There are quite a number of lines that are over 80 columns, can you fix those?
-
src/mem/SConscript (Diff revision 3) -
I still think that you should use more general names. Try to use the names that the M5 cache hierarchy does. As we merge the two, it would be better that way.
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 3) -
Can you please make sure that you don't create lines with more than 80 columns.
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 3) -
Again
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 3) -
80 columns
-
src/mem/protocol/MESI_CMP_directory-L1cache.sm (Diff revision 3) -
80 columns
-
src/mem/protocol/MESI_CMP_directory-L2cache.sm (Diff revision 3) -
80 columns
-
src/mem/protocol/MESI_CMP_directory-L2cache.sm (Diff revision 3) -
I completely agree.
-
src/mem/ruby/common/NetDest.hh (Diff revision 3) -
Does this compile? Ruby isn't a trace flag.
-
src/mem/slicc/ast/FuncCallExprAST.py (Diff revision 3) -
I think it would be better if we emitted #line statements in the output code instead of doing this. That would allow us to get better compiler errors too. That could be done in the future I guess.
Review request changed
Updated (Oct. 25, 2010, 6:10 a.m.)
Change Summary:
I have converted all the lines to <= 80 characters. But not all lines in the .sm files cannot follow this convention since SLICC does not support strings that are split across two different lines.
Diff: |
Revision 4 (+284 -394)
|
|---|
Overall, it looks good to me. The only thing I would like to see changes is removing the RubySlicc flag from the .sm DPRINTF statements.
Review request changed
Updated (Oct. 26, 2010, 3:17 a.m.)
Change Summary:
I have condensed a couple of lines that were more than 80 characters in length. I had failed to add '\n' in the DPRINTF() calls. So that has been fixed as well. Brad, though the programmer needs to specify the trace flag, SLICC compiler would still output RubySlicc as the trace flag. Nate, I will go through the added trace flags later and will see which one of them should exist and with what names. Currently, I had simple converted the components that were defined in Ruby.
Diff: |
Revision 5 (+284 -394)
|
|---|
