Skip to content

Commit aa2a7b2

Browse files
authored
misc: Add workflow guides and an ExecPlan example (#820)[skip ci]
* misc: Add repository workflow guides Add AGENTS.md and PLANS.md as repository-level workflow guides. Document planning expectations, environment assumptions, validation rules, and commit/PR conventions. Also stop ignoring AGENTS.md so the guide can be tracked in the repository. Change-Id: Ifa733278f3cf34cac7d87f4503f3e40f980c0e80 * misc: Add completed ExecPlan example Add a completed ExecPlan documenting the PHR target-alignment investigation for PR #814. The example records the RTL path-history findings, the consistency check against gem5, and the supporting gcc12-spec06-0.8c performance analysis. Change-Id: I545fb4d7a4eab68c2e339e2c4da514b62c50dc34 * misc: keep exec plans local by default Change-Id: Idb65704b0130bc3d0e12dd3fa77fc991584c1ef6
1 parent eb6a3fb commit aa2a7b2

3 files changed

Lines changed: 377 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ compile_commands.json
6060
.direnv
6161
.cursor/
6262

63+
docs/exec-plans/
64+
6365
# for use npm to install claude-code locally
6466
CLAUDE.md
6567
node_modules/
6668
package-lock.json
6769
package.json
68-
AGENTS.md
6970

7071
microbench/build/
7172
microbench/output/

AGENTS.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Repository Guidelines
2+
3+
This file defines the collaboration rules and workflow entry points for this repository.
4+
5+
- For complex tasks, follow the process first instead of jumping straight into code changes.
6+
- For non-trivial behavioral changes, explain the background, assumptions, risks, and validation plan.
7+
- If documentation conflicts, treat the source code as the ground truth, then consult architecture and process docs.
8+
9+
## Planning
10+
11+
If a task involves complex feature development, long-running debugging, performance or behavior alignment, larger refactors, or analysis that spans multiple turns, first create or update an ExecPlan according to [PLANS.md](PLANS.md) before continuing.
12+
13+
Typical cases that should use an ExecPlan include:
14+
15+
- gem5 / RTL behavior alignment
16+
- Frontend / BPU / FTQ / redirect / flush investigations
17+
- Performance regression analysis
18+
- Refactors that cross multiple modules
19+
- New features that need to be landed in stages
20+
21+
## Repository Map
22+
23+
Start with these directories first:
24+
25+
- `src/`: core source code (C++ / Python), especially `arch/riscv/`, `cpu/o3/`, and `cpu/pred/`
26+
- `configs/`: runtime configurations, especially `configs/example/kmhv3.py`
27+
- `tests/`: test entry points
28+
- `util/`: helper scripts and tools
29+
- `docs/`: documentation, including architecture and execution plans
30+
31+
For a higher-level map of the codebase, see [ARCHITECTURE.md](ARCHITECTURE.md).
32+
33+
## Environment Assumptions
34+
35+
This repository is primarily developed on shared Linux servers.
36+
37+
- For full-system, checkpoint, and difftest-related tasks, prefer assuming `GCBV_REF_SO` is available.
38+
- The default CI-style reference path is:
39+
`GCBV_REF_SO=/nfs/home/share/gem5_ci/ref/normal/riscv64-nemu-interpreter-so`
40+
- The default explicit setting for `GCB_RESTORER` is:
41+
`GCB_RESTORER=""`
42+
- Whether `GCB_RESTORER` and `AM_HOME` are needed depends on the task:
43+
- restore-related workflows may require checking `GCB_RESTORER`
44+
- some frontend micro-tests and bare-metal test flows may require checking `AM_HOME`
45+
- Before running environment-dependent tasks, check the relevant variables instead of assuming local defaults are correct.
46+
47+
## Build, Run, and Test Entry Points
48+
49+
Common entry points:
50+
51+
- Build optimized binary:
52+
`scons build/RISCV/gem5.opt --gold-linker -j64`
53+
- Build debug binary:
54+
`scons build/RISCV/gem5.debug --gold-linker -j64 --debug-cycle`
55+
- Run the XiangShan configuration:
56+
`./build/RISCV/gem5.opt ./configs/example/kmhv3.py --raw-cpt --generic-rv-cpt=<path>`
57+
- SE mode example:
58+
`./build/RISCV/gem5.opt ./configs/example/se.py -c <binary>`
59+
- Build all unit tests:
60+
`scons build/RISCV/unittests.opt -j100 --unit-test`
61+
62+
If you need a more systematic understanding of module boundaries, configuration entry points, or execution flow, read [ARCHITECTURE.md](ARCHITECTURE.md) first.
63+
64+
## Style and Naming
65+
66+
- C / C++: follow `.clang-format`
67+
- Python: follow the repository's existing formatting and checking workflow
68+
- Naming:
69+
- types / classes: UpperCamelCase
70+
- functions / methods: lower_snake_case
71+
- constants: ALL_CAPS
72+
- Use English for code comments and commit messages
73+
- Keep changes simple and avoid introducing functionality unrelated to the current task
74+
75+
## Validation Expectations
76+
77+
For non-trivial changes, do not stop at code edits alone. Validation should match the level of risk.
78+
79+
Prefer these principles:
80+
81+
- Behavioral changes: provide a minimal reproduction, key logs, statistics, or test results
82+
- Refactors: confirm there is no behavioral regression, and compare key statistics when needed
83+
- Frontend / BPU / timing-related changes: prefer targeted workloads, unit tests, or checkpoint-based regression
84+
- Analysis tasks: clearly distinguish confirmed facts, current hypotheses, and unresolved questions
85+
86+
If full validation cannot be completed in the current environment, explicitly state the gap and the remaining risk.
87+
88+
## Commit and PR Expectations
89+
90+
- Use imperative English in commit messages
91+
- Prefer module-prefixed commit titles focused on a single change, for example:
92+
`cpu-o3: Fix tage allocation`
93+
- PRs should explain:
94+
- motivation
95+
- approach
96+
- scope of impact
97+
- validation method and results
98+
- Run the repository's style checks and required tests before submission
99+
100+
## Related Documents
101+
102+
- [PLANS.md](PLANS.md): ExecPlan rules for complex tasks
103+
- [ARCHITECTURE.md](ARCHITECTURE.md): high-level architecture map of the repository

PLANS.md

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
# ExecPlan Guide
2+
3+
This document is adapted from [OpenAI's ExecPlan](https://developers.openai.com/cookbook/articles/codex_exec_plans) guidance and tailored to the needs of this repository.
4+
5+
It defines how execution plans (ExecPlans) should be written and maintained in this codebase.
6+
7+
ExecPlans are meant for tasks like these:
8+
9+
- Tasks that cannot realistically be completed in one or two exchanges
10+
- Work that spans multiple steps, files, or experiments
11+
- Investigations that need recorded evidence, decisions, intermediate findings, and current status
12+
- Long efforts where context can easily drift if it is not written down
13+
14+
If the task is just a very small change, a simple bug fix, or a single-file adjustment, a separate ExecPlan is usually unnecessary.
15+
16+
## 1. What an ExecPlan Is
17+
18+
An ExecPlan is not a casual TODO list and not a lightweight checklist.
19+
20+
It is a living execution document that should answer questions like:
21+
22+
- What problem is being solved?
23+
- Why is it worth doing?
24+
- What is already known?
25+
- What exactly happens next?
26+
- How do we know the result is correct?
27+
- What did we learn along the way?
28+
- Why did the plan change midway?
29+
30+
A good ExecPlan should let someone who does not know the previous conversation pick up the task and continue with reasonable confidence.
31+
32+
## 2. When to Use an ExecPlan
33+
34+
Create or update an ExecPlan when one or more of the following is true:
35+
36+
1. The task will likely take significant time or span multiple conversations
37+
2. The work combines at least two of: research, experimentation, debugging, implementation
38+
3. The task touches multiple modules, files, or evidence sources
39+
4. There is meaningful uncertainty and assumptions need to be validated first
40+
5. The task needs a record of why a decision was made, not just what changed
41+
6. The task may be paused and resumed later
42+
43+
Typical examples:
44+
45+
- Aligning gem5 behavior with RTL
46+
- Investigating frontend / BPU / FTQ / flush / redirect behavior
47+
- Analyzing a performance regression
48+
- Landing a larger refactor
49+
- Building a feature that must be implemented in phases
50+
- Prototyping before committing to a final design
51+
52+
## 3. Writing Principles
53+
54+
### 3.0 Language
55+
56+
By default, ExecPlans may be written in Chinese for internal development efficiency.
57+
58+
Use English when the expected audience includes external contributors, or when the plan is intended to be referenced from public-facing documentation, PR discussion, or broader cross-team communication.
59+
60+
### 3.1 Self-Contained
61+
62+
An ExecPlan should be as self-contained as possible.
63+
64+
Do not assume the reader remembers earlier chat history, and do not write things like "same as discussed above".
65+
66+
If background is necessary to move the task forward, write it into the current document.
67+
68+
### 3.2 Outcome-Oriented
69+
70+
Do not stop at "change function X" or "add field Y".
71+
72+
Explain:
73+
74+
- What effect you expect
75+
- What the user or developer should be able to observe afterward
76+
- How that outcome will be validated
77+
78+
### 3.3 Evidence-Oriented
79+
80+
Especially for analysis tasks, do not write guesses as if they were facts.
81+
82+
Clearly separate:
83+
84+
- confirmed facts
85+
- current hypotheses
86+
- open questions
87+
- the evidence supporting a conclusion
88+
89+
### 3.4 Continuously Updated
90+
91+
An ExecPlan is a living document, not a one-time writeup.
92+
93+
As the work progresses, update:
94+
95+
- current status
96+
- new findings
97+
- decision changes
98+
- next actions
99+
100+
### 3.5 Explain Why First
101+
102+
Implementation details can be expanded later, but important decisions must include their rationale.
103+
104+
Someone picking up the task later should be able to understand why this approach was chosen instead of another one.
105+
106+
## 4. Recommended Location
107+
108+
Prefer one ExecPlan file per complex task rather than putting everything into one large document.
109+
110+
By default, ExecPlan instances should be treated as local working documents instead of repository-tracked artifacts. They are useful as intermediate notes during long investigations, but they are often too noisy and task-specific to keep in git by default.
111+
112+
Recommended local directory structure:
113+
114+
```text
115+
docs/
116+
exec-plans/
117+
active/
118+
completed/
119+
blocked/
120+
```
121+
122+
Meaning:
123+
124+
- `active/`: tasks currently in progress
125+
- `completed/`: finished tasks kept locally for later reference
126+
- `blocked/`: tasks paused pending external conditions
127+
128+
Use concise, descriptive file names, for example:
129+
130+
- `docs/exec-plans/active/gem5-rtl-fetch-align.md`
131+
- `docs/exec-plans/active/bpu-override-investigation.md`
132+
- `docs/exec-plans/active/spec06-regression-debug.md`
133+
134+
Only commit an ExecPlan when there is explicit value in sharing it through the repository, such as cross-person handoff, review, or preserving a decision record that should live with the codebase.
135+
136+
## 5. Recommended Structure
137+
138+
Each ExecPlan should usually contain at least the following sections.
139+
140+
## Title
141+
142+
Use a short sentence that describes the goal.
143+
The title should prefer "action + object" over vague naming.
144+
145+
For example:
146+
147+
- Align gem5 frontend flush behavior with RTL
148+
- Investigate the IPC regression of a SPEC06 benchmark
149+
- Add verifiable observability for BPU override
150+
151+
---
152+
153+
## Background and Goal
154+
155+
Use a few paragraphs to explain:
156+
157+
- what the current problem is
158+
- why it matters
159+
- what result should be achieved
160+
- how that result will be observed
161+
162+
Focus first on the value of the task and the end result, not on implementation details.
163+
164+
---
165+
166+
## Current Known Information
167+
168+
Record the facts, observations, and constraints already confirmed.
169+
This can include:
170+
171+
- relevant modules, files, and paths
172+
- current behavior and how it differs from expectations
173+
- logs, counters, traces, waveforms, or test results already observed
174+
- environment constraints
175+
176+
Do not write guesses as facts in this section.
177+
178+
## Hypotheses and Open Questions
179+
180+
If uncertainty remains, list it explicitly. For example:
181+
182+
- We currently suspect the issue is the timing of override activation
183+
- We are not yet sure whether the second target comes from mainBTB
184+
- We need to verify whether a counter covers the split-request case
185+
186+
The purpose of this section is to keep the analysis from becoming muddled over time.
187+
188+
---
189+
190+
## Planned Steps
191+
192+
List the next steps in order.
193+
Each step should ideally be written as "action + goal + expected output".
194+
195+
For example:
196+
197+
1. Read the frontend redirect path and confirm the actual control flow in gem5
198+
2. Cross-check RTL documentation and implementation, then summarize the flush taxonomy
199+
3. Add the required logs or counters and construct a minimal reproduction
200+
4. Run the chosen workload and verify whether the behavior converges
201+
5. Decide whether to keep the current approach or revise it based on the results
202+
203+
Avoid cryptic shorthand that only the original author can understand.
204+
205+
---
206+
207+
## Validation
208+
209+
Always specify how success will be judged.
210+
211+
Validation may mean:
212+
213+
- tests pass
214+
- logs match expectations
215+
- counters move in the expected direction
216+
- a workload now behaves like RTL
217+
- a performance regression is eliminated
218+
- a scenario is reproducible and then fixed
219+
220+
Even for analysis-only tasks, define what "done" means. For example:
221+
222+
- root cause confirmed
223+
- minimal reproduction identified
224+
- candidate causes ruled out
225+
- a concrete recommendation for the next phase is available
226+
227+
## Progress
228+
229+
Progress must be updated continuously.
230+
Use checkboxes with timestamps.
231+
232+
Example:
233+
234+
- [x] 2026-03-24 10:00 Read the main frontend redirect path and identify the primary entry points
235+
- [x] 2026-03-24 11:20 Cross-check RTL docs and discover that the flush taxonomy differs from the earlier assumption
236+
- [ ] Add counters for the split-request case and verify whether `inflightLoads` fully covers it
237+
- [ ] Construct a minimal workload to validate the second-target selection logic
238+
239+
If a step is only partially complete, say what has been finished and what remains.
240+
241+
---
242+
243+
## Findings and Surprises
244+
245+
Record important new findings that appear during the work.
246+
Especially note things like:
247+
248+
- an earlier understanding was wrong
249+
- docs and code disagree
250+
- a counter definition is unreliable
251+
- a path is more important than expected
252+
- an experiment disproved an earlier hypothesis
253+
254+
This section matters because long tasks often fail when important intermediate learning is not written down.
255+
256+
---
257+
258+
## Decision Log
259+
260+
Whenever an important decision is made or the direction changes, record it.
261+
262+
Recommended format:
263+
264+
- Decision: ...
265+
- Reason: ...
266+
- Date: ...
267+
268+
For example:
269+
270+
- Decision: add observability before changing behavior
271+
- Reason: the root cause is not fully confirmed yet, so changing behavior immediately is too risky
272+
- Date: 2026-03-24

0 commit comments

Comments
 (0)