Skip to content

Instantly share code, notes, and snippets.

@lmb
lmb / Dockerfile
Created January 10, 2024 15:51
Build RHEL 8 kernel via rocky linux container
FROM rockylinux:8 AS builder
RUN dnf install -y 'dnf-command(builddep)' 'dnf-command(config-manager)'
RUN dnf config-manager --set-enabled powertools
RUN dnf builddep -y kernel
FROM builder
WORKDIR /tmp
RUN dnf download --source kernel && rpm -ivh kernel*.src.rpm
@lmb
lmb / bonch.sh
Created November 10, 2023 09:59
Benchmark Go code on a single core of an Intel CPU
#!/bin/bash
# Fiddle with frequency scaling settings to reduce variance when running Go benchmarks.
# Also pins the benchmark to a single CPU.
CPU=${CPU:-1}
original_governor=$(cat /sys/devices/system/cpu/cpu$CPU/cpufreq/scaling_governor)
original_turbo=$(cat /sys/devices/system/cpu/intel_pstate/no_turbo)
disable_turbo() {
@lmb
lmb / README.md
Last active November 14, 2023 13:45
macOS: use ssh-agent from nix-env

This recipe allows you to use the ssh-agent from nix-env with the auto generated SSH_AUTH_SOCK in /private/tmp. It works because disabling com.openssh.ssh-agent doesn't stop launchd from allocating SSH_AUTH_SOCK. com.nix.ssh-agent spawns a shell to remove the socket and then execute the homebrew ssh-agent.

  1. Install openssh from nix: nix-env --install --attr nikpkgs.openssh
  2. Disable the built in macOS agent: launchctl disable gui/$UID/com.openssh.ssh-agent
  3. Copy com.nix.ssh-agent.plist into ~/Library/LaunchAgents
  4. Enable the new agent: launchctl bootstrap gui/$UID ~/Library/LaunchAgents/com.nix.ssh-agent.plist
  5. Ensure that the correct agent is running:
@lmb
lmb / kvm-trace-first.txt
Last active March 16, 2022 11:47
KVM_EXIT_SHUTDOWN due to TRIPLE_FAULT on Ubuntu 20.04.1 LTS
[001] 770.553142: kvm:kvm_unmap_hva_range: mmu notifier unmap range: 0x007fd650000000 -- 0x007fd654000000
[001] 770.553145: kvm:kvm_unmap_hva_range: mmu notifier unmap range: 0x007fd64c000000 -- 0x007fd64c200000
[001] 770.553347: kvm:kvm_write_tsc_offset: vcpu=0 prev=0 next=18446741441723333646
[001] 770.553348: kvm:kvm_track_tsc: vcpu_id 0 masterclock 0 offsetmatched 0 nr_online 1 hostclock 0x2
[000] 770.579751: kvm:kvm_write_tsc_offset: vcpu=0 prev=18446741441723333646 next=18446741441723333646
[000] 770.579752: kvm:kvm_track_tsc: vcpu_id 0 masterclock 0 offsetmatched 0 nr_online 1 hostclock 0x2
[000] 770.579757: kvm:kvm_hv_stimer_set_config: vcpu_id 0 timer 0 config 0x0 host 1
[000] 770.579758: kvm:kvm_hv_stimer_cleanup: vcpu_id 0 timer 0
[000] 770.579759: kvm:kvm_hv_stimer_set_config: vcpu_id 0 timer 1 config 0x0 host 1
[000] 770.579759: kvm:kvm_hv_stimer_cleanup: vcpu_id 0 timer 1
@lmb
lmb / bug.zig
Created July 17, 2018 16:56
zig generics segfault
pub fn Generic(comptime len: usize) var {
return struct {
stack: [len]u8,
};
}
const Thing = Generic(1);
test "crash" {
Thing.bloop();
@lmb
lmb / lmdb-macos-test.sh
Created January 25, 2018 11:29
Test macOS fixes for LMDB
#!/bin/bash
set -euf -o pipefail
pushd "$(mktemp -d)"
echo Working in $PWD
git clone https://github.com/lmb/lmdb.git
@lmb
lmb / 0001-Use-F_SETNOSIGPIPE-on-OS-X.patch
Last active May 31, 2017 10:08
[PATCH] LMDB: Suppress SIGPIPE in mdb_env_copythr on OS X
From 5092fd69abc0d9fd81b62a0a00553ace556cbc0a Mon Sep 17 00:00:00 2001
From: Lorenz Bauer <lmb@xxx>
Date: Wed, 15 Feb 2017 18:58:05 +0000
Subject: [PATCH] Use F_SETNOSIGPIPE on OS X
It seems like OS X delivers SIGPIPE to the whole process, instead of the generating thread, as on other UNIXes. Therefore the current code sometimes works, but mostly doesn't, since the call to sigwait doesn't happen quickly enough.
Instead of masking SIGPIPE, we use an OS X specific fcntl to disable SIGPIPE for that particular fd.
---
libraries/liblmdb/mdb.c | 18 ++++++++----------
@lmb
lmb / main.go
Created February 9, 2017 11:00
Prometheus client_golang histogram race
package main
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
@lmb
lmb / sigpipe.patch
Last active September 25, 2016 18:13
[PATCH] Return EPIPE from mdb_env_copyfd2 instead abort on SIGPIPE
From 575a1386a9c47e2467e96c9e2be2abf32a56a734 Mon Sep 17 00:00:00 2001
From: Lorenz Bauer <lmb@cloudflare.com>
Date: Sun, 25 Sep 2016 11:11:08 -0700
Subject: [PATCH] Return EPIPE from mdb_env_copyfd2 instead abort on SIGPIPE
---
libraries/liblmdb/mdb.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
@lmb
lmb / copyfd1-leak.c
Last active June 28, 2016 09:51
Test case for mdb_env_copyfd1 leaking memory and pthread state
/*
* Copyright 2012 Howard Chu, Symas Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at