Skip to content

[ENG-2040] set_path_margin implementation in OpenSTA#57

Merged
akashlevy merged 24 commits into
mainfrom
path-margin
May 26, 2026
Merged

[ENG-2040] set_path_margin implementation in OpenSTA#57
akashlevy merged 24 commits into
mainfrom
path-margin

Conversation

@stanminlee
Copy link
Copy Markdown

@stanminlee stanminlee commented May 22, 2026

Support for set_path_margin in OpenSTA

Overview of command

  • set_path_margin artificially changes the required time for specific paths
  • a negative margin will 'loosen' the timing requirement (useful skew)
  • a positive margin will 'tighten' the timing requirement (harmful skew)
  • we can specify -to, -from, and -through just as any other command similar to this will do

Main implementation details - full workflow

  1. define a "set_path_margin" proc in Sdc.tcl as the command entry. The proc will validate arguments and call the swig wrapper.
  2. we created a swig wrapper in Sdc.i to call the C++ used to construct the timing exception.
  3. define a makePathMargin command in Sdc.cc to create the timing exception
  4. Create full class entry for pathMargin in Exception.cc, mirroring implementations of other clock timing exceptions. Most important detail is that a path margin on a pin is defined by the 'last set_path_margin command set on that pin' which means the last path margin defined in TCL file for the pin will be used.
  5. In visitPathsEnds.cc, we add checks to account for the path margin in addition to other timing exceptions.
  6. When we visit the endpoint, we will apply the margin if it is non-zero (PathEnd.cc)
  7. Dump the path margin in ReportPath.cc

Various updates were made in some header files for class and function definitions.

Test case

  • Added one test case to test that setup/hold margins are applied, do affect the required time/slack, and show up in the STA report.

@linear
Copy link
Copy Markdown

linear Bot commented May 22, 2026

ENG-2040

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 22, 2026

Greptile Summary

This PR implements set_path_margin, a new timing exception that artificially shifts the required time for specific paths by adjusting the capture clock arrival. A positive margin tightens the constraint (useful for hold guard-banding); a negative margin loosens it (useful skew). The command supports the standard -from/-through/-to path-scoping qualifiers and -setup/-hold applicability flags.

  • Adds a PathMargin exception class (mirroring PathDelay), registers it in the SDC engine, and serialises it via WriteSdc; LIFO override semantics mean the last set_path_margin with the same scope wins.
  • In PathEndClkConstrained::targetClkPathMargin, the lookup uses the full path-aware Search::exceptionTo overload so -from and -through constraints are correctly honoured; sign is flipped for setup checks so that a positive user margin always means "tighter."
  • VisitPathEnds pass-through conditions are extended to include isPathMargin() so margin-annotated paths reach the clock-constrained path-end visitor rather than being silently dropped.

Confidence Score: 5/5

The implementation is functionally correct and well-tested; the only findings are style inconsistencies in WriteSdc and a misleading test comment.

The core correctness concern from earlier review rounds — that targetClkPathMargin would ignore -from/-through constraints — is properly addressed by using the path-aware Search::exceptionTo overload, and the test suite validates -from, -through, -to, and their combinations end-to-end. The sign-flip convention (negate margin for setup) is consistent with the golden output.

sdc/WriteSdc.cc has a minor style inconsistency (gzprintf vs sta::print); test/set_path_margin.tcl has a misleading comment for the setup_through_r1 case.

Important Files Changed

Filename Overview
search/PathEnd.cc Adds targetClkPathMargin with path-aware Search::exceptionTo overload (properly evaluates -from/-through states); applies margin to targetClkArrivalNoCrpr in all three relevant path-end variants.
search/VisitPathEnds.cc Adds isPathMargin() to the pass-through conditions alongside isMultiCycle() so path-margin paths correctly reach the clock-constrained PathEnd visitor instead of being dropped.
sdc/ExceptionPath.cc Implements PathMargin methods; tighterThan always returns false (intentional LIFO) and overrides() uses priority+min_max match (correct given intersection pre-check in findMatchingExceptions).
sdc/WriteSdc.cc Adds path-margin serialization; uses gzprintf() directly where all adjacent exception types use sta::print() — style inconsistency.
test/set_path_margin.tcl Tests -to, -from, -through, and combined constraints; some comments say 'Should not see path margin' when earlier active exceptions still apply.

Reviews (4): Last reviewed commit: "Add JSON support and test for it" | Re-trigger Greptile

Comment thread search/PathEnd.cc
Comment thread sdc/ExceptionPath.cc
Comment thread search/PathEnd.cc
@stanminlee stanminlee marked this pull request as draft May 22, 2026 00:37
@stanminlee stanminlee marked this pull request as ready for review May 22, 2026 05:51
@stanminlee
Copy link
Copy Markdown
Author

@greptile please review again

@akashlevy
Copy link
Copy Markdown

@stanminlee can you resolve the conflicts?

@stanminlee
Copy link
Copy Markdown
Author

@akashlevy yes, will do tmr

@akashlevy
Copy link
Copy Markdown

akashlevy commented May 26, 2026

So path margin is implemented as a timing exception? I'm not quite sure that that's the correct formulation. I would have thought it would be implemented similar to CRPR (clock reconvergence pessimism) as opposed to something like multicycle path... let me think about this some more...

EDIT: ok I thought about it some more and now I see the motivation. It makes sense. Exceptions get applied to points in the circuit and are processed during reporting. Path margin is exactly the right use case for that, since it is applied at an endpoint.

Comment thread search/ReportPath.cc
Comment thread test/set_path_margin.tcl
@akashlevy
Copy link
Copy Markdown

@greptile can you re-review this from scratch?

@akashlevy akashlevy merged commit 034f001 into main May 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants