Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions cannon/mipsevm/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package mipsevm
import "github.com/ethereum/go-ethereum/common/hexutil"

type DebugInfo struct {
Pages int `json:"pages"`
MemoryUsed hexutil.Uint64 `json:"memory_used"`
NumPreimageRequests int `json:"num_preimage_requests"`
TotalPreimageSize int `json:"total_preimage_size"`
TotalSteps uint64 `json:"total_steps"`
Pages int `json:"pages"`
MemoryUsed hexutil.Uint64 `json:"memory_used"`
NumPreimageRequests int `json:"num_preimage_requests"`
TotalPreimageSize int `json:"total_preimage_size"`
TotalSteps uint64 `json:"total_steps"`
InstructionCacheMissCount uint64 `json:"instruction_cache_miss_count"`
HighestICacheMissPC hexutil.Uint64 `json:"highest_icache_miss_pc"`
// Multithreading-related stats below
RmwSuccessCount uint64 `json:"rmw_success_count"`
RmwFailCount uint64 `json:"rmw_fail_count"`
Expand Down
2 changes: 2 additions & 0 deletions cannon/mipsevm/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestDebugInfo_Serialization(t *testing.T) {
NumPreimageRequests: 3,
TotalPreimageSize: 4,
TotalSteps: 123456,
InstructionCacheMissCount: 10,
HighestICacheMissPC: 11,
RmwSuccessCount: 5,
RmwFailCount: 6,
MaxStepsBetweenLLAndSC: 7,
Expand Down
1 change: 1 addition & 0 deletions cannon/mipsevm/multithreaded/mips.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ func (m *InstrumentedState) doMipsStep() error {
insn, opcode, fun = decoded.insn, decoded.opcode, decoded.fun
} else {
// PC is outside eager region
m.statsTracker.trackInstructionCacheMiss(pc)
insn, opcode, fun = exec.GetInstructionDetails(pc, m.state.Memory)
}

Expand Down
14 changes: 14 additions & 0 deletions cannon/mipsevm/multithreaded/stats.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package multithreaded

import (
"github.com/ethereum/go-ethereum/common/hexutil"
lru "github.com/hashicorp/golang-lru/v2/simplelru"

"github.com/ethereum-optimism/optimism/cannon/mipsevm"
Expand All @@ -14,6 +15,7 @@ type StatsTracker interface {
trackReservationInvalidation()
trackForcedPreemption()
trackThreadActivated(tid Word, step uint64)
trackInstructionCacheMiss(pc Word)
populateDebugInfo(debugInfo *mipsevm.DebugInfo)
}

Expand All @@ -31,6 +33,7 @@ func (s *noopStatsTracker) trackReservationInvalidation() {}
func (s *noopStatsTracker) trackForcedPreemption() {}
func (s *noopStatsTracker) trackThreadActivated(tid Word, step uint64) {}
func (s *noopStatsTracker) populateDebugInfo(debugInfo *mipsevm.DebugInfo) {}
func (s *noopStatsTracker) trackInstructionCacheMiss(pc Word) {}

var _ StatsTracker = (*noopStatsTracker)(nil)

Expand All @@ -48,6 +51,8 @@ type statsTrackerImpl struct {
reservationInvalidationCount uint64
forcedPreemptionCount uint64
idleStepCountThread0 uint64
icacheMissCount uint64
highestICacheMissPC Word
}

func (s *statsTrackerImpl) populateDebugInfo(debugInfo *mipsevm.DebugInfo) {
Expand All @@ -57,6 +62,8 @@ func (s *statsTrackerImpl) populateDebugInfo(debugInfo *mipsevm.DebugInfo) {
debugInfo.ReservationInvalidationCount = s.reservationInvalidationCount
debugInfo.ForcedPreemptionCount = s.forcedPreemptionCount
debugInfo.IdleStepCountThread0 = s.idleStepCountThread0
debugInfo.InstructionCacheMissCount = s.icacheMissCount
debugInfo.HighestICacheMissPC = hexutil.Uint64(s.highestICacheMissPC)
}

func (s *statsTrackerImpl) trackLL(threadId Word, step uint64) {
Expand Down Expand Up @@ -105,6 +112,13 @@ func (s *statsTrackerImpl) trackThreadActivated(tid Word, step uint64) {
s.activeThreadId = tid
}

func (s *statsTrackerImpl) trackInstructionCacheMiss(pc Word) {
s.icacheMissCount += 1
if pc > s.highestICacheMissPC {
s.highestICacheMissPC = pc
}
}

func NewStatsTracker() StatsTracker {
return newStatsTracker(5)
}
Expand Down
2 changes: 2 additions & 0 deletions op-challenger/game/fault/trace/vm/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (e *Executor) DoGenerateProof(ctx context.Context, dir string, begin uint64
memoryUsed = fmt.Sprintf("%d", uint64(info.MemoryUsed))
e.metrics.RecordMemoryUsed(uint64(info.MemoryUsed))
e.metrics.RecordSteps(info.Steps)
e.metrics.RecordInstructionCacheMissCount(info.InstructionCacheMissCount)
e.metrics.RecordRmwSuccessCount(info.RmwSuccessCount)
e.metrics.RecordRmwFailCount(info.RmwFailCount)
e.metrics.RecordMaxStepsBetweenLLAndSC(info.MaxStepsBetweenLLAndSC)
Expand All @@ -215,6 +216,7 @@ func (e *Executor) DoGenerateProof(ctx context.Context, dir string, begin uint64
type debugInfo struct {
MemoryUsed hexutil.Uint64 `json:"memory_used"`
Steps uint64 `json:"total_steps"`
InstructionCacheMissCount uint64 `json:"instruction_cache_miss_count"`
RmwSuccessCount uint64 `json:"rmw_success_count"`
RmwFailCount uint64 `json:"rmw_fail_count"`
MaxStepsBetweenLLAndSC uint64 `json:"max_steps_between_ll_and_sc"`
Expand Down
23 changes: 14 additions & 9 deletions op-challenger/game/fault/trace/vm/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,26 @@ func newMetrics() *capturingVmMetrics {
}

type capturingVmMetrics struct {
executionTimeRecordCount int
memoryUsed hexutil.Uint64
steps uint64
rmwSuccessCount uint64
rmwFailCount uint64
maxStepsBetweenLLAndSC uint64
reservationInvalidations uint64
forcedPreemptions uint64
idleStepsThread0 uint64
executionTimeRecordCount int
memoryUsed hexutil.Uint64
steps uint64
instructionCacheMissCount uint64
rmwSuccessCount uint64
rmwFailCount uint64
maxStepsBetweenLLAndSC uint64
reservationInvalidations uint64
forcedPreemptions uint64
idleStepsThread0 uint64
}

func (c *capturingVmMetrics) RecordSteps(val uint64) {
c.steps = val
}

func (c *capturingVmMetrics) RecordInstructionCacheMissCount(val uint64) {
c.instructionCacheMissCount = val
}

func (c *capturingVmMetrics) RecordExecutionTime(t time.Duration) {
c.executionTimeRecordCount += 1
}
Expand Down
30 changes: 21 additions & 9 deletions op-challenger/metrics/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type VmMetricer interface {
RecordVmMemoryUsed(vmType string, memoryUsed uint64)
RecordVmRmwSuccessCount(vmType string, val uint64)
RecordVmSteps(vmType string, val uint64)
RecordVmInstructionCacheMissCount(vmType string, val uint64)
RecordVmRmwFailCount(vmType string, val uint64)
RecordVmMaxStepsBetweenLLAndSC(vmType string, val uint64)
RecordVmReservationInvalidationCount(vmType string, val uint64)
Expand All @@ -25,6 +26,7 @@ type TypedVmMetricer interface {
RecordExecutionTime(t time.Duration)
RecordMemoryUsed(memoryUsed uint64)
RecordSteps(val uint64)
RecordInstructionCacheMissCount(val uint64)
RecordRmwSuccessCount(val uint64)
RecordRmwFailCount(val uint64)
RecordMaxStepsBetweenLLAndSC(val uint64)
Expand All @@ -34,15 +36,16 @@ type TypedVmMetricer interface {
}

type VmMetrics struct {
vmExecutionTime *prometheus.HistogramVec
vmMemoryUsed *prometheus.HistogramVec
vmSteps *prometheus.GaugeVec
vmRmwSuccessCount *prometheus.GaugeVec
vmRmwFailCount *prometheus.GaugeVec
vmMaxStepsBetweenLLAndSC *prometheus.GaugeVec
vmReservationInvalidations *prometheus.GaugeVec
vmForcedPreemptions *prometheus.GaugeVec
vmIdleStepsThread0 *prometheus.GaugeVec
vmExecutionTime *prometheus.HistogramVec
vmMemoryUsed *prometheus.HistogramVec
vmSteps *prometheus.GaugeVec
vmInstructionCacheMissCount *prometheus.GaugeVec
vmRmwSuccessCount *prometheus.GaugeVec
vmRmwFailCount *prometheus.GaugeVec
vmMaxStepsBetweenLLAndSC *prometheus.GaugeVec
vmReservationInvalidations *prometheus.GaugeVec
vmForcedPreemptions *prometheus.GaugeVec
vmIdleStepsThread0 *prometheus.GaugeVec
}

var _ VmMetricer = (*VmMetrics)(nil)
Expand All @@ -59,6 +62,10 @@ func (m *VmMetrics) RecordVmSteps(vmType string, val uint64) {
m.vmSteps.WithLabelValues(vmType).Set(float64(val))
}

func (m *VmMetrics) RecordVmInstructionCacheMissCount(vmType string, val uint64) {
m.vmInstructionCacheMissCount.WithLabelValues(vmType).Set(float64(val))
}

func (m *VmMetrics) RecordVmRmwSuccessCount(vmType string, val uint64) {
m.vmRmwSuccessCount.WithLabelValues(vmType).Set(float64(val))
}
Expand Down Expand Up @@ -145,6 +152,7 @@ var _ VmMetricer = NoopVmMetrics{}
func (n NoopVmMetrics) RecordVmExecutionTime(vmType string, t time.Duration) {}
func (n NoopVmMetrics) RecordVmMemoryUsed(vmType string, memoryUsed uint64) {}
func (n NoopVmMetrics) RecordVmSteps(vmType string, val uint64) {}
func (n NoopVmMetrics) RecordVmInstructionCacheMissCount(vmType string, val uint64) {}
func (n NoopVmMetrics) RecordVmRmwSuccessCount(vmType string, val uint64) {}
func (n NoopVmMetrics) RecordVmRmwFailCount(vmType string, val uint64) {}
func (n NoopVmMetrics) RecordVmMaxStepsBetweenLLAndSC(vmType string, val uint64) {}
Expand All @@ -171,6 +179,10 @@ func (m *typedVmMetricsImpl) RecordSteps(val uint64) {
m.m.RecordVmSteps(m.vmType, val)
}

func (m *typedVmMetricsImpl) RecordInstructionCacheMissCount(val uint64) {
m.m.RecordVmInstructionCacheMissCount(m.vmType, val)
}

func (m *typedVmMetricsImpl) RecordRmwSuccessCount(val uint64) {
m.m.RecordVmRmwSuccessCount(m.vmType, val)
}
Expand Down