aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/cgocall.go12
-rw-r--r--src/runtime/proc.go4
-rw-r--r--src/runtime/runtime1.go2
3 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go
index 0effcb8053..326674cd2e 100644
--- a/src/runtime/cgocall.go
+++ b/src/runtime/cgocall.go
@@ -425,6 +425,13 @@ func cgocallbackg1(fn, frame unsafe.Pointer, ctxt uintptr) {
restore := true
defer unwindm(&restore)
+ var ditAlreadySet bool
+ if debug.dataindependenttiming == 1 && gp.m.isextra {
+ // We only need to enable DIT for threads that were created by C, as it
+ // should already by enabled on threads that were created by Go.
+ ditAlreadySet = sys.EnableDIT()
+ }
+
if raceenabled {
raceacquire(unsafe.Pointer(&racecgosync))
}
@@ -440,6 +447,11 @@ func cgocallbackg1(fn, frame unsafe.Pointer, ctxt uintptr) {
racereleasemerge(unsafe.Pointer(&racecgosync))
}
+ if debug.dataindependenttiming == 1 && !ditAlreadySet {
+ // Only unset DIT if it wasn't already enabled when cgocallback was called.
+ sys.DisableDIT()
+ }
+
// Do not unwind m->g0->sched.sp.
// Our caller, cgocallback, will do that.
restore = false
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 3f360ef129..17c375de1a 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -1848,6 +1848,10 @@ func mstart1() {
mstartm0()
}
+ if debug.dataindependenttiming == 1 {
+ sys.EnableDIT()
+ }
+
if fn := gp.m.mstartfn; fn != nil {
fn()
}
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go
index 56886ea571..7a092e8039 100644
--- a/src/runtime/runtime1.go
+++ b/src/runtime/runtime1.go
@@ -331,6 +331,7 @@ var debug struct {
traceadvanceperiod int32
traceCheckStackOwnership int32
profstackdepth int32
+ dataindependenttiming int32
// debug.malloc is used as a combined debug check
// in the malloc function and should be set
@@ -367,6 +368,7 @@ var dbgvars = []*dbgVar{
{name: "asynctimerchan", atomic: &debug.asynctimerchan},
{name: "cgocheck", value: &debug.cgocheck},
{name: "clobberfree", value: &debug.clobberfree},
+ {name: "dataindependenttiming", value: &debug.dataindependenttiming},
{name: "disablethp", value: &debug.disablethp},
{name: "dontfreezetheworld", value: &debug.dontfreezetheworld},
{name: "efence", value: &debug.efence},