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

Alpine Linux compatibility for pony #1844

Merged
merged 1 commit into from
Jul 20, 2017
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
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ else
AR = gcc-ar
endif
endif

ALPINE=$(wildcard /etc/alpine-release)
endif

ifeq ($(UNAME_S),Darwin)
Expand Down Expand Up @@ -396,9 +398,14 @@ endif

# target specific build options
libponyrt.buildoptions = -DPONY_NO_ASSERT
libponyrt-pic.buildoptions = -DPONY_NO_ASSERT

libponyrt.tests.linkoptions += -rdynamic

ifneq ($(ALPINE),)
libponyrt.tests.linkoptions += -lexecinfo
endif

libponyc.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.buildoptions += -D__STDC_LIMIT_MACROS
Expand All @@ -410,16 +417,29 @@ libponyc.tests.buildoptions += -DPONY_PACKAGES_DIR=\"$(packages_abs_src)\"

libponyc.tests.linkoptions += -rdynamic

ifneq ($(ALPINE),)
libponyc.tests.linkoptions += -lexecinfo
endif

libponyc.benchmarks.buildoptions = -D__STDC_CONSTANT_MACROS
libponyc.benchmarks.buildoptions += -D__STDC_FORMAT_MACROS
libponyc.benchmarks.buildoptions += -D__STDC_LIMIT_MACROS

libgbenchmark.buildoptions := -DHAVE_POSIX_REGEX

ifneq ($(ALPINE),)
libponyc.benchmarks.linkoptions += -lexecinfo
libponyrt.benchmarks.linkoptions += -lexecinfo
endif

ponyc.buildoptions = $(libponyc.buildoptions)

ponyc.linkoptions += -rdynamic

ifneq ($(ALPINE),)
ponyc.linkoptions += -lexecinfo
endif

ifeq ($(OSTYPE), linux)
libponyrt-pic.buildoptions += -fpic
endif
Expand Down
6 changes: 6 additions & 0 deletions src/common/platform.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef PLATFORM_H
#define PLATFORM_H

#ifdef __linux__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#endif

#include <stdbool.h>
#include <stdint.h>

Expand Down
4 changes: 2 additions & 2 deletions src/common/pony/detail/atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using std::atomic_thread_fence;
# endif
#elif defined(__GNUC__) && !defined(__clang__)
# include <features.h>
# if __GNUC_PREREQ(4, 9)
# if ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((4) << 16) + (9))
# ifdef __cplusplus
// g++ doesn't like C11 atomics. We never need atomic ops in C++ files so
// we only define the atomic types.
Expand All @@ -50,7 +50,7 @@ using std::atomic_thread_fence;
# define PONY_ATOMIC(T) T _Atomic
# define PONY_ATOMIC_RVALUE(T) T _Atomic
# endif
# elif __GNUC_PREREQ(4, 7)
# elif ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((4) << 16) + (7))
# define PONY_ATOMIC(T) alignas(sizeof(T)) T
# define PONY_ATOMIC_RVALUE(T) T
# define PONY_ATOMIC_BUILTINS
Expand Down
5 changes: 3 additions & 2 deletions src/common/ponyassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#define PLATFORM_PONYASSERT_H

#include "platform.h"
#include <assert.h>

PONY_EXTERN_C_BEGIN

#if defined(NDEBUG) && defined(PONY_NO_ASSERT)
# define pony_assert(expr) ((void)0)
#if defined(PONY_NO_ASSERT)
# define pony_assert(expr) assert(expr)
#else
# define pony_assert(expr) \
((expr) ? (void)0 : \
Expand Down
1 change: 1 addition & 0 deletions src/libponyc/codegen/genexe.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ static bool link_exe(compile_t* c, ast_t* program,
"Warning: environment variable $CC undefined, using %s as the linker\n",
PONY_COMPILER);
}

const char* mcx16_arg = target_is_ilp32(c->opt->triple) ? "" : "-mcx16";
const char* fuseld = target_is_linux(c->opt->triple) ? "-fuse-ld=gold" : "";
const char* ldl = target_is_linux(c->opt->triple) ? "-ldl" : "";
Expand Down
5 changes: 5 additions & 0 deletions src/libponyrt/asio/asio.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ asio_backend_t* ponyint_asio_get_backend()
return running_base.backend;
}

uint32_t ponyint_asio_get_cpu()
{
return asio_cpu;
}

void ponyint_asio_init(uint32_t cpu)
{
asio_cpu = cpu;
Expand Down
5 changes: 5 additions & 0 deletions src/libponyrt/asio/asio.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ bool ponyint_asio_start();
*/
asio_backend_t* ponyint_asio_get_backend();

/** Returns the cpu assigned for the ASIO thread.
*
*/
uint32_t ponyint_asio_get_cpu();

/** Attempts to stop an asynchronous event mechanism.
*
* Stopping an event mechanism is only possible if there are no pending "noisy"
Expand Down
2 changes: 2 additions & 0 deletions src/libponyrt/asio/epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "../actor/messageq.h"
#include "../mem/pool.h"
#include "../sched/cpu.h"
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/timerfd.h>
Expand Down Expand Up @@ -163,6 +164,7 @@ PONY_API void pony_asio_event_resubscribe_read(asio_event_t* ev)

DECLARE_THREAD_FN(ponyint_asio_backend_dispatch)
{
ponyint_cpu_affinity(ponyint_asio_get_cpu());
pony_register_thread();
asio_backend_t* b = arg;

Expand Down
2 changes: 2 additions & 0 deletions src/libponyrt/asio/iocp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "../actor/messageq.h"
#include "../mem/pool.h"
#include "../sched/cpu.h"
#include <string.h>
#include <signal.h>
#include <stdbool.h>
Expand Down Expand Up @@ -101,6 +102,7 @@ void ponyint_asio_backend_final(asio_backend_t* b)

DECLARE_THREAD_FN(ponyint_asio_backend_dispatch)
{
ponyint_cpu_affinity(ponyint_asio_get_cpu());
pony_register_thread();
asio_backend_t* b = (asio_backend_t*)arg;
asio_event_t* stdin_event = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/libponyrt/asio/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "../actor/messageq.h"
#include "../mem/pool.h"
#include "../sched/cpu.h"
#include "ponyassert.h"
#include <sys/event.h>
#include <string.h>
Expand Down Expand Up @@ -120,6 +121,7 @@ PONY_API void pony_asio_event_resubscribe_write(asio_event_t* ev)

DECLARE_THREAD_FN(ponyint_asio_backend_dispatch)
{
ponyint_cpu_affinity(ponyint_asio_get_cpu());
pony_register_thread();
asio_backend_t* b = arg;
struct kevent fired[MAX_EVENTS];
Expand Down
2 changes: 0 additions & 2 deletions src/libponyrt/platform/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ bool ponyint_thread_create(pony_thread_id_t* thread, thread_fn start,
CPU_ZERO(&set);
CPU_SET(cpu, &set);

pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &set);

if(use_numa)
{
struct rlimit limit;
Expand Down
6 changes: 5 additions & 1 deletion src/libponyrt/sched/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ void ponyint_cpu_affinity(uint32_t cpu)
return;

#if defined(PLATFORM_IS_LINUX)
// Affinity is handled when spawning the thread.
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);

sched_setaffinity(0, sizeof(cpu_set_t), &set);
#elif defined(PLATFORM_IS_FREEBSD)
// No pinning, since we cannot yet determine hyperthreads vs physical cores.
#elif defined(PLATFORM_IS_MACOSX)
Expand Down
5 changes: 3 additions & 2 deletions src/libponyrt/sched/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <string.h>
#include <stdio.h>

#define SCHED_BATCH 100
#define PONY_SCHED_BATCH 100

static DECLARE_THREAD_FN(run_thread);

Expand Down Expand Up @@ -284,7 +284,7 @@ static void run(scheduler_t* sched)
}

// Run the current actor and get the next actor.
bool reschedule = ponyint_actor_run(&sched->ctx, actor, SCHED_BATCH);
bool reschedule = ponyint_actor_run(&sched->ctx, actor, PONY_SCHED_BATCH);
pony_actor_t* next = pop_global(sched);

if(reschedule)
Expand Down Expand Up @@ -370,6 +370,7 @@ static void ponyint_sched_shutdown()
pony_ctx_t* ponyint_sched_init(uint32_t threads, bool noyield, bool nopin,
bool pinasio)
{
this_scheduler = NULL;
pony_register_thread();
this_scheduler->ctx.current = NULL;

Expand Down