Skip to content

Instantly share code, notes, and snippets.

@joelagnel
joelagnel / aref.md
Created May 11, 2025 00:43
ARef article

ARef: The “Abstract Reference” for Rust

I understand references, Rc and Arc. But wtf is ARef and why would I need one?

1. The problem: juggling multiple return types

Imagine you have a function that sometimes:

  • Returns a borrowed &str (no heap allocation)
  • Returns an owned String you just built
  • Returns a shared buffer (e.g. an Rc<String>) without copying
<!DOCTYPE html>
<html>
<head>
<title>RCU Sequence Visualization</title>
</head>
<body>
<div style='margin-top: 20px; margin-bottom: 20px;'>
<h3>Legend:</h3>
<ul>
<li style='background-color: #90EE90'>Green: Grace Period Completed (multiple of 4)</li>
@joelagnel
joelagnel / rcu_seq_done_4bit.html
Created January 29, 2025 22:37
RCU sequence number testing - 4bit numbers
<!DOCTYPE html>
<html>
<head>
<title>RCU Sequence Visualization</title>
</head>
<body>
<div style='margin-top: 20px; margin-bottom: 20px;'>
<h3>Legend:</h3>
<ul>
<li style='background-color: #90EE90'>Green: Grace Period Completed (multiple of 4)</li>
@joelagnel
joelagnel / readme
Created July 18, 2024 14:55
Build sched_ext for kernel
Note, llvm by default does not get on PATH, so should be added.
git remote add scx
git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext.git
git checkout -b scx_611 scx/for-6.11
agi clang-16 llvm-16 lld-16
PATH=/usr/lib/llvm-16/bin/:$PATH LLVM=1 make -j48 x86_64_defconfig
Then run:
@joelagnel
joelagnel / ignore-stdin-for-secs.sh
Created September 14, 2023 00:37
Script to ignore stdin for a $1 seconds
#!/bin/sh
# Check if at least one numeric arg is passed
if [ $# -eq 0 ]
then
echo "Usage: $0 <seconds>"
exit 1
fi
# Read and discard input for 1 second
#!/bin/sh
# Save this file as "init" in the root of your CPIO archive,
# and chmod +x it. This will chroot into an HDD if one is
# available. Or it will just give a prompt.
mkdir -p /proc /sys /d /pstore /dev
mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /d
mount -t debugfs none /sys/kernel/debug/
@joelagnel
joelagnel / run-qemu.sh
Last active November 30, 2023 04:43
run-qemu.sh script to run qemu for kernel development
#!/bin/bash
# Author: Joel Fernandes <joel@joelfernandes.org>
#
# Usage, run-qemu : Runs with busybox chrooting into a debian qemu.img
# run-qemu --rt : Set all Qemu vCPU threads as RT and pin them to different CPUs.
# run-qemu --rcu : Run qemu with rcutorture boot parameters
#
# run-qemu --cpio : Runs only with busy-box initramfs (no chrooting)
# run-qemu --debian : Boot into a debian rootfs (see end of this file for how to build debian images)
# If neither --cpio nor --debian is passed, then it will try to chroot into a qemu.img file.
@joelagnel
joelagnel / hrtimer_trace_parse.py
Last active April 11, 2023 18:36
Parse Traces to find top hrtimer users who actually have timers fire
#!/usr/bin/python3
# Run for tracing:
# With full screen video playing on device, run:
# trace-cmd record -e timer:hrtimer_start -R stacktrace -e hrtimer_cancel -e timer:hrtimer_expire_entry -- sleep 5
# trace-cmd report > trace.txt
# Pass the trace to this script.
# The script will produce a filter_trace.txt which only shows hrtimer events that actually fired and
# did not get canceled.
# The script will also output the top-most frequent stacks that queued a timer.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/list.h>