Skip to content

Commit

Permalink
Added support for real-time kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
NeroReflex committed Mar 4, 2024
1 parent f64a336 commit 16f1c52
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
8 changes: 8 additions & 0 deletions allynone.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
#include "rog_ally.h"
#include "legion_go.h"

#include <sys/mman.h>

static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";

int main(int argc, char ** argv) {
// Lock all current and future pages from preventing of being paged to swap
const int lockall_res = mlockall( MCL_CURRENT | MCL_FUTURE );
if (lockall_res) {
fprintf(stderr, "mlockall failed: %d", lockall_res);
}

int ret = 0;

// fill in configuration from file: automatic fallback to default
Expand Down
47 changes: 46 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
#include "rog_ally.h"
#include "legion_go.h"

#include <sys/mman.h>

static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";

int main(int argc, char ** argv) {
// Lock all current and future pages from preventing of being paged to swap
const int lockall_res = mlockall( MCL_CURRENT | MCL_FUTURE );
if (lockall_res) {
fprintf(stderr, "mlockall failed: %d", lockall_res);
}

int ret = 0;

dev_in_settings_t in_settings = {
Expand Down Expand Up @@ -74,8 +82,45 @@ int main(int argc, char ** argv) {

//memset(&dev_in_thread_data.communication.endpoint.socket.serveraddr, 0, sizeof(dev_in_thread_data.communication.endpoint.socket.serveraddr));

// Initialize pthread attributes (default values)
struct sched_param param;
pthread_attr_t attr;
ret = pthread_attr_init(&attr);
if (ret) {
printf("init pthread attributes failed\n");
goto main_err;
}

// Set a specific stack size
ret = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 8192);
if (ret) {
printf("pthread setstacksize failed\n");
goto main_err;
}

// Set scheduler policy and priority of pthread
ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
if (ret) {
printf("pthread setschedpolicy failed\n");
goto main_err;
}
param.sched_priority = 80;
ret = pthread_attr_setschedparam(&attr, &param);
if (ret) {
printf("pthread setschedparam failed\n");
goto main_err;
}

// Use scheduling parameters of attr
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (ret) {
printf("pthread setinheritsched failed\n");
goto main_err;
}


pthread_t dev_in_thread;
const int dev_in_thread_creation = pthread_create(&dev_in_thread, NULL, dev_in_thread_func, (void*)(&dev_in_thread_data));
const int dev_in_thread_creation = pthread_create(&dev_in_thread, &attr, dev_in_thread_func, (void*)(&dev_in_thread_data));
if (dev_in_thread_creation != 0) {
fprintf(stderr, "Error creating dev_in thread: %d\n", dev_in_thread_creation);
ret = -1;
Expand Down
46 changes: 45 additions & 1 deletion stray_ally.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
#include "dev_out.h"
#include "settings.h"

#include <sys/mman.h>

static const char* configuration_file = "/etc/ROGueENEMY/config.cfg";

int main(int argc, char ** argv) {
// Lock all current and future pages from preventing of being paged to swap
const int lockall_res = mlockall( MCL_CURRENT | MCL_FUTURE );
if (lockall_res) {
fprintf(stderr, "mlockall failed: %d", lockall_res);
}

int ret = 0;

dev_out_settings_t out_settings = {
Expand Down Expand Up @@ -62,8 +70,44 @@ int main(int argc, char ** argv) {

load_out_config(&dev_out_thread_data.settings, configuration_file);

// Initialize pthread attributes (default values)
struct sched_param param;
pthread_attr_t attr;
ret = pthread_attr_init(&attr);
if (ret) {
printf("init pthread attributes failed\n");
goto main_err;
}

// Set a specific stack size
ret = pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN + 8192);
if (ret) {
printf("pthread setstacksize failed\n");
goto main_err;
}

// Set scheduler policy and priority of pthread
ret = pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
if (ret) {
printf("pthread setschedpolicy failed\n");
goto main_err;
}
param.sched_priority = 80;
ret = pthread_attr_setschedparam(&attr, &param);
if (ret) {
printf("pthread setschedparam failed\n");
goto main_err;
}

// Use scheduling parameters of attr
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
if (ret) {
printf("pthread setinheritsched failed\n");
goto main_err;
}

pthread_t dev_out_thread;
const int dev_out_thread_creation = pthread_create(&dev_out_thread, NULL, dev_out_thread_func, (void*)(&dev_out_thread_data));
const int dev_out_thread_creation = pthread_create(&dev_out_thread, &attr, dev_out_thread_func, (void*)(&dev_out_thread_data));
if (dev_out_thread_creation != 0) {
fprintf(stderr, "Error creating dev_out thread: %d\n", dev_out_thread_creation);
ret = -1;
Expand Down

0 comments on commit 16f1c52

Please sign in to comment.