Skip to content

Instantly share code, notes, and snippets.

@pankkor
pankkor / perf.md
Created May 1, 2025 14:58
Linux perf howto.

Installation

sudo apt install linux-tools-common

Setup

To be able to grab performance and kernel events. Lower sampling rate to 10000, if it takes too much time. If it happens kernel will automatically lower perf_event_max_sample_rate. Examine dmesg  output for perf: interrupt took too long, lowering kernel.perf_event_max_sample_rate to value.

sudo dmesg -wH | grep perf:
// Counting sort algorithm
// https://en.m.wikipedia.org/wiki/Counting_sort
//
// Build clang:
// clang -Wall -Wextra -Wpedantic -g counting_sort.c -o counting_sort
//
// Build gcc:
// gcc -Wall -Wextra -Wpedantic -g counting_sort.c -o counting_sort
typedef int i32;
@d7samurai
d7samurai / .readme.md
Last active December 13, 2025 22:52
Minimal D3D11 sprite renderer NEO

sponsored by SuperNeo copy 4

Minimal D3D11 sprite renderer NEO

Ultra-compact sprite rendering code with example frame animation logic. This release contains tech bits from the upcoming SuperNeo™ 2D game engine and includes anchor/pivot point, rotation, color filtering, alpha blending and built-in antialiased point sampling. As usual: complete, runnable single-function app. ~150 LOC. No modern C++, OOP or (other) obscuring cruft.

Minimal D3D11 sprite renderer NEO 1337

Sprites are rendered back-to-front (AKA "painter's algorithm") in the order they are submitted, as one draw call. The provided setup employs a single texture atlas containing all the sprite graphics.

The renderer is "im

@mmozeiko
mmozeiko / _miniperf_readme.md
Last active December 4, 2025 18:05
get PMU counter values with ETW, perf or kperf

MiniPerf

Example of how to capture CPU counters with ETW on Windows, perf on Linux or kperf on Apple.

Using ETW needs somewhat recently updated Windows 10 or 11. Not sure about exact version.

Currently tested on:

  • etw on Qualcomm Snapdragon X Elite, Windows 11, arm64
  • etw on AMD Zen 3, Windows 11 (with virtualization enabled in BIOS)
@pankkor
pankkor / large_huge_super_pages.md
Last active May 1, 2025 14:32
Windows large pages, Linux huge pages, macOS super pages support
@pankkor
pankkor / no_alsr_lin.sh
Created October 2, 2023 14:10
Disable ASLR Linux
# Check what ASLR protection do you have (typically 2)
cat /proc/sys/kernel/randomize_va_space
# Disable ASLR global
sysctl -w kernel.randomize_va_space=0
# Revert ASLR global
sysctl -w kernel.randomize_va_space=2
# Run <my_binary> with ASLR disabled (-R option)
@d7samurai
d7samurai / .readme.md
Last active October 26, 2025 05:56
Minimal D3D11 sprite renderer

Minimal D3D11 sprite renderer

Minimal D3D11 sprite renderer: basic back-to-front sprite rendering reference code with example sprite sheet animation logic. As usual: Complete, runnable single-function app. No modern C++ / OOP / obscuring cruft.

adventurer

Swap out the sprite sheet with a font atlas for a lightweight GUI / text renderer. Clip individual sprites and glyphs by offsetting screenPos and atlasPos to top left corner of visible area and adjusting size accordingly (all values in pixels):

sprite.screenPos.x += 17;
sprite.screenPos.y += 10;
@ibireme
ibireme / kpc_demo.c
Last active December 1, 2025 00:45
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// M1 (Pro/Max/Ultra): /usr/share/kpep/a14.plist
// M2 (Pro/Max): /usr/share/kpep/a15.plist
// M3: /usr/share/kpep/as1.plist
@equalent
equalent / crt.glsl
Created October 23, 2021 19:29
CRT shader by Timothy Lottes
//
// PUBLIC DOMAIN CRT STYLED SCAN-LINE SHADER
//
// by Timothy Lottes
//
// This is more along the style of a really good CGA arcade monitor.
// With RGB inputs instead of NTSC.
// The shadow mask example has the mask rotated 90 degrees for less chromatic aberration.
//
// Left it unoptimized to show the theory behind the algorithm.