Skip to content

Instantly share code, notes, and snippets.

@jserv
jserv / readers.c
Last active March 24, 2022 02:31
user-level threads using clone system call (incomplete)
#if !defined(__x86_64__)
#error "This program only works for x86_64"
#endif
#define _GNU_SOURCE
#include <errno.h>
#include <limits.h>
#include <linux/futex.h>
#include <sched.h>
#include <signal.h>
@jserv
jserv / Makefile
Created August 20, 2021 12:05
lock-free hashmap
.PHONY: all clean
TARGET = test-hashmap
all: $(TARGET)
include common.mk
CFLAGS = -I.
CFLAGS += -O2 -g
CFLAGS += -std=gnu11 -Wall
@jserv
jserv / Makefile
Created August 20, 2021 11:49
Scheduler Plugin for Linux Kernel
obj-m += proc_queue.o
obj-m += proc_sched.o
obj-m += proc_set.o
PWD := $(shell pwd)
KERNELDIR ?= /lib/modules/`uname -r`/build
PWD := $(shell pwd)
all:
@jserv
jserv / norcu.patch
Created August 19, 2021 02:09
No RCU
diff --git a/fs/Kconfig b/fs/Kconfig
index c229f82..515f76d 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -4,6 +4,12 @@
menu "File systems"
+config DCACHE_NO_RCU
+ def_bool y
@jserv
jserv / Makefile
Last active August 1, 2022 07:26
Lock-free multiple-producer (MP) /multiple-consumer (MC) ring buffer (**incomplete**)
CC = gcc
CFLAGS = -O2 -g -Wall -I.
CFLAGS += -fsanitize=thread
LDFLAGS = -fsanitize=thread
all: lfring
# Control the build verbosity
ifeq ("$(VERBOSE)","1")
Q :=
@jserv
jserv / Makefile
Created August 13, 2021 10:26
Synthesize events for select/poll/epoll (**incomplete***)
MODULENAME := vpoll
obj-m += $(MODULENAME).o
$(MODULENAME)-y += module.o
KERNELDIR ?= /lib/modules/`uname -r`/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
gcc -Wall -o user user.c
@jserv
jserv / vwifi.c
Created August 6, 2021 11:58
virtual cfg80211 driver
#include <linux/module.h>
#include <linux/skbuff.h>
#include <net/cfg80211.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#define WIPHY_NAME "owl" /* Our WireLess */
#define NDEV_NAME WIPHY_NAME "%d"
@jserv
jserv / simrupt.c
Created August 6, 2021 11:48
A device that simulates interrupts
/* simrupt: A device that simulates interrupts */
#include <linux/cdev.h>
#include <linux/circ_buf.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <inttypes.h>
#include <sys/time.h>
enum {
EV_READ = (1 << 0),
EV_WRITE = (1 << 1),
EV_TIMEOUT_ONESHOT = (1 << 2),
EV_TIMEOUT_PERIODIC = (1 << 3),
EV_SIGNAL = (1 << 4),
EV_CLOEXEC = (1 << 0),
/* Simple port forwarder */
#define _GNU_SOURCE 1
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <netdb.h>
#include <stdbool.h>
#include <stdio.h>