mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
applying coding conventions
This commit is contained in:
parent
de37528788
commit
2959c44c58
7 changed files with 95 additions and 56 deletions
|
@ -32,12 +32,12 @@ struct opal;
|
|||
.destructor = dtor \
|
||||
}
|
||||
|
||||
#define FOREACH(list, elm) \
|
||||
for ( struct list_elm *elm = (list)->head; \
|
||||
#define FOREACH(list, elm) \
|
||||
for ( struct list_elm *elm = (list)->head; \
|
||||
elm; elm = elm->next )
|
||||
|
||||
#define FOREACH_R(list, elm) \
|
||||
for ( struct list_elm *elm = (list)->tail; \
|
||||
#define FOREACH_R(list, elm) \
|
||||
for ( struct list_elm *elm = (list)->tail; \
|
||||
elm; elm = elm->prev )
|
||||
|
||||
#define list_first(list) ((list)->head)
|
||||
|
|
|
@ -178,28 +178,38 @@ int config_parse_path(config_setting_t *cfg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list *all) {
|
||||
int config_parse_nodelist(config_setting_t *cfg, struct list *list, struct list *all) {
|
||||
const char *str;
|
||||
struct node *node;
|
||||
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_STRING:
|
||||
str = config_setting_get_string(cfg);
|
||||
node = node_lookup_name(str, all);
|
||||
if (!node)
|
||||
cerror(cfg, "Invalid outgoing node '%s'", str);
|
||||
|
||||
list_push(nodes, node);
|
||||
if (str) {
|
||||
node = list_lookup(all, str)
|
||||
if (node)
|
||||
list_push(list, node);
|
||||
else
|
||||
cerror(cfg, "Unknown outgoing node '%s'", str);
|
||||
}
|
||||
else
|
||||
cerror(cfg, "Invalid outgoing node");
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
for (int i=0; i<config_setting_length(cfg); i++) {
|
||||
str = config_setting_get_string_elem(cfg, i);
|
||||
node = node_lookup_name(str, all);
|
||||
if (!node)
|
||||
cerror(config_setting_get_elem(cfg, i), "Invalid outgoing node '%s'", str);
|
||||
|
||||
list_push(nodes, node);
|
||||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
config_setting_t *elm = config_setting_get_elem(cfg, i);
|
||||
|
||||
str = config_setting_get_string(elm);
|
||||
if (str) {
|
||||
node = list_lookup(all, str);
|
||||
if (node)
|
||||
list_push(list, node);
|
||||
else
|
||||
cerror(elm, "Unknown outgoing node '%s'", str);
|
||||
}
|
||||
else
|
||||
cerror(cfg, "Invalid outgoing node");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -210,30 +220,38 @@ int config_parse_nodelist(config_setting_t *cfg, struct list *nodes, struct list
|
|||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_hooklist(config_setting_t *cfg, struct list *hooks) {
|
||||
int config_parse_hooklist(config_setting_t *cfg, struct list *list) {
|
||||
const char *str;
|
||||
const struct hook *hook;
|
||||
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_STRING:
|
||||
str = config_setting_get_string(cfg);
|
||||
hook = hook_lookup(str);
|
||||
if (!hook)
|
||||
cerror(cfg, "Invalid hook function '%s'", str);
|
||||
|
||||
debug(10, "Adding hook %s to chain %u with prio %u", hook->name, hook->type, hook->priority);
|
||||
|
||||
list_insert(&hooks[hook->type], hook->priority, hook->callback);
|
||||
if (str) {
|
||||
hook = list_lookup(&hooks, str);
|
||||
if (hook)
|
||||
list_insert(&list[hook->type], hook->priority, hook->callback);
|
||||
else
|
||||
cerror(cfg, "Unknown hook function '%s'", str);
|
||||
}
|
||||
else
|
||||
cerror(cfg, "Invalid hook function");
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
for (int i=0; i<config_setting_length(cfg); i++) {
|
||||
str = config_setting_get_string_elem(cfg, i);
|
||||
hook = hook_lookup(str);
|
||||
if (!hook)
|
||||
cerror(config_setting_get_elem(cfg, i), "Invalid hook function '%s'", str);
|
||||
|
||||
list_insert(&hooks[hook->type], hook->priority, hook->callback);
|
||||
for (int i = 0; i<config_setting_length(cfg); i++) {
|
||||
config_setting_t *elm = config_setting_get_elem(cfg, i);
|
||||
|
||||
str = config_setting_get_string(elm);
|
||||
if (str) {
|
||||
hook = list_lookup(&hooks, str);
|
||||
if (hook)
|
||||
list_insert(&list[hook->type], hook->priority, hook->callback);
|
||||
else
|
||||
cerror(elm, "Invalid hook function '%s'", str);
|
||||
}
|
||||
else
|
||||
cerror(cfg, "Invalid hook function");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -266,7 +284,7 @@ int config_parse_node(config_setting_t *cfg, struct list *nodes, struct settings
|
|||
if (!config_setting_lookup_int(cfg, "affinity", &n->combine))
|
||||
n->affinity = set->affinity;
|
||||
|
||||
n->vt = node_lookup_vtable(type);
|
||||
n->vt = list_lookup(&node_types, type);
|
||||
if (!n->vt)
|
||||
cerror(cfg, "Invalid type for node '%s'", n->name);
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@ int check_kernel_module(char *module)
|
|||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (!(f = fopen(PROCFS_PATH "/modules", "r")))
|
||||
f = fopen(PROCFS_PATH "/modules", "r");
|
||||
if (!f)
|
||||
return -1;
|
||||
|
||||
while (getline(&line, &len, f) >= 0) {
|
||||
|
|
|
@ -130,7 +130,8 @@ static int gtfpga_load_driver(struct pci_dev *d)
|
|||
d->domain, d->bus, d->dev, d->func);
|
||||
|
||||
/* Add new ID to uio_pci_generic */
|
||||
if (!(f = fopen(SYSFS_PATH "/bus/pci/drivers/uio_pci_generic/new_id", "w")))
|
||||
f = fopen(SYSFS_PATH "/bus/pci/drivers/uio_pci_generic/new_id", "w");
|
||||
if (!f)
|
||||
serror("Failed to add PCI id to uio_pci_generic driver");
|
||||
|
||||
debug(5, "Adding ID to uio_pci_generic module: %04x %04x", d->vendor_id, d->device_id);
|
||||
|
|
|
@ -81,14 +81,16 @@ int if_start(struct interface *i, int affinity)
|
|||
error("Missing kernel module: cls_fw");
|
||||
|
||||
/* Replace root qdisc */
|
||||
if ((ret = tc_prio(i, &i->tc_qdisc, TC_HANDLE(1, 0), TC_H_ROOT, mark)))
|
||||
;//error("Failed to setup priority queuing discipline: %s", nl_geterror(ret));
|
||||
ret = tc_prio(i, &i->tc_qdisc, TC_HANDLE(1, 0), TC_H_ROOT, mark);
|
||||
if (ret)
|
||||
error("Failed to setup priority queuing discipline: %s", nl_geterror(ret));
|
||||
|
||||
/* Create netem qdisks and appropriate filter per netem node */
|
||||
FOREACH(&i->sockets, it) {
|
||||
struct socket *s = it->socket;
|
||||
if (s->tc_qdisc) {
|
||||
if ((ret = tc_mark(i, &s->tc_classifier, TC_HANDLE(1, s->mark), s->mark)))
|
||||
ret = tc_mark(i, &s->tc_classifier, TC_HANDLE(1, s->mark), s->mark);
|
||||
if (ret)
|
||||
error("Failed to setup FW mark classifier: %s", nl_geterror(ret));
|
||||
|
||||
char buf[256];
|
||||
|
@ -96,7 +98,8 @@ int if_start(struct interface *i, int affinity)
|
|||
debug(5, "Starting network emulation on interface '%s' for FW mark %u: %s",
|
||||
rtnl_link_get_name(i->nl_link), s->mark, buf);
|
||||
|
||||
if ((ret = tc_netem(i, &s->tc_qdisc, TC_HANDLE(0x1000+s->mark, 0), TC_HANDLE(1, s->mark))))
|
||||
ret = tc_netem(i, &s->tc_qdisc, TC_HANDLE(0x1000+s->mark, 0), TC_HANDLE(1, s->mark));
|
||||
if (ret)
|
||||
error("Failed to setup netem qdisc: %s", nl_geterror(ret));
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +151,8 @@ int if_get_egress(struct sockaddr *sa, struct rtnl_link **link)
|
|||
}
|
||||
|
||||
struct nl_cache *cache = nl_cache_mngt_require("route/link");
|
||||
if (!(*link = rtnl_link_get(cache, ifindex)))
|
||||
*link = rtnl_link_get(cache, ifindex);
|
||||
if (!*link)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
@ -166,7 +170,8 @@ int if_get_irqs(struct interface *i)
|
|||
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir)) && n < IF_IRQ_MAX) {
|
||||
if ((irq = atoi(entry->d_name)))
|
||||
irq = atoi(entry->d_name);
|
||||
if (irq)
|
||||
i->irqs[n++] = irq;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,12 +29,14 @@ struct nl_sock * nl_init()
|
|||
if (!sock)
|
||||
error("Failed to allocate memory");
|
||||
|
||||
if ((ret = nl_connect(sock, NETLINK_ROUTE)))
|
||||
ret = nl_connect(sock, NETLINK_ROUTE);
|
||||
if (ret)
|
||||
error("Failed to connect to kernel: %s", nl_geterror(ret));
|
||||
|
||||
/* Fill some caches */
|
||||
struct nl_cache *cache;
|
||||
if ((ret = rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache)))
|
||||
ret = rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache);
|
||||
if (ret)
|
||||
error("Failed to get list of interfaces: %s", nl_geterror(ret));
|
||||
|
||||
nl_cache_mngt_provide(cache);
|
||||
|
@ -72,10 +74,12 @@ int nl_get_egress(struct nl_addr *addr)
|
|||
.rtm_family = nl_addr_get_family(addr),
|
||||
.rtm_dst_len = nl_addr_get_prefixlen(addr),
|
||||
};
|
||||
|
||||
if ((ret = nlmsg_append(msg, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO)))
|
||||
|
||||
ret = nlmsg_append(msg, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO);
|
||||
if (ret)
|
||||
return ret;
|
||||
if ((ret = nla_put_addr(msg, RTA_DST, addr)))
|
||||
ret = nla_put_addr(msg, RTA_DST, addr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Send message */
|
||||
|
|
|
@ -35,28 +35,35 @@ int opal_init(int argc, char *argv[], struct settings *set)
|
|||
og->print_shmem_name = argv[3];
|
||||
|
||||
/* Enable the OpalPrint function. This prints to the OpalDisplay. */
|
||||
if ((err = OpalSystemCtrl_Register(og->print_shmem_name)) != EOK)
|
||||
err = OpalSystemCtrl_Register(og->print_shmem_name);
|
||||
if (err != EOK)
|
||||
error("OpalPrint() access not available (%d)", err);
|
||||
|
||||
/* Open Share Memory created by the model. */
|
||||
if ((err = OpalOpenAsyncMem(og->async_shmem_size, og->async_shmem_name)) != EOK)
|
||||
err = OpalOpenAsyncMem(og->async_shmem_size, og->async_shmem_name);
|
||||
if (err != EOK)
|
||||
error("Model shared memory not available (%d)", err);
|
||||
|
||||
if ((err = OpalGetAsyncCtrlParameters(&og->params, sizeof(Opal_GenAsyncParam_Ctrl))) != EOK)
|
||||
err = OpalGetAsyncCtrlParameters(&og->params, sizeof(Opal_GenAsyncParam_Ctrl));
|
||||
if (err != EOK)
|
||||
error("Could not get OPAL controller parameters (%d)", err);
|
||||
|
||||
/* Get list of Send and RecvIDs */
|
||||
if ((err = OpalGetNbAsyncSendIcon(&og->send_icons)) != EOK)
|
||||
err = OpalGetNbAsyncSendIcon(&og->send_icons);
|
||||
if (err != EOK)
|
||||
error("Failed to get number of send blocks (%d)", err);
|
||||
if ((err = OpalGetNbAsyncRecvIcon(&og->recv_icons)) != EOK)
|
||||
err = OpalGetNbAsyncRecvIcon(&og->recv_icons);
|
||||
if (err != EOK)
|
||||
error("Failed to get number of recv blocks (%d)", err);
|
||||
|
||||
og->send_ids = alloc(og->send_icons * sizeof(int));
|
||||
og->recv_ids = alloc(og->recv_icons * sizeof(int));
|
||||
|
||||
if ((err = OpalGetAsyncSendIDList(og->send_ids, og->send_icons * sizeof(int))) != EOK)
|
||||
err = OpalGetAsyncSendIDList(og->send_ids, og->send_icons * sizeof(int));
|
||||
if (err != EOK)
|
||||
error("Failed to get list of send ids (%d)", err);
|
||||
if ((err = OpalGetAsyncRecvIDList(og->recv_ids, og->recv_icons * sizeof(int))) != EOK)
|
||||
err = OpalGetAsyncRecvIDList(og->recv_ids, og->recv_icons * sizeof(int));
|
||||
if (err != EOK)
|
||||
error("Failed to get list of recv ids (%d)", err);
|
||||
|
||||
info("Started as OPAL Asynchronous process");
|
||||
|
@ -74,12 +81,14 @@ int opal_deinit()
|
|||
if (!og)
|
||||
return 0;
|
||||
|
||||
if ((err = OpalCloseAsyncMem(og->async_shmem_size, og->async_shmem_name)) != EOK)
|
||||
err = OpalCloseAsyncMem(og->async_shmem_size, og->async_shmem_name);
|
||||
if (err != EOK)
|
||||
error("Failed to close shared memory area (%d)", err);
|
||||
|
||||
debug(4, "Closing OPAL shared memory mapping");
|
||||
|
||||
if ((err = OpalSystemCtrl_UnRegister(og->print_shmem_name)) != EOK)
|
||||
err = OpalSystemCtrl_UnRegister(og->print_shmem_name);
|
||||
if (err != EOK)
|
||||
error("Failed to close shared memory for system control (%d)", err);
|
||||
|
||||
pthread_mutex_destroy(&og->lock);
|
||||
|
@ -193,7 +202,8 @@ int opal_read(struct node *n, struct msg *pool, int poolsize, int first, int cnt
|
|||
|
||||
/* This call unblocks when the 'Data Ready' line of a send icon is asserted. */
|
||||
do {
|
||||
if ((ret = OpalWaitForAsyncSendRequest(&id)) != EOK) {
|
||||
ret = OpalWaitForAsyncSendRequest(&id);
|
||||
if (ret != EOK) {
|
||||
state = OpalGetAsyncModelState();
|
||||
if ((state == STATE_RESET) || (state == STATE_STOP))
|
||||
error("OpalGetAsyncModelState(): Model stopped or resetted!");
|
||||
|
|
Loading…
Add table
Reference in a new issue