Title: feat:Implement perf event groups, scaled reads, and group snapshots by SiyuanSun0736 · Pull Request #22 · multikernel/kernelscript · GitHub
Open Graph Title: feat:Implement perf event groups, scaled reads, and group snapshots by SiyuanSun0736 · Pull Request #22 · multikernel/kernelscript
X Title: feat:Implement perf event groups, scaled reads, and group snapshots by SiyuanSun0736 · Pull Request #22 · multikernel/kernelscript
Description: Overview This PR introduces the ability to group multiple perf metrics (e.g., cache misses, branch misses, cycles) into a single scheduling group. This ensures that counters observing the same workload are started and stopped together, solving the issue of misaligned results from independently managed counters. Additionally, it brings comprehensive multiplex-aware read APIs, static PMU slot limit validations, and fixes several internal userspace codegen edges to stabilize snapshot data consumption. Key Features & User-Facing Changes 1. High-Level Grouping API New group field: Added a high-level group field in perf_options to easily attach members to a leader. var cache = attach(prog, perf_options { perf_type: perf_type_hardware, perf_config: cache_misses }, 0) var branch = attach(prog, perf_options { perf_type: perf_type_hardware, perf_config: branch_misses, group: cache }, 0) Compatibility: The lower-level group_fd: leader.perf_fd approach is preserved for backward compatibility. 2. Multiplex-Aware Read APIs read(att): Now returns scaled values by default, corrected via time_enabled / time_running when PMU multiplexing occurs. (Matches raw count if no multiplexing happens). read_raw(att): Returns the uncorrected, raw counter values. read_details(att): Returns a struct containing raw, scaled, time_enabled, and time_running—ideal for manual delta or rate calculations. read_group(leader): Captures an atomic snapshot of the entire group. Returns up to 16 ID/Value pairs (where values[] are pre-scaled according to snapshot timing) and snapshot time fields. 3. Group Lifecycle Management Group Restarts: Dynamically attaching a new member to an existing active group now triggers a disable/reset/enable sequence on the whole group, ensuring counters start from zero together. Cascading Detach: Detaching a group leader no longer conservatively rejects the operation. It now cascades and automatically detaches all active members. 4. Compile-Time PMU Slot Validation Statically visible perf groups are now evaluated during the type-checking phase to calculate hardware PMU slot consumption. Compilation will fail early if the group is too large. The limit defaults to 4 (or dynamically probes sysfs), and can be overridden via the KERNELSCRIPT_PERF_GROUP_MAX_EVENTS environment variable. perf_type_software and perf_type_tracepoint are correctly excluded from hardware PMU slot counts. Internal & Codegen Improvements Array IR Lowering: Fixed array indexing and dereferencing in IR lowering to ensure user-space C code generates correctly when iterating over read_group() snapshot arrays (snapshot.ids[i] / snapshot.values[i]). Array Initialization: Modified non-literal array initializations to "declare first, then memcpy", preventing invalid C generation from snapshot struct fields. Variable Declarations: Fixed an issue where reused for loop counters and subsequent variables of the same name produced duplicate function-level C declarations. Read Helpers: Added raw/details/group perf read helpers, leveraging 128-bit intermediate values for safe multiplex scaling. Documentation & Examples examples/perf_cache_miss.ks: Refactored to use the new group API. Added demonstrations of read_details() for rate calculation and read_group() for iterating through snapshot id/value pairs. examples/perf_page_fault.ks: Extended to demonstrate updated perf read semantics. Docs: Updated README.md, SPEC.md, and BUILTINS.md to reflect group semantics, read interfaces, and PMU slot constraints. Test Coverage Added IR and codegen assertions for both group_fd and high-level group paths. Covered member-attach group restarts, ioctl generation, and cascading leader detaches. Covered multiplex scaling fast/slow paths for read(), and helper generation for read_raw(), read_details(), and read_group(). Covered oversized static group validation during compilation. Added regression tests for for loop counter variable reuse in userspace codegen.
Open Graph Description: Overview This PR introduces the ability to group multiple perf metrics (e.g., cache misses, branch misses, cycles) into a single scheduling group. This ensures that counters observing the same work...
X Description: Overview This PR introduces the ability to group multiple perf metrics (e.g., cache misses, branch misses, cycles) into a single scheduling group. This ensures that counters observing the same work...
Opengraph URL: https://github.com/multikernel/kernelscript/pull/22
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b46a28e4-3c46-a8a9-b889-2736ad8f21c4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | EBE8:20F21A:83972:BFAEC:6A621229 |
| html-safe-nonce | da908df6181b16f014435e756fb0660ee0d7f6352e203200f6736c8490fa241e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkU4OjIwRjIxQTo4Mzk3MjpCRkFFQzo2QTYyMTIyOSIsInZpc2l0b3JfaWQiOiI0ODI4NTA1NDE4MjQyMzMxMTc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 32e4af0f892e2d5703c71491e5d4f8e3068af8164ff57876f1554bafe631214e |
| hovercard-subject-tag | pull_request:3707309186 |
| 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/22/files |
| twitter:image | https://avatars.githubusercontent.com/u/100674758?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/100674758?s=400&v=4 |
| og:image:alt | Overview This PR introduces the ability to group multiple perf metrics (e.g., cache misses, branch misses, cycles) into a single scheduling group. This ensures that counters observing the same work... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | be9a4d9589756e22b427637ffbf1123a96e067050e57f5cec403e3080a650ca4 |
| 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 | 7b5509702f01f876c214a2cbb142690847de0019 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width