Skip to content

Instantly share code, notes, and snippets.

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <assert.h>
#define tic() do { struct timespec ts_start, ts_end; clock_gettime(CLOCK_MONOTONIC, &ts_start)
#define toc() clock_gettime(CLOCK_MONOTONIC, &ts_end); \
printf("%lfs\n", (ts_end.tv_sec - ts_start.tv_sec) + (double)(ts_end.tv_nsec - ts_start.tv_nsec)/1e9); } \
A few weeks ago Linus Torvalds answered some questions (http://meta.slashdot.org/story/12/10/11/0030249/linus-torvalds-answers-your-questions) on slashdot. All his responses make good reading but one in particular caught my eye. Asked to describe his favourite kernel hack, Torvalds grumbles he rarely looks at code these days — unless it’s to sort out someone else’s mess. He then pauses to admit he’s proud of the kernel’s fiendishly cunning filename lookup cache before continuing to moan about incompetence.
几周前,Linus Torvalds 在 slashdot 上回答了一些问题。他的所有回答都值得一读,而其中之一尤其引起我的注意。当问及最喜欢的内核技巧,Tarvalds 说道,近来已经很少读代码 -- 除非需要修复他人引发的问题。随后,他承认自己为巧妙精密的文件名查找缓存的实现而自豪,但随即便抱怨起大多数人的能力缺陷。
____
At the opposite end of the spectrum, I actually wish more people understood the really core low-level kind of coding. Not big, complex stuff like the lockless name lookup, but simply good use of pointers-to-pointers etc. For example, I’ve seen too many people who delete a singly-linked list entry by keeping track of the prev entry, and then t
@5kg
5kg / time.c
Created January 16, 2014 01:50
#include <stdio.h>
#include <limits.h>
#include <time.h>
int main()
{
time_t lo = 0x0, hi = LONG_MAX, mid;
while (lo < hi) {
mid = lo + (hi-lo)/2;
if (ctime(&mid))
diff --git a/src/common/hashtable/rculfhash.h b/src/common/hashtable/rculfhash.h
index 17cf6db..601feea 100644
--- a/src/common/hashtable/rculfhash.h
+++ b/src/common/hashtable/rculfhash.h
@@ -34,6 +34,11 @@
#include "urcu-flavor.h"
+static int __attribute__((noinline)) __is_null_pointer(unsigned long v)
+{
Program terminated with signal 11, Segmentation fault.
#0 0x00007f59aeb1c45e in __printf_fp () from /usr/lib/libc.so.6
(gdb) bt
#0 0x00007f59aeb1c45e in __printf_fp () from /usr/lib/libc.so.6
#1 0x00007f59aeb1b185 in vfprintf () from /usr/lib/libc.so.6
#2 0x00007f59aeb207b9 in printf () from /usr/lib/libc.so.6
#3 0x0000000000400534 in main ()
#include <dyninst/BPatch.h>
int main (int argc, const char* argv[]) {
BPatch bpatch;
BPatch_process *proc = bpatch.processAttach(argv[1], atoi(argv[2]));
proc->detach(true);
return 0;
}
@5kg
5kg / run
Last active December 23, 2015 02:59
➜ test ./run
Session auto-20130915-214809 created.
Traces will be written in /home/zifeitong/lttng-traces/auto-20130915-214809
UST event test:call_foo created in channel channel0
Tracing started for session auto-20130915-214809
Hello World!
I am foo()
I am foo()
I am foo()
I am foo()
a.out: file format elf64-x86-64
Disassembly of section .init:
00000000004003e0 <_init>:
4003e0: 48 83 ec 08 sub $0x8,%rsp
4003e4: 48 8b 05 75 06 20 00 mov 0x200675(%rip),%rax # 600a60 <_DYNAMIC+0x1d0>
4003eb: 48 85 c0 test %rax,%rax
@5kg
5kg / c_printf.c
Last active December 20, 2015 09:39
#include <stdio.h>
int main()
{
int i;
for (i = 0; i < 500000; ++i) {
fprintf(stdout, "this is a test from error");
}
return 0;
}
/usr/include/dyninst:
ABI.h
Absloc.h
AbslocInterface.h
AddrLookup.h
AddrSpace.h
Aggregate.h
Annotatable.h
Archive.h
basetypes.h