# kernel-assistant **Repository Path**: zhang_tianran/kernel-assistant ## Basic Information - **Project Name**: kernel-assistant - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2026-09-07 - **Last Updated**: 2026-09-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Linux Kernel Assistant (VSCode Extension) Search a keyword and insert ready-to-use **Linux 6.6 kernel example code** straight into your editor. The bundled snippets cover the major knowledge points of the `linux-6.6.143` tree: from module basics to drivers, synchronization, memory management, networking, tracing, crypto, subsystem frameworks, power management and virtualization/security. ## Features - **QuickPick search box** — type a keyword (e.g. `spinlock`, `platform`, `netlink`, `ftrace`, `ioctl`, `mmap`, `bpf`...) and pick a snippet. - **Insert at cursor** — selected example is dropped into the active editor. - **Ranked fuzzy search** over titles, categories, ids and keyword tags. - **154 snippets** organized into **14 categories** spanning the kernel. - Configurable header comment and result limit (`kernelAssistant.*` settings). - Keybinding `Ctrl+Alt+K` (macOS `Cmd+Alt+K`) and editor context menu entry. ## Usage 1. Open a C / Makefile / DTS file. 2. Run **Kernel Assistant: Insert Example Code** from the Command Palette (or `Ctrl+Alt+K`, or right-click → context menu). 3. Type a keyword to filter the list and press `Enter`. 4. The example code is inserted at the cursor. There is also **Kernel Assistant: Search Knowledge Points**, which opens the result in a new document if no editor is focused. ## Build / install from source ```bash cd kernel-assistant-vscode npm install npm run compile # generates gen.ts from snippets/, then tsc -> out/ ``` Snippet code lives as standalone files under `snippets//.` (`.c` / `.mk` / `.config` / `.dts`). To edit an example, change the file and re-run `npm run gen` (or `npm run compile`, which does it automatically) — you never have to touch the TypeScript template metadata. Then in VSCode press `F5` to launch an Extension Development Host, or package with `vsce package` to get a `.vsix` and install via `code --install-extension kernel-assistant-0.1.0.vsix`. ## Covered knowledge points (by category) ### Core / Basics (10) loadable module skeleton, module parameters, character device (`cdev`), `miscdevice`, `ioctl` commands, `mmap`, full `file_operations`, `copy_to/from_user` & `get/put_user`, out-of-tree Kbuild Makefile, Kconfig entry. ### Synchronization (13) spinlock (incl. `_irqsave`/`_bh`), mutex, rwlock, rwsem, counting semaphore, completion, `atomic_t`/`atomic64_t` & `cmpxchg`, atomic bitops, seqlock, RCU (read-side + writer/synchronize), per-CPU variables, memory barriers (`smp_store_release`/`READ_ONCE`), lockdep annotations. ### Concurrency / Deferred (10) kthread, workqueue (`schedule_work`), delayed work, custom/ordered workqueue (`alloc_workqueue`), tasklet, `timer_list`, hrtimer, wait queue, poll + wakeup pattern, kthread worker. ### Memory Management (12) `kmalloc`/`kfree`, `vmalloc`/`vfree`, slab cache (`kmem_cache`), page allocator (`alloc_pages`), pin user pages (`pin_user_pages_fast`), coherent DMA, streaming DMA (`dma_map_single`), scatterlist/sg_table, MMIO (`ioremap`), managed resources (`devm_*`), genalloc pool, vmalloc fault resolution. ### Interrupts (7) `request_irq`/`devm_request_irq`, threaded IRQ (`request_threaded_irq`), platform IRQ from DT, bottom half via tasklet, interrupt controller (`irq_chip` + `irq_domain`), `irqreturn_t` & shared IRQ, disable/enable IRQ. ### Bus / Drivers (9) platform driver (DT match), PCI driver, USB driver, USB URB transfer, I2C client driver, SPI device driver, auxiliary bus driver, serdev driver, device-tree node (DTS). ### Device Frameworks (10) regmap MMIO & I2C, clock provider & consumer, regulator consumer, GPIO consumer (`gpiod_*`), GPIO controller (`gpio_chip`), pin controller (`pinctrl`), irqchip via generic-chip, canonical `devm_` probe body. ### VFS / Pseudo FS (8) procfs (`proc_create`), sysfs `kobj_attribute`, device `DEVICE_ATTR` group, debugfs, configfs subsystem, seq_file iterator, inode & file operations, register a `file_system_type`. ### Networking (9) generic netlink family, netlink unicast send, `sk_buff` handling, network device driver (`net_device` + `net_device_ops`), netfilter hook, nftables expression, in-kernel socket, XDP program skeleton, `register_netdevice_notifier`. ### Tracing / Debug (13) printk/pr_*/dev_* levels, dynamic debug, `TRACE_EVENT` tracepoint, ftrace function hook, kprobe, kretprobe, fprobe, BPF program skeleton, `kfifo` ring buffer, `kobject`/`kref` refcounting, kmemleak annotation, goto-based error unwinding, `ERR_PTR`/`IS_ERR`/`PTR_ERR`. ### Crypto (5) synchronous hash (`shash`), asynchronous hash (`ahash`), symmetric cipher (`skcipher`), async compression (`acomp`), random bytes (`get_random_*`). ### Subsystem samples (13) Input (evdev), HID, V4L2 sub-device, DRM simple-KMS, ALSA (ASoC component), IIO, hwmon, RTC, watchdog, LED, PWM controller, backlight, thermal zone. ### Power Management (7) runtime PM enable/autosuspend, runtime PM callbacks, system suspend/resume (S3), OPP layer, CPUFreq driver, CPUIdle driver, wakeup source. ### Security / Containers (9) seccomp filter, Landlock ruleset, LSM hook, capabilities (`capable`), cgroup subsystem (controller), namespaces (`nsproxy`), virtio driver, VFIO mediated device (mdev), KVM extension sketch. ### Data Structures (19) intrusive `list_head`, hash list (`hlist`), kernel hashtable (`DECLARE_HASHTABLE` + safe iteration), red-black tree, XArray, IDR/IDA, kfifo to/from user, string helpers (`kstrtol`/`strscpy`), common errno reference, fwnode device properties, OF property helpers, deferred probe (`-EPROBE_DEFER`), notifier chain, ktime/time helpers, DT binding YAML schema, current time formatting (`date_format_now`), CPU usage sampling (`get_cpu_usage_percent_x100`), memory usage sampling (`get_mem_usage_percent_x100`). > Total: **154 example snippets**. ## Configuration | Setting | Default | Description | | ------- | ------- | ----------- | | `kernelAssistant.includeHeader` | `true` | Prepend a comment header before each snippet. | | `kernelAssistant.searchLimit` | `80` | Max number of QuickPick items shown. | ## Layout ``` kernel-assistant-vscode/ ├── package.json # extension manifest, commands, keybindings ├── tsconfig.json ├── build/ │ └── snippets.mjs # scans snippets/ and regenerates gen.ts ├── snippets/ # snippet source files (edit these!) │ ├── core/char-device-cdev.c │ ├── sync/spinlock.c │ ├── core/makefile-module.mk │ ├── core/kconfig-entry.config │ └── .../. └── src/ ├── extension.ts # QuickPick + insert command └── templates/ ├── types.ts # KernelTemplate interface ├── gen.ts # AUTO-GENERATED: id -> snippet text (from snippets/) ├── index.ts # aggregator + ranked search() └── core.ts ... misc.ts # template metadata (title/keywords/description/...) ``` ## Notes - Snippets target the public 6.6 kernel APIs; some need the matching `CONFIG_*` option enabled (shown in each snippet's `Depends:` field). - They are starting points — adapt Kconfig/Makefile wiring and fill the hardware-specific parts to your device.