#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <netinet/in.h>
#include <setjmp.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <dirent.h>
#include <signal.h>
#include "flib.h"
#define SIG_PARENT_EXIT SIGUSR1
struct lcore_stat {
pid_t pid;
void *arg;
slave_exit_notify *cb_fn;
static struct lcore_stat *core_cfg;
static uint16_t *lcore_cfg = NULL;
static void
sighand_parent_exit(int sig)
{
printf(
"lcore = %u : Find parent leaves, sig=%d\n",
rte_lcore_id(),
sig);
printf("Child leaving\n");
exit(0);
return;
}
static int
slave_proc_func(void)
{
struct lcore_stat *cfg = &core_cfg[slave_id];
if (prctl(PR_SET_PDEATHSIG, SIG_PARENT_EXIT, 0, 0, 0, 0) != 0)
printf("Warning: Slave can't register for being notified in"
"case master process exited\n");
else {
struct sigaction act;
memset(&act, 0 , sizeof(act));
act.sa_handler = sighand_parent_exit;
if (sigaction(SIG_PARENT_EXIT, &act, NULL) != 0)
printf("Fail to register signal handler:%d\n", SIG_PARENT_EXIT);
}
if (NULL == config)
printf("Warning:Can't get rte_config\n");
else
printf("Core %u is ready (pid=%d)\n", slave_id, (int)cfg->pid);
exit(cfg->f(cfg->arg));
}
static int
lcore_func(void *arg __attribute__((unused)))
{
struct lcore_stat *cfg = &core_cfg[slave_id];
int pid, stat;
return cfg->f(cfg->arg);
pid = fork();
if (pid == -1) {
printf("Failed to fork\n");
return -1;
} else if (pid == 0)
return slave_proc_func();
else {
cfg->pid = pid;
waitpid(pid, &stat, 0);
cfg->pid = 0;
cfg->f = NULL;
cfg->arg = NULL;
if(cfg->cb_fn)
cfg->cb_fn(slave_id, stat);
return stat;
}
}
static int
lcore_id_init(void)
{
int i;
sizeof(uint16_t) * RTE_MAX_LCORE,
RTE_CACHE_LINE_SIZE);
if(lcore_cfg == NULL)
for (i = 0; i < RTE_MAX_LCORE; i++) {
lcore_cfg[i] = 1;
}
return 0;
}
int
flib_assign_lcore_id(void)
{
unsigned i;
int ret;
return -1;
do {
for (i = 1; i < RTE_MAX_LCORE; i++) {
if (lcore_cfg[i] == 0)
break;
}
if (i == RTE_MAX_LCORE)
return -1;
return i;
}
void
flib_free_lcore_id(unsigned lcore_id)
{
if (lcore_id >= RTE_MAX_LCORE || lcore_id == 0 ||
return;
lcore_cfg[lcore_id] = 0;
}
int
flib_register_slave_exit_notify(unsigned slave_id,
slave_exit_notify *cb)
{
if (cb == NULL)
return -EFAULT;
return -ENOENT;
core_cfg[slave_id].cb_fn = cb;
return 0;
}
enum slave_stat
flib_query_slave_status(unsigned slave_id)
{
return ST_FREEZE;
if (core_cfg[slave_id].pid != 0)
return ST_RUN;
else
return ST_IDLE;
}
int
void *arg, unsigned slave_id)
{
if (f == NULL)
return -1;
return -1;
core_cfg[slave_id].f = f;
core_cfg[slave_id].arg = arg;
}
int
{
int i;
core_cfg[i].arg = arg;
core_cfg[i].f = f;
}
}
int
flib_init(void)
{
sizeof(struct lcore_stat) * RTE_MAX_LCORE,
RTE_CACHE_LINE_SIZE)) == NULL ) {
printf("rte_zmalloc failed\n");
return -1;
}
if (lcore_id_init() != 0) {
printf("lcore_id_init failed\n");
return -1;
}
return 0;
}