Skip to content

Plugin deadlock in circular dependency on Handle #1331

Open
@KireinaHoro

Description

@KireinaHoro

I'm trying out the plugin framework and encountered some deadlock issue:

import spinal.core._
import spinal.core.fiber.Handle
import spinal.lib._
import spinal.lib.misc.plugin._

class Plugin1 extends FiberPlugin {
  val logic = during setup new Area {
    val int = host[Plugin2].logic.const
  }
}

class Plugin2 extends FiberPlugin {
  val logic: Handle[Area with Object{val const: Bool}] = during setup new Area {
    val const = True
    awaitBuild()
    val o = out(Bool())
    o := host[Plugin1].logic.int
  }
}

class PluginTest extends Component {
  val host = new PluginHost
  host.asHostOf(new Plugin2, new Plugin1)
}

object PluginTest extends App {
  SpinalVerilog(new PluginTest)
}

Elaboration failed with a rather cryptic error message:

[Progress] at 0.137 : Elaborate components

! SpinalHDL async engine is stuck !
Waiting on global_elab_inflightLock defined at ???:
1) global_elab loader
Waiting on global_elab_lock_1000000_lock defined at spinal.lib.misc.plugin.FiberPlugin.awaitBuild(Fiber.scala:31):
1) Plugin2_logic

My understanding is that since Plugin1.logic.int and Plugin2.logic.o are in different phases (setup and build), there should not be a real loop here. An ugly workaround is to have a null-initialized const outside of the logic block:

class Plugin1 extends FiberPlugin {
  val logic = during setup new Area {
    val int = host[Plugin2].const // instead of `logic.const`
  }
}

class Plugin2 extends FiberPlugin {
  var const: Bool = null
  val logic = during setup new Area {
    const = True
    awaitBuild()
    val o = out(Bool())
    o := host[Plugin1].logic.int
  }
}

But with this workaround const loses its name inside the area. Is there a better way to specify this type of dependency?

Also, it would save a lot of headaches if the error message is improved / documentation is updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions