|
1 |
| -# KMLdrv: A device driver that performs tic-tac-toe game between kernel threads |
| 1 | +# kxo: A Tic-Tac-Toe Game Engine implemented as Linux kernel module |
| 2 | + |
2 | 3 | ## Introduction
|
3 |
| -`kmldrv` is a simple Linux kernel module which includes the concept of deferred |
4 |
| -work and kernel concepts as following: |
5 |
| - - circular buffer |
6 |
| - - mutex lock |
7 |
| - - irq |
8 |
| - - softirq |
9 |
| - - tasklet |
10 |
| - - workqueue |
11 |
| - - kernel thread |
| 4 | +`kxo` is a Linux kernel module that implements the [tic-tac-toe game](https://en.wikipedia.org/wiki/Tic-tac-toe) |
| 5 | +(aka XO Game) as kernel threads. |
| 6 | +This educational module demonstrates several essential Linux kernel programming concepts: |
| 7 | + - Circular buffer implementation |
| 8 | + - Mutex lock synchronization |
| 9 | + - IRQ handling |
| 10 | + - SoftIRQ processing |
| 11 | + - Tasklet scheduling |
| 12 | + - Workqueue management |
| 13 | + - Kernel thread creation and execution |
12 | 14 |
|
13 |
| -It can use different machine-learning algorithm and perform tic-tac-toe games between kernel threads. The demo video are in the link below: |
14 |
| - - [Kernel space tic-tac-toe game](https://www.youtube.com/watch?v=Y_xdLrDVGzk) |
| 15 | +The module supports multiple AI algorithms for game strategy, allowing kernel threads to compete against each other in tic-tac-toe matches. |
| 16 | +`kxo` implements two advanced algorithms for tic-tac-toe gameplay: |
| 17 | +- Monte Carlo Tree Search (MCTS): A probabilistic algorithm that uses random sampling to evaluate moves and determine optimal game strategies |
| 18 | +- Negamax Algorithm: A depth-first minimax variant that efficiently evaluates game positions by alternating between maximizing and minimizing players |
15 | 19 |
|
16 |
| -## Installation & Usage |
17 |
| -You can download the source code via the following command |
18 |
| -``` |
19 |
| -$ git clone https://github.com/vax-r/KMLdrv.git |
20 |
| -``` |
| 20 | +## Build and Run |
21 | 21 | After the source code is downloaded, go into the directory and do as the following
|
22 | 22 | ```
|
23 | 23 | $ make
|
24 |
| -make -C /lib/modules/6.5.0-28-generic/build M=/home/vax-r/linux2024/KMLdrv modules |
25 |
| -make[1]: Entering directory '/usr/src/linux-headers-6.5.0-28-generic' |
26 |
| -warning: the compiler differs from the one used to build the kernel |
27 |
| - The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 |
28 |
| - You are using: gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 |
29 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/simrupt.o |
30 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/game.o |
31 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/wyhash.o |
32 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/xoroshiro.o |
33 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/mcts.o |
34 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/negamax.o |
35 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/zobrist.o |
36 |
| - LD [M] /home/vax-r/linux2024/KMLdrv/kmldrv.o |
37 |
| - MODPOST /home/vax-r/linux2024/KMLdrv/Module.symvers |
38 |
| - CC [M] /home/vax-r/linux2024/KMLdrv/kmldrv.mod.o |
39 |
| - LD [M] /home/vax-r/linux2024/KMLdrv/kmldrv.ko |
40 |
| - BTF [M] /home/vax-r/linux2024/KMLdrv/kmldrv.ko |
41 |
| -make[1]: Leaving directory '/usr/src/linux-headers-6.5.0-28-generic' |
42 |
| -cc -std=gnu99 -Wno-declaration-after-statement -o kmldrv-user kmldrv-user.c |
43 | 24 | ```
|
44 |
| -Make sure the kernel object file is compiled correctly, then you can insert the kernel module |
| 25 | + |
| 26 | +Make sure the kernel object file (`kxo.ko`) is built correctly, then you can insert the kernel module |
45 | 27 | ```
|
46 |
| -$ sudo insmod kmldrv.ko |
| 28 | +$ sudo insmod kxo.ko |
47 | 29 | ```
|
48 |
| -Now you can enjoy the tic-tac-toe games performed between kernel threads through the following command |
| 30 | + |
| 31 | +`kxo` provides an interface for userspace interaction through the companion tool `kxo-user`. |
| 32 | +This utility offers the following functionality: |
| 33 | +- Display the current status of the `kxo` module (loaded/unloaded) |
| 34 | +- Real-time visualization of the tic-tac-toe game board |
| 35 | +- Control commands: |
| 36 | + - `Ctrl + P`: Toggle pause/resume of the game board display |
| 37 | + - `Ctrl + Q`: Terminate all tic-tac-toe games running in kernel space |
| 38 | + |
| 39 | +Simply run the command below after the kernel module is loaded: |
49 | 40 | ```
|
50 |
| -$ sudo ./kmldrv-user |
| 41 | +$ sudo ./kxo-user |
51 | 42 | ```
|
52 |
| -Enjoy the show ! |
53 |
| - |
54 |
| -## Features |
55 |
| -### User space tool `kmldrv-user` |
56 |
| -`kmldrv` provide a interface for userspace program to interact with it, for example you can use the userspace tool `kmldrv-user`. It has the following ability |
57 |
| -- Display the status of `kmldrv`, to show whether its loaded or not |
58 |
| -- `Ctrl + P` : Stop/Resume the displaying of chess board |
59 |
| -- `Ctrl + Q` : Stop the tic-tac-toe games in kernel space |
60 |
| -### Machine Learning Algorithms |
61 |
| -Currently `kmldrv` supports two machine learning algorithms |
62 |
| -- Monte-Carlo Tree Search |
63 |
| -- Negamax AI Algorithm |
64 |
| -### PRNG support |
65 |
| -Currently `kmldrv` utilize two different PRNG (Pseudo-Random Number Generator) to generate random number |
66 |
| -- `xoroshift` |
67 |
| -- `wyhash` |
68 | 43 |
|
69 | 44 | ## License
|
70 | 45 |
|
71 |
| -`simrupt` is released under the MIT license. Use of this source code is governed |
| 46 | +`kxo` is released under the MIT license. Use of this source code is governed |
72 | 47 | by a MIT-style license that can be found in the LICENSE file.
|
0 commit comments