Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/bpftrace
BEGIN {
@rw_compl_addr = kaddr("io_req_rw_complete");
@compl_addr = kaddr("io_req_task_complete");
}
kprobe:io_req_task_complete {
$req = (struct io_kiocb *)arg0;
#!/usr/bin/env bash
if [ "s$1" == "smax" ]; then
noturbo=0
online=1
governor=performance
preference=performance
elif [ "s$1" == "smin" ]; then
noturbo=1
online=0
@isilence
isilence / runtime_indirect_remover.c
Last active September 23, 2018 18:29
test code for indirect call elimination in runtime with runtime code generation
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <error.h>
#include <stdint.h>
// int mprotect(void *addr, size_t len, int prot);
__attribute__((noinline))
int foo(int a1, int a2, int a3)
@isilence
isilence / defer.h
Last active August 4, 2018 14:02
optimised defer for c & c++ (c++11, gcc, partially clang)
/*
* MIT License
*
* Copyright (c) 2018 Pavel Begunkov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is

Keybase proof

I hereby claim:

  • I am isilence on github.
  • I am silence (https://keybase.io/silence) on keybase.
  • I have a public key whose fingerprint is FBA2 6E3D 38D3 6F1E 3BF6 8DCE 5ADE 5BD4 696B FBA5

To claim this, I am signing this object:

{--
- Copyright 2017 Pavel Begunkov.
-
- Permission is hereby granted, free of charge, to any person obtaining a
- copy of this software and associated documentation files (the "Software"),
- to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
- and/or sell copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following conditions:
-
#! /usr/bin/env python3
import numpy as np
def shift_bit_length(x):
return 1 << (x - 1).bit_length()
def multh(a, b, c, d, e):
if (a.shape[0] <= 1024):
@isilence
isilence / most_significant_bit.c
Last active July 7, 2019 12:05
Fast most significant bit
inline unsigned long msb_intrin(unsigned long x)
{
const int zs = __builtin_clzl(x);
return 1ul << (sizeof(x) * CHAR_BIT - zs - 1);
}
inline unsigned long msb_fast(unsigned long x)
{
int bit_size = sizeof(x) * CHAR_BIT;
CC = g++
LD = g++
CFLAGS = -O3 -std=c++11
# LDFLAGS
files = $(shell find ./ -type f -name '*.c')
program: $(patsubst %.c, %.o, $(files))
$(LD) $(LDFLAGS) -o solution $^
// preferred device arithmetic vector width
#if !defined(DLM_ARCH_VECSZ_CHAR)
#define DLM_ARCH_VECSZ_CHAR 4
#endif
#if !defined(DLM_ARCH_VECSZ_SHORT)
#define DLM_ARCH_VECSZ_SHORT 1
#endif
#if !defined(DLM_ARCH_VECSZ_INT)
#define DLM_ARCH_VECSZ_INT 1
#endif