Andy Lin
Andy Lin

Reputation: 447

How to know the control flow during transition in state-machine?

I've been studying spaghetti-based state-machine, meaning that it's composed of a bunch of if-else statements scattered everywhere, in large kernel module recently in order to port this module to other platform.

To understand how control flow goes between each state, I use printk() in the first place to print every line number so that I can see every detail of program behavior in run-time. However, too many printk() increase too much processing load and result in wrong behavior.

Afterward, I try printk_once() and printk_ratelimited() to reduce line number. But this way causes another problem, especially at the time during transition.

Let me explain why:

Suppose there are four states A, B, C, and D, and each state's control flow is overlapped partly with each other. Also, there are two events e1 and e2 that I can trigger by plugging/unplugging hardware.

Furthermore, we define stable state as a state being stable, meaning that the path of control flow for this state is not changing until event occurs; We also define unstable state as a state being unstable, meaning that this state is just a transition state for other states.

event    current state    next state

x              A              A   <---- always start from A
e1             A              B
x              B              C
e2             C              D
x              D              A

A, C: stable state
B, D: unstable state

If I use printk_once(), I'm not able to get all path of control flow from A to C as a whole, because some part of it are the same, and already be printed.

If I use printk_ratelimited(), it's not guaranteed to capture the path of control flow for transition from A to C because the span is too short to be captured.

What I want is a control flow that clearly shows how program runs step by step from state A to B then to C, so that I can totally understand what's going on between each state.

That's it.

I would like to know how people deal with this. Thanks!

Upvotes: 0

Views: 99

Answers (0)

Related Questions