Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH v1] [RFC] fdserver executable #628

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ aclocal.m4
autom4te.cache/
ar-lib
compile
config/odp-*.conf
config.guess
config.log
config.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ sched_basic: {
# value is the number of threads using the scheduler.
prio_spread = 4
}

fdserver: {
socket_path = "/tmp/fdserver_socket"
binary_path = "@bindir@/fdserver"
}
21 changes: 19 additions & 2 deletions platform/linux-generic/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Uncomment this if you need to change the CUSTOM_STR string
#export CUSTOM_STR=https://github.com/Linaro/odp.git

SUBDIRS = fdserver

include $(top_srcdir)/platform/Makefile.inc

AM_CPPFLAGS = $(ODP_INCLUDES)
Expand All @@ -9,6 +11,8 @@ AM_CPPFLAGS += -I$(top_builddir)/platform/$(with_platform)/include
AM_CPPFLAGS += -I$(top_srcdir)/platform/$(with_platform)/arch
AM_CPPFLAGS += -I$(top_srcdir)/platform/$(with_platform)/arch/@ARCH_DIR@
AM_CPPFLAGS += -I$(top_srcdir)/platform/$(with_platform)/arch/default
AM_CPPFLAGS += -I$(top_srcdir)/platform/$(with_platform)/fdserver/include
AM_CPPFLAGS += -I$(top_srcdir)/platform/$(with_platform)/fdserver/src/include

AM_CPPFLAGS += $(OPENSSL_CPPFLAGS)
AM_CPPFLAGS += $(DPDK_CPPFLAGS)
Expand All @@ -17,6 +21,18 @@ AM_CPPFLAGS += $(NETMAP_CPPFLAGS)
AM_CFLAGS += $(LIBCONFIG_CFLAGS)

DISTCLEANFILES = include/odp_libconfig_config.h
CLEANFILES = $(top_dir)/config/odp-$(with_platform).conf

do_subst = $(SED) \
-e 's|[@]prefix[@]|$(prefix)|g' \
-e 's|[@]exec_prefix[@]|$(exec_prefix)|g' \
-e 's|[@]bindir[@]|$(bindir)|g' \
-e 's|[@]datarootdir[@]|$(datarootdir)|g' \
< "$<" > "$@"

$(top_srcdir)/config/odp-$(with_platform).conf: $(top_srcdir)/config/odp-$(with_platform).conf.in
$(do_subst)

include/odp_libconfig_config.h: $(top_srcdir)/config/odp-$(with_platform).conf $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@

Expand Down Expand Up @@ -94,7 +110,6 @@ noinst_HEADERS = \
include/odp_config_internal.h \
include/odp_debug_internal.h \
include/odp_errno_define.h \
include/odp_fdserver_internal.h \
include/odp_forward_typedefs_internal.h \
include/odp_global_data.h \
include/odp_init_internal.h \
Expand Down Expand Up @@ -223,7 +238,9 @@ __LIB__libodp_linux_la_SOURCES = \
pktio/ring.c \
pktio/socket.c \
pktio/socket_mmap.c \
pktio/tap.c
pktio/tap.c \
fdserver/src/fdserver_lib.c

if ODP_ABI_COMPAT
__LIB__libodp_linux_la_SOURCES += \
odp_atomic_api.c \
Expand Down
18 changes: 18 additions & 0 deletions platform/linux-generic/fdserver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
fdserver
*.swp
*.o
*.lo
*.la
*.in
*.log
*.trs
.deps
.libs
m4
build-aux
Makefile
libtool
configure
config.status
autom4te.cache
aclocal.m4
1 change: 1 addition & 0 deletions platform/linux-generic/fdserver/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBDIRS = src
2 changes: 2 additions & 0 deletions platform/linux-generic/fdserver/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
share_pipe_reader
share_pipe_writer
11 changes: 11 additions & 0 deletions platform/linux-generic/fdserver/examples/share_pipe_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Copyright (c) 2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef SHARE_PIPE_COMMON_H
#define SHARE_PIPE_COMMON_H

#define SHARE_PIPE_KEY_WRITER 1

#endif
101 changes: 101 additions & 0 deletions platform/linux-generic/fdserver/examples/share_pipe_reader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* Copyright (c) 2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <sys/prctl.h>
#include <signal.h>

#include <fdserver.h>

#include "share_pipe_common.h"

static void run_writer(fdserver_context_t *context)
{
int fd;

sleep(2); /* give time to register, etc */

fd = fdserver_lookup_fd(context, SHARE_PIPE_KEY_WRITER);
if (fd == -1) {
fprintf(stderr, "Could not retrive fd\n");
exit(EXIT_FAILURE);
}

printf("Writer: got file descriptor %d, sending\n", fd);
write(fd, &fd, sizeof(int));
printf("Writer: done\n");
close(fd);

exit(EXIT_SUCCESS);
}

int main(int argc, char *argv[])
{
int fd[2];
int ret;
int data;
fdserver_context_t *context;
pid_t pid;

ret = fdserver_new_context(&context);
if (ret == -1) {
fprintf(stderr, "Could not create a new context\n");
exit(EXIT_FAILURE);
}

pid = fork();
if (pid == -1) {
fdserver_del_context(&context);
exit(EXIT_FAILURE);
}
if (pid == 0) {
/* die if parent dies too */
prctl(PR_SET_PDEATHSIG, SIGTERM);
run_writer(context);
}

/* parent */
ret = pipe(fd);
if (ret == -1) {
fdserver_del_context(&context);
perror("pipe");
exit(EXIT_FAILURE);
}

ret = fdserver_register_fd(context,
SHARE_PIPE_KEY_WRITER,
fd[1]);
if (ret == -1) {
fdserver_del_context(&context);
fprintf(stderr, "failed to register fd\n");
exit(EXIT_FAILURE);
}

close(fd[1]);

/* wait for the other end to write an integer */
while (read(fd[0], &data, sizeof(int)) == -1) {
if (errno == EAGAIN || errno == EINTR) {
printf("again\n");
continue;
}
perror("read");
fdserver_del_context(&context);
exit(EXIT_FAILURE);
}

printf("Reader: Received: %d\n", data);

close(fd[0]);

fdserver_del_context(&context);

exit(EXIT_SUCCESS);
}

17 changes: 17 additions & 0 deletions platform/linux-generic/fdserver/examples/share_pipe_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# (c) 2018, Linaro Limited
#
# SPDX-License-Identifier: BSD-3-Clause

echo "Running server"

../fdserver &
# Give time to start the server
sleep 1

echo "Running reader"
./share_pipe_reader

killall -HUP fdserver
wait
29 changes: 29 additions & 0 deletions platform/linux-generic/fdserver/include/fdserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (c) 2016-2018, Linaro Limited
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _FD_SERVER_INTERNAL_H
#define _FD_SERVER_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

typedef struct fdserver_context fdserver_context_t;

int fdserver_init(const char *path);
int fdserver_new_context(fdserver_context_t **context);
int fdserver_del_context(fdserver_context_t **context);
int fdserver_register_fd(fdserver_context_t *context, uint64_t key, int fd);
int fdserver_deregister_fd(fdserver_context_t *context, uint64_t key);
int fdserver_lookup_fd(fdserver_context_t *context, uint64_t key);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions platform/linux-generic/fdserver/src/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FDSERVER_INCLUDES = -I$(srcdir)/../include \
-I$(srcdir)/include

AM_CPPFLAGS = $(FDSERVER_INCLUDES) \
$(ODP_INCLUDES)

bin_PROGRAMS = fdserver
fdserver_SOURCES = fdserver.c
Loading