Skip to content

Commit

Permalink
build on 32-bit platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
vlm committed Feb 23, 2015
1 parent 6fde699 commit 40fe853
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions configure.ac
Expand Up @@ -32,6 +32,8 @@ AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing], [TK_CFLAGS="$TK_CFLAGS -fno-strict
dnl Apply TK_CFLAGS only for tcpkali sources, not third-party dependencies.
AC_SUBST(TK_CFLAGS)

AC_CHECK_SIZEOF([size_t])

AC_CHECK_HEADERS(sched.h uv.h)
AC_CHECK_FUNCS(sched_getaffinity)

Expand Down
8 changes: 8 additions & 0 deletions deps/libcows/libcows.c
Expand Up @@ -40,6 +40,7 @@
#include "libcows_frame.h"

#include "libcows.h"
#include "config.h"

/*
* Kick off writing of the output chain.
Expand Down Expand Up @@ -357,10 +358,17 @@ static void libcows_queue_hdr(libcows_ctx *ctx, size_t size) {
} else {
fhdr_buf[0] = *(unsigned char *)&frame;
fhdr_buf[1] = 127;
#if SIZEOF_SIZE_T == 4
fhdr_buf[2] = 0;
fhdr_buf[3] = 0;
fhdr_buf[4] = 0;
fhdr_buf[5] = 0;
#else
fhdr_buf[2] = size >> 56;
fhdr_buf[3] = size >> 48;
fhdr_buf[4] = size >> 40;
fhdr_buf[5] = size >> 32;
#endif
fhdr_buf[6] = size >> 24;
fhdr_buf[7] = size >> 16;
fhdr_buf[8] = size >> 8;
Expand Down
21 changes: 16 additions & 5 deletions src/tcpkali_atomic.h
Expand Up @@ -27,8 +27,23 @@
#ifndef TCPKALI_ATOMIC_H
#define TCPKALI_ATOMIC_H


#if SIZEOF_SIZE_T == 4
typedef uint32_t atomic_t;
typedef uint32_t atomic_wide_t;

static inline void __attribute__((unused)) atomic_add(atomic_wide_t *i, uint64_t v) {
asm volatile("lock addl %1, %0" : "+m" (*i) : "r" (v));
}

#elif SIZEOF_SIZE_T == 8
typedef uint32_t atomic_t;
typedef uint64_t atomic64_t;
typedef uint64_t atomic_wide_t;

static inline void __attribute__((unused)) atomic_add(atomic_wide_t *i, uint64_t v) {
asm volatile("lock addq %1, %0" : "+m" (*i) : "r" (v));
}
#endif /* SIZEOF_SIZE_T */

static inline void __attribute__((unused)) atomic_increment(atomic_t *i) {
asm volatile("lock incl %0" : "+m" (*i));
Expand All @@ -38,8 +53,4 @@ static inline void __attribute__((unused)) atomic_decrement(atomic_t *i) {
asm volatile("lock decl %0" : "+m" (*i));
}

static inline void __attribute__((unused)) atomic_add(atomic64_t *i, uint64_t v) {
asm volatile("lock addq %1, %0" : "+m" (*i) : "r" (v));
}

#endif /* TCPKALI_ATOMIC_H */
7 changes: 5 additions & 2 deletions src/tcpkali_engine.c
Expand Up @@ -112,8 +112,8 @@ struct loop_arguments {
int private_control_pipe_wr; /* Private blocking pipe for this worker (write side). */
int thread_no;
/* The following atomic members are accessed outside of worker thread */
atomic64_t worker_data_sent;
atomic64_t worker_data_received;
atomic_wide_t worker_data_sent __attribute__((aligned(sizeof(atomic_wide_t))));
atomic_wide_t worker_data_received __attribute__((aligned(sizeof(atomic_wide_t))));
atomic_t outgoing_connecting;
atomic_t outgoing_established;
atomic_t incoming_established;
Expand Down Expand Up @@ -228,6 +228,9 @@ static socklen_t sockaddr_len(struct sockaddr *sa) {
struct engine *engine_start(struct engine_params params) {
int fildes[2];

/* Check that worker_data_sent is properly aligned for atomicity */
assert(((long)(&((struct loop_arguments *)0)->worker_data_sent) & 7) == 0);

/* Global control pipe. Engine -> workers. */
int rc = pipe(fildes);
assert(rc == 0);
Expand Down

0 comments on commit 40fe853

Please sign in to comment.