Skip to content

Commit a6ebbe9

Browse files
committed
Update README.md to enhance clarity on eBPF programming challenges and KernelScript features.
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent fcff065 commit a6ebbe9

File tree

1 file changed

+39
-26
lines changed

1 file changed

+39
-26
lines changed

README.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ KernelScript aims to become the programming language for Linux kernel customizat
1717

1818
Writing eBPF programs today is challenging and error-prone:
1919

20-
- **Raw C + libbpf**: Requires deep eBPF knowledge, verbose boilerplate, manual memory management, and complex build systems
21-
- **Kernel development complexity**: Understanding verifier constraints, BPF helper functions, and kernel APIs
20+
- **Raw C + libbpf**: Requires deep eBPF knowledge, extensive boilerplate code for multiple program types
21+
- **Kernel development complexity**: Understanding eBPF verifier constraints, BPF helper functions, and kernel context
22+
- **Kernel version compatibility**: Managing different kernel APIs, struct layouts, and available kfuncs across kernel versions
2223
- **Complex tail call management**: Manual program array setup, explicit `bpf_tail_call()` invocation, and error handling for failed tail calls
2324
- **Intricate dynptr APIs**: Manual management of `bpf_ringbuf_reserve_dynptr()`, `bpf_dynptr_data()`, `bpf_dynptr_write()`, and proper cleanup sequences
2425
- **Complex struct_ops implementation**: Manual function pointer setup, intricate BTF type registration, kernel interface compliance, and lifecycle management
2526
- **Complex kfunc implementation**: Manual kernel module creation, BTF symbol registration, export management, and module loading coordination
26-
- **Userspace coordination**: Manually writing loaders, map management, and program lifecycle code
27-
- **Multi-program systems**: No coordination between related eBPF programs sharing resources
27+
- **Userspace coordination**: Manually writing loaders, map management, and program lifecycle management of different kinds
28+
- **Multiple programming paradigms**: Developers must master userspace application development, eBPF kernel programming, and kernel module (kfunc) programming
2829

2930
### Why Not Existing Tools?
3031

@@ -51,23 +52,40 @@ Writing eBPF programs today is challenging and error-prone:
5152

5253
KernelScript addresses these problems through revolutionary language features:
5354

54-
**Single-file multi-target compilation** - Write userspace, eBPF, and kernel module code in one file. The compiler automatically targets each function correctly based on attributes (`@xdp`, `@helper`, regular functions)
55+
**Single-file multi-target compilation** - Write userspace, eBPF, and kernel module code in one file. The compiler automatically targets each function correctly based on attributes (`@xdp`, `@helper`, `@kfunc`, and regular userspace functions)
5556

5657
**Automatic tail call orchestration** - Simply write `return other_xdp_func(ctx)` and the compiler handles program arrays, `bpf_tail_call()` generation, and error handling automatically
5758

58-
**Transparent dynptr integration** - Use simple pointer operations (`event_log.reserve()`, `buffer[index]`) while the compiler automatically uses complex dynptr APIs (`bpf_ringbuf_reserve_dynptr`, `bpf_dynptr_write`) behind the scenes
59+
**Transparent dynptr integration** - Use simple pointer operations (`ringbuffer.reserve()`, `some_map[key]`) while the compiler automatically uses complex dynptr APIs (`bpf_ringbuf_reserve_dynptr`, `bpf_dynptr_write`) behind the scenes
5960

6061
**First-class program lifecycle safety** - Programs are typed values with compile-time guarantees that prevent calling `attach()` before `load()` succeeds
6162

62-
**Zero-boilerplate shared state** - Global maps and config blocks are automatically accessible across all programs without imports, exports, or coordination code
63+
**Zero-boilerplate shared state** - Maps are automatically accessible across all programs as regular global variables in a programming language
6364

64-
**Custom kernel functions (@kfunc)** - Write full-privilege kernel functions that eBPF programs can call, automatically generating kernel modules and BTF registrations
65+
**Builtin kfunc support** - Define full-privilege kernel functions that eBPF programs can call directly, automatically generating kernel modules and BTF registrations
6566

6667
**Unified error handling** - C-style integer throw/catch works seamlessly in both eBPF and userspace contexts, unlike complex Result types
6768

6869
**Verifier-optimized type system** - Fixed-size arrays (`u8[64]`), simple type aliases, and no complex generics that confuse the eBPF verifier
6970

70-
**Complete automated toolchain** - Generate ready-to-use projects with Makefiles, userspace loaders, and build systems from a single source file
71+
**Complete automated toolchain** - Generate ready-to-use projects with Makefiles, userspace loaders, kernel modules (if kfunc is defined) and build systems from a single source file
72+
73+
**Automatic BTF extraction** - Seamlessly extract available kfuncs and kernel struct definitions from specified BTF files during project initialization
74+
75+
76+
### Why Choose KernelScript?
77+
78+
| Feature | Raw C + libbpf | Rust eBPF | bpftrace | **KernelScript** |
79+
|---------|---------------|-----------|----------|------------------|
80+
| **Syntax** | Complex C | Complex Rust | Simple but limited | Clean & readable |
81+
| **Type Safety** | Manual | Yes | Limited | Yes |
82+
| **Multi-program** | Manual | Manual | No | Automatic |
83+
| **Build System** | Manual Makefiles | Cargo complexity | N/A | Generated |
84+
| **Userspace Code** | Manual | Manual | N/A | Generated |
85+
| **Learning Curve** | Steep | Steep | Easy but limited | Moderate |
86+
| **Program Types** | All | Most | Tracing only | All |
87+
88+
KernelScript combines the power of low-level eBPF programming with the productivity of modern programming languages, making eBPF development accessible to a broader audience while maintaining the performance and flexibility that makes eBPF powerful.
7189

7290
## Language Overview
7391

@@ -79,6 +97,8 @@ KernelScript supports all major eBPF program types with typed contexts:
7997
// XDP program for packet processing
8098
@xdp fn packet_filter(ctx: *xdp_md) -> xdp_action {
8199
var packet_size = ctx->data_end - ctx->data
100+
var timestamp = get_current_timestamp() // Call our custom kfunc
101+
82102
if (packet_size > 1500) {
83103
return XDP_DROP
84104
}
@@ -148,14 +168,21 @@ var recent_packets : lru_hash<IpAddress, PacketInfo>(1000)
148168
Clean function syntax with helper function support:
149169

150170
```kernelscript
171+
// Custom kernel function - runs in kernel space with full privileges
172+
@kfunc
173+
fn get_current_timestamp() -> u64 {
174+
// Access kernel-only functionality using kernel APIs
175+
return ktime_get_ns() // Direct kernel API call
176+
}
177+
151178
// Helper functions for eBPF programs
152179
@helper
153180
fn extract_src_ip(ctx: *xdp_md) -> IpAddress {
154181
// Packet parsing logic
155182
return 0x7f000001 // 127.0.0.1
156183
}
157184
158-
// Regular functions
185+
// Regular userspace functions
159186
fn update_stats(ip: IpAddress, size: PacketSize) {
160187
connection_count[ip] = connection_count[ip] + 1
161188
}
@@ -186,7 +213,7 @@ fn handle_action(action: FilterAction) -> xdp_action {
186213
}
187214
}
188215
189-
// Truthy/falsy patterns for maps
216+
// Map lookup and update patterns
190217
fn lookup_or_create(ip: IpAddress) -> Counter {
191218
var count = connection_count[ip]
192219
if (count != none) {
@@ -200,7 +227,7 @@ fn lookup_or_create(ip: IpAddress) -> Counter {
200227

201228
### Multi-Program Coordination
202229

203-
KernelScript can coordinate multiple eBPF programs:
230+
Cordination between multiple eBPF programs is just natural:
204231

205232
```kernelscript
206233
// Shared map between programs
@@ -377,20 +404,6 @@ The `examples/` directory contains comprehensive examples:
377404
- `types_demo.ks` - Type system features
378405
- `error_handling_demo.ks` - Error handling patterns
379406

380-
## Why Choose KernelScript?
381-
382-
| Feature | Raw C + libbpf | Rust eBPF | bpftrace | **KernelScript** |
383-
|---------|---------------|-----------|----------|------------------|
384-
| **Syntax** | Complex C | Complex Rust | Simple but limited | Clean & readable |
385-
| **Type Safety** | Manual | Yes | Limited | Yes |
386-
| **Multi-program** | Manual | Manual | No | Automatic |
387-
| **Build System** | Manual Makefiles | Cargo complexity | N/A | Generated |
388-
| **Userspace Code** | Manual | Manual | N/A | Generated |
389-
| **Learning Curve** | Steep | Steep | Easy but limited | Moderate |
390-
| **Program Types** | All | Most | Tracing only | All |
391-
392-
KernelScript combines the power of low-level eBPF programming with the productivity of modern programming languages, making eBPF development accessible to a broader audience while maintaining the performance and flexibility that makes eBPF powerful.
393-
394407
## License
395408

396409
Copyright 2025 Multikernel Technologies, Inc.

0 commit comments

Comments
 (0)