SystemC调试记录(一)

随着我用SystemC写的工程越来越大,遇到的问题也是接踵而至。很多东西可能在其他地方也遇不到,所以记下来。

1. sensitive列表。

在SystemC中SC_METHOD和SC_THREAD可以使用敏感列表,但是他们的意义完全不一样。对SC_METHOD使用敏感列表和普通RTL代码里面的敏感列表意义是一样的。然而,对于SC_THREAD,敏感列表仅仅触发该方法执行一次,以后所有的执行由方法自行触发(即使用wait和next_trigger的方式)。但是SC_METHOD当中不允许使用wait,甚至任何可能会导致wait的语句都是危险的。比如对一个sc_fifo执行write操作(fifo可能已经满了)。这样会造成一个问题,用SystemC写的standard cell将很难模拟门延时。

另外一个关键问题是上升沿和下降沿。2.0版本还可以使用sensitive_pos()或者sensitive_neg(),但是2.2版本不建议使用,改成在端口上使用.pos()和.neg()。如果看sensitive的定义,只要是event都可以加入敏感列表,但实际上并不是。注意到这样一个问题,在构造函数中将一个端口加入敏感列表时,其对应的信号并没有绑定。所以使用posedge_event()和negedge_event()对其取事件会导致运行时错误。我认为这也是使用.pos()和.neg()的原因。只是一个绕过错误的办法。

1. Sensitive List

It is possible to use sensitive list to SC_METHOD and SC_THREAD functions in SystemC but they have totally different meanings. SC_METHOD is triggerred by sensitive signals during the simulation process but SC_THREAD is only triggerred once. The following triggers for SC_THREAD are required to settled by the function itself, using the wait() and next_trigger() functions. It is not allowed to use wait() in SC_METHOD functions and any actions that may incur a wait is dengerous to SC_METHOD function, which will lead to a run-time error. Therefore, it is dengerous to write a value to a sc_fifo in SC_METHOD. In case the fifo is already full, this write action will stall the SC_METHOD. As a result, I believe, it is hard to simulate gate latency by writing a SystemC simulation cell library.

About the posedge and negedge of sensitive signals, in SystemC 2.0, it is possible to use sensitive_pos and sensitive_neg but in SystemC 2.2, it is recommended to use sig.pos() and sig.neg(). In data type analysis, it is only required to give sensitive an event but in fact it is not correct in all circumstances. For example, when we add ports to sensitive list in construction function for a certain class, the signals are not bonded yet. Therefore, using the posedge_event() or negedge_event() functions to extract events will cause run-time error. This is another explaination why the pos() and neg() functions are necessary: they are walkaround methods.

2. 模块的命名

这是SystemC很令人讨厌的一个特性。所有的模块都必须有自己独一无二的名字。对于RTL建模,也许不是问题,但是对于更广泛的模型,却成了制约。比如,我要建立一个模块组,这个名字规则导致我必须建立指针数组,并一个一个的初始化。

为了能够之间建立数组,我必须构造能够自动命名的构造函数。我想到了默认参数列表。这样,我可以把构造函数写成如下形式:

SC_HAS_PROCESS(EXAMPLE);

EXAMPLE(sc_module_name m_name = sc_module_name("example"))

: sc_module(m_name)

{}

这样,当需要名字的时候,可以给出名字。不需要的时候,特别是建立数组的时候,这个构造函数可以当作默认构造函数使用,模块的名字会自动命名为example。但是,建立数组意味着多个对象被命名为同一个名字,SystemC会报出运行时警告:

Warning: (W505) object already exists: example Latter declaration will be renamed to example_1

不过,这只是一个警告,对实际仿真没有任何影响。我的办法是屏蔽它。可以在sc_start()之前改变对于该警告的默认操作。具体的语句如下:

sc_report_handler::set_actions(SC_ID_OBJECT_EXISTS_, SC_DO_NOTHING);

sc_report_handler是SystemC管理报告的全局静态类,set_actions将改变操作。SC_ID_OBJECT_EXISTS_是这个警告的msg_type,在systemc-2.2.0/include/sysc/kernel/sc_kernel_ids.h文件中定义。同样的方法,可以屏蔽任何不想显示的警告。同时,sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);将屏蔽所有的警告。

2. Naming the Modules

One of the disgusting features of SystemC is its unique naming systems. Every single object in simulation must has a unique name. It is not a problem for RTL modulation but for some general modulations, it is a severe problem: it blocks us to difine a group of objects by a vector. The naming rule requires us to initialize them one by one and name them differently.

To ease the object group definition, we can use the default parameter list. So a construction method could be written as:

SC_HAS_PROCESS(EXAMPLE);

EXAMPLE(sc_module_name m_name = sc_module_name("example"))

: sc_module(m_name)

{}

Consequently, we can explicitly name the object or build up vector directly, thanks to the default construction. However, when use this method in realistic vectors, multiple objects are renamed automatically by SystemC simulator and WARNING 505 are reported, such as:

Warning: (W505) object already exists: example Latter declaration will be renamed to example_1

This warning has no impact to simulation results but will flash your screen. Fortunately, we can block its display by use the following sentence before calling the sc_start() function,

sc_report_handler::set_actions(SC_ID_OBJECT_EXISTS_, SC_DO_NOTHING);

sc_report_handler is the global static class for reporting. set_actions can modify the default actions of sepcific warnings even errors. SC_ID_OBJECT_EXISTS_ is the msg_type of warning 505, defined in systemc-2.2.0/include/sysc/kernel/sc_kernel_ids.h. SC_DO_NOTHING will tell the SystemC simulator to block the display of warning 505.

By the same means, all other warning can be blocked. You even can use the sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING); to block all warnings.

Advertisements

关于 W. Song
Research Associate in the University of Cambridge

7 Responses to SystemC调试记录(一)

  1. Wei says:

    to 文 江, 恐怕要一个一个来,每一个数组单元是一个对象,对象的数组指针则不是,所以不太可能.以后也许会有改进.

  2. says:

    你好 我初学SystemC 可否向你请教一个问题:如何实现数组端口的关联?难道要一个个关联还是可以一次性的?谢谢啦

  3. Wei says:

    to zx,
    学姐好!
    现在主要是事件级的,一个片上网络的项目(NoC),我拿它写系统级的功能模型。以后也许会联合仿真,不过这里有人说联合仿真跑不起来,还不知道问题是什么。

  4. shuo says:

    哎呀,不好意思,是知识 :)

  5. shuo says:

    从你这里可以学习好多致使阿 :)

  6. zx says:

    呵呵,你们也用systemC呀.你主要用它做哪个层面的仿真(是在什么样的系统里?)?会和RTL联合仿真吗?

  7. Unknown says:

    生活中的好玩儿事,出去转转吧:)

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: