Skip to content

Commit e1c7c13

Browse files
committedOct 7, 2016
Code cleanup for the runtime without monitor thread
This change removes/disables unnecessary code when monitor thread is not used. Patch by Hansang Bae Differential Revision: https://reviews.llvm.org/D25102 llvm-svn: 283577
1 parent a1234cf commit e1c7c13

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed
 

‎openmp/runtime/src/kmp.h

+17-4
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,6 @@ extern int __kmp_place_num_threads_per_core;
10281028
# define KMP_DEFAULT_STKSIZE ((size_t)(1024 * 1024))
10291029
#endif
10301030

1031-
#define KMP_DEFAULT_MONITOR_STKSIZE ((size_t)(64 * 1024))
1032-
10331031
#define KMP_DEFAULT_MALLOC_POOL_INCR ((size_t) (1024 * 1024))
10341032
#define KMP_MIN_MALLOC_POOL_INCR ((size_t) (4 * 1024))
10351033
#define KMP_MAX_MALLOC_POOL_INCR (~((size_t)1<<((sizeof(size_t)*(1<<3))-1)))
@@ -1045,12 +1043,16 @@ extern int __kmp_place_num_threads_per_core;
10451043
#define KMP_MIN_STKPADDING (0)
10461044
#define KMP_MAX_STKPADDING (2 * 1024 * 1024)
10471045

1048-
#define KMP_MIN_MONITOR_WAKEUPS (1) /* min number of times monitor wakes up per second */
1049-
#define KMP_MAX_MONITOR_WAKEUPS (1000) /* maximum number of times monitor can wake up per second */
10501046
#define KMP_BLOCKTIME_MULTIPLIER (1000) /* number of blocktime units per second */
10511047
#define KMP_MIN_BLOCKTIME (0)
10521048
#define KMP_MAX_BLOCKTIME (INT_MAX) /* Must be this for "infinite" setting the work */
10531049
#define KMP_DEFAULT_BLOCKTIME (200) /* __kmp_blocktime is in milliseconds */
1050+
1051+
#if KMP_USE_MONITOR
1052+
#define KMP_DEFAULT_MONITOR_STKSIZE ((size_t)(64 * 1024))
1053+
#define KMP_MIN_MONITOR_WAKEUPS (1) /* min number of times monitor wakes up per second */
1054+
#define KMP_MAX_MONITOR_WAKEUPS (1000) /* maximum number of times monitor can wake up per second */
1055+
10541056
/* Calculate new number of monitor wakeups for a specific block time based on previous monitor_wakeups */
10551057
/* Only allow increasing number of wakeups */
10561058
#define KMP_WAKEUPS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
@@ -1063,6 +1065,7 @@ extern int __kmp_place_num_threads_per_core;
10631065
#define KMP_INTERVALS_FROM_BLOCKTIME(blocktime, monitor_wakeups) \
10641066
( ( (blocktime) + (KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)) - 1 ) / \
10651067
(KMP_BLOCKTIME_MULTIPLIER / (monitor_wakeups)) )
1068+
#endif // KMP_USE_MONITOR
10661069

10671070
#define KMP_MIN_STATSCOLS 40
10681071
#define KMP_MAX_STATSCOLS 4096
@@ -1810,7 +1813,9 @@ typedef struct kmp_internal_control {
18101813
kmp_int8 dynamic; /* internal control for dynamic adjustment of threads (per thread) */
18111814
kmp_int8 bt_set; /* internal control for whether blocktime is explicitly set */
18121815
int blocktime; /* internal control for blocktime */
1816+
#if KMP_USE_MONITOR
18131817
int bt_intervals; /* internal control for blocktime intervals */
1818+
#endif
18141819
int nproc; /* internal control for #threads for next parallel region (per thread) */
18151820
int max_active_levels; /* internal control for max_active_levels */
18161821
kmp_r_sched_t sched; /* internal control for runtime schedule {sched,chunk} pair */
@@ -2001,7 +2006,9 @@ typedef struct kmp_local {
20012006

20022007
#define get__blocktime( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime)
20032008
#define get__bt_set( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set)
2009+
#if KMP_USE_MONITOR
20042010
#define get__bt_intervals( xteam, xtid ) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals)
2011+
#endif
20052012

20062013
#define get__nested_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.nested)
20072014
#define get__dynamic_2(xteam,xtid) ((xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.dynamic)
@@ -2011,8 +2018,10 @@ typedef struct kmp_local {
20112018
#define set__blocktime_team( xteam, xtid, xval ) \
20122019
( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.blocktime ) = (xval) )
20132020

2021+
#if KMP_USE_MONITOR
20142022
#define set__bt_intervals_team( xteam, xtid, xval ) \
20152023
( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_intervals ) = (xval) )
2024+
#endif
20162025

20172026
#define set__bt_set_team( xteam, xtid, xval ) \
20182027
( ( (xteam)->t.t_threads[(xtid)]->th.th_current_task->td_icvs.bt_set ) = (xval) )
@@ -2380,7 +2389,9 @@ typedef struct KMP_ALIGN_CACHE kmp_base_info {
23802389
/* at the start of a barrier, and the values stored in the team are used */
23812390
/* at points in the code where the team struct is no longer guaranteed */
23822391
/* to exist (from the POV of worker threads). */
2392+
#if KMP_USE_MONITOR
23832393
int th_team_bt_intervals;
2394+
#endif
23842395
int th_team_bt_set;
23852396

23862397

@@ -2835,8 +2846,10 @@ extern int __kmp_tp_capacity; /* capacity of __kmp_threads if threadpr
28352846
extern int __kmp_tp_cached; /* whether threadprivate cache has been created (__kmpc_threadprivate_cached()) */
28362847
extern int __kmp_dflt_nested; /* nested parallelism enabled by default a la OMP_NESTED */
28372848
extern int __kmp_dflt_blocktime; /* number of milliseconds to wait before blocking (env setting) */
2849+
#if KMP_USE_MONITOR
28382850
extern int __kmp_monitor_wakeups;/* number of times monitor wakes up per second */
28392851
extern int __kmp_bt_intervals; /* number of monitor timestamp intervals before blocking */
2852+
#endif
28402853
#ifdef KMP_ADJUST_BLOCKTIME
28412854
extern int __kmp_zero_bt; /* whether blocktime has been forced to zero */
28422855
#endif /* KMP_ADJUST_BLOCKTIME */

‎openmp/runtime/src/kmp_barrier.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ __kmp_barrier(enum barrier_type bt, int gtid, int is_split, size_t reduce_size,
11081108
the team struct is not guaranteed to exist. */
11091109
// See note about the corresponding code in __kmp_join_barrier() being performance-critical.
11101110
if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1111+
#if KMP_USE_MONITOR
11111112
this_thr->th.th_team_bt_intervals = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1113+
#endif
11121114
this_thr->th.th_team_bt_set = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
11131115
}
11141116

@@ -1425,7 +1427,9 @@ __kmp_join_barrier(int gtid)
14251427
down EPCC parallel by 2x. As a workaround, we do not perform the copy if blocktime=infinite,
14261428
since the values are not used by __kmp_wait_template() in that case. */
14271429
if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1430+
#if KMP_USE_MONITOR
14281431
this_thr->th.th_team_bt_intervals = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1432+
#endif
14291433
this_thr->th.th_team_bt_set = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
14301434
}
14311435

@@ -1612,7 +1616,9 @@ __kmp_fork_barrier(int gtid, int tid)
16121616
access it when the team struct is not guaranteed to exist. */
16131617
// See note about the corresponding code in __kmp_join_barrier() being performance-critical
16141618
if (__kmp_dflt_blocktime != KMP_MAX_BLOCKTIME) {
1619+
#if KMP_USE_MONITOR
16151620
this_thr->th.th_team_bt_intervals = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_intervals;
1621+
#endif
16161622
this_thr->th.th_team_bt_set = team->t.t_implicit_task_taskdata[tid].td_icvs.bt_set;
16171623
}
16181624
} // master

‎openmp/runtime/src/kmp_global.c

+2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ enum sched_type __kmp_static = kmp_sch_static_greedy; /* default static sched
141141
enum sched_type __kmp_guided = kmp_sch_guided_iterative_chunked; /* default guided scheduling method */
142142
enum sched_type __kmp_auto = kmp_sch_guided_analytical_chunked; /* default auto scheduling method */
143143
int __kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
144+
#if KMP_USE_MONITOR
144145
int __kmp_monitor_wakeups = KMP_MIN_MONITOR_WAKEUPS;
145146
int __kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( KMP_DEFAULT_BLOCKTIME, KMP_MIN_MONITOR_WAKEUPS );
147+
#endif
146148
#ifdef KMP_ADJUST_BLOCKTIME
147149
int __kmp_zero_bt = FALSE;
148150
#endif /* KMP_ADJUST_BLOCKTIME */

‎openmp/runtime/src/kmp_runtime.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,9 @@ __kmp_get_global_icvs( void ) {
30343034
(kmp_int8)__kmp_global.g.g_dynamic, //internal control for dynamic adjustment of threads (per thread)
30353035
(kmp_int8)__kmp_env_blocktime, //int bt_set; //internal control for whether blocktime is explicitly set
30363036
__kmp_dflt_blocktime, //int blocktime; //internal control for blocktime
3037+
#if KMP_USE_MONITOR
30373038
__kmp_bt_intervals, //int bt_intervals; //internal control for blocktime intervals
3039+
#endif
30383040
__kmp_dflt_team_nth, //int nproc; //internal control for # of threads for next parallel region (per thread)
30393041
// (use a max ub on value if __kmp_parallel_initialize not called yet)
30403042
__kmp_dflt_max_active_levels, //int max_active_levels; //internal control for max_active_levels
@@ -6376,8 +6378,10 @@ __kmp_do_serial_initialize( void )
63766378

63776379
// Three vars below moved here from __kmp_env_initialize() "KMP_BLOCKTIME" part
63786380
__kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
6381+
#if KMP_USE_MONITOR
63796382
__kmp_monitor_wakeups = KMP_WAKEUPS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
63806383
__kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
6384+
#endif
63816385
// From "KMP_LIBRARY" part of __kmp_env_initialize()
63826386
__kmp_library = library_throughput;
63836387
// From KMP_SCHEDULE initialization
@@ -7449,7 +7453,9 @@ void
74497453
__kmp_aux_set_blocktime (int arg, kmp_info_t *thread, int tid)
74507454
{
74517455
int blocktime = arg; /* argument is in milliseconds */
7456+
#if KMP_USE_MONITOR
74527457
int bt_intervals;
7458+
#endif
74537459
int bt_set;
74547460

74557461
__kmp_save_internal_controls( thread );
@@ -7463,20 +7469,29 @@ __kmp_aux_set_blocktime (int arg, kmp_info_t *thread, int tid)
74637469
set__blocktime_team( thread->th.th_team, tid, blocktime );
74647470
set__blocktime_team( thread->th.th_serial_team, 0, blocktime );
74657471

7472+
#if KMP_USE_MONITOR
74667473
/* Calculate and set blocktime intervals for the teams */
74677474
bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME(blocktime, __kmp_monitor_wakeups);
74687475

74697476
set__bt_intervals_team( thread->th.th_team, tid, bt_intervals );
74707477
set__bt_intervals_team( thread->th.th_serial_team, 0, bt_intervals );
7478+
#endif
74717479

74727480
/* Set whether blocktime has been set to "TRUE" */
74737481
bt_set = TRUE;
74747482

74757483
set__bt_set_team( thread->th.th_team, tid, bt_set );
74767484
set__bt_set_team( thread->th.th_serial_team, 0, bt_set );
7477-
KF_TRACE(10, ( "kmp_set_blocktime: T#%d(%d:%d), blocktime=%d, bt_intervals=%d, monitor_updates=%d\n",
7478-
__kmp_gtid_from_tid(tid, thread->th.th_team),
7479-
thread->th.th_team->t.t_id, tid, blocktime, bt_intervals, __kmp_monitor_wakeups ) );
7485+
KF_TRACE(10, ( "kmp_set_blocktime: T#%d(%d:%d), blocktime=%d"
7486+
#if KMP_USE_MONITOR
7487+
", bt_intervals=%d, monitor_updates=%d"
7488+
#endif
7489+
"\n",
7490+
__kmp_gtid_from_tid(tid, thread->th.th_team), thread->th.th_team->t.t_id, tid, blocktime
7491+
#if KMP_USE_MONITOR
7492+
, bt_intervals, __kmp_monitor_wakeups
7493+
#endif
7494+
) );
74807495
}
74817496

74827497
void

‎openmp/runtime/src/kmp_settings.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,11 @@ __kmp_stg_parse_blocktime( char const * name, char const * value, void * data )
659659
}; // if
660660
__kmp_env_blocktime = TRUE; // KMP_BLOCKTIME was specified.
661661
}; // if
662-
// calculate number of monitor thread wakeup intervals corresonding to blocktime.
662+
#if KMP_USE_MONITOR
663+
// calculate number of monitor thread wakeup intervals corresponding to blocktime.
663664
__kmp_monitor_wakeups = KMP_WAKEUPS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
664665
__kmp_bt_intervals = KMP_INTERVALS_FROM_BLOCKTIME( __kmp_dflt_blocktime, __kmp_monitor_wakeups );
666+
#endif
665667
K_DIAG( 1, ( "__kmp_env_blocktime == %d\n", __kmp_env_blocktime ) );
666668
if ( __kmp_env_blocktime ) {
667669
K_DIAG( 1, ( "__kmp_dflt_blocktime == %d\n", __kmp_dflt_blocktime ) );

0 commit comments

Comments
 (0)
Please sign in to comment.