-
Notifications
You must be signed in to change notification settings - Fork 1
Adding possibility of pinning libe3 to specific CPU cores #82
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.2.0 | ||
| 0.2.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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> | ||
|
|
||
|
|
@@ -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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
There was a problem hiding this comment.
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