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
16 changes: 16 additions & 0 deletions doc/admin-guide/files/records.yaml.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5055,9 +5055,11 @@ Sockets
PACKET_MARK (16)
PACKET_TOS (32)
TCP_NOTSENT_LOWAT (64)
INCOMING_CPU (128)

Note: If MPTCP is enabled, TCP_NODELAY is only supported on Linux kernels 5.17+. TCP_FASTOPEN
and TCP_NOTSENT_LOWAT socket options are currently not supported.

.. note::

This is a bitmask and you need to decide what bits to set. Therefore,
Expand All @@ -5069,6 +5071,20 @@ Sockets
To allow TCP Fast Open for client sockets on Linux, bit 2 of
the ``net.ipv4.tcp_fastopen`` sysctl must be set.

.. note::

As for SO_INCOMING_CPU, using it with SO_REUSEPORT and exec_thread affinity 4 is recommended.

.. code-block:: yaml

ts:
accept_threads: 0
exec_thread:
listen: 1
affinity: 4
net:
sock_option_flag_in: 0x80

.. ts:cv:: CONFIG proxy.config.net.sock_send_buffer_size_out INT 0
:overridable:

Expand Down
17 changes: 14 additions & 3 deletions include/iocore/eventsystem/EThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "iocore/eventsystem/ProtectedQueue.h"
#include "tsutil/Histogram.h"

#if TS_USE_HWLOC
struct hwloc_obj;
using hwloc_obj_t = hwloc_obj *;
#endif

// TODO: This would be much nicer to have "run-time" configurable (or something)
#define PER_THREAD_DATA (1024 * 1024)

Expand Down Expand Up @@ -333,9 +338,15 @@ class EThread : public Thread

static constexpr int NO_ETHREAD_ID = -1;
int id = NO_ETHREAD_ID;
unsigned int event_types = 0;
bool is_event_type(EventType et);
void set_event_type(EventType et);

#if TS_USE_HWLOC
hwloc_obj_t hwloc_obj = nullptr;
#endif

unsigned int event_types = 0;

bool is_event_type(EventType et);
void set_event_type(EventType et);

// Private Interface

Expand Down
2 changes: 2 additions & 0 deletions include/iocore/net/NetVCOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ struct NetVCOptions {
static uint32_t const SOCK_OPT_PACKET_TOS = 32;
/// Value for TCP_NOTSENT_LOWAT @c sockopt_flags
static uint32_t const SOCK_OPT_TCP_NOTSENT_LOWAT = 64;
/// Value for SO_INCOMING_CPU @c sockopt_flags
static uint32_t const SOCK_OPT_INCOMING_CPU = 128;

uint32_t packet_mark;
uint32_t packet_tos;
Expand Down
2 changes: 2 additions & 0 deletions src/iocore/eventsystem/UnixEventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ ThreadAffinityInitializer::set_affinity(int, Event *)
if (obj_count > 0) {
// Get our `obj` instance with index based on the thread number we are on.
hwloc_obj_t obj = hwloc_get_obj_by_type(ink_get_topology(), obj_type, t->id % obj_count);
t->hwloc_obj = obj;

#if HWLOC_API_VERSION >= 0x00010100
int cpu_mask_len = hwloc_bitmap_snprintf(nullptr, 0, obj->cpuset) + 1;
char *cpu_mask = static_cast<char *>(alloca(cpu_mask_len));
Expand Down
28 changes: 26 additions & 2 deletions src/iocore/net/Connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@
Commonality across all platforms -- move out as required.

**************************************************************************/
#include "tscore/ink_platform.h"
#include "tscore/ink_defs.h"

#include "P_Net.h"

#include "tscore/ink_defs.h"
#include "tscore/ink_platform.h"
#include "tscore/ink_sock.h"

#if TS_USE_HWLOC
#include <hwloc.h>
#endif

#ifdef SO_ACCEPTFILTER
#include <sys/param.h>
#include <sys/linker.h>
Expand All @@ -49,6 +55,7 @@ DbgCtl dbg_ctl_http_tproxy{"http_tproxy"};
DbgCtl dbg_ctl_proxyprotocol{"proxyprotocol"};
DbgCtl dbg_ctl_iocore_net_server{"iocore_net_server"};
DbgCtl dbg_ctl_connection{"connection"};
DbgCtl dbg_ctl_iocore_thread{"iocore_thread"};

} // end anonymous namespace

Expand Down Expand Up @@ -238,6 +245,23 @@ Server::setup_fd_for_listen(bool non_blocking, const NetProcessor::AcceptOptions
#endif
}

#ifdef SO_INCOMING_CPU
if (opt.sockopt_flags & NetVCOptions::SOCK_OPT_INCOMING_CPU) {
int cpu = 0;
EThread *ethread = this_ethread();

#ifdef TS_USE_HWLOC
cpu = ethread->hwloc_obj->os_index;
Copy link
Contributor Author

@masaori335 masaori335 May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hwloc_obj::os_index looks "OS-provided physical index number" and it's working with exec_thread.affinity: 4 as expected. However, hwloc has any better API?
https://github.com/open-mpi/hwloc/blob/63a8288d31a1baf67a909466aba9a022c78ca7b1/include/hwloc.h#L491

#else
cpu = ethread->id;
#endif
if (safe_setsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, &cpu, sizeof(cpu)) < 0) {
goto Lerror;
}
Dbg(dbg_ctl_iocore_thread, "SO_INCOMING_CPU - fd=%d cpu=%d", fd, cpu);
}
#endif

if ((opt.sockopt_flags & NetVCOptions::SOCK_OPT_NO_DELAY) && setsockopt_on(fd, IPPROTO_TCP, TCP_NODELAY) < 0) {
goto Lerror;
}
Expand Down