Skip to content

Instantly share code, notes, and snippets.

View cwshu's full-sized avatar

Jim Shu cwshu

  • Hsinchu, Taiwan
View GitHub Profile
** experimental setting **
- 192.168.1.1: host OS
- 192.168.1.10: guest OS
- 192.168.1.2: remote machine's OS
** sender side **
192.168.1.10$ netperf -H 192.168.1.2 -c -C -l 70
TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.1.2 (192.168.1.2) port 0 AF_INET : demo
Recv Send Send Utilization Service Demand
Socket Socket Message Elapsed Send Recv Send Recv
@cwshu
cwshu / adder1.c
Last active August 18, 2017 16:17
container_of, interface inheritance
#include <stdio.h>
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
struct Adder {
@cwshu
cwshu / qdev.cpp
Last active July 13, 2017 18:14
qdev realize 的物件導向示意程式,以 c++ 為範例
class QDev {
private:
bool realized;
public:
void set_realized(bool value); // setter of realized
virtual void realize(void) = 0;
};
void QDev::set_realized(bool value){
@cwshu
cwshu / rl-header.dpatch
Created June 3, 2017 15:30
GNU readline 的 header 沒 include <stdio.h> , 這是 debian 幫 readline 打的 patch ....
rl-header.dpatch by <[email protected]>
Include stdio.h in readline.h and history.h
Index: b/history.h
===================================================================
--- a/history.h 2010-04-10 12:05:07.792336522 +0000
+++ b/history.h 2010-04-10 12:12:39.462336737 +0000
@@ -32,6 +32,7 @@
# include "rlstdc.h"
@cwshu
cwshu / latency.txt
Created May 31, 2017 09:04 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
#include "syscalls.h"
SYSCALL_DEFINE2(add, int, a, int, b){
return a + b;
}
@cwshu
cwshu / s1.c
Created April 1, 2017 18:18
Linux Kernel system call macro magic 1: syscall arguments
#define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
#define SYSCALL_DEFINEx(x, name, ...) \
static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
#define __SC_DECL(t, a) t a
#define __SC_ARGS(t, a) a
#define __MAP0(m,...)
#define __MAP1(m,t,a) m(t,a)

golang runtime implement libc pthread_create, mutex, malloc. it doesn't use libc API, use OS syscall instead.

  1. malloc
  • golang memory allocator: src/runtime/malloc.go
  • golang memory allocator os specific: src/runtime/mem_bsd.go
    • sysAlloc() use mmap() syscall instead of libc malloc()
  1. pthread_create
APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
const char *progname,
const char * const *args,
const char * const *env,
apr_procattr_t *attr,
apr_pool_t *pool)
{
apr_status_t rv;
apr_size_t i;
const char *argv0;
kvm source in odroid_c2's linux 3.14
KVM = virt/kvm/
X86 = arch/x86/kvm/
ARM = arch/arm/kvm/
ARM64 = arch/arm/kvm/
ARMGIC = virt/kvm/arm/
x86