• Kirill Smelkov's avatar
    tracing/runtime: Add support for Go1.23 (preliminary, incomplete) · 48920809
    Kirill Smelkov authored
    Generate g for today's state of Go 1.23 (go1.23rc1-0-g7dff7439dc).
    Compared to Go1.22 many new fields and several new types were
    introduced as shown by the diff below.
    
    Regenerated files stay without changes for Go1.22 and previous releases.
    
    Support for Go1.23 remains incomplete because currently there is no way to
    access runtime.stopTheWorld via go:linkname :
    
    https://github.com/golang/go/issues/68167#issuecomment-2192263282
    
    ---- 8< ----
    diff --git a/zruntime_g_go1.22.go b/zruntime_g_go1.23.go
    index 910382b..4aa6799 100644
    --- a/zruntime_g_go1.22.go
    +++ b/zruntime_g_go1.23.go
    @@ -1,7 +1,7 @@
     // Code generated by g_typedef; DO NOT EDIT.
    
    -//go:build go1.22 && !go1.23
    -// +build go1.22,!go1.23
    +//go:build go1.23 && !go1.24
    +// +build go1.23,!go1.24
    
     package xruntime
    
    @@ -26,6 +26,7 @@ type g struct {
     	sched     gobuf
     	syscallsp uintptr // if status==Gsyscall, syscallsp = sched.sp to use during gc
     	syscallpc uintptr // if status==Gsyscall, syscallpc = sched.pc to use during gc
    +	syscallbp uintptr // if status==Gsyscall, syscallbp = sched.bp to use in fpTraceback
     	stktopsp  uintptr // expected sp at top of stack, to check in traceback
     	// param is a generic pointer parameter field used to pass
     	// values in particular contexts where other storage for the
    @@ -95,14 +96,15 @@ type g struct {
     	cgoCtxt       []uintptr      // cgo traceback context
     	labels        unsafe.Pointer // profiler labels
     	timer         *timer         // cached timer for time.Sleep
    +	sleepWhen     int64          // when to sleep until
     	selectDone    atomic.Uint32  // are we participating in a select and did someone win the race?
    
    -	coroarg *coro // argument during coroutine transfers
    -
     	// goroutineProfiled indicates the status of this goroutine's stack for the
     	// current in-progress goroutine profile
     	goroutineProfiled goroutineProfileStateHolder
    
    +	coroarg *coro // argument during coroutine transfers
    +
     	// Per-G tracer state.
     	trace gTraceState
    
    @@ -182,27 +184,51 @@ type funcval struct {
     	fn uintptr
     }
     type timer struct {
    -	// If this timer is on a heap, which P's heap it is on.
    -	// puintptr rather than *p to match uintptr in the versions
    -	// of this struct defined in other packages.
    -	pp puintptr
    +	// mu protects reads and writes to all fields, with exceptions noted below.
    +	mu mutex
    +
    +	astate  uint8  // atomic copy of state bits at last unlock
    +	state   uint8  // state bits
    +	isChan  bool   // timer has a channel; immutable; can be read without lock
    +	blocked uint32 // number of goroutines blocked on timer's channel
    
     	// Timer wakes up at when, and then at when+period, ... (period > 0 only)
    -	// each time calling f(arg, now) in the timer goroutine, so f must be
    +	// each time calling f(arg, seq, delay) in the timer goroutine, so f must be
     	// a well-behaved function and not block.
     	//
    -	// when must be positive on an active timer.
    +	// The arg and seq are client-specified opaque arguments passed back to f.
    +	// When used from netpoll, arg and seq have meanings defined by netpoll
    +	// and are completely opaque to this code; in that context, seq is a sequence
    +	// number to recognize and squech stale function invocations.
    +	// When used from package time, arg is a channel (for After, NewTicker)
    +	// or the function to call (for AfterFunc) and seq is unused (0).
    +	//
    +	// Package time does not know about seq, but if this is a channel timer (t.isChan == true),
    +	// this file uses t.seq as a sequence number to recognize and squelch
    +	// sends that correspond to an earlier (stale) timer configuration,
    +	// similar to its use in netpoll. In this usage (that is, when t.isChan == true),
    +	// writes to seq are protected by both t.mu and t.sendLock,
    +	// so reads are allowed when holding either of the two mutexes.
    +	//
    +	// The delay argument is nanotime() - t.when, meaning the delay in ns between
    +	// when the timer should have gone off and now. Normally that amount is
    +	// small enough not to matter, but for channel timers that are fed lazily,
    +	// the delay can be arbitrarily long; package time subtracts it out to make
    +	// it look like the send happened earlier than it actually did.
    +	// (No one looked at the channel since then, or the send would have
    +	// not happened so late, so no one can tell the difference.)
     	when   int64
     	period int64
    -	f      func(interface{}, uintptr)
    +	f      func(arg interface{}, seq uintptr, delay int64)
     	arg    interface{}
     	seq    uintptr
    
    -	// What to set the when field to in timerModifiedXX status.
    -	nextwhen int64
    +	// If non-nil, the timers containing t.
    +	ts *timers
    
    -	// The status field holds one of the values below.
    -	status atomic.Uint32
    +	// sendLock protects sends on the timer's channel.
    +	// Not used for async (pre-Go 1.23) behavior when debug.asynctimerchan.Load() != 0.
    +	sendLock mutex
     }
     type guintptr uintptr
     type puintptr uintptr
    @@ -221,6 +247,11 @@ type traceTime uint64
     type coro struct {
     	gp guintptr
     	f  func(*coro)
    +
    +	// State for validating thread-lock interactions.
    +	mp        *m
    +	lockedExt uint32 // mp's external LockOSThread counter at coro creation time.
    +	lockedInt uint32 // mp's internal lockOSThread counter at coro creation time.
     }
     type traceSchedResourceState struct {
     	// statusTraced indicates whether a status event was traced for this resource
    @@ -240,7 +271,18 @@ type traceSchedResourceState struct {
     	// GoStatus and GoCreate events to omit a sequence number (implicitly 0).
     	seq [2]uint64
     }
    +type mutex struct {
    +	// Empty struct if lock ranking is disabled, otherwise includes the lock rank
    +	lockRankStruct
    +	// Futex-based impl treats it as uint32 key,
    +	// while sema-based impl as M* waitm.
    +	// Used to be a union, but unions break precise GC.
    +	key uintptr
    +}
    +type lockRankStruct struct {
    +}
     type uintreg uint          // FIXME wrong on amd64p32
     type m struct{}            // FIXME stub
     type sudog struct{}        // FIXME stub
     type timersBucket struct{} // FIXME stub
    +type timers struct{}       // FIXME stub
    48920809
zruntime_g_go1.23.go 11.9 KB