Skip to content

Commit e517dc1

Browse files
authored
Merge pull request #12091 from The-OpenROAD-Project-staging/fix/8075
rsz: detect cross-clock-domain hold violations on clock-as-data endpoints (#8075)
2 parents 13e1fff + 574e73b commit e517dc1

10 files changed

Lines changed: 338 additions & 3 deletions

‎src/rsz/src/RepairHold.cc‎

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "odb/dbObject.h"
1919
#include "odb/geom.h"
2020
#include "rsz/Resizer.hh"
21+
#include "sta/ClkNetwork.hh"
2122
#include "sta/ContainerHelpers.hh"
2223
#include "sta/Delay.hh"
2324
#include "sta/Fuzzy.hh"
@@ -60,6 +61,8 @@ void RepairHold::init()
6061
db_network_ = resizer_->db_network_;
6162
estimate_parasitics_ = resizer_->estimate_parasitics_;
6263
initial_design_area_ = resizer_->computeDesignArea();
64+
clk_tree_pins_.clear();
65+
clk_tree_pins_valid_ = false;
6366
}
6467

6568
bool RepairHold::repairHold(
@@ -503,7 +506,18 @@ void RepairHold::findHoldViolations(sta::VertexSeq& ends,
503506
debugPrint(logger_, RSZ, "repair_hold", 3, "Hold violations");
504507
for (sta::Vertex* end : ends) {
505508
const sta::Slack slack = holdSlack(end);
506-
if (!sta_->isClock(end->pin(), sta_->cmdMode()) && slack < hold_margin) {
509+
// Skip endpoints that lie on the clock network so we do not try to fix
510+
// hold on the clock tree itself. isClock() reports any pin in a clock
511+
// network's combinational fanout, which incorrectly includes register
512+
// data (D) pins that sample a signal sourced from a clock (e.g. a clock
513+
// used as data crossing into a different sampling-clock domain). Such
514+
// register data pins are genuine hold endpoints: they carry a timing
515+
// check (hasChecks()). Only exclude clock pins that are NOT data check
516+
// endpoints, so real cross-clock-domain hold violations are not silently
517+
// skipped. See OpenROAD issue #8075.
518+
const bool clk_tree_endpoint
519+
= sta_->isClock(end->pin(), sta_->cmdMode()) && !end->hasChecks();
520+
if (!clk_tree_endpoint && slack < hold_margin) {
507521
debugPrint(logger_,
508522
RSZ,
509523
"repair_hold",
@@ -568,6 +582,76 @@ class RepairHoldPredicate : public sta::SearchPred1
568582
}
569583
};
570584

585+
bool RepairHold::isClockTreeDriver(const sta::Pin* drvr_pin)
586+
{
587+
if (!sta_->isClock(drvr_pin, sta_->cmdMode())) {
588+
return false;
589+
}
590+
if (!clk_tree_pins_valid_) {
591+
findClockTreePins();
592+
}
593+
return clk_tree_pins_.contains(drvr_pin);
594+
}
595+
596+
// Walk backward from every clock sink in the clock network (register or
597+
// timing-check clock pins and clock output ports) through clock-network
598+
// fanin. The pins reached form the clock tree proper. Clock-network pins
599+
// that only feed data pins (clock used as data) are not included.
600+
void RepairHold::findClockTreePins()
601+
{
602+
clk_tree_pins_.clear();
603+
const sta::Mode* mode = sta_->cmdMode();
604+
sta_->ensureClkNetwork(mode);
605+
sta::ClkNetwork* clk_network = mode->clkNetwork();
606+
std::vector<const sta::Pin*> queue;
607+
for (const sta::Clock* clk : mode->sdc()->clocks()) {
608+
const sta::PinSet* clk_pins = clk_network->pins(clk);
609+
if (clk_pins == nullptr) {
610+
continue;
611+
}
612+
for (const sta::Pin* pin : *clk_pins) {
613+
const bool clk_sink = network_->isRegClkPin(pin)
614+
|| network_->isCheckClk(pin)
615+
|| (network_->isTopLevelPort(pin)
616+
&& network_->direction(pin)->isAnyOutput());
617+
if (clk_sink && clk_tree_pins_.insert(pin).second) {
618+
queue.push_back(pin);
619+
}
620+
}
621+
}
622+
while (!queue.empty()) {
623+
const sta::Pin* pin = queue.back();
624+
queue.pop_back();
625+
sta::Vertex* vertex;
626+
sta::Vertex* bidir_drvr_vertex;
627+
graph_->pinVertices(pin, vertex, bidir_drvr_vertex);
628+
for (sta::Vertex* to_vertex : {vertex, bidir_drvr_vertex}) {
629+
if (to_vertex == nullptr) {
630+
continue;
631+
}
632+
sta::VertexInEdgeIterator edge_iter(to_vertex, graph_);
633+
while (edge_iter.hasNext()) {
634+
sta::Edge* edge = edge_iter.next();
635+
if (edge->role()->isTimingCheck()) {
636+
continue;
637+
}
638+
const sta::Pin* from_pin = edge->from(graph_)->pin();
639+
if (clk_network->isClock(from_pin)
640+
&& clk_tree_pins_.insert(from_pin).second) {
641+
queue.push_back(from_pin);
642+
}
643+
}
644+
}
645+
}
646+
clk_tree_pins_valid_ = true;
647+
debugPrint(logger_,
648+
RSZ,
649+
"repair_hold",
650+
2,
651+
"found {} clock tree pins",
652+
clk_tree_pins_.size());
653+
}
654+
571655
void RepairHold::repairEndHold(sta::Vertex* end_vertex,
572656
sta::LibertyCell* buffer_cell,
573657
const double setup_margin,
@@ -613,8 +697,11 @@ void RepairHold::repairEndHold(sta::Vertex* end_vertex,
613697
if (group_only && !(group_hold_slack < hold_margin)) {
614698
break;
615699
}
616-
if (path_vertex->isDriver(network_)
617-
&& resizer_->okToBufferNet(path_pin)) {
700+
// Hold paths that start at a clock source (clock used as data)
701+
// run through clock-network drivers. Only buffer on the data
702+
// side so the clock latency of other sinks is not changed.
703+
if (path_vertex->isDriver(network_) && resizer_->okToBufferNet(path_pin)
704+
&& !isClockTreeDriver(path_pin)) {
618705
sta::PinSeq load_pins;
619706
Slacks slacks;
620707
mergeInit(slacks);

‎src/rsz/src/RepairHold.hh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#pragma once
55

6+
#include <unordered_set>
7+
68
#include "db_sta/dbNetwork.hh"
79
#include "db_sta/dbSta.hh"
810
#include "odb/db.h"
@@ -89,6 +91,11 @@ class RepairHold : public sta::dbStaState
8991
int max_buffer_count,
9092
bool verbose,
9193
int& pass);
94+
// True if drvr_pin is part of the clock tree proper, i.e. it is in the
95+
// clock network and (transitively) drives a clock sink. Hold buffers
96+
// must not be inserted on such nets: that would change clock latency.
97+
bool isClockTreeDriver(const sta::Pin* drvr_pin);
98+
void findClockTreePins();
9299
void repairEndHold(sta::Vertex* end_vertex,
93100
sta::LibertyCell* buffer_cell,
94101
double setup_margin,
@@ -116,6 +123,10 @@ class RepairHold : public sta::dbStaState
116123
Resizer* resizer_;
117124
est::EstimateParasitics* estimate_parasitics_ = nullptr;
118125

126+
// Clock-network pins that drive a clock sink. Computed lazily.
127+
std::unordered_set<const sta::Pin*> clk_tree_pins_;
128+
bool clk_tree_pins_valid_ = false;
129+
119130
int resize_count_ = 0;
120131
int inserted_buffer_count_ = 0;
121132
int cloned_gate_count_ = 0;

‎src/rsz/test/BUILD‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ TESTS = [
109109
"repair_hold8",
110110
"repair_hold9",
111111
"repair_hold9_verbose",
112+
"repair_hold_clock_as_data",
113+
"repair_hold_clock_as_data_clk_tree",
112114
"repair_hold_multi_output_load",
113115
"repair_setup_max_iter",
114116
"repair_setup_path1",

‎src/rsz/test/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ or_integration_tests(
9393
repair_hold13
9494
repair_hold14
9595
repair_hold15
96+
repair_hold_clock_as_data
97+
repair_hold_clock_as_data_clk_tree
9698
repair_hold_multi_output_load
9799
repair_setup_buffer_legacy_basic
98100
repair_setup_clone_legacy_flat
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
VERSION 5.8 ;
2+
DIVIDERCHAR "/" ;
3+
BUSBITCHARS "[]" ;
4+
DESIGN top ;
5+
UNITS DISTANCE MICRONS 1000 ;
6+
DIEAREA ( 0 0 ) ( 100000 100000 ) ;
7+
ROW ROW_0 FreePDK45_38x28_10R_NP_162NW_34O 40090 40600 N DO 104 BY 1 STEP 190 0 ;
8+
ROW ROW_1 FreePDK45_38x28_10R_NP_162NW_34O 40090 42000 FS DO 104 BY 1 STEP 190 0 ;
9+
ROW ROW_2 FreePDK45_38x28_10R_NP_162NW_34O 40090 43400 N DO 104 BY 1 STEP 190 0 ;
10+
ROW ROW_3 FreePDK45_38x28_10R_NP_162NW_34O 40090 44800 FS DO 104 BY 1 STEP 190 0 ;
11+
ROW ROW_4 FreePDK45_38x28_10R_NP_162NW_34O 40090 46200 N DO 104 BY 1 STEP 190 0 ;
12+
ROW ROW_5 FreePDK45_38x28_10R_NP_162NW_34O 40090 47600 FS DO 104 BY 1 STEP 190 0 ;
13+
COMPONENTS 5 ;
14+
- c1 BUF_X1 + PLACED ( 40090 40600 ) N ;
15+
- dbuf BUF_X1 + PLACED ( 40280 40600 ) N ;
16+
- r1 DFF_X1 + PLACED ( 40090 42000 ) FS ;
17+
- r2 DFF_X1 + PLACED ( 40280 42000 ) FS ;
18+
- i1 BUF_X1 + PLACED ( 40470 40600 ) N ;
19+
END COMPONENTS
20+
PINS 3 ;
21+
- clk1 + NET clk1 + DIRECTION INPUT + USE SIGNAL
22+
+ PORT
23+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
24+
+ FIXED ( 40000 0 ) N ;
25+
- clk2 + NET clk2 + DIRECTION INPUT + USE SIGNAL
26+
+ PORT
27+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
28+
+ FIXED ( 41000 0 ) N ;
29+
- out + NET out + DIRECTION OUTPUT + USE SIGNAL
30+
+ PORT
31+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
32+
+ FIXED ( 0 0 ) N ;
33+
END PINS
34+
NETS 7 ;
35+
- clk1 ( PIN clk1 ) ( i1 A ) ( dbuf A ) + USE SIGNAL ;
36+
- i1z ( i1 Z ) ( r1 CK ) + USE SIGNAL ;
37+
- clk2 ( PIN clk2 ) ( c1 A ) + USE SIGNAL ;
38+
- c1z ( c1 Z ) ( r2 CK ) + USE SIGNAL ;
39+
- dz ( dbuf Z ) ( r2 D ) + USE SIGNAL ;
40+
- r1q ( r1 Q ) ( r1 D ) + USE SIGNAL ;
41+
- out ( PIN out ) ( r2 Q ) + USE SIGNAL ;
42+
END NETS
43+
END DESIGN
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[INFO ODB-0227] LEF file: Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells
2+
[INFO ODB-0128] Design: top
3+
[INFO ODB-0130] Created 3 pins.
4+
[INFO ODB-0131] Created 5 components and 24 component-terminals.
5+
[INFO ODB-0133] Created 7 nets and 12 connections.
6+
=== r2/D hold slack (min) before repair: real cross-domain violation ===
7+
(clk1 ^) r -0.59:2.55 f ---:---
8+
(clk1 v) r ---:--- f 0.42:1.54
9+
[INFO RSZ-0046] Found 1 endpoints with hold violations.
10+
Iteration | Resized | Buffers | Cloned Gates | Area | WNS | TNS | Endpoint
11+
--------------------------------------------------------------------------------------
12+
0 | 0 | 0 | 0 | +0.0% | -0.587 | -0.587 | r2/D
13+
final | 0 | 24 | 0 | +167.4% | 0.015 | 0.000 | r2/D
14+
--------------------------------------------------------------------------------------
15+
[INFO RSZ-0032] Inserted 24 hold buffers.
16+
=== r2/D hold slack (min) after repair: must be detected and fixed ===
17+
(clk1 ^) r 0.01:1.95 f ---:---
18+
(clk1 v) r ---:--- f 1.01:0.95
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# OpenROAD issue #8075: repair_timing -hold must detect hold violations on
2+
# register data (D) pins that sample a signal sourced from a clock, i.e. a
3+
# clock used as data crossing into a different sampling-clock domain.
4+
#
5+
# Here clk1 is used BOTH as a clock (for r1) and as data into r2/D (r2 is
6+
# clocked by clk2). Because clk1 is a clock, r2/D lands in clk1's clock
7+
# network and isClock(r2/D) is true -- yet r2/D carries a genuine hold check
8+
# from clk2. Before the fix, findHoldViolations skipped this endpoint:
9+
# repair_timing -hold reported "No hold violations found" while a real
10+
# cross-clock-domain hold violation (negative min slack) remained on r2/D.
11+
#
12+
# This test fails on the unfixed code (hold violation silently missed,
13+
# slack stays negative) and passes after the fix (violation detected and
14+
# repaired to non-negative slack).
15+
source helpers.tcl
16+
read_liberty Nangate45/Nangate45_typ.lib
17+
read_lef Nangate45/Nangate45.lef
18+
read_def repair_hold_clock_as_data.def
19+
20+
create_clock -period 2 -name clk1 [get_ports clk1]
21+
create_clock -period 2 -name clk2 [get_ports clk2]
22+
set_propagated_clock [all_clocks]
23+
24+
# Make the capture clock (clk2) arrive much later than the launch (clk1) so
25+
# the very short clk1->dbuf->r2/D data path arrives far too early for clk2:
26+
# a real hold violation on r2/D.
27+
set_clock_latency 0.6 [get_clocks clk2]
28+
29+
source Nangate45/Nangate45.rc
30+
set_wire_rc -layer metal1
31+
estimate_parasitics -placement
32+
33+
puts "=== r2/D hold slack (min) before repair: real cross-domain violation ==="
34+
report_slack r2/D
35+
36+
repair_timing -hold
37+
38+
puts "=== r2/D hold slack (min) after repair: must be detected and fixed ==="
39+
report_slack r2/D
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
VERSION 5.8 ;
2+
DIVIDERCHAR "/" ;
3+
BUSBITCHARS "[]" ;
4+
DESIGN top ;
5+
UNITS DISTANCE MICRONS 1000 ;
6+
DIEAREA ( 0 0 ) ( 100000 100000 ) ;
7+
ROW ROW_0 FreePDK45_38x28_10R_NP_162NW_34O 40090 40600 N DO 104 BY 1 STEP 190 0 ;
8+
ROW ROW_1 FreePDK45_38x28_10R_NP_162NW_34O 40090 42000 FS DO 104 BY 1 STEP 190 0 ;
9+
ROW ROW_2 FreePDK45_38x28_10R_NP_162NW_34O 40090 43400 N DO 104 BY 1 STEP 190 0 ;
10+
ROW ROW_3 FreePDK45_38x28_10R_NP_162NW_34O 40090 44800 FS DO 104 BY 1 STEP 190 0 ;
11+
ROW ROW_4 FreePDK45_38x28_10R_NP_162NW_34O 40090 46200 N DO 104 BY 1 STEP 190 0 ;
12+
ROW ROW_5 FreePDK45_38x28_10R_NP_162NW_34O 40090 47600 FS DO 104 BY 1 STEP 190 0 ;
13+
COMPONENTS 6 ;
14+
- c1 BUF_X1 + PLACED ( 40090 40600 ) N ;
15+
- dbuf BUF_X1 + PLACED ( 40280 40600 ) N ;
16+
- i1 BUF_X1 + PLACED ( 40470 40600 ) N ;
17+
- r1 DFF_X1 + PLACED ( 40090 42000 ) FS ;
18+
- r2 DFF_X1 + PLACED ( 40280 42000 ) FS ;
19+
- r3 DFF_X1 + PLACED ( 40090 43400 ) N ;
20+
END COMPONENTS
21+
PINS 4 ;
22+
- clk1 + NET clk1 + DIRECTION INPUT + USE SIGNAL
23+
+ PORT
24+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
25+
+ FIXED ( 40000 0 ) N ;
26+
- clk2 + NET clk2 + DIRECTION INPUT + USE SIGNAL
27+
+ PORT
28+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
29+
+ FIXED ( 41000 0 ) N ;
30+
- out + NET out + DIRECTION OUTPUT + USE SIGNAL
31+
+ PORT
32+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
33+
+ FIXED ( 0 0 ) N ;
34+
- out2 + NET out2 + DIRECTION OUTPUT + USE SIGNAL
35+
+ PORT
36+
+ LAYER metal2 ( 0 0 ) ( 0 0 )
37+
+ FIXED ( 0 1000 ) N ;
38+
END PINS
39+
NETS 8 ;
40+
- clk1 ( PIN clk1 ) ( i1 A ) ( dbuf A ) + USE SIGNAL ;
41+
- i1z ( i1 Z ) ( r1 CK ) + USE SIGNAL ;
42+
- clk2 ( PIN clk2 ) ( c1 A ) + USE SIGNAL ;
43+
- c1z ( c1 Z ) ( r2 CK ) ( r3 CK ) + USE SIGNAL ;
44+
- dz ( dbuf Z ) ( r2 D ) + USE SIGNAL ;
45+
- r1q ( r1 Q ) ( r1 D ) ( r3 D ) + USE SIGNAL ;
46+
- out ( PIN out ) ( r2 Q ) + USE SIGNAL ;
47+
- out2 ( PIN out2 ) ( r3 Q ) + USE SIGNAL ;
48+
END NETS
49+
END DESIGN
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[INFO ODB-0227] LEF file: Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells
2+
[INFO ODB-0128] Design: top
3+
[INFO ODB-0130] Created 4 pins.
4+
[INFO ODB-0131] Created 6 components and 30 component-terminals.
5+
[INFO ODB-0133] Created 8 nets and 15 connections.
6+
=== before repair ===
7+
clk1 net: clk1 dbuf/A i1/A
8+
i1z net: i1/Z r1/CK
9+
r1/CK arrival_max_rise: 0.017601
10+
r1/CK arrival_min_rise: 0.017601
11+
i1/A hold slack: -0.501438
12+
(clk1 ^) r -0.59:2.55 f ---:---
13+
(clk1 v) r ---:--- f 0.42:1.54
14+
(clk1 ^) r -0.50:2.46 f -0.50:2.46
15+
[INFO RSZ-0046] Found 2 endpoints with hold violations.
16+
Iteration | Resized | Buffers | Cloned Gates | Area | WNS | TNS | Endpoint
17+
--------------------------------------------------------------------------------------
18+
0 | 0 | 0 | 0 | +0.0% | -0.587 | -1.088 | r2/D
19+
final | 0 | 45 | 0 | +225.0% | 0.015 | 0.000 | r3/D
20+
--------------------------------------------------------------------------------------
21+
[INFO RSZ-0032] Inserted 45 hold buffers.
22+
=== after repair ===
23+
clk1 net: clk1 dbuf/A i1/A
24+
i1z net: i1/Z r1/CK
25+
r1/CK arrival_max_rise: 0.017601
26+
r1/CK arrival_min_rise: 0.017601
27+
i1/A hold slack: 0.014702
28+
(clk1 ^) r 0.01:1.95 f ---:---
29+
(clk1 v) r ---:--- f 1.01:0.95
30+
(clk1 ^) r 0.03:1.93 f 0.01:1.94

0 commit comments

Comments
 (0)