Commit 7453497
committed
runtime: don't count nGsyscallNoP for extra Ms in C
In #76435, it turns out that the new metric
/sched/goroutines/not-in-go:goroutines counts C threads that have called
into Go before (on Linux) as not-in-go goroutines. The reason for this
is that the M is still attached to the C thread on Linux as an
optimization, so we don't go through all the trouble of detaching the M
and, of course, decrementing nGsyscallNoP.
There's an easy fix to this accounting issue. The flag on the M,
isExtraInC, says whether a thread with an extra M attached no longer has
any Go on its (logical) stack. When we take the P from an M in this
state, we simply just don't increment nGsyscallNoP. When it calls back
into Go, we similarly skip the decrement to nGsyscallNoP.
This is more efficient than alternatives, like always updating
nGsyscallNoP in cgocallbackg, since that would add a new
read-modify-write atomic onto that fast path. It does mean we count
threads in C with a P still attached as not-in-go, but this transient in
most real programs, assuming the thread indeed does not call back into
Go any time soon.
Fixes #76435.
Change-Id: Id05563bacbe35d3fae17d67fb5ed45fa43fa0548
Reviewed-on: https://go-review.googlesource.com/c/go/+/726964
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>1 parent f3d572d commit 7453497
File tree
4 files changed
+169
-10
lines changed- src/runtime
- testdata/testprogcgo
4 files changed
+169
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1584 | 1584 | | |
1585 | 1585 | | |
1586 | 1586 | | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2433 | 2433 | | |
2434 | 2434 | | |
2435 | 2435 | | |
2436 | | - | |
| 2436 | + | |
2437 | 2437 | | |
2438 | 2438 | | |
2439 | 2439 | | |
| |||
2455 | 2455 | | |
2456 | 2456 | | |
2457 | 2457 | | |
2458 | | - | |
| 2458 | + | |
| 2459 | + | |
2459 | 2460 | | |
2460 | 2461 | | |
2461 | 2462 | | |
| |||
2590 | 2591 | | |
2591 | 2592 | | |
2592 | 2593 | | |
2593 | | - | |
| 2594 | + | |
2594 | 2595 | | |
2595 | 2596 | | |
2596 | 2597 | | |
| |||
4732 | 4733 | | |
4733 | 4734 | | |
4734 | 4735 | | |
4735 | | - | |
| 4736 | + | |
4736 | 4737 | | |
4737 | 4738 | | |
4738 | 4739 | | |
| |||
4763 | 4764 | | |
4764 | 4765 | | |
4765 | 4766 | | |
4766 | | - | |
| 4767 | + | |
4767 | 4768 | | |
4768 | 4769 | | |
4769 | 4770 | | |
| |||
5001 | 5002 | | |
5002 | 5003 | | |
5003 | 5004 | | |
| 5005 | + | |
5004 | 5006 | | |
5005 | | - | |
5006 | 5007 | | |
5007 | 5008 | | |
5008 | 5009 | | |
| |||
5017 | 5018 | | |
5018 | 5019 | | |
5019 | 5020 | | |
5020 | | - | |
| 5021 | + | |
5021 | 5022 | | |
5022 | 5023 | | |
5023 | 5024 | | |
| |||
5043 | 5044 | | |
5044 | 5045 | | |
5045 | 5046 | | |
5046 | | - | |
| 5047 | + | |
5047 | 5048 | | |
5048 | 5049 | | |
5049 | 5050 | | |
| |||
5081 | 5082 | | |
5082 | 5083 | | |
5083 | 5084 | | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
| 5104 | + | |
| 5105 | + | |
| 5106 | + | |
| 5107 | + | |
| 5108 | + | |
| 5109 | + | |
| 5110 | + | |
| 5111 | + | |
| 5112 | + | |
| 5113 | + | |
| 5114 | + | |
| 5115 | + | |
| 5116 | + | |
| 5117 | + | |
| 5118 | + | |
| 5119 | + | |
5084 | 5120 | | |
5085 | 5121 | | |
5086 | 5122 | | |
| |||
6758 | 6794 | | |
6759 | 6795 | | |
6760 | 6796 | | |
6761 | | - | |
| 6797 | + | |
6762 | 6798 | | |
6763 | 6799 | | |
6764 | 6800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
945 | 945 | | |
946 | 946 | | |
947 | 947 | | |
948 | | - | |
| 948 | + | |
949 | 949 | | |
950 | 950 | | |
951 | 951 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments