How to trace pthread scheduling in Linux?
strace - simple tool to trace process behavior, but seems can not check the core id.
lttng - need patch the kernel, but more impressive, you can know exactly what each core is doing like context switch/interrupt handling.
Update: As Mathieu Desnoyers mentioned, lttng can be used as Linux kernel modules since 2.6.36, no kernel patching needed now.
pthread scheduling
I assume that what you're after is simulating a scheduler for some OS, using pthreads as the basis for your implementation. What you can do is to create a pthread for each simulated thread, and put an implicit wait on a condition variable in each of the threading primitives of your OS. You can then, by picking which condition variable to signal, decide which thread gets to run when. I'm glossing over the details (ask if you want more info), but it's fairly straight-forward to implement.
Keep track of pthread
A thread's entire identity resides in
pthread_t
Initializing a thread returns its
pthread_t
typed ID to its parentEach thread can get it's own ID with
pthread_self()
You can compare thread IDs using the function:
int pthread_equal (pthread_t, pthread_t)
So: Maintain a common data structure where you can store thread status as STARTED, RUNNING, FINISHED using the pthread_t
IDs and pthread_equal
comparison function to differentiate between the threads. The parent sets the value to STARTED when it starts the thread, the thread itself sets its own state to RUNNING, does its work, and sets itself to FINISHED when done. Use a mutex to make sure values are not changed while being read.
EDIT:
You can set up a sort of 'thread destructor' using pthread_cleanup_push
:
http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cleanup_pop.html
i.e. register a routine to be called when the thread exits (either itself, or by cancellation externally). This routine can update the status.
litmus-rt scheduling traces
Seems like the Feather-Trace wasn't enabled by default when applying the litmus-rt patch to my kernel. After entering menuconfig (make menuconfig
) I disabled the RELOCATABLE dependency under processor type and features. Afterwards the option Feather-Trace Infrastructure was made visible, found under LITMUS RT -> tracing.
Related Topics
Using "And" in Bash While Loop
Short Command to Find Total Size of Files Matching a Wild Card
Opening Default Text Editor in Bash
Trying to Launch an External Editor from Within a Go Program
Open Eclipse Juno with Error "No More Handles ..." in Ubuntu 12.04
How to Set Default Arguments for "Ls" in Linux
Amazon Ec2 Lost Private Key, How to Get Access to The Server
Bash - How to Print Multi Line Strings (With '\N') Using Printf
How to Tell Binary from Text Files in Linux
Unix Bash Shell Programming If Directory Exists
Git Clone Fails: Server Certificate Verification Failed
Customize Tab Completion in Shell