runtime: don't start workers between mark 1 & 2
runtime: don't start workers between mark 1 & 2

Currently we clear both the mark 1 and mark 2 signals at the beginning
of concurrent mark. If either if these is clear, it acts as a signal
to the scheduler that it should start background workers. However,
this means that in the interim *between* mark 1 and mark 2, the
scheduler basically loops starting up new workers only to have them
return with nothing to do. In addition to harming performance and
delaying mutator work, this approach has a race where workers started
for mark 1 can mistakenly signal mark 2, causing it to complete
prematurely. This approach also interferes with starting assists
earlier to fix #11677.

Fix this by initially setting both mark 1 and mark 2 to "signaled".
The scheduler will not start background mark workers, though assists
can still run. When we're ready to enter mark 1, we clear the mark 1
signal and wait for it. Then, when we're ready to enter mark 2, we
clear the mark 2 signal and wait for it.

This structure also lets us deal cleanly with the situation where all
work is drained *prior* to the mark 2 wait, meaning that there may be
no workers to signal completion. Currently we deal with this using a
racy (and possibly incorrect) check for work in the coordinator itself
to skip the mark 2 wait if there's no work. This change makes the
coordinator unconditionally wait for mark completion and makes the
scheduler itself signal completion by slightly extending the logic it
already has to determine that there's no work and hence no use in
starting a new worker.

This is a prerequisite to fixing the remaining component of #11677,
which will require enabling assists during the scan phase. However, we
don't want to enable background workers until the mark phase because
they will compete with the scan. This change lets us use bgMark1 and
bgMark2 to indicate when it's okay to start background workers
independent of assists.

This is also a prerequisite to fixing #11694. It significantly reduces
the occurrence of long mark termination pauses in #11694 (from 64 out
of 1000 to 2 out of 1000 in one experiment).

Coincidentally, this also reduces the final heap size (and hence run
time) of TestTraceStress from ~100 MB and ~1.9 seconds to ~14 MB and
~0.4 seconds because it significantly shortens concurrent mark
duration.

Rick Hudson <rlh> did the hard work of tracking this down.

Change-Id: I12ea9ee2db9a0ae9d3a90dde4944a75fcf408f4c
Reviewed-on: https://go-review.googlesource.com/12672
Reviewed-by: Russ Cox <5ad239cb8a44f659eaaee0aa1ea5b94947abe557@golang.org>

ErikDubbelboer/go,devpadawan/go,jdhenke/go,dterei/go,samanalysis/go,g522342435/go,nawawi/go,cloudflare/go,GeorgiCodes/go,roth1002/go,likesea/go,yasarkunduz/go,chinanjjohn2012/go,andrewchambers/go,cloudflare/go,sosop/go,jonahglover/go,skatsuta/go,jasonxiong/go,ericsnowcurrently/go,derekmarcotte/go,rentongzhang/go,leeric92/go,shines77/go,sndnvaps/go,g522342435/go,mdp/go,donnel6809/go,skotti/go,mwhudson/go,skatsuta/go,yasarkunduz/go,CarterTsai/go,arschles/golang-go,skotti/go,joshsammut/go,dterei/go,Badredapple/go,roth1002/go,CiscoCloud/go,zcwfeng/go,Badredapple/go,devpadawan/go,mwhudson/go,mwhudson/go,jacobhaven/go,zhangg/go,Endika/go,yangzhongj/go,roth1002/go,zouchao2010/go,mdp/go,jmptrader/go,likesea/go,myPublicGit/go,snowsnail/go,ErikDubbelboer/go,roth1002/go,xiuzhifu/go,goodlang/good,linux-on-ibm-z/go,danycoro/go,kakuhiroshi/go,jonathanmarvens/go,ichu501/go,andrewchambers/go,albertjin/golang-go,cookerzhu/go,jacobsa/go,samanalysis/go,theass/go,cainiaocome/go,Jordanzuo/go,CodyGuo/go,beealone/go,danycoro/go,gohin/go,jameskumar/go,ObjectiveJoe/go,uileyar/go,parkdy/go,4ad/go,Jordanzuo/go,cloudflare/go,beealone/go,alex-zhang/go,jonathanmarvens/go,willjunspecial/go,josharian/go,constantine001/go,AALEKH/go,honsiorovskyi/go,gdey/go,b54898533/go,baiyunping333/go,GeorgiCodes/go,rentongzhang/go,springning/go,theif519/go,roth1002/go,famorted/go,sosop/go,binarycrusader/go,rachtsingh/gogojuice,Jordanzuo/go,dterei/go,ericsnowcurrently/go,josharian/go,samanalysis/go,honsiorovskyi/go,jonahglover/go,xiuzhifu/go,binarycrusader/go,suncycheng/go,vishsingh/go,xinhuang327/go,g522342435/go,jdhenke/go,famorted/go,parkdy/go,gohin/go,jonasi/go,cloudflare/go,myPublicGit/go,polyverse-security/go,famorted/go,cyberroadie/go,mikekap/go,danielsoro/go,yuhengye/go,likesea/go,ImJasonH/go,miolini/go,ichu501/go,danycoro/go,shazow/go,vsekhar/elastic-go,alash3al/go,g522342435/go,Samurais/go,danielsoro/go,miolini/go,shazow/go,deft-code/go,NunoEdgarGub1/go,goodlang/good,dterei/go,ifagnosticism/go,ObjectiveJoe/go,snowsnail/go,vsdutka/go,theass/go,springning/go,Pulgafree/go,xujianhai/go,Young55555/go,mdp/go,momchil-velikov/go,JioCloud/go,dafyddcrosby/go,mikekap/go,nakedgc/go,miolini/go,Young55555/go,vanloswang/go,CodyGuo/go,mbrukman/go,snowsnail/go,ImJasonH/go,albertjin/golang-go,derekmarcotte/go,ErikDubbelboer/go,alash3al/go,willjunspecial/go,donnel6809/go,monetate/go,malvira/go,jonathanmarvens/go,kevinc0825/go,g522342435/go,jacobxk/go,xiaobodu/go,andrewchambers/go,ImJasonH/go,springning/go,vsdutka/go,skatsuta/go,NunoEdgarGub1/go,greyhwndz/go,nakedgc/go,CarterTsai/go,shazow/go,qskycolor/go,sndnvaps/go,kim-racktop/go,jonahglover/go,mdp/go,miolini/go,joshsammut/go,momchil-velikov/go,Young55555/go,cookerzhu/go,fjballest/golang,sinuos/go,youprofit/go,devpadawan/go,Young55555/go,danielsoro/go,honsiorovskyi/go,gdey/go,donnel6809/go,chinanjjohn2012/go,yuhengye/go,ericsnowcurrently/go,ifagnosticism/go,skotti/go,suncycheng/go,Samurais/go,ErikDubbelboer/go,greyhwndz/go,cloudflare/go,CarterTsai/go,mgyenik/go,Cofyc/go,shines77/go,jonathanmarvens/go,rachtsingh/gogojuice,samanalysis/go,nakedgc/go,Stan-Lin-/go,mgyenik/go,yuhengye/go,Cofyc/go,ganboing/go-esx,shines77/go,skotti/go,lihuanghai/go,CAFxX/go,jacobxk/go,mwhudson/go,constantine001/go,sosop/go,stormltf/go,zouchao2010/go,youprofit/go,theass/go,ImJasonH/go,b54898533/go,honsiorovskyi/go,XuYunnan/go,youprofit/go,vsekhar/elastic-go,monetate/go,skotti/go,cloudrain21/go,WIZARD-CXY/go,fjballest/golang,Cofyc/go,qskycolor/go,uileyar/go,sosop/go,donnel6809/go,jefby/go,roth1002/go,dafyddcrosby/go,xujianhai/go,alex-zhang/go,binarycrusader/go,momchil-velikov/go,jonahglover/go,ifagnosticism/go,jdhenke/go,jonasi/go,sinuos/go,yangzhongj/go,ichu501/go,Cofyc/go,constantine001/go,Charlesdong/go-1,NichoZhang/go,polyverse-security/go,mbrukman/go,baiyunping333/go,lihuanghai/go,zcwfeng/go,donnel6809/go,jacobxk/go,honsiorovskyi/go,vishsingh/go,theif519/go,AALEKH/go,Samurais/go,ImJasonH/go,mgyenik/go,jacobsa/go,GeorgiCodes/go,cyberroadie/go,cyberroadie/go,mikekap/go,springning/go,andrewchambers/go,jacobxk/go,jdhenke/go,famorted/go,devpadawan/go,jdeng/go,akutz/go,gohin/go,CAFxX/go,monetate/go,nawawi/go,goodlang/good,devpadawan/go,ericsnowcurrently/go,arschles/golang-go,uileyar/go,josharian/go,Pulgafree/go,vishsingh/go,slavau/go,parkdy/go,WIZARD-CXY/go,mdp/go,4ad/go,b54898533/go,cookerzhu/go,danielsoro/go,kevinc0825/go,zouchao2010/go,beealone/go,kakuhiroshi/go,Young55555/go,sosop/go,akutz/go,ericsnowcurrently/go,deft-code/go,mdp/go,Endika/go,alex-zhang/go,beealone/go,sinuos/go,zcwfeng/go,ganboing/go-esx,codestation/go,alex-zhang/go,vanloswang/go,jameskumar/go,josharian/go,derekmarcotte/go,nawawi/go,jmptrader/go,arschles/golang-go,Young55555/go,miolini/go,AALEKH/go,jonasi/go,xujianhai/go,nakedgc/go,miolini/go,theif519/go,binarycrusader/go,Pulgafree/go,arschles/golang-go,kim-racktop/go,Badredapple/go,WIZARD-CXY/go,jdhenke/go,yangzhongj/go,rachtsingh/gogojuice,kevinc0825/go,ObjectiveJoe/go,albertjin/golang-go,vanloswang/go,NunoEdgarGub1/go,chinanjjohn2012/go,shazow/go,mbrukman/go,dpatel06/go,NichoZhang/go,jameskumar/go,CiscoCloud/go,andrewchambers/go,jacobsa/go,jameskumar/go,golang/go,dpatel06/go,momchil-velikov/go,undergrowthlinear/go,beealone/go,jasonxiong/go,derekmarcotte/go,Charlesdong/go-1,leeric92/go,jefby/go,XuYunnan/go,slavau/go,Stan-Lin-/go,CiscoCloud/go,jacobhaven/go,parkdy/go,alex-zhang/go,shines77/go,jonahglover/go,XuYunnan/go,jacobsa/go,rachtsingh/gogojuice,danielsoro/go,greyhwndz/go,cainiaocome/go,NichoZhang/go,NichoZhang/go,vsekhar/elastic-go,baiyunping333/go,zouchao2010/go,odeke-em/go,danielsoro/go,polyverse-security/go,zhangg/go,mwhudson/go,skatsuta/go,kakuhiroshi/go,cookerzhu/go,dterei/go,jonathanmarvens/go,4ad/go,JioCloud/go,zcwfeng/go,qskycolor/go,jasonxiong/go,likesea/go,roth1002/go,rentongzhang/go,mbrukman/go,dpatel06/go,gohin/go,WIZARD-CXY/go,Charlesdong/go-1,sinuos/go,undergrowthlinear/go,christopher-henderson/Go,jefby/go,vsdutka/go,Samurais/go,xinhuang327/go,kim-racktop/go,theif519/go,Jordanzuo/go,binarycrusader/go,alash3al/go,vsekhar/elastic-go,jasonxiong/go,Stan-Lin-/go,willjunspecial/go,alash3al/go,nawawi/go,ganboing/go-esx,ImJasonH/go,CAFxX/go,theass/go,NunoEdgarGub1/go,derekmarcotte/go,springning/go,alex-zhang/go,Endika/go,xinhuang327/go,dafyddcrosby/go,zhangg/go,jefby/go,deft-code/go,ifagnosticism/go,akutz/go,Young55555/go,NunoEdgarGub1/go,cookerzhu/go,albertjin/golang-go,xiaobodu/go,parkdy/go,rentongzhang/go,gdey/go,xujianhai/go,linux-on-ibm-z/go,gohin/go,leeric92/go,willjunspecial/go,devpadawan/go,shines77/go,mbrukman/go,mgyenik/go,skatsuta/go,goodlang/good,CAFxX/go,jacobsa/go,kim-racktop/go,linux-on-ibm-z/go,jacobhaven/go,jasonxiong/go,willjunspecial/go,cloudrain21/go,cyberroadie/go,joshsammut/go,jmptrader/go,cainiaocome/go,gdey/go,shazow/go,ganboing/go-esx,shines77/go,vsdutka/go,beealone/go,dafyddcrosby/go,jonasi/go,jasonxiong/go,mgyenik/go,snowsnail/go,andrewchambers/go,Badredapple/go,alash3al/go,ichu501/go,lihuanghai/go,cloudrain21/go,arschles/golang-go,NunoEdgarGub1/go,codestation/go,cainiaocome/go,zouchao2010/go,myPublicGit/go,rentongzhang/go,ganboing/go-esx,dpatel06/go,constantine001/go,derekmarcotte/go,deft-code/go,vsekhar/elastic-go,ObjectiveJoe/go,Badredapple/go,stormltf/go,jonahglover/go,arschles/golang-go,CiscoCloud/go,jacobxk/go,ifagnosticism/go,josharian/go,roth1002/go,suncycheng/go,CarterTsai/go,gdey/go,CarterTsai/go,albertjin/golang-go,uileyar/go,jdeng/go,JioCloud/go,dafyddcrosby/go,CAFxX/go,jmptrader/go,g522342435/go,ichu501/go,monetate/go,danycoro/go,binarycrusader/go,Charlesdong/go-1,mwhudson/go,kakuhiroshi/go,jonathanmarvens/go,zouchao2010/go,cloudflare/go,joshsammut/go,momchil-velikov/go,XuYunnan/go,danycoro/go,skatsuta/go,GeorgiCodes/go,zcwfeng/go,cookerzhu/go,rachtsingh/gogojuice,willjunspecial/go,b54898533/go,zhangg/go,yangzhongj/go,likesea/go,yangzhongj/go,arschles/go-1,zhangg/go,cainiaocome/go,rachtsingh/gogojuice,codestation/go,donnel6809/go,4ad/go,kevinc0825/go,jmptrader/go,lihuanghai/go,jacobsa/go,greyhwndz/go,zcwfeng/go,xinhuang327/go,zhangg/go,dterei/go,malvira/go,NichoZhang/go,constantine001/go,likesea/go,gdey/go,linux-on-ibm-z/go,arschles/go-1,ifagnosticism/go,donnel6809/go,deft-code/go,ericsnowcurrently/go,constantine001/go,JioCloud/go,yasarkunduz/go,theass/go,snowsnail/go,ifagnosticism/go,xinhuang327/go,sndnvaps/go,beealone/go,malvira/go,fjballest/golang,cloudrain21/go,albertjin/golang-go,leeric92/go,arschles/go-1,polyverse-security/go,theif519/go,lihuanghai/go,dpatel06/go,arschles/golang-go,myPublicGit/go,goodlang/good,skatsuta/go,slavau/go,Pulgafree/go,4ad/go,vsekhar/elastic-go,wangfakang/go-1,youprofit/go,miolini/go,uileyar/go,arschles/go-1,vanloswang/go,sosop/go,skotti/go,likesea/go,CAFxX/go,miolini/go,jonasi/go,derekmarcotte/go,WIZARD-CXY/go,zcwfeng/go,Cofyc/go,sinuos/go,akutz/go,Pulgafree/go,jefby/go,sndnvaps/go,cainiaocome/go,mikekap/go,kevinc0825/go,yasarkunduz/go,ImJasonH/go,slavau/go,albertjin/golang-go,CodyGuo/go,CiscoCloud/go,fjballest/golang,yangzhongj/go,shazow/go,fjballest/golang,yasarkunduz/go,zhangg/go,XuYunnan/go,monetate/go,CAFxX/go,4ad/go,famorted/go,ObjectiveJoe/go,ganboing/go-esx,yuhengye/go,undergrowthlinear/go,Young55555/go,xiaobodu/go,snowsnail/go,CiscoCloud/go,xiuzhifu/go,Badredapple/go,odeke-em/go,binarycrusader/go,jacobhaven/go,dterei/go,monetate/go,wangfakang/go-1,kevinc0825/go,myPublicGit/go,yuhengye/go,jdeng/go,jasonxiong/go,CodyGuo/go,g522342435/go,slavau/go,odeke-em/go,wangfakang/go-1,akutz/go,akutz/go,greyhwndz/go,theif519/go,XuYunnan/go,jameskumar/go,leeric92/go,sinuos/go,Badredapple/go,xiaobodu/go,jdeng/go,CarterTsai/go,nawawi/go,polyverse-security/go,jonahglover/go,yasarkunduz/go,b54898533/go,vishsingh/go,Cofyc/go,Endika/go,kakuhiroshi/go,jacobxk/go,rentongzhang/go,devpadawan/go,cloudrain21/go,jacobxk/go,monetate/go,vsekhar/elastic-go,Jordanzuo/go,GeorgiCodes/go,samanalysis/go,xiuzhifu/go,xiaobodu/go,albertjin/golang-go,nakedgc/go,slavau/go,ErikDubbelboer/go,zhangg/go,famorted/go,jefby/go,wangfakang/go-1,arschles/go-1,Jordanzuo/go,ganboing/go-esx,leeric92/go,josharian/go,4ad/go,xinhuang327/go,springning/go,b54898533/go,suncycheng/go,shines77/go,CodyGuo/go,vishsingh/go,ichu501/go,Endika/go,xiuzhifu/go,deft-code/go,jdeng/go,CodyGuo/go,lihuanghai/go,vanloswang/go,goodlang/good,yangzhongj/go,jacobhaven/go,golang/go,nawawi/go,greyhwndz/go,alash3al/go,sndnvaps/go,alex-zhang/go,GeorgiCodes/go,NunoEdgarGub1/go,dpatel06/go,undergrowthlinear/go,Stan-Lin-/go,baiyunping333/go,AALEKH/go,AALEKH/go,devpadawan/go,xujianhai/go,AALEKH/go,theif519/go,youprofit/go,golang/go,jonathanmarvens/go,gdey/go,vishsingh/go,nakedgc/go,jacobxk/go,uileyar/go,theass/go,malvira/go,akutz/go,lihuanghai/go,codestation/go,NichoZhang/go,gohin/go,cloudrain21/go,shazow/go,qskycolor/go,jameskumar/go,Jordanzuo/go,momchil-velikov/go,baiyunping333/go,joshsammut/go,baiyunping333/go,mwhudson/go,yasarkunduz/go,mdp/go,rentongzhang/go,ganboing/go-esx,danycoro/go,codestation/go,mikekap/go,CodyGuo/go,polyverse-security/go,Endika/go,famorted/go,4ad/go,cainiaocome/go,skotti/go,xujianhai/go,cloudflare/go,jdhenke/go,honsiorovskyi/go,wangfakang/go-1,kakuhiroshi/go,stormltf/go,goodlang/good,Charlesdong/go-1,suncycheng/go,xinhuang327/go,sinuos/go,dafyddcrosby/go,yuhengye/go,sndnvaps/go,binarycrusader/go,ifagnosticism/go,stormltf/go,Endika/go,ericsnowcurrently/go,qskycolor/go,stormltf/go,youprofit/go,cyberroadie/go,malvira/go,xinhuang327/go,joshsammut/go,myPublicGit/go,mgyenik/go,undergrowthlinear/go,CiscoCloud/go,jdhenke/go,jacobhaven/go,jdhenke/go,odeke-em/go,odeke-em/go,suncycheng/go,stormltf/go,arschles/go-1,nakedgc/go,rentongzhang/go,theif519/go,uileyar/go,ichu501/go,xiaobodu/go,andrewchambers/go,myPublicGit/go,chinanjjohn2012/go,greyhwndz/go,constantine001/go,Jordanzuo/go,kakuhiroshi/go,Badredapple/go,myPublicGit/go,undergrowthlinear/go,golang/go,theass/go,jonasi/go,dterei/go,famorted/go,xiuzhifu/go,odeke-em/go,nawawi/go,ObjectiveJoe/go,joshsammut/go,mikekap/go,baiyunping333/go,youprofit/go,derekmarcotte/go,ericsnowcurrently/go,snowsnail/go,rachtsingh/gogojuice,xiaobodu/go,xiuzhifu/go,Stan-Lin-/go,jefby/go,yuhengye/go,chinanjjohn2012/go,vsdutka/go,linux-on-ibm-z/go,Stan-Lin-/go,chinanjjohn2012/go,jdeng/go,jonasi/go,parkdy/go,vanloswang/go,willjunspecial/go,kim-racktop/go,golang/go,WIZARD-CXY/go,jefby/go,akutz/go,CarterTsai/go,ImJasonH/go,samanalysis/go,mikekap/go,xiaobodu/go,jacobsa/go,CodyGuo/go,xujianhai/go,zouchao2010/go,jacobhaven/go,beealone/go,kim-racktop/go,rachtsingh/gogojuice,golang/go,polyverse-security/go,qskycolor/go,sinuos/go,gdey/go,dpatel06/go,nawawi/go,sosop/go,fjballest/golang,Samurais/go,cyberroadie/go,cookerzhu/go,jonasi/go,vsdutka/go,chinanjjohn2012/go,dafyddcrosby/go,deft-code/go,Charlesdong/go-1,wangfakang/go-1,uileyar/go,shines77/go,arschles/go-1,fjballest/golang,nakedgc/go,cookerzhu/go,jasonxiong/go,leeric92/go,dafyddcrosby/go,honsiorovskyi/go,JioCloud/go,AALEKH/go,linux-on-ibm-z/go,alash3al/go,xujianhai/go,yuhengye/go,kevinc0825/go,monetate/go,AALEKH/go,Stan-Lin-/go,leeric92/go,mdp/go,kim-racktop/go,vsdutka/go,Samurais/go,kakuhiroshi/go,b54898533/go,fjballest/golang,Cofyc/go,springning/go,kim-racktop/go,andrewchambers/go,codestation/go,skotti/go,polyverse-security/go,malvira/go,momchil-velikov/go,yasarkunduz/go,undergrowthlinear/go,ErikDubbelboer/go,mbrukman/go,malvira/go,GeorgiCodes/go,Cofyc/go,ObjectiveJoe/go,gohin/go,zouchao2010/go,baiyunping333/go,cyberroadie/go,GeorgiCodes/go,mbrukman/go,danielsoro/go,alex-zhang/go,snowsnail/go,JioCloud/go,chinanjjohn2012/go,stormltf/go,golang/go,stormltf/go,jonahglover/go,yangzhongj/go,jdeng/go,josharian/go,Endika/go,mgyenik/go,lihuanghai/go,mgyenik/go,theass/go,qskycolor/go,joshsammut/go,samanalysis/go,kevinc0825/go,gohin/go,jameskumar/go,dpatel06/go,ErikDubbelboer/go,Samurais/go,danycoro/go,mwhudson/go,constantine001/go,skatsuta/go,sosop/go,cloudflare/go,zcwfeng/go,Charlesdong/go-1,jonathanmarvens/go,linux-on-ibm-z/go,undergrowthlinear/go,b54898533/go,JioCloud/go,vsdutka/go,samanalysis/go,jmptrader/go,suncycheng/go,jmptrader/go,WIZARD-CXY/go,XuYunnan/go,honsiorovskyi/go,codestation/go,WIZARD-CXY/go,shazow/go,arschles/golang-go,suncycheng/go,vanloswang/go,xiuzhifu/go,CAFxX/go,donnel6809/go,likesea/go,wangfakang/go-1,ichu501/go,danielsoro/go,goodlang/good,ObjectiveJoe/go,momchil-velikov/go,codestation/go,Charlesdong/go-1,cainiaocome/go,NunoEdgarGub1/go,Pulgafree/go,qskycolor/go,Pulgafree/go,youprofit/go,Pulgafree/go,cyberroadie/go,jacobsa/go,Samurais/go,mbrukman/go,NichoZhang/go,vishsingh/go,jmptrader/go,parkdy/go,slavau/go,mikekap/go,parkdy/go,malvira/go,sndnvaps/go,arschles/go-1,vsekhar/elastic-go,cloudrain21/go,vishsingh/go,cloudrain21/go,deft-code/go,golang/go,ErikDubbelboer/go,greyhwndz/go,josharian/go,willjunspecial/go,jacobhaven/go,JioCloud/go,odeke-em/go,springning/go,linux-on-ibm-z/go,CarterTsai/go,sndnvaps/go,g522342435/go,slavau/go,jdeng/go,NichoZhang/go,wangfakang/go-1,danycoro/go,jameskumar/go,alash3al/go,Stan-Lin-/go,odeke-em/go,XuYunnan/go,vanloswang/go,CiscoCloud/go