Skip to content

Instantly share code, notes, and snippets.

View vtta's full-sized avatar
🎯
Focusing

vtta vtta

🎯
Focusing
  • The Chinese University of Hong Kong
  • Hong Kong
View GitHub Profile
@vtta
vtta / cwisstable.h
Last active May 6, 2024 02:12
A modified swisstable header for kernel use, orignal version: https://github.com/google/cwisstable. We need this because kernel's `rhashtable` does not support the "flat" mode in which small objects are stored directly in the table.
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
#ifndef LOG_HPP
#define LOG_HPP
#include <print>
#include <source_location>
template <class... Args>
struct info {
info(std::format_string<Args...> fmt, Args &&...args,
std::source_location const &loc = std::source_location::current()) {
std::print(stderr, "[{}:{}]{}: ", loc.file_name(), loc.line(),
// clang-format off
u64 mt19937_u64(void)
{
#define NN 312
#define MM 156
#define MATRIX_A 0xB5026F5AA96619E9ULL
// Most significant 33 bits
#define UM 0xFFFFFFFF80000000ULL
// Least significant 31 bits
#define LM 0x7FFFFFFFULL
@vtta
vtta / acmart.typ
Last active April 25, 2024 12:23
acmart typst template
// made according to typst ieee template and official acm word template
// --- Draft Formatting
// Papers will be submitted electronically in PDF format via the web submission form.
// 1. Submissions may have at most 12 pages of technical content, including all text, figures, tables, etc. Bibliographic references are not included in the 12-page limit.
// 2. Use A4 or US letter paper size, with all text and figures fitting inside a 178 x 229 mm (7 x 9 in) block centered on the page, using two columns separated by 8 mm (0.33) of whitespace.
// 3. Use 10-point font (typeface Times Roman, Linux Libertine, etc.) on 12-point (single-spaced) leading.
// 4. Graphs and figures should be readable when printed in grayscale, without magnification.
@vtta
vtta / list.rs
Created May 17, 2023 02:13
A simple lock free list implementation to be use in the linux kernel based on [this](https://www.microsoft.com/en-us/research/wp-content/uploads/2001/10/2001-disc.pdf) microsoft paper
use core::{
fmt, ptr,
sync::atomic::{AtomicPtr, Ordering::SeqCst},
};
use kernel::prelude::*;
#[derive(Debug)]
pub struct Node<T> {
value: Option<T>,
next: AtomicPtr<Node<T>>,
@vtta
vtta / rpath.md
Created May 3, 2023 03:25
rpath that allows searching library relative to its location

source

We can use the $ORIGIN "special" path to have a path relative to the executable with -Wl,-rpath,'$ORIGIN' in bash or -Wl,-rpath,'$$ORIGIN' in Makefile

note that you need quotes around it to avoid having the shell interpret it as a variable, and if you try to do this in a Makefile, you need $$ to avoid having make interpret the $ as well

@vtta
vtta / usenix.typ
Last active May 8, 2023 08:50
https://typst.app/ template for USENIX paper submission
// - No longer than 12 single-spaced 8.5" x 11" pages, including figures and tables, plus as many pages as needed for references.
// - Submissions may include as many additional pages as needed for references but not for supplementary material in appendices.
// - Use 10-point type on 12-point (single-spaced) leading and Times Roman or a similar font for the body of the paper.
// - All text and figures fit inside a 7" x 9" (178 mm x 229 mm) block centered on the page, using two columns separated by 0.33" (8 mm) of whitespace. All graphs and figures should be readable when printed in black and white.
// - Papers not meeting these criteria will be rejected without review, and no deadline extensions will be granted for reformatting.
// - Pages should be numbered, and figures and tables should be legible in black and white, without requiring magnification.
// - The paper review process is double-blind. Authors must make a good faith effort to anonymize their submissions, and they should not identify themselves eit
#!/usr/bin/awk -f
# https://unix.stackexchange.com/a/495105
# usage: match_block START END MATCH [FILE]
# output a whole block of text enclosed by START and END that contains MATCH
BEGIN {
pstart=ARGV[1];
pstop=ARGV[2];
pmatch=ARGV[3];
ARGV[1]=ARGV[4];
ARGC=2;
@vtta
vtta / iostat2csv.awk
Last active June 11, 2022 10:44
S_TIME_FORMAT=ISO iostat -xydt sda sdc 1 | awk -f iostat2csv.awk
# we should print the header once
BEGIN {
header = 1
}
# match each block, e.g.
# 2022-06-11T18:42:05+0800
# Device r/s rkB/s rrqm/s %rrqm r_await rareq-sz w/s wkB/s wrqm/s %wrqm w_await wareq-sz d/s dkB/s drqm/s %drqm d_await dareq-sz f/s f_await aqu-sz %util
# sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
# sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
@vtta
vtta / perf_raw_event_code.c
Last active May 16, 2022 08:14
gcc perf_raw_event_code.c -lpfm -o perf_raw_event_code
#include <err.h>
#include <inttypes.h>
#include <perfmon/pfmlib.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
if (argc < 2) {
errx(1, "Usage: %s EVENT...\n", argv[0]);
}