Skip to content

[ESI][Runtime] Add cycle count and frequency to SysInfo#9423

Merged
teqdruid merged 9 commits intomainfrom
teqdruid/cycle-count
Jan 12, 2026
Merged

[ESI][Runtime] Add cycle count and frequency to SysInfo#9423
teqdruid merged 9 commits intomainfrom
teqdruid/cycle-count

Conversation

@teqdruid
Copy link
Copy Markdown
Contributor

@teqdruid teqdruid commented Jan 7, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds cycle count and core clock frequency information to the ESI runtime's SysInfo service, enabling clients to query simulation time and clock characteristics from the accelerator.

Key changes:

  • Extended the SysInfo API with getCycleCount() and getCoreClockFrequency() methods
  • Added SystemVerilog module Cosim_CycleCount to track cycle counts in cosimulation
  • Updated RPC protocol (protobuf) and all backend implementations (MMIO, RpcServer, RpcClient, Cosim)

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/Dialect/ESI/runtime/cpp/include/esi/Services.h Added virtual methods getCycleCount() and getCoreClockFrequency() to SysInfo base class
lib/Dialect/ESI/runtime/cpp/include/esi/Accelerator.h Defined memory layout constants (CycleCountOffset, CoreFreqOffset) for MMIO access
lib/Dialect/ESI/runtime/cpp/include/esi/backends/RpcServer.h Added GetCycleCountFunc typedef and updated setSysInfo signature
lib/Dialect/ESI/runtime/cpp/include/esi/backends/RpcClient.h Added getCycleCount() and getCoreClockFrequency() methods to RPC client
lib/Dialect/ESI/runtime/cpp/lib/Services.cpp Implemented MMIO-based cycle count and frequency reading with offset constants
lib/Dialect/ESI/runtime/cpp/lib/backends/RpcServer.cpp Renamed GetManifest to GetSysInfo, added cycle count/frequency to RPC response
lib/Dialect/ESI/runtime/cpp/lib/backends/RpcClient.cpp Implemented getCycleCount/getCoreClockFrequency using getSysInfo RPC call
lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp Added cycle count/frequency passthrough methods in CosimSysInfo
lib/Dialect/ESI/runtime/python/esiaccel/esiCppAccel.cpp Exposed new SysInfo methods to Python bindings
lib/Dialect/ESI/runtime/cosim_dpi_server/dpi.h Added DPI export and import declarations for cycle count callback
lib/Dialect/ESI/runtime/cosim_dpi_server/DpiEntryPoints.cpp Implemented setSysInfo logic with cycle count callback registration
lib/Dialect/ESI/runtime/cosim_dpi_server/DummySvDpi.cpp Added stub for c2svCosimserverGetCycleCount DPI export
lib/Dialect/ESI/runtime/cosim_dpi_server/Cosim_DpiPkg.sv Added cosim_set_cycle_count_callback DPI import
lib/Dialect/ESI/runtime/cosim_dpi_server/Cosim_CycleCount.sv New SystemVerilog module implementing cycle counter with DPI export
lib/Dialect/ESI/runtime/cosim_dpi_server/CMakeLists.txt Added Cosim_CycleCount.sv to build collateral
lib/Dialect/ESI/runtime/cosim.proto Renamed Manifest to SysInfo, added cycle_count and core_clock_frequency_hz fields
lib/Dialect/ESI/Passes/ESILowerToHW.cpp Created __ESICycleCounter wrapper module and Cosim_CycleCount extern declaration
frontends/PyCDE/src/pycde/bsp/common.py Extended MMIO header array with cycle counter (though with incorrect layout)
frontends/PyCDE/integration_test/test_software/esi_test.py Added integration tests for cycle count monotonicity and clock frequency
test/Dialect/ESI/manifest.mlir Added test expectations for cycle counter module generation

Comment thread frontends/PyCDE/src/pycde/bsp/common.py Outdated
Comment thread frontends/PyCDE/src/pycde/bsp/common.py Outdated
Comment thread lib/Dialect/ESI/Passes/ESILowerToHW.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread lib/Dialect/ESI/ESIServices.cpp Outdated
Comment thread lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp
Comment thread frontends/PyCDE/integration_test/CMakeLists.txt
Comment thread frontends/PyCDE/src/pycde/bsp/cosim.py Outdated
@teqdruid teqdruid marked this pull request as ready for review January 9, 2026 03:10
Comment thread frontends/PyCDE/integration_test/test_software/esi_ram.py
Comment thread frontends/PyCDE/integration_test/test_software/esi_test.py Outdated
Comment thread lib/Dialect/ESI/ESIServices.cpp Outdated
Comment on lines +91 to +100
header = Array(Bits(64), 8)([
0, # Generally a good idea to not use address 0.
MagicNumber, # ESI magic number.
VersionNumber, # ESI version number.
manifest_loc, # Absolute address of the manifest ROM.
0, # Reserved for future use.
cycles.out.as_bits(), # Cycle counter.
core_freq, # Core frequency, if known.
0,
])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is there some way to correlate this better with the metadata constants presented in Accelerator.h? While we can't share code, there could maybe be some injection of these values into an array using the same hex offsets as what is used in Accelerator.h. I think that would help debuggability and code clarity a lot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the hardware and software sides of the BSPs are so intertwined, I've been considering moving the PyCDE BSP libraries into esiaccel. Then I'd have esiaccel depend on some public version of PyCDE so we could co-locate the cosim runtime tests. It would also provide an opportunity to read the constants out of Accelerator.h from python.

WDYT?

Comment thread lib/Dialect/ESI/runtime/cpp/include/esi/Services.h
@teqdruid teqdruid merged commit 953584f into main Jan 12, 2026
7 checks passed
@teqdruid teqdruid deleted the teqdruid/cycle-count branch January 12, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants