Sysfs vs ioctl (Control Plane Design)¶
1. Data Plane vs Control Plane¶
In Linux driver design, it is important to distinguish between data plane and control plane.
Data Plane¶
Responsible for data flow: - read() - write() - poll() - event queue
Control Plane¶
Responsible for configuration and management: - sysfs - ioctl
2. What is sysfs?¶
sysfs stands for system filesystem.
It is a virtual filesystem used to expose kernel device model information to user space.
Each attribute is represented as a file.
Example:
3. Characteristics of sysfs¶
- Text-based interface
- One attribute = one file
- Easy to use with shell (cat / echo)
- Suitable for configuration and status
- Not suitable for high-frequency data
4. What is ioctl?¶
ioctl is a command-based interface used to control device behavior.
It supports: - Binary data - Struct-based arguments - Complex operations
Example:
5. sysfs vs ioctl¶
| Feature | sysfs | ioctl |
|---|---|---|
| Format | Text | Binary |
| Complexity | Simple | Complex |
| Usage | Shell-friendly | Program-only |
| Data Type | Single value | Struct / multiple fields |
| Best for | Attributes | Commands |
6. When to use what?¶
- read() / poll()
- Data flow
-
Event stream
-
sysfs
- Simple configuration
-
Simple status
-
ioctl
- Complex control
- Structured data
7. Example: mygpio driver¶
Data Plane¶
- read() → event queue
- poll() → wait for event
Control Plane¶
sysfs¶
- debounce_ms
ioctl¶
- SET_DEBOUNCE
- GET_STATUS
- CLR_EVENTS
8. Key Design Guidelines¶
- Do not use sysfs for data streaming
- Do not overload ioctl with simple parameters
- Keep control plane simple and observable
- Use sysfs for simple attributes
- Use ioctl for complex operations
9. Important Insight¶
Control plane can have multiple interfaces, but they must operate on the same driver state.
Example: - sysfs modifies debounce_ms - ioctl modifies debounce_ms - both affect the same internal variable