Callback, Override, Knob or Delegate: A Decision Lab
Build one requirement four ways, combine two teams' changes, and choose the extension point that survives the combination. Then write the VIP author's checklist for hooks.
You Will Be Able To
- Build one change as a knob, an override, a callback and a delegate.
- Predict what happens when two teams combine overrides or callbacks on one driver.
- Choose an extension point from who must foresee the change and whether changes stack.
- List what a VIP author promises with each hook.
- Lesson
- U18.5
- Time
- 30 min
- Runs on
- Verilator with UVM
- Check
- 4 questions
Two teams each needed one change on the same lane driver: bad parity on item 2, and inverted data on item 3. Each delivered a factory override, and each test passed alone. Combined on one lane, the parity change vanished without a message.
| Lane 4 setup | Bad parity on | Changed data on |
|---|---|---|
| Two instance overrides, parity team first | 2 | - |
| Two callbacks (lane 5) | 2 | 3 |
Measured in the example: with two overrides on one path, only the first one set is built.
One Requirement, Four Ways
The example's VIP offers four extension points around the beat. They are a knob cfg.bad_par_on, a delegate policy.parity(), a virtual method shape() and the pre_send callbacks. Each of lanes 0 to 3 sends item 2 with bad parity through one of them.
| Knob | Override | Callback | Delegate | |
|---|---|---|---|---|
| Code the test writes | one field set | a subclass and an override | a subclass and an add | a subclass and a config set |
| Must the VIP author foresee it? | the exact value | a virtual method | a hook point | the delegate role |
| Two teams at once | only if both knobs exist | one class wins | stack in queue order | one object per role |
| Change during the run | if the VIP rereads it | no | add, delete, switch off | swap the handle |
| Work per beat | a field read | a virtual call | one iterator per hook point run | a virtual call |
| Silent failure | wrong path or read too early | path matches nothing, or another override wins | wrong instance or type | set after the VIP read it |
Lanes 0-3 of the example all send item 2 with bad parity; the differences show only when changes combine.
Combining Two Teams
Lanes 4 and 5 carry both requirements. Lane 4 gets two instance overrides for the same driver path; lane 5 gets two callbacks. Lane 5 shows both changes. Lane 4 shows only the parity change: the factory found the first override for that path and built par2_driver. That is the standard's rule (IEEE 1800.2-2020 §8.3.1.4.1). Instance overrides are searched in the order they were set, and the first match wins.
- Control / FSM
- Result
- Control
- Foreseen values
If the author can name the variation, a knob is the cheapest: one field, set per instance.
- Stacking
Only callbacks stack: two teams add two objects to one driver. lane5 in the example.
- Replacing
One replaced algorithm fits a delegate if the VIP offers one, else an override of the class.
Read the diagram as text
- A value the VIP author foresaw?: a delay, an idle value, an error rate
- Config knob: a field the VIP reads
- Several changes must stack or switch during the run?: two teams on one driver
- Callback: at a hook point the VIP offers
- One algorithm replaced as a whole?: timing, arbitration, a checksum
- Delegate object: a handle the VIP calls
- Factory override: a subclass built in its place
- A value the VIP author foresaw? → Config knob: yes
- A value the VIP author foresaw? → Several changes must stack or switch during the run?: no
- Several changes must stack or switch during the run? → Callback: yes
- Several changes must stack or switch during the run? → One algorithm replaced as a whole?: no
- One algorithm replaced as a whole? → Delegate object: yes, the VIP offers a handle
- One algorithm replaced as a whole? → Factory override: no: change the class
The Cookbook prefers overrides and delegates to callbacks; callbacks earn their place when changes must stack.
The VIP Author's Checklist
Offer knobs for foreseen values
Put them in a config object, read them where they are used, and document when they are read.
Offer a delegate for each replaceable algorithm
Timing, arbitration, a checksum: a small base class with a default, set before build.
Offer few hooks, per item
Pass the objects a callback may change, such as the beat, and keep their prototypes stable.
Document the order
Say when each hook runs, whether it is a task, and what a veto does.
Keep methods virtual and creation in the factory
So an override stays possible for the cases nobody foresaw.
The Cookbook's guideline is to avoid callbacks and use overrides or a delegate instead. That fits changes that replace behaviour. Callbacks remain the one point where independent additions stack and can be switched during the run. That is why vendor VIP offers them.
Try It
Lanes 0-3 are the four ways to the same result. Lane 4 built only par2_driver, so team B's change is missing; lane 5 runs both callbacks.
Change lane 0's knob to item 3 and lane 3's policy to flip every item, and compare the edits each needs.
lane0 knob lane_driver bad parity on 2, changed data on - lane1 override par2_driver bad parity on 2, changed data on - lane2 callback lane_driver bad parity on 2, changed data on - lane3 delegate lane_driver bad parity on 2, changed data on - lane4 2 overrides par2_driver bad parity on 2, changed data on - lane5 2 callbacks lane_driver bad parity on 2, changed data on 3Check Yourself
Common Mistakes
Wrong Give two teams' changes as two factory overrides for the same driver.
Only one class is built per instance; with two instance overrides on one path, the first one set wins.
Fix Make additions callbacks, or write one subclass that does both.
Wrong Set a delegate in the configuration database after the driver's build_phase.
The driver reads the handle once in build_phase and keeps the default.
Fix Set it before the driver is built, from the test's build_phase.
Wrong Use a callback to replace the driver's timing.
A callback runs only at the points the VIP offers; it cannot change how the driver waits between them.
Fix Replace an algorithm with a delegate or an override.
Remember
- Knobs for foreseen values, delegates or overrides for replaced algorithms, callbacks for additions that must stack or switch.
- One instance gets one class: two overrides for one path do not combine, and the first one set wins.
- A delegate or knob is read when the VIP reads it, usually in build_phase; set it before.
- A VIP author offers few per-item hooks with stable arguments and documents their order.