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
#!/usr/bin/env python3
# Output looks like this:
# $ python3 /data/pressure.py --resource all
# cpu,cpu,cpu,cpu,cpu,cpu,cpu,cpu,memory,memory,memory,memory,memory,memory,memory,memory,io,io,io,io,io,io,io,io
# some,some,some,some,full,full,full,full,some,some,some,some,full,full,full,full,some,some,some,some,full,full,full,full
# avg10,avg60,avg300,total,avg10,avg60,avg300,total,avg10,avg60,avg300,total,avg10,avg60,avg300,total,avg10,avg60,avg300,total,avg10,avg60,avg300,total
# 9.24,2.86,0.65,2300327,0.0,0.0,0.0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0,0.09,0.02,0.0,59850,0.0,0.0,0.0,50820
# 8.11,2.86,0.67,2368262,0.0,0.0,0.0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0,0.08,0.02,0.0,59850,0.0,0.0,0.0,50820
# ...
#!/usr/bin/env python3
# Output looks like this:
# Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 1,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2,Node 2
# MemTotal,MemFree,MemUsed,SwapCached,Active,Inactive,Active(anon),Inactive(anon),Active(file),Inactive(file),Unevictable,Mlocked,Dirty,Writeback,FilePages,Mapped,AnonPages,Shmem,KernelStack,PageTables,SecPageTables,NFS_Unstable,Bounce,WritebackTmp,KReclaimable,Slab,SReclaimable,SUnreclaim,AnonHugePages,ShmemHugePages,ShmemPmdMapped,FileHugePages,FilePmdMapped,Unaccepted,HugePages_Total,HugePages_Free,HugePages_Surp,MemTotal,MemFree,MemUsed,SwapCache
@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 June 4, 2024 13:27
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;