Linux real time scheduler priority attributes and timing analysis
Hello,
(You can skip to questions at the end.)
I have a real time program in C simply as below:
void func() /* This would be called as a normal pthread from main */
{
/* some code here */
attr.sched_runtime = 500000; // 0.5 ms
attr.sched_deadline = 500000; // 0.5 ms
attr.sched_period = 1000000; // 1ms
attr.size = sizeof (attr);
attr.sched_flags = 0;
attr.sched_nice = 0;
attr.sched_priority = 0;
ret = sched_setattr(0, &attr, flags);
if (ret != 0)
perror("Error ");
/* some more code here */
while(1)
{
/* realtime processing code here */
sched_yield();
/* time_elapsed() returns time diff (in ms) between previous and current invocation of time_elapsed() */
cycle_period_time_taken = time_elapsed();
/* cycle_period_time_taken is plotted across time to check jitter*/
time_elapsed();
/* Data produce to be consumed by other process */
/* while break condition code */
}
Now, the questions are:
1) Am not able to modify attr.sched_priority and am getting error Invalid argument, in case I modify it to other than 0. How can I set attr values to make the thread of the highest real time priority thread, I think I need to set to 99 but unable to do so.
2) is it apt method to do timing analysis as above using time_elapsed() in the code. (This is easier especially to plot, may be I can use tracefs but that would be difficult to plot. Inputs appreciated in better or other methods for doing timing analysis using tools like perf, tracefs, uprobes).
Thanks and regards,
Bhargav
|