Skip to content

Commit

Permalink
comment realtime scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 18, 2025
1 parent 7ca4495 commit bdb002f
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ int sched_setattr(pid_t pid, const struct sched_attr * attr, unsigned int flags)

int main(int argc, char * argv[])
{
struct sched_attr attr;
// struct sched_attr attr;

/* Lock memory */
if(mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
{
printf("mlockall failed: %m\n");
if(errno == ENOMEM)
{
printf("\nIt is likely your user does not have enough memory limits, you can change the limits by adding the "
"following line to /etc/security/limits.conf:\n\n");
printf("%s - memlock 1000000000\n\n", getlogin());
printf("Then log-in and log-out\n");
}
return -2;
}
// /* Lock memory */
// if(mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
// {
// printf("mlockall failed: %m\n");
// if(errno == ENOMEM)
// {
// printf("\nIt is likely your user does not have enough memory limits, you can change the limits by adding the "
// "following line to /etc/security/limits.conf:\n\n");
// printf("%s - memlock 1000000000\n\n", getlogin());
// printf("Then log-in and log-out\n");
// }
// return -2;
// }

/* Configure deadline policy */
memset(&attr, 0, sizeof(attr));
attr.size = sizeof(attr);
// memset(&attr, 0, sizeof(attr));
// attr.size = sizeof(attr);

uint64_t cycle_ns = 1 * 1000 * 1000; // 1 ms default cycle
char * MC_RT_FREQ = nullptr;
Expand All @@ -57,17 +57,17 @@ int main(int argc, char * argv[])
}

/* Time reservation */
attr.sched_policy = SCHED_DEADLINE;
attr.sched_runtime = attr.sched_deadline = attr.sched_period = cycle_ns; // nanoseconds
// attr.sched_policy = SCHED_DEADLINE;
// attr.sched_runtime = attr.sched_deadline = attr.sched_period = cycle_ns; // nanoseconds

printf("Running real-time thread at %fms per cycle\n", cycle_ns / 1e6);

/* Set scheduler policy */
if(sched_setattr(0, &attr, 0) < 0)
{
printf("sched_setattr failed: %m\n");
return -2;
}
// if(sched_setattr(0, &attr, 0) < 0)
// {
// printf("sched_setattr failed: %m\n");
// return -2;
// }

/* Run */
mc_rtde::run(data);
Expand Down

0 comments on commit bdb002f

Please sign in to comment.