Skip to content

Commit 277ecba

Browse files
committed
Add HID-BPF tutorial and implementation for virtual mouse input modification
- Introduced a comprehensive tutorial in README.md explaining how to fix broken HID devices using eBPF without kernel patches. - Implemented a userspace program (hid-input-modifier.c) that creates a virtual HID mouse using the uhid interface and sends synthetic mouse events. - Developed a BPF program (hid-input-modifier.bpf.c) that intercepts HID events and modifies mouse movement data, effectively doubling the X and Y movement. - Created necessary header files (hid_bpf.h, hid_bpf_defs.h, hid_bpf_helpers.h) to define structures and helper functions for the BPF program. - Added functionality to find and manage the virtual HID device, ensuring seamless integration with the BPF program.
1 parent 5319e02 commit 277ecba

File tree

35 files changed

+1101
-5
lines changed

35 files changed

+1101
-5
lines changed

scripts/generate_toc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ def generate_toc(base_dir, project_root):
1515
"GPU": "\n\nGPU:\n\n",
1616
"Scheduler": "\n\nScheduler:\n\n",
1717
"Networking": "\n\nNetworking:\n\n",
18-
"tracing": "\n\nTracing:\n\n",
18+
"Tracing": "\n\nTracing:\n\n",
1919
"Security": "\n\nSecurity:\n\n",
2020
"Features": "\n\nFeatures:\n\n",
21-
"Other": "\n\nFeatures:\n\n"
21+
"Other": "\nOther:\n\n"
2222
}
2323

24-
subsection_order = ['GPU', 'Scheduler', 'Networking', 'tracing', 'Security', 'Features', 'Other', 'Android']
24+
subsection_order = ['GPU', 'Scheduler', 'Networking', 'Tracing', 'Security', 'Features', 'Other', 'Android']
2525

2626
# To ensure numeric sorting of directories
2727
def sort_key(directory_name):

src/10-hardirqs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ eBPF (Extended Berkeley Packet Filter) is a powerful network and performance ana
55
This article is the tenth part of the eBPF Tutorial by Example, focusing on capturing interrupt events using hardirqs or softirqs in eBPF.
66
hardirqs and softirqs are two different types of interrupt handlers in the Linux kernel. They are used to handle interrupt requests generated by hardware devices, as well as asynchronous events in the kernel. In eBPF, we can use the eBPF tools hardirqs and softirqs to capture and analyze information related to interrupt handling in the kernel.
77

8+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/10-hardirqs>
9+
810
## What are hardirqs and softirqs?
911

1012
hardirqs are hardware interrupt handlers. When a hardware device generates an interrupt request, the kernel maps it to a specific interrupt vector and executes the associated hardware interrupt handler. Hardware interrupt handlers are commonly used to handle events in device drivers, such as completion of device data transfer or device errors.

src/11-bootstrap/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (Extended Berkeley Packet Filter) is a powerful network and performance ana
44

55
In this tutorial, we will learn how kernel-space and user-space eBPF programs work together. We will also learn how to use the native libbpf to develop user-space programs, package eBPF applications into executable files, and distribute them across different kernel versions.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/11-bootstrap>
8+
79
## The libbpf Library and Why We Need to Use It
810

911
libbpf is a C language library that is distributed with the kernel version to assist in loading and running eBPF programs. It provides a set of C APIs for interacting with the eBPF system, allowing developers to write user-space programs more easily to load and manage eBPF programs. These user-space programs are typically used for system performance analysis, monitoring, or optimization.

src/12-profile/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This tutorial will guide you on using eBPF programs for performance analysis wit
44

55
This implementation uses libbpf-rs, a Rust wrapper around libbpf, along with blazesym for symbol resolution. Perf is a performance analysis tool in the Linux kernel that allows users to measure and analyze the performance of kernel and user space programs, as well as obtain corresponding call stacks. It collects performance data using hardware counters and software events in the kernel.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/12-profile>
8+
79
## eBPF Tool: profile Performance Analysis Example
810

911
The `profile` tool is implemented based on eBPF and utilizes the perf events in the Linux kernel for performance analysis. The `profile` tool periodically samples each processor to capture the execution of kernel and user space functions.

src/13-tcpconnlat/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (Extended Berkeley Packet Filter) is a powerful network and performance ana
44

55
This article is the thirteenth installment of the eBPF Tutorial by Example, mainly about how to use eBPF to statistics TCP connection delay and process data in user space using libbpf.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/13-tcpconnlat>
8+
79
## Background
810

911
When developing backends, regardless of the programming language used, we often need to call databases such as MySQL and Redis, perform RPC remote calls, or call other RESTful APIs. The underlying implementation of these calls is usually based on the TCP protocol. This is because TCP protocol has advantages such as reliable connection, error retransmission, congestion control, etc., so TCP is more widely used in network transport layer protocols than UDP. However, TCP also has some drawbacks, such as longer connection establishment delay. Therefore, some alternative solutions have emerged, such as QUIC (Quick UDP Internet Connections).

src/14-tcpstates/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (Extended Berkeley Packet Filter) is a powerful network and performance ana
44

55
In this article of our eBPF Tutorial by Example series, we will introduce two sample programs: `tcpstates` and `tcprtt`. `tcpstates` is used to record the state changes of TCP connections, while `tcprtt` is used to record the Round-Trip Time (RTT) of TCP.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/14-tcpstates>
8+
79
## `tcprtt` and `tcpstates`
810

911
Network quality is crucial in the current Internet environment. There are many factors that affect network quality, including hardware, network environment, and the quality of software programming. To help users better locate network issues, we introduce the tool `tcprtt`. `tcprtt` can monitor the Round-Trip Time of TCP connections, evaluate network quality, and help users identify potential problems.

src/15-javagc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (Extended Berkeley Packet Filter) is a powerful network and performance ana
44

55
In this article of our eBPF Tutorial by Example series, we will explore how to use eBPF and USDT to capture and analyze the duration of Java garbage collection (GC) events.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/15-javagc>
8+
79
## Introduction to USDT
810

911
USDT is a mechanism for inserting static tracepoints into applications, allowing developers to insert probes at critical points in the program for debugging and performance analysis purposes. These probes can be dynamically activated at runtime by tools such as DTrace, SystemTap, or eBPF, allowing access to the program's internal state and performance metrics without the need to restart the application or modify the program code. USDT is widely used in many open-source software applications such as MySQL, PostgreSQL, Ruby, Python, and Node.js.

src/16-memleak/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (extended Berkeley Packet Filter) is a powerful network and performance ana
44

55
In this tutorial, we will explore how to write a Memleak program using eBPF to monitor memory leaks in programs.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/16-memleak>
8+
79
## Background and Importance
810

911
Memory leaks are a common problem in computer programming and should not be underestimated. When memory leaks occur, programs gradually consume more memory resources without properly releasing them. Over time, this behavior can lead to a gradual depletion of system memory, significantly reducing the overall performance of the program and system.

src/17-biopattern/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ eBPF (Extended Berkeley Packet Filter) is a new technology in the Linux kernel t
44

55
In this tutorial, we will explore how to use eBPF to write programs to count random and sequential disk I/O. Disk I/O is one of the key metrics of computer performance, especially in data-intensive applications.
66

7+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/17-biopattern>
8+
79
## Random/Sequential Disk I/O
810

911
As technology advances and data volumes explode, disk I/O becomes a critical bottleneck in system performance. The performance of an application depends heavily on how it interacts with the storage tier. Therefore, it becomes especially important to deeply understand and optimise disk I/O, especially random and sequential I/O.

src/18-further-reading/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ You may find more about eBPF in these places:
55
- A curated list of awesome projects related to eBPF: <https://github.com/zoidbergwill/awesome-ebpf>
66
- A website of eBPF projects and tutorials: <https://ebpf.io/>
77

8+
> The complete source code: <https://github.com/eunomia-bpf/bpf-developer-tutorial/tree/main/src/18-further-reading>
9+
810
This is also list of eBPF related papers I read in recent years, might be helpful for people who are interested in eBPF related research.
911

1012
eBPF (extended Berkeley Packet Filter) is an emerging technology that allows safe execution of user-provided programs in the Linux kernel. It has gained widespread adoption in recent years for accelerating network processing, enhancing observability, and enabling programmable packet processing.

0 commit comments

Comments
 (0)