Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
f19ef24f
Commit
f19ef24f
authored
2 years ago
by
Peter W. Draper
Committed by
Matthieu Schaller
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Keep affinity of threadpool threads the same as the main thread on entry
parent
24867f22
No related branches found
No related tags found
3 merge requests
!1715
Update planetary strength after planetary plus's master rebase
,
!1693
More threapool plotting tweaks
,
!1686
Keep affinity of threadpool threads the same as the main thread on entry
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/engine.c
+5
-0
5 additions, 0 deletions
src/engine.c
src/threadpool.c
+39
-0
39 additions, 0 deletions
src/threadpool.c
src/threadpool.h
+3
-0
3 additions, 0 deletions
src/threadpool.h
with
47 additions
and
0 deletions
src/engine.c
+
5
−
0
View file @
f19ef24f
...
...
@@ -2913,6 +2913,11 @@ void engine_pin(void) {
#ifdef HAVE_SETAFFINITY
cpu_set_t
*
entry_affinity
=
engine_entry_affinity
();
/* Share this affinity with the threadpool, it will use this even when the
* main thread is otherwise pinned. */
threadpool_set_affinity_mask
(
entry_affinity
);
int
pin
;
for
(
pin
=
0
;
pin
<
CPU_SETSIZE
&&
!
CPU_ISSET
(
pin
,
entry_affinity
);
++
pin
)
;
...
...
This diff is collapsed.
Click to expand it.
src/threadpool.c
+
39
−
0
View file @
f19ef24f
...
...
@@ -24,6 +24,7 @@
#include
<float.h>
#include
<limits.h>
#include
<math.h>
#include
<sched.h>
#include
<stdlib.h>
#include
<string.h>
#ifdef SWIFT_DEBUG_THREADPOOL
...
...
@@ -42,6 +43,13 @@
/* Keys for thread specific data. */
static
pthread_key_t
threadpool_tid
;
/* Affinity mask shared by all threads, and if set. */
static
cpu_set_t
thread_affinity
;
static
int
thread_affinity_set
=
0
;
/* Local declarations. */
static
void
threadpool_apply_affinity_mask
(
void
);
#ifdef SWIFT_DEBUG_THREADPOOL
/**
* @brief Store a log entry of the given chunk.
...
...
@@ -178,11 +186,19 @@ static void threadpool_chomp(struct threadpool *tp, int tid) {
}
}
/**
* @brief The thread start routine. Loops until told to exit.
*
* @param data the threadpool we are part of.
*/
static
void
*
threadpool_runner
(
void
*
data
)
{
/* Our threadpool. */
struct
threadpool
*
tp
=
(
struct
threadpool
*
)
data
;
/* Our affinity, if set. */
threadpool_apply_affinity_mask
();
/* Main loop. */
while
(
1
)
{
...
...
@@ -412,3 +428,26 @@ int threadpool_gettid() {
int
*
tid
=
(
int
*
)
pthread_getspecific
(
threadpool_tid
);
return
*
tid
;
}
#ifdef HAVE_SETAFFINITY
/**
* @brief set an affinity mask to be used for all threads.
*
* @param affinity the mask to use.
*/
void
threadpool_set_affinity_mask
(
cpu_set_t
*
affinity
)
{
memcpy
(
&
thread_affinity
,
affinity
,
sizeof
(
cpu_set_t
));
thread_affinity_set
=
1
;
}
#endif
/**
* @brief apply the affinity mask the current thread, if set.
*
*/
static
void
threadpool_apply_affinity_mask
(
void
)
{
if
(
thread_affinity_set
)
{
pthread_setaffinity_np
(
pthread_self
(),
sizeof
(
cpu_set_t
),
&
thread_affinity
);
}
}
This diff is collapsed.
Click to expand it.
src/threadpool.h
+
3
−
0
View file @
f19ef24f
...
...
@@ -101,6 +101,9 @@ void threadpool_map(struct threadpool *tp, threadpool_map_function map_function,
void
*
extra_data
);
int
threadpool_gettid
(
void
);
void
threadpool_clean
(
struct
threadpool
*
tp
);
#ifdef HAVE_SETAFFINITY
void
threadpool_set_affinity_mask
(
cpu_set_t
*
entry_affinity
);
#endif
#ifdef SWIFT_DEBUG_THREADPOOL
void
threadpool_reset_log
(
struct
threadpool
*
tp
);
void
threadpool_dump_log
(
struct
threadpool
*
tp
,
const
char
*
filename
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment