From 90351e1167a3bf21c2378306b68f560601e8415f Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Tue, 11 Jun 2013 17:30:47 +0200 Subject: erts: Add the +sfwi system flag +sfwi Interval Set scheduler forced wakeup interval. All run queues will be scanned each Interval milliseconds. While there are sleeping schedulers in the system, one scheduler will be woken for each non-empty run queue found. An Interval of zero disables this feature, which also is the default. This feature has been introduced as a temporary workaround for lengthy executing native code, and native code that do not bump reductions properly in OTP. When these bugs have be fixed the +sfwi flag will be removed. Conflicts: erts/doc/src/erl.xml erts/etc/common/erlexec.c --- erts/doc/src/erl.xml | 14 +++++++ erts/emulator/beam/erl_init.c | 16 ++++++++ erts/emulator/beam/erl_process.c | 85 ++++++++++++++++++++++++++++++++++++++-- erts/emulator/beam/erl_process.h | 4 ++ erts/etc/common/erlexec.c | 3 ++ 5 files changed, 119 insertions(+), 3 deletions(-) diff --git a/erts/doc/src/erl.xml b/erts/doc/src/erl.xml index f931445a3e..12cdb4b628 100644 --- a/erts/doc/src/erl.xml +++ b/erts/doc/src/erl.xml @@ -907,6 +907,20 @@

For more information, see erlang:system_info(cpu_topology).

+ +sfwi Interval + +

Set scheduler forced wakeup interval. All run queues will + be scanned each Interval milliseconds. While there are + sleeping schedulers in the system, one scheduler will be woken + for each non-empty run queue found. An Interval of zero + disables this feature, which also is the default. +

+

This feature has been introduced as a temporary workaround + for lengthy executing native code, and native code that do not + bump reductions properly in OTP. When these bugs have be fixed + the +sfwi flag will be removed. +

+
+sws default|legacy|proposal

Set scheduler wakeup strategy. Default is legacy (has been diff --git a/erts/emulator/beam/erl_init.c b/erts/emulator/beam/erl_init.c index 1eb3dba240..7f52b111ac 100644 --- a/erts/emulator/beam/erl_init.c +++ b/erts/emulator/beam/erl_init.c @@ -1240,6 +1240,22 @@ erl_start(int argc, char **argv) ("suggested scheduler thread stack size %d kilo words\n", erts_sched_thread_suggested_stack_size)); } + else if (has_prefix("fwi", sub_param)) { + long val; + arg = get_arg(sub_param+3, argv[i+1], &i); + errno = 0; + val = strtol(arg, NULL, 10); + if (errno != 0 || val < 0) { + erts_fprintf(stderr, + "bad scheduler forced wakeup " + "interval %s\n", + arg); + erts_usage(); + } +#ifdef ERTS_SMP + erts_runq_supervision_interval = val; +#endif + } else { erts_fprintf(stderr, "bad scheduling option %s\n", argv[i]); erts_usage(); diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index 9425fa7088..b84b5b39a5 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -218,6 +218,10 @@ static erts_smp_atomic32_t function_calls; #ifdef ERTS_SMP static erts_smp_atomic32_t doing_sys_schedule; static erts_smp_atomic32_t no_empty_run_queues; +long erts_runq_supervision_interval = 0; +static ethr_event runq_supervision_event; +static erts_tid_t runq_supervisor_tid; +static erts_atomic_t runq_supervisor_sleeping; #else /* !ERTS_SMP */ ErtsSchedulerData *erts_scheduler_data; #endif @@ -1885,7 +1889,13 @@ empty_runq(ErtsRunQueue *rq) */ ASSERT(0 <= empty && empty < 2*erts_no_run_queues); #endif - erts_smp_atomic32_inc_relb(&no_empty_run_queues); + if (!erts_runq_supervision_interval) + erts_smp_atomic32_inc_relb(&no_empty_run_queues); + else { + erts_smp_atomic32_inc_mb(&no_empty_run_queues); + if (erts_atomic_read_nob(&runq_supervisor_sleeping)) + ethr_event_set(&runq_supervision_event); + } } } @@ -1903,7 +1913,14 @@ non_empty_runq(ErtsRunQueue *rq) */ ASSERT(0 < empty && empty <= 2*erts_no_run_queues); #endif - erts_smp_atomic32_dec_relb(&no_empty_run_queues); + if (!erts_runq_supervision_interval) + erts_smp_atomic32_dec_relb(&no_empty_run_queues); + else { + erts_aint32_t no; + no = erts_smp_atomic32_dec_read_mb(&no_empty_run_queues); + if (no > 0 && erts_atomic_read_nob(&runq_supervisor_sleeping)) + ethr_event_set(&runq_supervision_event); + } } } @@ -2505,7 +2522,6 @@ try_inc_no_active_runqs(int active) return 0; } - static ERTS_INLINE int chk_wake_sched(ErtsRunQueue *crq, int ix, int activate) { @@ -3829,6 +3845,53 @@ set_wakeup_other_data(void) } } +static int +no_runqs_to_supervise(void) +{ + int used; + erts_aint32_t nerq = erts_smp_atomic32_read_acqb(&no_empty_run_queues); + if (nerq <= 0) + return 0; + get_no_runqs(NULL, &used); + if (nerq >= used) + return 0; + return used; +} + +static void * +runq_supervisor(void *unused) +{ + while (1) { + int ix, no_rqs; + + erts_milli_sleep(erts_runq_supervision_interval); + no_rqs = no_runqs_to_supervise(); + if (!no_rqs) { + erts_atomic_set_nob(&runq_supervisor_sleeping, 1); + while (1) { + ethr_event_reset(&runq_supervision_event); + no_rqs = no_runqs_to_supervise(); + if (no_rqs) { + erts_atomic_set_nob(&runq_supervisor_sleeping, 0); + break; + } + ethr_event_wait(&runq_supervision_event); + } + } + + for (ix = 0; ix < no_rqs; ix++) { + ErtsRunQueue *rq = ERTS_RUNQ_IX(ix); + if (ERTS_RUNQ_FLGS_GET(rq) & ERTS_RUNQ_FLG_NONEMPTY) { + erts_smp_runq_lock(rq); + if (rq->len != 0) + wake_scheduler_on_empty_runq(rq); /* forced wakeup... */ + erts_smp_runq_unlock(rq); + } + } + } + return NULL; +} + #endif void @@ -5235,6 +5298,22 @@ erts_start_schedulers(void) ethr_thr_opts opts = ETHR_THR_OPTS_DEFAULT_INITER; opts.detached = 1; + +#ifdef ERTS_SMP + if (erts_runq_supervision_interval) { + opts.suggested_stack_size = 16; + erts_atomic_init_nob(&runq_supervisor_sleeping, 0); + if (0 != ethr_event_init(&runq_supervision_event)) + erl_exit(1, "Failed to create run-queue supervision event\n"); + if (0 != ethr_thr_create(&runq_supervisor_tid, + runq_supervisor, + NULL, + &opts)) + erl_exit(1, "Failed to create run-queue supervision thread\n"); + + } +#endif + opts.suggested_stack_size = erts_sched_thread_suggested_stack_size; if (wanted < 1) diff --git a/erts/emulator/beam/erl_process.h b/erts/emulator/beam/erl_process.h index 968971ed4c..9b0e9f1ccd 100644 --- a/erts/emulator/beam/erl_process.h +++ b/erts/emulator/beam/erl_process.h @@ -371,6 +371,10 @@ struct ErtsRunQueue_ { } ports; }; +#ifdef ERTS_SMP +extern long erts_runq_supervision_interval; +#endif + typedef union { ErtsRunQueue runq; char align[ERTS_ALC_CACHE_LINE_ALIGN_SIZE(sizeof(ErtsRunQueue))]; diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c index 52add1c1ba..c4bdc4ee4b 100644 --- a/erts/etc/common/erlexec.c +++ b/erts/etc/common/erlexec.c @@ -124,6 +124,9 @@ static char *pluss_val_switches[] = { "bwt", "cl", "ct", + "fwi", + "tbt", + "wct", "wt", "ws", "ss", -- cgit v1.2.3 From 68e43ed95a52713d80d9ae721f6c5b6ca451570d Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Mon, 16 Sep 2013 14:11:23 +0200 Subject: erts: bumped version number --- erts/vsn.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/vsn.mk b/erts/vsn.mk index f522b4c758..7e1d43429c 100644 --- a/erts/vsn.mk +++ b/erts/vsn.mk @@ -17,7 +17,7 @@ # %CopyrightEnd% # -VSN = 5.9.3.2 +VSN = 5.9.3.3 SYSTEM_VSN = R15B03 # Port number 4365 in 4.2 -- cgit v1.2.3 From 1fefbd886bf3f02f0d34d64ea49d3d0838cba9ee Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Mon, 16 Sep 2013 15:16:57 +0200 Subject: erts: reorganization of functions to r15b03 standards --- erts/emulator/beam/erl_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/emulator/beam/erl_process.c b/erts/emulator/beam/erl_process.c index b84b5b39a5..d7d440d81a 100644 --- a/erts/emulator/beam/erl_process.c +++ b/erts/emulator/beam/erl_process.c @@ -3881,7 +3881,7 @@ runq_supervisor(void *unused) for (ix = 0; ix < no_rqs; ix++) { ErtsRunQueue *rq = ERTS_RUNQ_IX(ix); - if (ERTS_RUNQ_FLGS_GET(rq) & ERTS_RUNQ_FLG_NONEMPTY) { + if (erts_smp_atomic32_read_acqb(&rq->info_flags) & ERTS_RUNQ_IFLG_NONEMPTY) { erts_smp_runq_lock(rq); if (rq->len != 0) wake_scheduler_on_empty_runq(rq); /* forced wakeup... */ -- cgit v1.2.3 From 98412eababc3f81719e9c150c9cff6c629e2a3ff Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Mon, 16 Sep 2013 16:21:39 +0200 Subject: Update release notes --- erts/doc/src/notes.xml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/erts/doc/src/notes.xml b/erts/doc/src/notes.xml index 1099d76545..087ac01405 100644 --- a/erts/doc/src/notes.xml +++ b/erts/doc/src/notes.xml @@ -30,6 +30,44 @@

This document describes the changes made to the ERTS application.

+
Erts 5.9.3.3 + +
Known Bugs and Problems + + +

Miscellaneous native code in OTP misbehave either due + to lengthy execution, or due to not bumping reductions + properly. Problems typically occur when passing huge sets + of data to a misbehaving BIF. Fixing this has high + priority and is being worked on, but there will remain + issues like this for some time.

+

In order to alleviate problems with scheduling which + might occur when executing misbehaving native code, the + command line argument +sfwi has been + introduced.

+

By default this feature is disabled and you are + advised not to enable it if you do not encounter problems + with misbehaving native code.

+

When enabled it has the following impact on the + characteristics of the system:

Work will + always be distributed between schedulers even when + executing misbehaving native code. It may + cause an increased amount of processes and/or ports + bouncing between schedulers which in turn will cause a + performance loss. It may cause reduced + performance due to reduced or lost work compaction when + all schedulers do not execute under full load. + An increased contention on run queue locks. + +

+ Own Id: OTP-11164

+
+
+
+ +
+
Erts 5.9.3.2
Improvements and New Features -- cgit v1.2.3