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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
3 changes: 3 additions & 0 deletions include/libe3/c_api.h

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

keep these comments but let's have them trimmed a little bit

Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ typedef struct {
size_t io_threads; /* 0=default */
int log_level; /* -1=default */
const char* log_path; /* NULL=auto (/tmp/e3_<role>[_<id>]_<euid>.log) */
/* A flag rather than a sentinel: core 0 is a legitimate target. */
int pin_io_threads; /* 0=no pinning */
int io_thread_affinity; /* logical core; Linux only, best-effort */
} e3_config_t;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ e3_agent_handle_t* e3_agent_create_with_config(const e3_config_t* config) {
if (config->io_threads != 0) cfg.io_threads = config->io_threads;
if (config->log_level >= 0) cfg.log_level = config->log_level;
if (config->log_path) cfg.log_path = config->log_path;
// Gated by the flag, not a sentinel: core 0 is a real target.
if (config->pin_io_threads)
cfg.io_thread_affinity = config->io_thread_affinity;
}
e3_agent_handle_t* h = new e3_agent_handle_s();
h->agent = std::make_unique<E3Agent>(std::move(cfg));
Expand Down
19 changes: 15 additions & 4 deletions src/core/e3_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include "libe3/logger.hpp"
#include "libe3/latrec.h"
#include <cctype>
#include <cerrno>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <signal.h>
#include <string>

Expand Down Expand Up @@ -79,17 +81,26 @@ void apply_thread_config(int affinity, int niceness, const char* role) noexcept
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(static_cast<size_t>(affinity), &cpuset);
// Non-fatal if this fails (e.g. core index out of range).
(void)pthread_setaffinity_np(pthread_self(),
sizeof(cpu_set_t), &cpuset);
// Non-fatal, but say so: a silent miss looks identical to a working pin.
int rc = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (rc != 0) {
E3_LOG_WARN(LOG_TAG) << "Failed to pin " << role << " thread to core "
<< affinity << ": " << std::strerror(rc)
<< " (thread left unpinned)";
} else {
E3_LOG_INFO(LOG_TAG) << "Pinned " << role << " thread to core " << affinity;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd probably use debug to reduce the logs but I am not 100% convinced of my own opinion, how does AERIAL and OAI usually do for these kinds of messages?

I see the value in our logs to have it always shown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's just a single message at startup.

}
}
if (niceness != 0) {
// Use the kernel TID so only this thread's scheduling priority changes.
// syscall(SYS_gettid) returns the kernel thread ID as a long; cast it
// to pid_t first, then to the id_t expected by setpriority(PRIO_PROCESS).
auto tid = static_cast<id_t>(static_cast<pid_t>(syscall(SYS_gettid)));
// Non-fatal: negative values require CAP_SYS_NICE.
(void)setpriority(PRIO_PROCESS, tid, niceness);
if (setpriority(PRIO_PROCESS, tid, niceness) == -1) {
E3_LOG_WARN(LOG_TAG) << "Failed to set niceness " << niceness << " on "
<< role << " thread: " << std::strerror(errno);
}
}
#else
(void)affinity;
Expand Down
Loading