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

added code to determine local interface and interface irqs (not yet

finished and POC!)

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@61 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-06-05 09:35:40 +00:00
parent 7f4eb885ff
commit d3723022ac
3 changed files with 109 additions and 1 deletions

32
include/if.h Normal file
View file

@ -0,0 +1,32 @@
/** Interface related functions
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
* @file if.h
*/
#ifndef _IF_H_
#define _IF_H_
#include <net/if.h>
/** Get the name of first interface which listens on addr.
*
* @param addr The address whose related interface is searched
* @return
* - A pointer to the interface name (has to be freed by caller)
* - NULL if the address is not used on the system
*/
char* if_addrtoname(struct sockaddr *addr);
/** Change the SMP affinity of NIC interrupts.
*
* @param ifname The interface whose IRQs should be pinned
* @param affinity A mask specifying which cores should handle this interrupt.
* @return
* - 0 on success
* - otherwise an error occured
*/
int if_setaffinity(const char *ifname, int affinity);
#endif /* _IF_H_ */

77
src/if.c Normal file
View file

@ -0,0 +1,77 @@
/**
* Interface related functions
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <ifaddrs.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include "utils.h"
char* if_addrtoname(struct sockaddr *addr)
{
char *ifname = NULL;
struct ifaddrs *ifas, *ifa;
if(getifaddrs(&ifas))
return NULL;
for(ifa = ifas; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr && !sockaddr_cmp(ifa->ifa_addr, addr)) {
ifname = malloc(strlen(ifa->ifa_name) + 1);
if (!ifname)
goto out;
strcpy(ifname, ifa->ifa_name);
goto out;
}
}
out:
freeifaddrs(ifas);
return ifname;
}
int if_setaffinity(const char *ifname, int affinity)
{
char *dirname[NAME_MAX];
char *filename[NAME_MAX];
DIR *dir;
FILE *file;
/* Determine IRQs numbers */
snprintf(dirname, sizeof(dirname), "/sys/class/net/%s/device/msi_irqs/", ifname);
dir = opendir(dirname);
if (!dir)
return -1;
struct dirent *entry;
while (entry = readdir(dir)) {
/* Set SMP affinity */
snprintf(filename, sizeof(filename), "/proc/irq/%s/smp_affinity");
file = fopen(filename, "w");
if (!file)
continue;
debug(3, "Setting SMP affinity of IRQ %s (%s) to %8x\n", entry->d_name, ifname, affinity);
fprintf("%8x", affinity);
fclose(file);
}
closedir(dir);
return 0;
}

View file

@ -95,4 +95,3 @@ struct node* node_lookup_name(const char *str, struct node *nodes, int len)
return NULL;
}