1. 05 Oct, 2022 1 commit
    • Kirill Smelkov's avatar
      tracing/runtime: Add support for Go1.19 · 179529a7
      Kirill Smelkov authored
      Generate g for today's state of Go 1.19 (go1.19.2-0-g895664482c).
      Compared to Go1.18 the only change is that new field `goroutineProfiled`
      is added to g struct.
      
      Regenerated files stay without changes for Go1.18 and previous releases.
      
      ---- 8< ----
      diff --git a/zruntime_g_go1.18.go b/zruntime_g_go1.19.go
      index 76f905d..3b33cbe 100644
      --- a/zruntime_g_go1.18.go
      +++ b/zruntime_g_go1.19.go
      @@ -1,10 +1,11 @@
       // Code generated by g_typedef; DO NOT EDIT.
      
      -// +build go1.18,!go1.19
      +// +build go1.19,!go1.20
      
       package xruntime
      
       import "unsafe"
      +import "sync/atomic"
      
       type g struct {
       	// Stack parameters.
      @@ -91,6 +92,10 @@ type g struct {
       	timer          *timer         // cached timer for time.Sleep
       	selectDone     uint32         // are we participating in a select and did someone win the race?
      
      +	// goroutineProfiled indicates the status of this goroutine's stack for the
      +	// current in-progress goroutine profile
      +	goroutineProfiled goroutineProfileStateHolder
      +
       	// gcAssistBytes is this G's GC assist credit in terms of
       	// bytes allocated. If this is positive, then the G has credit
       	// to allocate gcAssistBytes bytes without assisting. If this
      @@ -195,6 +200,7 @@ type ancestorInfo struct {
       	goid int64     // goroutine id of this goroutine; original goroutine possibly dead
       	gopc uintptr   // pc of go statement that created this goroutine
       }
      +type goroutineProfileStateHolder atomic.Uint32
       type uintreg  uint	// FIXME wrong on amd64p32
       type m struct {}		// FIXME stub
       type sudog struct {}	// FIXME stub
      179529a7
  2. 16 Mar, 2022 1 commit
  3. 24 Nov, 2021 7 commits
    • Kirill Smelkov's avatar
      tracing/tracetest: Cosmetics · 01e8697d
      Kirill Smelkov authored
      01e8697d
    • Kirill Smelkov's avatar
      tracing/tracetest: Prevent deadlocks when there are extra events not consumed by main checker · 3b19f68c
      Kirill Smelkov authored
      A deadlock scenario was possible before this patch:
      
      - main thread finished checks, wants to return, goes to deferred wg.Wait();
      - that wg.Wait waits for other spawned threads to complete;
      - in one of that thread there is extra event being sent to a stream;
      - that send is blocked waiting for main thread to receive it, but the
        main thread is waiting in wg.Wait() and only after that it would go to
        call T.closeStreamTab() which marks all the channels as down -> deadlock.
      
      -> Fix it by explicitly detecting deadlocks not only in Recv, but also on Send.
      
      NOTE Contrary to Recv - which is always called from main thread - Send is
      always called from non-main threads. T.unsentv and the logic prepared in
      the previous patch care to handle that correctly.
      3b19f68c
    • Kirill Smelkov's avatar
      tracing/tracetest: Make sure that log from non-main threads always comes after log of main · aeac6236
      Kirill Smelkov authored
      If we don't, it won't be automatically the case when Send's will be
      adjusted to detect and log deadlocks. And then, if there will be no
      ordering, it will be hard to do tests in example_test.go which expects
      logging output in particular "main -> everything else" order.
      aeac6236
    • Kirill Smelkov's avatar
      tracing/tracetest: There might be multiple pending sends on the same channel · 50586bc7
      Kirill Smelkov authored
      This is possible if the system is incorrectly decomposed into serial
      streams. We want to show all pending events in that case, not only the
      first random one.
      50586bc7
    • Kirill Smelkov's avatar
      tracing/tracetest: Goodbye fatalLogMu · d6963bdf
      Kirill Smelkov authored
      -> Reuse T.mu for serialization.
      
      closeStreamTab changes locking so that acquired t.mu covers whole time
      when that function could log anything.
      d6963bdf
    • Kirill Smelkov's avatar
      tracing/tracetest: Mark T failed on fatalfInNonMain · 71b9f3fd
      Kirill Smelkov authored
      There is no guaranty that the main thread would call Fatal or Fail if a
      non-main thread calls fatalfInNonMain. This way it was possible for a
      test to succeed if only non-main thread(s) failed somehow.
      
      -> Fix it by marking the test as failed if any non-main thread fails.
      71b9f3fd
    • Kirill Smelkov's avatar
      tracing/runtime: Add support for Go1.18 (preliminary) · e292c06f
      Kirill Smelkov authored
      Generate g for today state of Go 1.18 (go1.17beta1-2522-g47db3bb443)
      Compared to Go1.17 there are small number of changes in _defer struct.
      
      Regenerated files stay without changes for Go1.17 and previous releases.
      
      ---- 8< ----
      diff --git a/zruntime_g_go1.17.go b/zruntime_g_go1.18.go
      index 7a76db6..5e2fafb 100644
      --- a/zruntime_g_go1.17.go
      +++ b/zruntime_g_go1.18.go
      @@ -1,6 +1,6 @@
       // Code generated by g_typedef; DO NOT EDIT.
      
      -// +build go1.17,!go1.18
      +// +build go1.18,!go1.19
      
       package xruntime
      
      @@ -115,7 +115,6 @@ type _panic struct {
       	goexit    bool
       }
       type _defer struct {
      -	siz     int32 // includes both arguments and results
       	started bool
       	heap    bool
       	// openDefer indicates that this _defer is for a frame with open-coded
      @@ -124,9 +123,9 @@ type _defer struct {
       	openDefer bool
       	sp        uintptr // sp at time of defer
       	pc        uintptr // pc at time of defer
      -	fn        *funcval // can be nil for open-coded defers
      +	fn        func()  // can be nil for open-coded defers
       	_panic    *_panic // panic that is running defer
      -	link      *_defer
      +	link      *_defer // next defer on G; can point to either heap or stack!
      
       	// If openDefer is true, the fields below record values about the stack
       	// frame and associated function that has the open-coded defer(s). sp
      e292c06f
  4. 06 Sep, 2021 1 commit
  5. 01 Jul, 2021 1 commit
  6. 11 Jun, 2021 1 commit
    • Kirill Smelkov's avatar
      tracing/runtime: Add support for Go1.17 (preliminary) · 68f3a266
      Kirill Smelkov authored
      Generate g for ~ Go 1.17beta1 (go1.17beta1-2-g770f1de8c5)
      Compared to Go1.16 there is one non-cosmetic change to g related to tracking
      scheduling latencies:
      
      https://github.com/golang/go/commit/bedfeed54a7a
      
      Regenerated files stay without changes for Go1.16 and previous releases.
      
      ---- 8< ----
      diff --git a/zruntime_g_go1.16.go b/zruntime_g_go1.17.go
      index 9604d6b..7a76db6 100644
      --- a/zruntime_g_go1.16.go
      +++ b/zruntime_g_go1.17.go
      @@ -1,6 +1,6 @@
       // Code generated by g_typedef; DO NOT EDIT.
      
      -// +build go1.16,!go1.17
      +// +build go1.17,!go1.18
      
       package xruntime
      
      @@ -25,7 +25,18 @@ type g struct {
              syscallsp uintptr // if status==Gsyscall, syscallsp = sched.sp to use during gc
              syscallpc uintptr // if status==Gsyscall, syscallpc = sched.pc to use during gc
              stktopsp  uintptr // expected sp at top of stack, to check in traceback
      -       param        unsafe.Pointer // passed parameter on wakeup
      +       // param is a generic pointer parameter field used to pass
      +       // values in particular contexts where other storage for the
      +       // parameter would be difficult to find. It is currently used
      +       // in three ways:
      +       // 1. When a channel operation wakes up a blocked goroutine, it sets param to
      +       //    point to the sudog of the completed blocking operation.
      +       // 2. By gcAssistAlloc1 to signal back to its caller that the goroutine completed
      +       //    the GC cycle. It is unsafe to do so in any other way, because the goroutine's
      +       //    stack may have moved in the meantime.
      +       // 3. By debugCallWrap to pass parameters to a new goroutine because allocating a
      +       //    closure in the runtime is forbidden.
      +       param        unsafe.Pointer
              atomicstatus uint32
              stackLock    uint32 // sigprof/scang lock; TODO: fold in to atomicstatus
              goid         int64
      @@ -57,6 +68,10 @@ type g struct {
      
              raceignore     int8     // ignore race detection events
              sysblocktraced bool     // StartTrace has emitted EvGoInSyscall about this goroutine
      +       tracking       bool     // whether we're tracking this G for sched latency statistics
      +       trackingSeq    uint8    // used to decide whether to track this G
      +       runnableStamp  int64    // timestamp of when the G last became runnable, only used when tracking
      +       runnableTime   int64    // the amount of time spent runnable, cleared when running, only used when tracking
              sysexitticks   int64    // cputicks when syscall has returned (for tracing)
              traceseq       uint64   // trace event sequencer
              tracelastp     puintptr // last P emitted an event for this goroutine
      @@ -142,7 +157,7 @@ type gobuf struct {
              pc   uintptr
              g    guintptr
              ctxt unsafe.Pointer
      -       ret  uintreg
      +       ret  uintptr
              lr   uintptr
              bp   uintptr // for framepointer-enabled architectures
       }
      68f3a266
  7. 02 Mar, 2021 1 commit
  8. 28 Jan, 2021 1 commit
  9. 10 Jan, 2021 1 commit
  10. 03 Jan, 2021 4 commits
  11. 29 Dec, 2020 3 commits
    • Kirill Smelkov's avatar
      tracing/runtime: Add support for Go1.16 (preliminary) · 60bad2d1
      Kirill Smelkov authored
      Generate g for ~ Go 1.16beta1 (go1.16beta1-34-g4fd9455882)
      Compared to Go1.15 there are only cosmetic changes:
      
          --- a/zruntime_g_go1.15.go
          +++ b/zruntime_g_go1.16.go
          @@ -1,6 +1,6 @@
           // Code generated by g_typedef; DO NOT EDIT.
      
          -// +build go1.15,!go1.16
          +// +build go1.16,!go1.17
      
           package xruntime
      
          @@ -144,7 +144,7 @@ type gobuf struct {
           	ctxt unsafe.Pointer
           	ret  uintreg
           	lr   uintptr
          -	bp   uintptr // for GOEXPERIMENT=framepointer
          +	bp   uintptr // for framepointer-enabled architectures
           }
           type funcval struct {
           	fn uintptr
          @@ -158,6 +158,8 @@ type timer struct {
           	// 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
           	// a well-behaved function and not block.
          +	//
          +	// when must be positive on an active timer.
           	when   int64
           	period int64
           	f      func(interface{}, uintptr)
      
      Regenerated files stay without changes for Go1.15 and previous releases.
      60bad2d1
    • Kirill Smelkov's avatar
      xnet/virtnet: SubNetwork += AutoClose · 3070cec4
      Kirill Smelkov authored
      When a virtnet network - e.g. lonet - is explicitly used in tests, the
      open and close sequence is easy to implement:
      
          network = lonet.Join(...)
          defer network.Close()
      
          hostα = network.NewHost("α")
          defer hostα.Close()
          hostβ = network.NewHost("β")
          defer hostβ.Close()
          ...
      
      However in other scenarios - for example when the code wants to call
      xnet.Networker factory that creates a networker out of several potential
      choices according to given parameters, only interface for network
      access-point (e.g. Host in lonet/virtnet case) is returned. The network
      itself (virtnet.SubNetwork) is not returned to the user. As it is this
      makes it impossible to close the network and release its resources.
      
      Instead of adding complexity to such "create-networker" functions to
      e.g. change Close of returned networker to also close subnetwork, or
      return both networker and a separate close func, let's teach virtnet to
      close SubNetwork automatically when last host of this subnetwork is
      closed. Make it opt-in since this behaviour is not universally wanted.
      
      This way a factory that is asked to connect to network as e.g. a node on
      lonet, could do the following:
      
          func neonet.Join(...) xnet.Networker {
              ...
              // join lonet "<net>" as host "<node>"
              network = lonet.Join("<net>")
              host = network.NewHost("<node>")
              network.AutoClose() // host.Close will close network
              return host
          }
      
      and network will be closed on host.Close() call.
      
      -> Add SubNetwork.AutoClose to schedule Close to be called after last host on the subnetwork is closed.
      -> Mirror this change in virtnet part of lonet.py
      3070cec4
    • Kirill Smelkov's avatar
      xnet: Networker += Close · 01a77bb9
      Kirill Smelkov authored
      Even though there is no need to manually release resources for NetPlain
      and NetTLS, for other networkers - for example lonet - releasing
      resources is needed. In general programs cannot always use lonet
      explicitly, as there might be a factory function that creates a
      Networker according to given parameters.
      
      -> Adjust Networker interface to include general Close.
      -> Adjust NetPlain to follow added "interrupt-on-close" semantic for uniformity.
      01a77bb9
  12. 17 Dec, 2020 3 commits
    • Kirill Smelkov's avatar
      xnet: Provide way to convert xnet.Listener <-> net.Listener · b03d65ff
      Kirill Smelkov authored
      Similarly to what we do in package xio (see 7ad867a3 "xio: Add
      Reader/Writer/... interfaces - io analogs that add support for
      contexts"), add utilities to bind xnet.Listener to context (giving
      net.Listener), and, on the other hand, adapt uncontextified net.Listener
      to xnet.Listener that handles cancellation.
      
      This utilities are needed because a lot of third-party code wants to
      work with net.Listener interface only.
      
      Contrary to xio, we can make it working reliably in both ways (because
      Accept already buffers accepting connections starting at OS level).
      b03d65ff
    • Kirill Smelkov's avatar
      *: Adapt code to xnet.Networker changes for Listen/Accept to handle cancellation · b50ecee2
      Kirill Smelkov authored
      In the previous patch xnet.Networker was changed: Listen now accepts ctx
      and returns xnet.Listener instead of net.Listener.
      
      -> Adapt the code all around to that.
      b50ecee2
    • Kirill Smelkov's avatar
      xnet: Adjust Networker.Listen to return listener that can handle cancellation in Accept · 3354b401
      Kirill Smelkov authored
      We already handle cancellation in Dial, but Accepting was out of luck
      until now. This makes it more difficult for clients to implement and
      wrap acceptors where they need to handle cancellations. This also makes
      it possible for a test or program to get stuck in Accept loop if it is
      not careful enough to manually handle ctx cancel around Accept calls.
      
      -> Fix it in one place - here, in xnet - so that users are offloaded
      from all this and can just call Accept(ctx) and rely on underlying
      implementation to handle ctx cancel.
      
      This patch:
      
      - introduces xnet.Listener interface, which is like net.Listener, but
        Accept goes with ctx argument.
      - changes Networker.Listen signature to return xnet.Listener instead of
        net.Listener. While we are here - changing it - also add ctx argument
        to Listen call itself.
      - Adds listenerCtx - which, given net.Listener, provides xnet.Listener
        by wrapping some logic around original.
      - Adapts NetPlain, NetTLS and NetTrace to provide updated interface.
      
      We'll fix up everything in other packages to match/use updated interface
      in the next patch.
      3354b401
  13. 01 Dec, 2020 1 commit
  14. 18 Oct, 2020 1 commit
  15. 16 Sep, 2020 1 commit
    • Kirill Smelkov's avatar
      exc: Contextf · 31661766
      Kirill Smelkov authored
      A shorthand for when exception context is just formatted string.
      Simplifies
      
      	func doSomething(path string) {
      		defer exc.Context(func() interface{} {
      			return fmt.Sprintf("doing something %s", path)
      		})()
      		...
      
      to
      
      	func doSomething(path string) {
      		defer exc.Contextf("doing something %s", path)
      		...
      31661766
  16. 15 Sep, 2020 1 commit
  17. 27 May, 2020 4 commits
  18. 03 Apr, 2020 1 commit
  19. 16 Jan, 2020 1 commit
  20. 13 Jan, 2020 1 commit
  21. 26 Dec, 2019 4 commits