File tree 3 files changed +23
-0
lines changed
3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2537,6 +2537,8 @@ func execute(gp *g, inheritTime bool) {
2537
2537
_g_ .m .p .ptr ().schedtick ++
2538
2538
}
2539
2539
// BEGIN - CockroachDB tweaks
2540
+ // Accounting for the new G, the one we're scheduling into.
2541
+ gp .lastSchedTime = nanotime ()
2540
2542
if gp .taskGroupCtx != nil {
2541
2543
atomic .Xadd64 (& gp .taskGroupCtx .schedtick , 1 )
2542
2544
}
@@ -3185,6 +3187,15 @@ top:
3185
3187
func dropg () {
3186
3188
_g_ := getg ()
3187
3189
3190
+ // BEGIN - CockroachDB tweaks
3191
+ // Accounting for the past G, the one we're scheduling away from.
3192
+ if _g_ .m .curg != nil && _g_ .m .curg .taskGroupCtx != nil {
3193
+ endTickTime := nanotime ()
3194
+ lastTime := _g_ .m .curg .lastSchedTime
3195
+ atomic .Xadd64 (& _g_ .m .curg .taskGroupCtx .nanos , endTickTime - lastTime )
3196
+ }
3197
+ // END - CockroachDB tweaks
3198
+
3188
3199
setMNoWB (& _g_ .m .curg .m , nil )
3189
3200
setGNoWB (& _g_ .m .curg , nil )
3190
3201
}
Original file line number Diff line number Diff line change @@ -474,6 +474,10 @@ type g struct {
474
474
// BEGIN - CockroachDB tweaks
475
475
taskGroupId int64 // inherited goroutine task group ID. Typically set from the task group root's own goroutine ID via SetGoroutineGroupID(GetGID()).
476
476
taskGroupCtx * t // inherited task group context.
477
+
478
+ // lastSchedTime is the nanotime of the last time a goroutine
479
+ // was scheduled into a P.
480
+ lastSchedTime int64
477
481
// END - CockroachDB tweaks
478
482
479
483
// Per-G GC state
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import "runtime/internal/atomic"
10
10
11
11
type t struct {
12
12
schedtick uint64 // incremented atomically on every scheduler call
13
+ nanos uint64 // cumulative slices of CPU time used by the task group, in nanoseconds
13
14
}
14
15
15
16
// defaulTaskGroupCtx is used for top level goroutines without a task group yet.
@@ -35,3 +36,10 @@ func GetInternalTaskGroupSchedTicks(taskGroup InternalTaskGroup) uint64 {
35
36
tg := (* t )(taskGroup )
36
37
return atomic .Load64 (& tg .schedtick )
37
38
}
39
+
40
+ // GetInternalTaskGroupNanos retrieves the number of CPU nanoseconds used by
41
+ // all goroutines in the given task group.
42
+ func GetInternalTaskGroupNanos (taskGroup InternalTaskGroup ) uint64 {
43
+ tg := (* t )(taskGroup )
44
+ return atomic .Load64 (& tg .nanos )
45
+ }
You can’t perform that action at this time.
0 commit comments