Skip to content

Instantly share code, notes, and snippets.

@michaeljclark
michaeljclark / auto-merge.yml
Last active November 30, 2021 22:40
GitHub Action to merge commits > n-days from work branch to trunk
# GitHub workflow to merge commits > n-days from a work branch to trunk.
#
# this is a low-overhead workflow implementing a time lock intended to
# allow people to rebase on a work branch but avoid rebases on trunk.
#
# the workflow is scheduled to fast-forward the target branch to the
# most recent commit in the source branch that is older than n-days.
#
# if there is a commit older than n-days common to both branches, the
# action will do nothing. the action will error in the case of commits
@michaeljclark
michaeljclark / glibc-2.31-ldd-relative-justify-v1.patch
Last active May 14, 2021 03:21
[PATCH] ldd - add left-justified relative addresses to trace
Dear All,
I am sharing a patch for ld.so to show relative addresses and add
justified output. The goal of this patch is to increase `ldd` readability:
- modify trace output to use relative addresses by default.
- add alternative trace output mode with left-justified addresses.
The relative addresses are composed by subtracting the ELF ehdr address
which makes the output constant under address space layout randomization.
@michaeljclark
michaeljclark / disasm-x86.sh
Last active May 4, 2021 03:02
script that uses xxd and objdump to allow interactive decode of x86 instructions
#!/bin/sh
T=$(mktemp fooXXXXXX)
echo $* | xxd -r -p - > ${T}
objdump -D -bbinary -mi386:x86-64 -Mintel ${T} | \
sed -n '/<.data>:/{n;s/0://g p}'
rm -f ${T}
@michaeljclark
michaeljclark / mimalloc-histogram.patch
Created April 28, 2021 07:43
mimalloc pow2 alloc size histograms on exit - `MIMALLOC_SHOW_HISTOGRAM=1`
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index 7160bc474a71..3970e35a2c25 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -114,6 +114,8 @@ void _mi_heap_set_default_direct(mi_heap_t* heap);
// "stats.c"
void _mi_stats_done(mi_stats_t* stats);
+void _mi_hist_log(size_t size);
+void _mi_hist_dump(mi_output_fun* out);
@michaeljclark
michaeljclark / ISO-6093-NR3.pl
Last active March 21, 2021 05:09
regex to parse ISO 6093 floating point decimal representation NR3
#!/usr/bin/perl
#
# usage ./ISO-6093-NR3.pl (relaxed|stric) <float>
#
# parse ISO 6093 floating point decimal representation NR3
#
# 'relaxed'
#
# - prohibits missing decimal point. e.g. '1' ERROR
# - permits leading zeros on integer. e.g. '01.23e10' OK
@michaeljclark
michaeljclark / Makefile
Last active March 1, 2021 04:11
C++ modules using clang and make
#
# clang modules-ts example
#
source = src
modules = build/modules
objects = build/objects
output = build/output
CXX = clang++
@michaeljclark
michaeljclark / ticket-lock-riscv.s
Last active June 2, 2021 23:40
Queued ticket lock description in English and some RISC-V assembly for a possible implementation
#pragma once
# Ticket Lock
#
# Ticket locks are fair spinlocks that order acccess on a first-in,
# first-out basis. The lock is composed of a head counter and a tail
# counter. The head counter indicates the ticket number of the current
# lock owner. The tail counter indicates the last issued ticket number.
# To acquire the lock, the acquiring thread atomically increments the
# tail counter to assign itself a ticket number. It then waits until
@michaeljclark
michaeljclark / atomic_latency.cc
Created December 12, 2020 07:35
atomic memory interlock latency benchmark
/*
* atomic memory interlock latency benchmark (public domain)
* author: Michael Clark <michaeljclark@mac.com>
* c++ -pthread -O2 atomic_latency.cc -o atomic_latency
*/
#include <cstdio>
#include <thread>
#include <atomic>
#include <chrono>
@michaeljclark
michaeljclark / please-license.c
Created November 21, 2020 08:15
PLEASE LICENSE is a software license somewhere in between the ISC license and public domain.
/*
* PLEASE LICENSE 11/2020, John Smith <john.smith@example.com>
*
* All rights to this work are granted for all purposes, with exception of
* author's implied right of copyright to defend the free use of this work.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@michaeljclark
michaeljclark / workmule.cc
Last active November 11, 2020 19:03
C++ threaded worker pool that executes work-items from a queue
// See LICENSE for license details.
#include <vector>
#include <atomic>
#include <thread>
#include <mutex>
#include <memory>
#include <functional>
#include <condition_variable>