Title: Simplify and tighten the @perf_event API by congwang-mk · Pull Request #23 · multikernel/kernelscript · GitHub
Open Graph Title: Simplify and tighten the @perf_event API by congwang-mk · Pull Request #23 · multikernel/kernelscript
X Title: Simplify and tighten the @perf_event API by congwang-mk · Pull Request #23 · multikernel/kernelscript
Description: Summary Reworks the @perf_event user-facing API for safety, consistency, and a smaller compiler footprint. Five focused commits: Fold perf_type + perf_config into one event constant. The two old fields had to agree (every config belongs to exactly one type — cache_misses is always hardware), and mismatching them was a silent footgun. A single perf_event enum now packs the perf_event_attr.type tag in the high 32 bits and the config in the low 32 bits, so naming the event fixes both. // before attach(prog, perf_options { perf_type: perf_type_hardware, perf_config: cache_misses }, 0) // after attach(prog, perf_options { event: cache_misses }, 0) Single-source the encoding in stdlib. The PMU-slot analysis had hard-coded the bit layout (>> 32, type tags) and the enum name in the type checker, duplicating what stdlib defined. The layout now lives only in stdlib (perf_event_pack); the type checker resolves the constant generically. Remove the host-dependent static perf-group PMU-budget check. It rejected groups needing more PMU counters than a limit read from the build host's sysfs (or a guessed default of 4) — the wrong layer for a host-dependent resource check, and wrong under cross-compilation. The kernel already enforces group sizing authoritatively at perf_event_open(2) on the real host, and the generated runtime reports it. This removes ~240 lines and all perf-group/PMU/encoding knowledge from type_checker.ml (perf references: 55 → 11, the survivors being the same uniform per-program-type handling @xdp/@kprobe get). Drop the raw group_fd field from perf_options. It exposed a kernel ABI integer alongside the typed group handle. Since every perf fd comes from attach() as a perf_attachment, the raw form was redundant; grouping is now expressed only via group. group_fd: now fails type checking as an unknown field. snake_case the perf types. PerfAttachment → perf_attachment, PerfRead → perf_read, so the whole perf surface matches perf_options and the rest of the language. Behavioral notes Capability trimmed (deliberately): the unified event enum currently covers the named hardware/software events (everything examples/tests used). The old tracepoint/hw_cache/raw/breakpoint type tags and arbitrary numeric configs are not expressible; they can return as encoded enum entries or a raw_event(type, config) constructor if needed. No safety regression from removing the static check: oversized hardware groups fail at perf_event_open(2); >16-member software groups truncate-with-warning in the bounded group read (no overflow); group cycles are already prevented by use-before-definition; non-leader group references are rejected by the kernel. Verification Full test suite green (dune runtest, exit 0). Both perf examples (perf_cache_miss, perf_page_fault) compile and the generated C builds to working binaries — including the software-event path that crosses the 32-bit encoding boundary. Docs (README, SPEC, BUILTINS) updated throughout. Net: +180 / −633 lines. 🤖 Generated with Claude Code
Open Graph Description: Summary Reworks the @perf_event user-facing API for safety, consistency, and a smaller compiler footprint. Five focused commits: Fold perf_type + perf_config into one event constant. The two old ...
X Description: Summary Reworks the @perf_event user-facing API for safety, consistency, and a smaller compiler footprint. Five focused commits: Fold perf_type + perf_config into one event constant. The two old ...
Opengraph URL: https://github.com/multikernel/kernelscript/pull/23
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:97bfeda0-9065-a942-56fd-59a0f8b04125 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9892:11D53A:26A2DA:347F56:6A6290D7 |
| html-safe-nonce | 9c0f996b3274d7210b406573315642d676251133fec059848aa1b519fa160b0a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODkyOjExRDUzQToyNkEyREE6MzQ3RjU2OjZBNjI5MEQ3IiwidmlzaXRvcl9pZCI6IjgwMTY4MTQ2Mzg4NDI5NDE2NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 490b142c32e6cf61e50cd7d2ec8ea6c862778deae5bac1f3ac2facec9dd2d477 |
| hovercard-subject-tag | pull_request:3944137611 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/multikernel/kernelscript/pull/23/files |
| twitter:image | https://avatars.githubusercontent.com/u/227915880?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/227915880?s=400&v=4 |
| og:image:alt | Summary Reworks the @perf_event user-facing API for safety, consistency, and a smaller compiler footprint. Five focused commits: Fold perf_type + perf_config into one event constant. The two old ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ac2209d8cb6970a1bd08cb0a3f821d7166ac544c2ca1c87819c335bb84310ecd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/multikernel/kernelscript git https://github.com/multikernel/kernelscript.git |
| octolytics-dimension-user_id | 202362072 |
| octolytics-dimension-user_login | multikernel |
| octolytics-dimension-repository_id | 1019261571 |
| octolytics-dimension-repository_nwo | multikernel/kernelscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1019261571 |
| octolytics-dimension-repository_network_root_nwo | multikernel/kernelscript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2fca8cd598678aaa64706088ad13b4e19177e108 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width