diff options
author | Michael Pratt <mpratt@google.com> | 2019-04-03 18:05:30 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-04-03 18:06:36 -0700 |
commit | 9cf33960fc61309140a67587748570a36e78fc75 (patch) | |
tree | a11e598bad1d28c22393d110850200dfd3482c93 /pkg/sentry/kernel/task_run.go | |
parent | 61d8c361c6639ecbc262076be9f1214dd82065d1 (diff) |
Only CopyOut CPU when it changes
This will save copies when preemption is not caused by a CPU migration.
PiperOrigin-RevId: 241844399
Change-Id: I2ba3b64aa377846ab763425bd59b61158f576851
Diffstat (limited to 'pkg/sentry/kernel/task_run.go')
-rw-r--r-- | pkg/sentry/kernel/task_run.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/pkg/sentry/kernel/task_run.go b/pkg/sentry/kernel/task_run.go index 596b9aa16..359986b21 100644 --- a/pkg/sentry/kernel/task_run.go +++ b/pkg/sentry/kernel/task_run.go @@ -21,6 +21,7 @@ import ( "gvisor.googlesource.com/gvisor/pkg/abi/linux" "gvisor.googlesource.com/gvisor/pkg/sentry/arch" + "gvisor.googlesource.com/gvisor/pkg/sentry/hostcpu" ktime "gvisor.googlesource.com/gvisor/pkg/sentry/kernel/time" "gvisor.googlesource.com/gvisor/pkg/sentry/memmap" "gvisor.googlesource.com/gvisor/pkg/sentry/platform" @@ -169,12 +170,16 @@ func (*runApp) execute(t *Task) taskRunState { if t.rseqPreempted { t.rseqPreempted = false if t.rseqCPUAddr != 0 { - if err := t.rseqCopyOutCPU(); err != nil { - t.Warningf("Failed to copy CPU to %#x for RSEQ: %v", t.rseqCPUAddr, err) - t.forceSignal(linux.SIGSEGV, false) - t.SendSignal(sigPriv(linux.SIGSEGV)) - // Re-enter the task run loop for signal delivery. - return (*runApp)(nil) + cpu := int32(hostcpu.GetCPU()) + if t.rseqCPU != cpu { + t.rseqCPU = cpu + if err := t.rseqCopyOutCPU(); err != nil { + t.Warningf("Failed to copy CPU to %#x for RSEQ: %v", t.rseqCPUAddr, err) + t.forceSignal(linux.SIGSEGV, false) + t.SendSignal(sigPriv(linux.SIGSEGV)) + // Re-enter the task run loop for signal delivery. + return (*runApp)(nil) + } } } t.rseqInterrupt() |