From 013ad89c9bc5c2903c535d217af242063c797251 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Tue, 12 Jul 2011 01:25:14 -0400 Subject: [PATCH] runtime: eliminate false sharing on runtime.goidgen runtime.goidgen can be quite frequently modified and shares cache line with the following variables, it leads to false sharing. 50c6b0 b nfname 50c6b4 b nfunc 50c6b8 b nfunc$17 50c6bc b nhist$17 50c6c0 B runtime.checking 50c6c4 B runtime.gcwaiting 50c6c8 B runtime.goidgen 50c6cc B runtime.gomaxprocs 50c6d0 B runtime.panicking 50c6d4 B strconv.IntSize 50c6d8 B src/pkg/runtime/_xtest_.ss 50c6e0 B src/pkg/runtime/_xtest_.stop 50c6e8 b addrfree 50c6f0 b addrmem 50c6f8 b argv R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4673054 --- src/pkg/runtime/proc.c | 5 +++-- src/pkg/runtime/runtime.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index 814a68e2ec6..76356c11bc3 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -56,6 +56,7 @@ struct Sched { Lock; G *gfree; // available gs (status == Gdead) + int32 goidgen; G *ghead; // gs waiting to run G *gtail; @@ -907,8 +908,8 @@ runtime·newproc1(byte *fn, byte *argp, int32 narg, int32 nret, void *callerpc) newg->gopc = (uintptr)callerpc; runtime·sched.gcount++; - runtime·goidgen++; - newg->goid = runtime·goidgen; + runtime·sched.goidgen++; + newg->goid = runtime·sched.goidgen; newprocreadylocked(newg); schedunlock(); diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index 48cd482dd90..83ea0f9ce2e 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -369,7 +369,6 @@ extern Alg runtime·algarray[Amax]; extern String runtime·emptystring; G* runtime·allg; M* runtime·allm; -int32 runtime·goidgen; extern int32 runtime·gomaxprocs; extern uint32 runtime·panicking; extern int32 runtime·gcwaiting; // gc is waiting to run