[lttng-dev] What is _prev_state in sched_switch?

Sebastien Boisvert sboisvert at gydle.com
Wed Jul 24 10:30:40 EDT 2019


Hello Ravindra,

On 2019-07-24 10:09 a.m., Ravindra Kumar Meena wrote:
> 
> 
> On Wed, Jul 24, 2019, 7:33 PM Sebastien Boisvert <sboisvert at gydle.com <mailto:sboisvert at gydle.com>> wrote:
> 
> 
> 
>     On 2019-07-24 2:44 a.m., Ravindra Kumar Meena wrote:
>     > Hi,
>     >
>     > I had a looked at TraceCompass example. I came across sched_swithc event in present in the metadata.
>     >
>     > event {
>     > name = "sched_switch";
>     > id = 27;
>     > stream_id = 0;
>     > fields := struct {
>     > integer { size = 8; align = 8; signed = 0; encoding = UTF8; base = 10; } _prev_comm[16];
>     > integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _prev_tid;
>     > integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _prev_prio;
>     > integer { size = 64; align = 8; signed = 1; encoding = none; base = 10; } _prev_state;
>     > integer { size = 8; align = 8; signed = 0; encoding = UTF8; base = 10; } _next_comm[16];
>     > integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _next_tid;
>     > integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _next_prio;
>     > };
>     > };
>     >
>     > All event.fields variables are clear to me but what does _prev_state do here? I had a looked at its babeltrace output but found no pattern in _prev_state value.
>     >
>     > Please attend this email ASAP.
> 
>     I think that writing "Please attend this email ASAP" is somehow rude.
> 
> Okay. Sorry for that. It won't happen again.
> 
> I want to know what _prev_state means in sched_switch event.
> 

In the Linux kernel, the tracepoint for sched_switch does not have the
field prev_state:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/tracepoint.h?id=52a6e82ac27288f591c750f201de5c3e6ef24385#n465


In lttng-modules, however, there is the field prev_state:

http://git.lttng.org/?p=lttng-modules.git;a=blob;f=instrumentation/events/lttng-module/sched.h;h=77d77b2aeeddbe6ac34e2228b077734721f45b18;hb=4ea9b7c98ade603b08f0d945f4d99bc079eb57b6#l237


My guess would be that prev_state is the previous state of the thread (TID):

in "man ps":

PROCESS STATE CODES
       Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:

               D    uninterruptible sleep (usually IO)
               R    running or runnable (on run queue)
               S    interruptible sleep (waiting for an event to complete)
               T    stopped by job control signal
               t    stopped by debugger during the tracing
               W    paging (not valid since the 2.6.xx kernel)
               X    dead (should never be seen)
               Z    defunct ("zombie") process, terminated but not reaped by its parent


In the Linux kernel:

$ grep "#define TASK_" include/linux/sched.h
#define TASK_RUNNING			0x0000
#define TASK_INTERRUPTIBLE		0x0001
#define TASK_UNINTERRUPTIBLE		0x0002
#define TASK_PARKED			0x0040
#define TASK_DEAD			0x0080
#define TASK_WAKEKILL			0x0100
#define TASK_WAKING			0x0200
#define TASK_NOLOAD			0x0400
#define TASK_NEW			0x0800
#define TASK_STATE_MAX			0x1000
#define TASK_KILLABLE			(TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
#define TASK_STOPPED			(TASK_WAKEKILL | __TASK_STOPPED)
#define TASK_TRACED			(TASK_WAKEKILL | __TASK_TRACED)
#define TASK_IDLE			(TASK_UNINTERRUPTIBLE | TASK_NOLOAD)
#define TASK_NORMAL			(TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)
#define TASK_REPORT			(TASK_RUNNING | TASK_INTERRUPTIBLE | \




More information about the lttng-dev mailing list