Skip to content

Instantly share code, notes, and snippets.

@avagin
avagin / gist:146f0190a766bd7d4543c2ae132218d0
Created December 20, 2019 02:27
ptrace/syscall/arm64
#define _GNU_SOURCE
#include <sys/ptrace.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/uio.h>
#define _GNU_SOURCE
#include <sys/ptrace.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <stdlib.h>
#include <stdio.h>
class Solution(object):
def threeSum(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if len(nums) < 3:
return []
nums.sort()
r = []
@avagin
avagin / futex.c
Created November 19, 2019 00:49
futex performance measurements
#define _GNU_SOURCE
#include <sys/ucontext.h>
#include <seccomp.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
@avagin
avagin / gettime_perf_cold.c
Created October 10, 2019 06:20
Measure performance of clock_gettime with cold cpu caches
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <time.h>
#include <stdio.h>
@avagin
avagin / CONFIG_TIMENS=y
Created July 18, 2019 17:29
vdsotest for timens
clock-gettime-monotonic: syscall: 293 nsec/call
clock-gettime-monotonic: libc: 20 nsec/call
clock-gettime-monotonic: vdso: 18 nsec/call
clock-getres-monotonic: syscall: 264 nsec/call
clock-getres-monotonic: libc: 261 nsec/call
clock-getres-monotonic: vdso: 3 nsec/call
clock-gettime-monotonic-coarse: syscall: 274 nsec/call
clock-gettime-monotonic-coarse: libc: 5 nsec/call
clock-gettime-monotonic-coarse: vdso: 3 nsec/call
clock-getres-monotonic-coarse: syscall: 265 nsec/call
arch/x86/entry/vdso/vdso64.so: file format elf64-x86-64
Disassembly of section .text:
00000000000005e0 <__vdso_clock_gettime@@LINUX_2.6-0x140>:
5e0: 55 push %rbp
5e1: 48 63 ff movslq %edi,%rdi
5e4: 4c 8d 0d 95 ca ff ff lea -0x356b(%rip),%r9 # ffffffffffffd080 <__vdso_getcpu@@LINUX_2.6+0xffffffffffffc870>
[avagin@laptop ~]$ cat t.py
import sys
items = {}
class Item:
def __init__(self, key, parent):
self.parent = parent
self.key = key
self.children = []
@avagin
avagin / gist:7e5854df28c63e5abaf3
Created February 3, 2016 02:13
nf_conntrac vs tcp
04:58:30.279397 IP (tos 0x0, ttl 64, id 24922, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.8880 > 127.0.0.1.43814: Flags [.], cksum 0xfe28 (incorrect -> 0x7b33), seq 1081132048, ack 2965916432, win 342, options [nop,nop,TS val 404987 ecr 0], length 0
04:58:30.283197 IP (tos 0x0, ttl 64, id 61017, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.43814 > 127.0.0.1.8880: Flags [.], cksum 0xfe28 (incorrect -> 0x7b30), seq 2965916431, ack 1081132049, win 342, options [nop,nop,TS val 404990 ecr 0], length 0
04:58:30.285500 IP (tos 0x0, ttl 64, id 24923, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.8880 > 127.0.0.1.43814: Flags [.], cksum 0xfe28 (incorrect -> 0x7b28), seq 1081132049, ack 2965916432, win 342, options [nop,nop,TS val 404997 ecr 0], length 0
04:58:30.289530 IP (tos 0x0, ttl 64, id 61018, offset 0, flags [DF], proto TCP (6), length 52)
127.0.0.1.43814 > 127.0.0.1.8880: Flags [.], cksum 0xfe28 (incorrect -> 0x7b23), seq 2965916432, ack 1081132049, win 3
From 9adc21d0236d9ef28da9064299789092388aa7e9 Mon Sep 17 00:00:00 2001
From: Andrey Vagin <avagin@openvz.org>
Date: Thu, 1 Oct 2015 23:28:07 +0300
Subject: [PATCH] net/unix: fix logic about sk_peek_offset
Now send with MSG_PEEK can return data from multiple SKBs.
Unfortunately we take into account the peek offset for each skb,
that is wrong. We need to skip data only once.