1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

moved realtime initialization to main()

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@67 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-06-10 19:44:22 +00:00
parent f4767d6814
commit a34e20c172
3 changed files with 47 additions and 57 deletions

View file

@ -13,6 +13,8 @@
#include <errno.h>
#include <string.h>
#include <sched.h>
struct settings;
struct sockaddr_in;
struct sockaddr;
@ -44,18 +46,6 @@ void print(enum log_level lvl, const char *fmt, ...);
*/
int resolve_addr(const char *addr, struct sockaddr_in *sa, int flags);
/** Setup various realtime related things.
*
* We use the following techniques for performance tuning
* - Prefault the stack
* - Lock memory
* - Use FIFO scheduler with realtime priority
* - Set CPU affinity
*
* @param g The global configuration
*/
void init_realtime(struct settings *g);
/** Compare two socket addresses based on their family and address.
*
* Only the family and the address is compared.
@ -69,6 +59,13 @@ void init_realtime(struct settings *g);
*/
int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b);
/** Convert integer into cpu_set_t
*
* @param set A cpu bitmask
* @return The opaque cpu_set_t datatype
*/
cpu_set_t to_cpu_set_t(int set);
/** Append an element to a single linked list */
#define list_add(list, elm) do { \
elm->next = list; \

View file

@ -9,9 +9,13 @@
#include <stdio.h>
#include <error.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#include "cfg.h"
@ -114,8 +118,39 @@ int main(int argc, char *argv[])
if (!paths)
error("No paths found. Terminating...");
/* Setup various realtime related things */
init_realtime(&settings);
/* Lock memory */
/*if(mlockall(MCL_CURRENT | MCL_FUTURE))
perror("Failed mlockall");
else
debug(3, "Locked memory");*/
/* Prefault stack */
/*char dummy[MAX_SAFE_STACK];
memset(dummy, 0, MAX_SAFE_STACK);
debug(3, "Prefaulted stack");*/
/* Check for realtime kernel patch */
struct stat st;
if (stat("/sys/kernel/realtime", &st))
warn("This is not a a realtime patched kernel!");
else
debug(3, "This is a realtime patched kernel");
/* Use FIFO scheduler with realtime priority */
struct sched_param param;
param.sched_priority = settings.priority;
if (sched_setscheduler(0, SCHED_FIFO, &param))
perror("Failed to set realtime priority");
else
debug(3, "Set task priority to %u", settings.priority);
/* Pin threads to CPUs by setting the affinity */
cpu_set_t cset = to_cpu_set_t(settings.affinity);
pid_t pid = getpid();
if (sched_setaffinity(pid, sizeof(cset), &cset))
perror("Failed to set CPU affinity");
else
debug(3, "Set affinity to %#x", settings.affinity);
/* Connect all nodes and start one thread per path */
start();

View file

@ -10,16 +10,11 @@
#include <string.h>
#include <time.h>
#include <errno.h>
#include <sched.h>
#include <unistd.h>
#include <netdb.h>
#include <sched.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#include "cfg.h"
@ -113,7 +108,7 @@ int sockaddr_cmp(struct sockaddr *a, struct sockaddr *b)
return -1;
}
static cpu_set_t to_cpu_set_t(int set)
cpu_set_t to_cpu_set_t(int set)
{
cpu_set_t cset;
@ -124,40 +119,3 @@ static cpu_set_t to_cpu_set_t(int set)
return cset;
}
void init_realtime(struct settings *g)
{
/* Prefault stack */
char dummy[MAX_SAFE_STACK];
memset(dummy, 0, MAX_SAFE_STACK);
debug(3, "Prefaulted stack");
/* Lock memory */
if(mlockall(MCL_CURRENT | MCL_FUTURE))
perror("Failed mlockall");
else
debug(3, "Locked memory");
/* Check for realtime kernel patch */
struct stat st;
if (stat("/sys/kernel/realtime", &st))
warn("This is not a a realtime patched kernel!");
else
debug(3, "This is a realtime patched kernel");
/* Use FIFO scheduler with realtime priority */
struct sched_param param;
param.sched_priority = g->priority;
if (sched_setscheduler(0, SCHED_FIFO, &param))
perror("Failed to set realtime priority");
else
debug(3, "Set task priority to %u", g->priority);
/* Pin threads to CPUs by setting the affinity */
cpu_set_t cset = to_cpu_set_t(g->affinity);
pid_t pid = getpid();
if (sched_setaffinity(pid, sizeof(cset), &cset))
perror("Failed to set CPU affinity");
else
debug(3, "Set affinity to %#x", g->affinity);
}