Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/ff_dpdk_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
*
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>

#include <rte_common.h>
Expand Down Expand Up @@ -103,6 +107,9 @@ typedef char ff_reload_ring_name_fit_check[
+ 2 + 1 /* "_g" + generation */
<= (size_t)(RTE_RING_NAMESIZE - 1)) ? 1 : -1];

/* also read by tools/compat/ff_ipc.c */
#define FF_PRIMARY_RECORD "/var/run/ff_primary.conf"

#ifdef FF_KNI
#define KNI_MBUF_MAX 2048
#define KNI_QUEUE_SIZE KNI_MBUF_MAX
Expand Down Expand Up @@ -2001,6 +2008,51 @@ fdir_add_tcp_flow(uint16_t port_id, uint16_t queue, uint16_t dir,

#endif

/* lets the F-Stack tools find this primary's EAL file prefix
* (tools/compat/ff_ipc.c reads it back). Best effort: a missing record
* only means the tools fall back to FF_FILE_PREFIX or the default. */
static void
ff_primary_record_write(void)
{
char path[64], buf[1024], tmp[sizeof(FF_PRIMARY_RECORD) + 24], *p;
unsigned long long start;
int fd, i, rc;
ssize_t n;

snprintf(path, sizeof(path), "/proc/%d/stat", (int)getpid());
fd = open(path, O_RDONLY);
if (fd < 0)
return;
n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (n <= 0)
return;
buf[n] = '\0';

/* field 22 (starttime), counted after the ")" that ends comm */
p = strrchr(buf, ')');
if (p == NULL || p[1] != ' ')
return;
p += 2;
for (i = 0; i < 19; i++) {
p = strchr(p, ' ');
if (p == NULL)
return;
p++;
}
start = strtoull(p, NULL, 10);

snprintf(tmp, sizeof(tmp), FF_PRIMARY_RECORD ".%d.tmp", (int)getpid());
fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0644);
if (fd < 0)
return;
rc = dprintf(fd, "pid=%d\nstart_time=%llu\nruntime_dir=%s\n",
(int)getpid(), start, rte_eal_get_runtime_dir());
close(fd);
if (rc <= 0 || rename(tmp, FF_PRIMARY_RECORD) != 0)
unlink(tmp);
}

int
ff_dpdk_init(int argc, char **argv)
{
Expand All @@ -2019,6 +2071,10 @@ ff_dpdk_init(int argc, char **argv)
rte_exit(EXIT_FAILURE, "Error with EAL initialization\n");
}

if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
ff_primary_record_write();
}

if (ff_global_cfg.log.level) {
ff_log_open_set();
}
Expand Down
3 changes: 2 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ Each tool add an option `-p`(Which F-Stack process to communicate with, default
The tools attach to the stack as DPDK secondary processes, so they must use the stack's EAL file prefix (the directory name under `/var/run/dpdk/`):

- with `graceful_reload=1` the prefix is read from the resident slim primary's record `/var/run/ff_slim_primary.conf` (only while that primary is alive);
- otherwise from the record every F-Stack primary writes, `/var/run/ff_primary.conf` (only while that primary is alive; with several stacks on one host it names the one started last);
- otherwise the DPDK default `rte` is used;
- `FF_FILE_PREFIX=<name>` overrides both. Note that `[dpdk] file_prefix=<v>` in config.ini gives the directory `container-<v>`, and a config with `[vdevN]` but no file_prefix gives `container`, e.g. `FF_FILE_PREFIX=container-<v> ff_top`.
- `FF_FILE_PREFIX=<name>` overrides all of them, e.g. to pick one of several stacks. Note that `[dpdk] file_prefix=<v>` in config.ini gives the directory `container-<v>`, and a config with `[vdevN]` but no file_prefix gives `container`, e.g. `FF_FILE_PREFIX=container-<v> ff_top`.

The tools do not probe PCI devices (`--no-pci`). `ff_top` and `ff_traffic` follow graceful reloads while sampling: a sample taken right after the target switched generations is not printed, because the new generation's counters start from zero.

Expand Down
15 changes: 11 additions & 4 deletions tools/compat/ff_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static int ff_ipc_exited;
/* EAL file prefix override, the directory name under /var/run/dpdk */
#define FF_IPC_PREFIX_ENV "FF_FILE_PREFIX"
#define FF_IPC_PRIMARY_RECORD "/var/run/ff_slim_primary.conf"
/* written by every F-Stack primary (lib/ff_dpdk_if.c) */
#define FF_IPC_FSTACK_RECORD "/var/run/ff_primary.conf"
#define FF_IPC_RUNTIME_BASE "/var/run/dpdk/"

static struct rte_mempool *message_pool;
Expand Down Expand Up @@ -408,8 +410,9 @@ ff_ipc_proc_start(long pid, unsigned long long *start)
return 0;
}

/* EAL file prefix of the runtime directory recorded by a live resident
* slim primary (graceful_reload=1). No heap use: the EAL is not up yet. */
/* EAL file prefix of the runtime directory recorded by a live primary:
* the resident slim primary (graceful_reload=1) or any F-Stack primary.
* No heap use: the EAL is not up yet. */
static int
ff_ipc_record_prefix(const char *record, char *prefix, size_t len)
{
Expand Down Expand Up @@ -450,8 +453,9 @@ ff_ipc_record_prefix(const char *record, char *prefix, size_t len)
return 0;
}

/* FF_FILE_PREFIX wins, then the resident primary's record; otherwise
* the EAL default prefix is used. */
/* FF_FILE_PREFIX wins, then the resident primary's record; ff_ipc_init()
* then tries the F-Stack primary's record, otherwise the EAL default
* prefix is used. */
static const char *
ff_ipc_file_prefix(const char *record, char *prefix, size_t len)
{
Expand Down Expand Up @@ -500,6 +504,9 @@ ff_ipc_init(void)

argc = (int)(sizeof(dpdk_argv) / sizeof(dpdk_argv[0])) - 2;
p = ff_ipc_file_prefix(FF_IPC_PRIMARY_RECORD, prefix, sizeof(prefix));
if (p == NULL && ff_ipc_record_prefix(FF_IPC_FSTACK_RECORD, prefix,
sizeof(prefix)) == 0)
p = prefix;
if (p != NULL) {
snprintf(prefix_arg, sizeof(prefix_arg), "--file-prefix=%s", p);
dpdk_argv[argc++] = prefix_arg;
Expand Down
Loading