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

[19435] Apply thread settings #3874

Merged
merged 38 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c1499f6
Refs #19436. Added thread creation wrapper infrastructure.
MiguelCompany Sep 13, 2023
9c515c0
Refs #19436. Added empty implementation for apply_thread_settings_to_…
MiguelCompany Sep 13, 2023
8cf6176
Refs #19436. Refactor on Log.cpp
MiguelCompany Sep 13, 2023
fc45783
Refs #19436. Add implementation for setting scheduler and priority.
MiguelCompany Sep 19, 2023
12f5572
Refs #19436. Add implementation for setting cpu affinity.
MiguelCompany Sep 19, 2023
9327aaf
Refs #19436. Add test setting config for Log thread.
MiguelCompany Sep 19, 2023
14ac33e
Refs #19436. Fix SystemInfoTests link issue.
MiguelCompany Sep 20, 2023
b41d405
Refs #19436. Changes on ResourceEvent.
MiguelCompany Sep 20, 2023
0c2448c
Refs #19436. Changes on DataSharingListener.
MiguelCompany Sep 20, 2023
8048446
Refs #19436. Changes on FlowControllerImpl.
MiguelCompany Sep 20, 2023
b8e68a9
Refs #19436. Changes on security LogTopic.
MiguelCompany Sep 20, 2023
8071ff5
Refs #19436. Apply settings on SharedMemWatchdog.
MiguelCompany Sep 20, 2023
a456704
Refs #19436. Apply settings on SharedMem reception threads.
MiguelCompany Sep 21, 2023
974b09e
Refs #19436. Apply settings on SharedMem packet dump threads.
MiguelCompany Sep 21, 2023
30ba24a
Refs #19436. Apply settings on UDP reception threads.
MiguelCompany Sep 21, 2023
580cc07
Refs #19436. Apply settings on TCP accept and keep_alive threads.
MiguelCompany Sep 21, 2023
0a9d3bb
Refs #19436. Apply settings on TCP reception threads.
MiguelCompany Sep 21, 2023
ee8c2db
Refs #19436. Include what you use.
MiguelCompany Sep 21, 2023
c63e9f0
Refs #19436. Add MacOS implementation for setting scheduler and prior…
MiguelCompany Sep 25, 2023
0babc87
Refs #19436. Add MacOS implementation for setting thread affinity.
MiguelCompany Sep 25, 2023
84cc93b
Refs #19437. Member cpu_mask changed to affinity and made it 64 bits.
MiguelCompany Oct 5, 2023
711e4e7
Refs #19437. Windows implementation for thread affinity.
MiguelCompany Oct 5, 2023
cd8ea38
Refs #19437. Windows implementation for thread priority.
MiguelCompany Oct 5, 2023
e88a574
Refs #19436. Made `get_thread_config_for_port` a const method.
MiguelCompany Oct 6, 2023
a9ed0d9
Refs #19436. Apply suggestions from code review.
MiguelCompany Oct 6, 2023
59b53c0
Refs #19435. Some refactors on FileWatch:
MiguelCompany Oct 10, 2023
41c3702
Refs #19435. SystemInfo::watch_file receives thread settings.
MiguelCompany Oct 10, 2023
3245527
Refs #19435. Added RTPSDomain::set_filewatch_thread_config
MiguelCompany Oct 11, 2023
06ef85d
Refs #19435. Call RTPSDomain::set_filewatch_thread_config inside Doma…
MiguelCompany Oct 11, 2023
a9f64d6
Refs #19435. Change priority default value.
MiguelCompany Oct 16, 2023
f1a299f
Refs #19435. Account for default values in threading_pthread
MiguelCompany Oct 16, 2023
393617a
Refs #19435. Account for default values in threading_osx
MiguelCompany Oct 16, 2023
2383e86
Refs #19435. Account for default values in threading_win32
MiguelCompany Oct 16, 2023
76f12a4
Refs #19435. Linters.
MiguelCompany Oct 16, 2023
0c5d7d7
Refs #19435. Use C++ headers.
MiguelCompany Oct 16, 2023
2f7faec
Refs #19435. Documentation updates.
MiguelCompany Oct 16, 2023
68aac31
Refs #19435. Suggestions on Log test.
MiguelCompany Oct 16, 2023
a7ef83c
Refs #19435. Removed unused overload of create_thread.
MiguelCompany Oct 17, 2023
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
62 changes: 60 additions & 2 deletions src/cpp/utils/threading/threading_pthread.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
// limitations under the License.

#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
EduPonz marked this conversation as resolved.
Show resolved Hide resolved
#include <sys/resource.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/types.h>

#include <fastdds/dds/log/Log.hpp>

namespace eprosima {

Expand Down Expand Up @@ -49,9 +55,61 @@ void set_name_to_current_thread(
set_name_to_current_thread_impl(fmt, arg1, arg2);
}

static void configure_current_thread_scheduler(
int sched_class,
int sched_priority)
{
pthread_t self_tid = pthread_self();
sched_param param;
int result = 0;

memset(&param, 0, sizeof(param));
param.sched_priority = 0;

//
// Set Scheduler Class and Priority
//

if((sched_class == SCHED_OTHER) ||
(sched_class == SCHED_BATCH) ||
(sched_class == SCHED_IDLE))
{
//
// BATCH and IDLE do not have explicit priority values.
// - Requires priorty value to be zero (0).

result = pthread_setschedparam(self_tid, sched_class, &param);

//
// Sched OTHER has a nice value, that we pull from the priority parameter.
//

if(sched_class == SCHED_OTHER)
{
result = setpriority(PRIO_PROCESS, gettid(), sched_priority);
}
}
else if((sched_class == SCHED_FIFO) ||
(sched_class == SCHED_RR))
{
//
// RT Policies use a different priority numberspace.
//

param.sched_priority = sched_priority;
result = pthread_setschedparam(self_tid, sched_class, &param);
}
EduPonz marked this conversation as resolved.
Show resolved Hide resolved

if (0 != result)
{
EPROSIMA_LOG_ERROR(SYSTEM, "Error '" << strerror(result) << "' configuring scheduler for thread " << self_tid);
}
}

void apply_thread_settings_to_current_thread(
const fastdds::rtps::ThreadSettings& /*settings*/)
const fastdds::rtps::ThreadSettings& settings)
{
configure_current_thread_scheduler(settings.scheduling_policy, settings.priority);
}

} // namespace eprosima