Skip to content

Commit 60a047d

Browse files
committed
Import from the internal tree
The kernel module is now capable of performing concurrent sort.
1 parent e2991bf commit 60a047d

File tree

14 files changed

+458
-990
lines changed

14 files changed

+458
-990
lines changed

.clang-format

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ UseTab: Never
1313
IndentWidth: 4
1414
BreakBeforeBraces: Linux
1515
AccessModifierOffset: -4
16-
ForEachMacros:
16+
ForEachMacros:
1717
- foreach
1818
- Q_FOREACH
1919
- BOOST_FOREACH
@@ -24,4 +24,3 @@ ForEachMacros:
2424
- hlist_for_each_entry
2525
- rb_list_foreach
2626
- rb_list_foreach_safe
27-
- vec_foreach

.gitignore

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
1-
# Prerequisites
2-
*.d
3-
.cache.mk
4-
5-
# Object files
61
*.o
72
*.ko
8-
*.elf
9-
10-
# Linker output
11-
*.map
12-
13-
# Precompiled Headers
14-
*.gch
15-
*.pch
16-
17-
# Libraries
18-
*.a
19-
20-
# Kernel Module Compile Results
21-
*.mod*
3+
*.mod
4+
*.mod.c
5+
*.mod.o
6+
*.order
227
*.cmd
23-
.tmp_versions/
24-
modules.order
25-
Module.symvers
26-
Mkfile.old
27-
dkms.conf
28-
29-
# test-oriented
30-
out
8+
*.symvers
9+
user

LICENSE

Lines changed: 21 additions & 339 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
1-
CONFIG_MODULE_SIG = n
2-
TARGET_MODULE := ksort
1+
MODULENAME := ksort
2+
obj-m += $(MODULENAME).o
3+
$(MODULENAME)-y += main.o sort.o
34

4-
obj-m := $(TARGET_MODULE).o
5-
ksort-objs := \
6-
xoroshiro128plus.o \
7-
heap.o \
8-
main.o
9-
10-
ccflags-y := -std=gnu99 -Wno-declaration-after-statement
5+
GIT_HOOKS := .git/hooks/applied
116

127
KDIR := /lib/modules/$(shell uname -r)/build
138
PWD := $(shell pwd)
149

15-
GIT_HOOKS := .git/hooks/applied
16-
17-
all: $(GIT_HOOKS) test_xoro
10+
all: $(GIT_HOOKS) user
1811
$(MAKE) -C $(KDIR) M=$(PWD) modules
1912

2013
$(GIT_HOOKS):
2114
@scripts/install-git-hooks
2215
@echo
2316

24-
test_xoro: test_xoro.c
17+
user: user.c
2518
$(CC) -o $@ $^
2619

20+
insmod: all
21+
sudo insmod $(MODULENAME).ko
22+
23+
rmmod:
24+
sudo rmmod $(MODULENAME)
25+
26+
check:
27+
$(MAKE) insmod
28+
sudo ./user
29+
$(MAKE) rmmod
30+
2731
clean:
2832
$(MAKE) -C $(KDIR) M=$(PWD) clean
29-
$(RM) test_xoro
30-
31-
load:
32-
sudo insmod $(TARGET_MODULE).ko
33-
unload:
34-
sudo rmmod $(TARGET_MODULE) || true >/dev/null
35-
36-
PRINTF = env printf
37-
PASS_COLOR = \e[32;01m
38-
NO_COLOR = \e[0m
39-
pass = $(PRINTF) "$(PASS_COLOR)$1 Passed [-]$(NO_COLOR)\n"
40-
41-
check: all
42-
$(MAKE) unload
43-
sudo dmesg -C
44-
$(MAKE) load
45-
@sudo ./test_xoro && $(call pass)
46-
@dmesg | grep "test passed" >/dev/null && $(call pass)
47-
$(MAKE) unload
33+
$(RM) user

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# ksort
22

3-
Linux kernel module that implements and validates sorting algorithms.
3+
A Linux kernel module that creates the device `/dev/ksort`, capable of performing concurrent sorts.
44

5-
## Origin
6-
7-
The implementation was taken from Linux kernel source tree.
8-
* [lib/sort.c](https://github.com/torvalds/linux/tree/master/lib/sort.c)
9-
* [lib/test_sort.c](https://github.com/torvalds/linux/blob/master/lib/test_sort.c)
5+
## References
6+
* [The Linux Kernel Module Programming Guide](https://sysprog21.github.io/lkmpg/)
7+
* [Writing a simple device driver](https://www.apriorit.com/dev-blog/195-simple-driver-for-linux-os)
8+
* [Character device drivers](https://linux-kernel-labs.github.io/refs/heads/master/labs/device_drivers.html)
9+
* [cdev interface](https://lwn.net/Articles/195805/)
10+
* [Character device files](https://sysplay.in/blog/linux-device-drivers/2013/06/character-device-files-creation-operations/)
11+
* [Linux Workqueue](https://www.kernel.org/doc/html/latest/core-api/workqueue.html)
1012

1113
## License
1214

13-
`ksort`is released under the GNU GPLv2. Use of this source code is governed by
14-
the GNU GPL license version 2 that can be found in the LICENSE file.
15+
`ksort`is released under the MIT license. Use of this source code is governed by
16+
a MIT-style license that can be found in the `LICENSE` file.

0 commit comments

Comments
 (0)