virshã®vcpupinã¨vcpuinfoã§è¡¨ç¤ºãããaffinityã®éã
以åvirsh vcpupin
㨠virsh vcpuinfo
ã§è¡¨ç¤ºãããCPUã®Affinityæ
å ±ãéãã¨ãããã¨ãããã¾ããï¼
% sudo virsh vcpupin vm1 VCPU CPU Affinity ---------------------- 0 0-47 1 0-47 2 0-47 [...]
% sudo virsh vcpuinfo vm1 VCPU: 0 CPU: 25 State: running CPU time: 508.0s CPU Affinity: ------------------------yyyyyyyyyyyyyyyyyyyyyyyy
åä½çã«ã¯ virsh vcpuinfo
ã®æ
å ±ã®æ¹ãæ£ããï¼ãªãã§ããªãã¨æã£ã¦ããã§ããï¼ã½ã¼ã¹ã調ã¹ã¦ã¿ãã virsh vcpuinfo
ã¯å¼ã°ãããã³ã« sched_getaffinity()
ã§ã¢ãã£ããã£ãåå¾ããã®ã«å¯¾ãã¦ï¼ virsh vcpupin
ã®æ¹ã¯libvirtå
é¨ã®æ
å ±ãåç
§ãã¦ããããã§ããï¼çµæã¨ãã¦libvirtã®å¤é¨ããCPUã¢ãã£ããã£ãå¤æ´ãããã¨ãã®ããã«æ
å ±ã«å·®ç°ãçããããã§ãï¼
å®éã«libvirtdãstraceãããï¼bpftraceãªã©ã§ sched_getaffinity()
ã®å¼ã³åºããç£è¦ããã¨ï¼ virsh cpuinfo
ã³ãã³ããå®è¡ãã㨠shced_getaffinity()
ãå®è¡ãããã®ã«å¯¾ãã¦ï¼ããä¸æ¹ã¯ãããªããã¨ã確èªã§ãã¾ãï¼ãªãï¼virshã³ãã³ãã¯libvirtdã¨RPCã§ããã¨ããã¦ãã¾ãã®ã§ï¼virshã³ãã³ãã®æ¹ã対象ã«ç£è¦ãã¦ãçµæã¯å¾ããã¾ããï¼ï¼
ã¨ãããã¨ã§libvirtã使ã£ã¦ããã¨ãã²ã¹ãã®CPU affinityãç¥ããããªã virsh vcpuinfo
ã使ã£ãæ¹ãè¯ãã¨ãã話ã§ããï¼â»ãã¡ã2020å¹´10æããã®libvirtdãã³ã³ãã¤ã«ãã¦ä½¿ã£ãã¨ãã®æ
å ±ã«ãªãã¾ãï¼ï¼
bpftrace 2020
(ãã®è¨äºã¯Linux Advent Calendar 2020 - Qiitaã®2æ¥ç®ã®è¨äºã§ãï¼åæ¥ã¯masami256ããã®Tiny Core Linuxã§Linuxã®initããã»ã¹ãå®è¡ããããããã調ã¹ãã§ããï¼)
ã¿ãªããããã«ã¡ã¯ããã°ãã¯ï¼bpftraceã使ã£ã¦ãã¾ãã? (e)BPFã¨ããã°æè¿ã¯å°ãCiliumãªã©ãããã¯ã¼ã¯ã話é¡ã§ããï¼bpftraceã¯BPF*1ãå©ç¨ãããã¬ã¼ã·ã³ã°ãã¼ã«ã§ãï¼ç§ã¯æ¨å¹´ããã¼ã¡ã¼ã¡ä½¿ãå§ãã¦ï¼æ©è½è¿½å ããã°ä¿®æ£ã®ããããããããã¨æãã¦ãã(130+)ãæ°ã¥ãããã³ããã¿ã«ãªã£ã¦ãã¾ããï¼ã¨ãããã¨ã§bpftraceã«ã¤ãã¦ã¯æ¯è¼çããç¥ã£ã¦ããã¨æãã®ã§ï¼ä»å¹´ã«bpftraceã«è¿½å ããã主è¦ãªæ©è½ãå¤æ´ç¹ãç´¹ä»ãããã¨æãã¾ãï¼
bpftraceç¥ããªããªãã¨ããæ¹ã¯ãã¡ã(ææã§ã)ãï¼bpftrace使ã£ã¦ãªããªãã¨ããæ¹ã¯æè§ã§ãããæå¾ã®å°è©±ã ãã§ãèªãã§ã¿ã¦ã¯ãããã§ããããï¼ã¾ãæè¿bpftraceãmacããç°¡åã«è©¦ãããã®ãä½ã£ãã®ã§ï¼macã¦ã¼ã¶ã§bpftraceã«èå³ã®ããæ¹ã¯ãã¡ããã©ããï¼å¿è«M1ã¯å¯¾è±¡å¤ã§ã..ï¼ï¼
ç®æ¬¡
- ç®æ¬¡
- æ¬é¡ã«å ¥ãåã«
- BTFãµãã¼ãã®å¼·å
- Docker ãã«ãã»ã¹ã¿ãã£ãã¯ãã«ãã®æä¾
- ç¥ã£ã¦ããã¨ä¾¿å©ãªæ©è½
- ãã®ä»ä¸»è¦ãªå¤æ´ã»æ´æ°ç¹
- ãã°æ å ±
- ãã¾ã
- æå¾ã«-- bpftraceã«é¢ãã£ã¦ãã¦
- æ¥å¹´ã®æ±è²
æ¬é¡ã«å ¥ãåã«
bpftraceã¯ãã®ä¸å¹´éã§å¤ãã®æ©è½è¿½å ï¼ãã°ä¿®æ£ããããªããã¾ããï¼bpftraceãã使ãã®æ¹ã¯ä»ä¸åº¦ã¢ãããã¼ãã®ç¢ºèªããããããã¾ãï¼ãã以ä¸ã§ç´¹ä»ããæ©è½ã使ããªãå ´åï¼bpftraceã®ãã¼ã¸ã§ã³ãå¤ãå¯è½æ§ãé«ãã§ãï¼ã¾ãä¸é¨æ©è½ã¯ã«ã¼ãã«ãã¼ã¸ã§ã³ï¼ä¸»ã«ã«ã¼ãã«5.6以ä¸ï¼ãï¼libbpfã¨ä¸ç·ã«bpftraceãã³ã³ãã¤ã«ããå¿ è¦ãããã¾ãï¼ç¹ã«BTFãããã«è©²å½ãã¾ãï¼ï¼
bpftraceã®ãã¼ã¸ã§ã³ããµãã¼ããã¦ããæ©è½ã®ç¢ºèª
bpftraceã®ãã¼ã¸ã§ã³ãï¼ãµãã¼ããã¦ããæ©è½ã¯ï¼bpftrace --info
ã³ãã³ããã確èªã§ãã¾ãï¼
$ sudo bpftrace --info System OS: Linux 5.9.0+ #26 SMP Mon Nov 16 11:50:54 JST 2020 Arch: x86_64 Build version: v0.11.0-287-gc62f LLVM: 10.0.1 foreach_sym: yes unsafe uprobe: no bfd: yes bpf_attach_kfunc: yes bcc_usdt_addsem: yes bcc bpf_attach_uprobe refcount: no libbpf: yes libbpf btf dump: yes libbpf btf dump type decl: yes Kernel helpers probe_read: yes probe_read_str: yes probe_read_user: yes probe_read_user_str: yes probe_read_kernel: yes probe_read_kernel_str: yes get_current_cgroup_id: yes send_signal: yes override_return: yes get_boot_ns: yes dpath: no Kernel features Instruction limit: 1000000 Loop support: yes btf (depends on Build:libbpf): yes map batch (depends on Build:libbpf): yes uprobe refcount (depends on Build:bcc bpf_attach_uprobe refcount): no Map types hash: yes percpu hash: yes array: yes percpu array: yes stack_trace: yes perf_event_array: yes Probe types kprobe: yes tracepoint: yes perf_event: yes kfunc: yes
BTFãµãã¼ãã®å¼·å
ããã§ã¯æ©é追å ããã主è¦ãªæ©è½ãæ¯ãè¿ã£ã¦ããããã¨æãã¾ãï¼ä»å¹´ã¯ãªãã¨ãã£ã¦ãBTF (BPF Type Format) ãå©ç¨ããæ©è½ãããããã¨è¿½å ããã¾ããï¼ä»¥ä¸ã§ã¯ã©ããªãã¨ãã§ãããç°¡åã«ç´¹ä»ãã¦ããã¾ãï¼
ããããBTFã¨ã¯
BTFã«ã¯ãããããªç¨éãããããï¼ç°¡åã«èª¬æããã®ã¯é£ããã®ã§ããï¼bpftraceã®æèã§ããã¨/proc/kallsyms ãç¾å¨åãã¦ããã«ã¼ãã«ã·ã³ãã«ã®ã¢ãã¬ã¹ãæä¾ããã®ã¨åãããã«ï¼BTFã¯ç¾å¨åãã¦ããã«ã¼ãã«ãå©ç¨ãã¦ããé¢æ°ããã¼ã¿æ§é ã®æ
å ±ãæä¾ãã¾ãï¼ä¾ãã°ï¼BTFãåç
§ããã°ãã®ã«ã¼ãã«ãå©ç¨ãã¦ããï¼ããã»ã¹ã®ç¶æ
ãä¿æãã struct task_struct
ã®æ§é ãç¥ããã¨ãã§ãï¼ã©ã®ã¡ã³ãã«ã¢ã¯ã»ã¹ããã«ã¯ã©ãã ãã®ãªãã»ãããå¿
è¦ããåããã¾ãï¼ä»ã«ã¯ä¾ãã°ï¼vfs_open()
é¢æ°ã®å¼æ°ã®æ°ãå¼æ°ã®åãåããã¾ãï¼ããã§ä½ãå¬ããã®? ã¨æãããããã¾ãããï¼ã«ã¼ãã«å
ã®é¢æ°ãæ§é ä½ã¯unstableã§å¸¸ã«å¤åãã¾ãï¼ã«ã¼ãã«ãã¬ã¼ã·ã³ã°ãããå ´åï¼å¤ãã®å ´åã¯ã«ã¼ãã«ã®é¢æ°ãæ§é ä½ã«ã¢ã¯ã»ã¹ããããï¼é¢æ°ãæ§é ä½ãå¤åãã¦ãã¾ãã¨æè§æ¸ãããã¬ã¼ã·ã³ã°ã¹ã¯ãªãããç¹å®ã®ã«ã¼ãã«ã§ããåããªãã¨ãããã¨ã«ãªãã¾ãï¼BTFã«ãããã®ã«ã¼ãã«ãå©ç¨ãã¦ããé¢æ°ãã«ã¼ãã«ãåããã°ï¼ãã®æ
å ±ãå©ç¨ãã¦ã¹ã¯ãªãããè£æ£ãããã¨ã§ï¼è¤æ°ã«ã¼ãã«ã§åä½ãããã¬ã¼ã·ã³ã°ã¹ã¯ãªãããåä½ã§ããããã«ãªãã¨ããããã§ãï¼éãæ¹ã¯ããã£ã¦DWARFã§ã§ããã®ã§ã¯?ã¨æããã¨ã§ãããï¼å¿è«DWARFã§ãå¯è½ã§ããï¼BTFã¯ãã¬ã¼ã·ã³ã°ç¨éã«ç¹åãã¦ãããã¯ã·ã§ã³ç°å¢ã§ãå©ç¨ã§ãããã¨ãä¸ã¤ã®ç®æ¨ã«ãã¦ããããï¼ãµã¤ãºãé常ã«å°ããã§ãï¼æ°MBç¨åº¦ï¼ï¼ãã ããã®ä»£ããDWARFã¨æ¯ã¹ã¦å½ç¶æ
å ±éãå°ãªãããï¼ã§ãããã¨ã¯å¿
ç¶çã«éããã¾ãï¼
bpftraceã¯å®è¡æã«ãã¬ã¼ã·ã³ã°ã¹ã¯ãªãããã³ã³ãã¤ã«ããå½¢ã§ãï¼BTFãå©ç¨å¯è½ãªå ´åã¯ï¼bpftraceã¯ã³ã³ãã¤ã«æã«BTFæ å ±ãå©ç¨ãã¦ï¼é©åãªãªãã»ããã§ãã¼ã¿ã«ã¢ã¯ã»ã¹ããBPFããã°ã©ã ãçæãã¾ãï¼ããBTFãå©ç¨ã§ããªãå ´åã¯ï¼includeãããããã«å«ã¾ããå®ç¾©æ å ±ãå©ç¨ãã¾ãï¼ï¼ä¸æ¹ã§ï¼å®è¡åã«ãã¬ã¼ã¹ããã°ã©ã ãããã«ã¼ãã«ãã¼ã¸ã§ã³ä¸ã§ã³ã³ãã¤ã«ãã¦ããï¼BTFãå©ç¨ãã¦ãã®ãã¬ã¼ã¹ããã°ã©ã ããã¼ãããåã«ï¼ãã¼ã¿æ§é ã¢ã¯ã»ã¹ã®ãªãã»ããã®ä¿®æ£ããããªãã¨ããæ¹æ³ãããã¾ãï¼ãã¡ã㯠BPF CO-REã¨å¼ã°ããæ©è½ã§ï¼ãã¡ãã¯ãã¡ãã§é常ã«éè¦ã§ç©æ¥µçã«éçºãé²ãããã¦ãã¾ããï¼ç¹ã«iovisor/bccã®æ¹ã§ï¼ï¼bpftraceã¨ã¯ç´æ¥ã¯é¢ä¿ããã¾ããï¼
BTFã¯ã«ã¼ãã«ã®é¢æ°ãæ§é ä½ã®æ å ±ãæä¾ããã ãã®ãã®ã§ã¯ããã¾ããï¼BTFã«ã¤ãã¦ãã詳ããã¯ãã®è¾ºã(ææã§ã)ãã«ã¼ãã«ã®ããã¥ã¡ã³ãããåç §ãã ããï¼
BTFã使ç¨ããã«ã¯
BTFã®æ©è½ãå©ç¨ããã«ã¯ï¼CONFIG_DEBUG_INFO_BTF
ãæå¹ã«ããã«ã¼ãã«ãå¿
è¦ã§ãï¼ã¾ãã«ã¼ãã«5.6以ä¸ã§ãªãã¨ä»¥ä¸ã§èª¬æããkfuncã®æ©è½ã¯ä½¿ãã¾ããï¼bpftraceèªä½ãlibbpfã¨ä¸ç·ã«ã³ã³ãã¤ã«ããå¿
è¦ãããã¾ãï¼ã
bpftrace --info
ã§BTFã®æ©è½ãå©ç¨ã§ããã確èªã§ãã¾ãï¼ç¹ã«ï¼
- BTFã使ãããå ´å㯠"Kernel features" ã®btf ã yes
- kfuncã使ãããå ´å㯠Probe typesã® kfunc ãyes
ã§ããå¿ è¦ããã¾ãï¼
BTFã§ã§ãããã¨
ããã§ã¯BTFã§ã§ãããã¨ãã¿ã¦ããã¾ãããï¼
ã«ã¼ãã«æ§é ä½ã®èªå解決
ä¾ã¨ãã¦ï¼vfs_open(struct path*, strust file *)
é¢æ°ã®å¼ã³åºããããã¯ãã¦ï¼vfs_openãå¼ã°ããæã®path
ã®ãã¡ã¤ã«åãå¼ã³åºãã¹ã¯ãªãããèãã¾ã(ããã¯bptraceã®reference guideããã®å¼ç¨ã§ã)ï¼BTFãç¡ã以åã¯ï¼ã¹ã¯ãªãããå©ç¨ãã struct path
ãï¼ struct dentry
ãå®ç¾©ãã¦ããããããã¤ã³ã¯ã«ã¼ãããå¿
è¦ãããã¾ããï¼
#include <linux/path.h> #include <linux/dcache.h> kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }
ããBTFã使ç¨ã§ããç°å¢ã§ããã°ï¼ä»¥ä¸ã®ããã«ããããã¤ã³ã¯ã«ã¼ãããªãã¦ãï¼ã¹ã¯ãªããå´ã§å©ç¨ããã«ã¼ãã«æ§é ä½ãï¼ç¹ã«ä½ãããªãã¦ãå©ç¨ã§ããããã«ãªãã¾ãï¼
kprobe:vfs_open { printf("open path: %s\n", str(((struct path *)arg0)->dentry->d_name.name)); }
å
é¨çã«ã¯ã¾ãBTFãã struct path
ã®æ
å ±ãåã£ã¦ãã¦ï¼ããããã¹ã¯ãªãããã¢ã¯ã»ã¹ããæ§é ä½æ
å ±ãéãã¦ãã¦ãããå©ç¨ãã¦ãã¾ãï¼
kfuncã®å©ç¨
ä¸è¨ã®ã¹ã¯ãªããä¾ã§ã¯kprobeãå©ç¨ãã¦ãã¾ããï¼kprobeã¯åºæ¬çã«ã«ã¼ãã«å
ã®ã©ã®ã¢ãã¬ã¹ã«ãã¢ã¿ããã§ããã®é常ã«ä¾¿å©ã§ããï¼ä¸æ¹ã§bpftraceã§ã¯é¢æ°ã«ã¢ã¿ããããã¨ãï¼èªåã§å¼æ°ããã£ã¹ãããå¿
è¦ï¼ä¸è¨ã®ä¾ã 㨠(struct path *)arg0)
ãããã¾ããï¼ï¼ã«ã¼ãã«5.6ããï¼kfuncã¨ããï¼kprobeã¨ã¯ã¾ãéããã¬ã¼ã¹æ¹æ³ã追å ããã¾ããï¼kfuncã¯kprobeã¨éãé¢æ°ã®entryã¾ãã¯exitã«ããã¢ã¿ããã§ãã¾ãããï¼BTFã®æ
å ±ãå©ç¨ãããã¨ã§ï¼ä»¥ä¸ã®ããã«æ§é ä½ã®ãã£ã¹ããªãã«é¢æ°ã®å¼æ°ã«ã¢ã¯ã»ã¹ã§ãã¾ãï¼
kfunc:vfs_open { printf("open path: %s\n", str(args->path->dentry->d_name.name)); }
ãã¤ã³ã㯠args->path
ã§ï¼ããã«ãã vfs_open()
ã®å¼æ° path
ã«ã¢ã¯ã»ã¹ãã¦ãã¾ãï¼ä½æ
ãããã§ãããã¨ããã¨ï¼BTFã«ã¯é¢æ°ã®æ
å ±ãå
¥ã£ã¦ããã®ã§ï¼ã¾ã vfs_open
ã®é¢æ°ã®ãããã¿ã¤ãæ
å ±ãã¨ã¦ãã¦ï¼ãããã args->path
ã§vfs_open
ã®pathã«ã¢ã¯ã»ã¹ãã¦ããã¨ãåããã®ã§ï¼ããããã¹ã¯ãªãããçæã§ããã¨ããããã§ãï¼ ã¾ãkfuncã®å ´åkprobeã¨éã£ã¦å¼æ°ãèªåã§ãã£ã¹ããããã®ã§ï¼ééã£ããã£ã¹ãããã¦ãã¾ãã¨ãããã¹ããªããªãã¾ãï¼
ã«ã¼ãã«é¢æ°ã®å¼æ°ãæ§é ä½ã®ç¢ºèª
ãããã¾ãçæ©è½ã§ããï¼ä»¥ä¸ã®ããã«ãã¦BTFãå©ç¨ãã¦é¢æ°ã®ãããã¿ã¤ããï¼æ§é ä½ã®ã¡ã³ãã確èªã§ãã¾ãï¼
% sudo bpftrace -lv "kfunc:vfs_open" kfunc:vfs_open const struct path * path; struct file * file;
% sudo ./src/bpftrace -lv "struct path" struct path { struct vfsmount *mnt; struct dentry *dentry; };
ãã®æ§é ä½ã®ã¡ã³ããªãã ã£ãï¼ã¨ãªã£ãã¨ãã«ã¼ãã«ã½ã¼ã¹ã確èªããå¿ è¦ããªããªãã¾ãï¼
ç¾ç¶ã®BTFã®å¶ç´
BTFã¯é常ã«ä¾¿å©ã§ããï¼ä»¥ä¸ã®ãããªå¶ç´ã»èª²é¡ãããã¾ãï¼
- ç¾ç¶BTFã«å«ã¾ããé¢æ°ã¯non-statitcãªãã®ã®ã¿ (kprobeã¯staticãªé¢æ°ã«ã対å¿ãã¦ãã¾ã)
- ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã«æªå¯¾å¿ (ããã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãBTFã§ãã¬ã¼ã·ã³ã°ãããå ´åã¯ï¼ã«ã¼ãã«å´ã«ã¢ã¸ã¥ã¼ã«ãã¯ãªãçµã¿è¾¼ãã§ãã«ãããå¿ è¦ãããã¾ã)
- define å¤ã®æ¬ å¦
ãã®è¾ºãã®åé¡ã¯ããããã¨è§£æ±ºã«åãã¦è°è«ãããã¦ãã¾ãï¼ç¹ã«æå¾ã®defineããã¦ããå¤ãæ¬ å¦ããã¦ããã¨ããã®ã¯å°å³ã«ãã¬ã¼ã¹ããã°ã©ã ãæ¸ãæã«é害ã«ãªãã¾ãï¼ä¾ãã° AF_INET
ã®å¤ãç¥ãããã¨ãã¯ï¼BTFããã£ã¦ããããdefineããã¦ããããããã¤ã³ã¯ã«ã¼ãããå¿
è¦ãããããã§ãï¼è§£æ±ºçã®ä¸ã¤ã¯#defineã§ã¯ãªãenumã使ããã¨ã§ (enumã®æ
å ±ã¯BTFã«å«ã¾ãã¾ã)ï¼å®ã¯ä¸é¨ãããã¯BTFã«å¯¾å¿ã§ããããã«ãã®ãããªå¤æ´ãå ãããã¦ãã¾ãï¼å°æ¥çã«ã¯ãã®è¾ºãã®åé¡ã解決ãããã¨å¬ããã§ããï¼
Docker ãã«ãã»ã¹ã¿ãã£ãã¯ãã«ãã®æä¾
x86_64ç¨ã§ããï¼ãã¹ãããã¬ã¼ã¹ããããã®Dockerãã«ããããã¾ãï¼ä»¥ä¸ã®ããã«ãã¦å©ç¨ã§ãã¾ãï¼
% sudo docker run -it --privileged -v /sys/kernel/debug:/sys/kernel/debug:rw -v /lib/modules/:/lib/modules:ro -v /usr/src:/usr/src:ro quay.io/iovisor/bpftrace tcpconnect.bt
é©åã«debugfsãã«ã¼ãã«ãããã®å ´æãã³ã³ããå´ã«ãã¦ã³ãããå¿ è¦ãããã¾ããï¼docker buildã使ãã¨bpftraceã®ææ°çã使ãã¦ä¾¿å©ã§ãï¼ãã æ®å¿µãªããç¾ç¶BTFã®ãµãã¼ã(ã¨ãããlibbpfã¨ã®ãã«ã)ã¯ããã¾ããï¼
ã¾ãï¼github actionã«ããã¹ã¿ãã£ãã¯ãã«ããæä¾ãããããã«ãªã£ã¦ãã¾ãï¼Releaseãããªãªã¼ã¹ãã¼ã¸ã§ã³ã®ã¹ã¿ãã£ãã¯ãã«ããåå¾ã§ããä»ï¼ããåããã«ããã§ããgithubã¢ã¯ã·ã§ã³ã®embedded buildã®é ç®ããææ°ã®ã¹ã¿ãã£ãã¯ãã«ããåå¾ã§ãã¾ãï¼
ç¥ã£ã¦ããã¨ä¾¿å©ãªæ©è½
ã¿ãã«
以ä¸ã®ããã«ã¿ãã«ã使ããããã«ãªãã¾ããï¼ããããè¤æ°ããããä½ããªãã¦ãå¤ãæ ¼ç´ã§ãã¾ãï¼
% bpftrace -e 'BEGIN { @ = (0, 1, "abc"); printf("%d\n", @.0); print(@); }' Attaching 1 probe... 0 @: (0, 1, abc)
ãããã®è¤æ°ãã¼ã®å©ç¨
å¥ã«ããèªä½ã¯åãããã£ãæ©è½ãªã®ã§ããï¼ãã¾ãã¡èªç¥ããã¦ããªããããªã®ã§æ¸ãã¦ããã¾ãï¼ä»¥ä¸ã®ããã« @[]
ã«ä½¿ããã¼ã¯è¤æ°åæå®ã§ãã¾ãï¼
% sudo ./share/bpftrace -e 'BEGIN { @[pid, cpu] = 1; print(@); }' Attaching 1 probe... @[10189, 35]: 1
ããã使ãã¨æ¡ä»¶ï¼ä¾ãã°CPUçªå·ï¼ã«å¿ããéè¨ãªã©ãç°¡åã«ã§ãã¾ãï¼
ãã¤ããªå¤ã®ãã³ã
buf()
ã使ãã¨ï¼ãã¤ã³ã¿å
ã®ãã¼ã¿ããã³ããã§ãã¾ãï¼ä¼¼ããããªé¢æ°ã« str()
ãããã¾ããï¼ str()
ã¯NULLçµç«¯ãããæååãæ±ãç¹ãç°ãªãã¾ãï¼
% bpftrace -e 'tracepoint:syscalls:sys_enter_sendto { printf("Datagram bytes: %r\n", buf(args->buff, args->len)); }' -c 'ping 8.8.8.8 -c1' Attaching 1 probe... PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. Datagram bytes: \x08\x00@\xc3\x05\xb6\x00\x01\xe9\x0aW_\x00\x00\x00\x00\xb0H\x02\x00\x00\x00\x00\x00\x10\x11\x12\x13\x14\x15\x1 6\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&'()*+,-./01234567 ^C --- 8.8.8.8 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms
ã¨ã©ã¼ãã§ãã¯
-k
ããã㯠-kk
ãªãã·ã§ã³ã§BPFããã°ã©ã å®è¡ä¸ã®ã¨ã©ã¼ããã§ãã¯ããããã«ãªãã¾ãï¼
% bpftrace -kk -e 'BEGIN { @[0] = 1; @[1]++; }' Attaching 1 probe... stdin:1:19-25: WARNING: Failed to map_lookup_elem: 0 BEGIN { @[0] = 0; @[1]++;} ~~~~~~
ããbpftraceã®ã¹ã¯ãªãããæå¾
ããã¨ããã«åããªãå ´åï¼ã¨ãããã -kk
ãã¤ãã¦å®è¡ãã¦ã¿ãã¨è¯ãã¨æãã¾ãï¼
ãã®æ©è½ã«ã¤ãã¦è£è¶³ããã¨ï¼BPFããã°ã©ã ã«ã¯ãã«ãã¼é¢æ°ã¨å¼ã°ããé¢æ°ãå©ç¨ãã¦ï¼ã«ã¼ãã«ã®å¦çãå¼ã³åºãæ©è½ãããã¾ãï¼ããã¯ããã°ã¦ã¼ã¶ããã°ã©ã ã«ãããã·ã¹ãã ã³ã¼ã«ã®ãããªãã®ã§ï¼BPFãããã®æä½ãåºåå¦çãªã©ã®æ©è½ã¯å
¨ã¦ãã®ãã«ãã¼é¢æ°ã«ãã£ã¦æãç«ã£ã¦ãã¾ãï¼bpftraceãå©ç¨ããå ´åã¯ç¹ã«ãã®ãã«ãã¼é¢æ°ãæèããå¿
è¦ã¯ãªãã§ããï¼éè¦ãªã®ã¯ãã«ãã¼é¢æ°ã®å¦çã¯ä½ããã®çç±ã«ãã£ã¦å¤±æãããã¨ãããã¨ãããã¨ã§ãï¼ãã®ã¨ãï¼ãã«ãã¼é¢æ°ã¯æ»ãå¤ã¨ãã¦ã¨ã©ã¼ãè¿ãã¾ããï¼ããã©ã«ãã§ã¯ãã®ã¨ã©ã¼å¤ã¯ç¡è¦ããã¾ãï¼ããããã§ãã¯ããã®ã -k
ããã³ -kk
ãªãã·ã§ã³ã§ãï¼ -k
㨠-kk
ã®éãã¯ï¼ãã§ãã¯ãããã«ãã¼é¢æ°ã®æ°ã§ãï¼bpftraceã¯ãã¼ã¿ã®èªã¿åºãããããªããã«ãã¼é¢æ°ã失æããã¨ï¼å¤ã0ã¨ãã¦è¿ãã¨ããä»æ§ã«ãªã£ã¦ãã¾ãï¼ããã«ãã£ã¦ï¼ä¾ãã° / @[tid] /
ã®ããã«æ¸ãã¨ï¼ @[tid]
ãåå¨ããªãå ´åã¯ãã®å¦çãã¹ãããã§ãããã¨ã«ãªãã¾ãï¼ãã®ãããªãã¯ããã¯ã¯bpftraceã®ã¹ã¯ãªããã§åºã使ããã¦ãã¦ï¼ãã®ã¨ã©ã¼ããã§ãã¯ãã¦ãã¾ãã¨åé·ãªå ´åãããããï¼ -k
ãªãã·ã§ã³ã§ã¯ãã®ãããªãã¼ã¿èªã¿åºãã®é¢æ°ã«é¢ãã¦ã¨ã©ã¼ã¯ãã§ãã¯ãã¾ããï¼ -kk
ã ã¨å
¨ã¦ã®ãã«ãã¼é¢æ°ã®ã¨ã©ã¼ããã§ãã¯ãã¾ãï¼ä¸ã¤æ³¨æç¹ã¨ãã¦ï¼ã¨ã©ã¼ãã§ãã¯æ©è½ãæå¹ã«ããã¨BPFããã°ã©ã ããã®åé·ããªãã¾ãï¼å ´åã«ãã£ã¦ã¯ãã®ãªã¼ãããããåé¡ã«ãªãå¯è½æ§ãããã¾ãï¼ã¾ãï¼ãã¼ãã§ããBPFããã°ã©ã é·ã«ã¯å¶éãããããï¼å¤§ããªbpftraceã¹ã¯ãªããã§ã¯ã¨ã©ã¼ãã§ãã¯æ©è½ãå©ç¨ã§ããªãå¯è½æ§ãããã¾ãï¼
whileã«ã¼ã
ãã¨ãã¨BPFããã°ã©ã ã¯åæ¢æ§ä¿è¨¼ã®ããã«ã«ã¼ãï¼å¾æ¹ã¸ã£ã³ãï¼ãä¸å許å¯ããã¦ãã¾ããã§ãããï¼verifierãè³¢ããªã£ã¦æéåã§åæ¢ããã«ã¼ãå¦çãæ¸ããããã«ãªãã¾ããï¼ã«ã¼ãã«5.3以ä¸ãå¿
è¦ã§ãï¼bpftraceã§ã¯ while()
ã使ãã¾ãï¼
% bpftrace -e 'i:ms:100 { $i = 0; while ($i <= 100) { printf("%d ", $i); $i++} exit(); }'
ããã§ï¼verifierã¯å®éã«ã«ã¼ãå¦çãä¸ã¤ä¸ã¤è§£éãã¦ããï¼ãã®ã«ã¼ããåæ¢ããããã¿ã¦ãã¾ãï¼å¾ã£ã¦ï¼æ¥µç«¯ã«å¤§ããªã«ã¼ãã¯verifierã®å½ä»¤è§£éæ°ä¸éã«å¼ã£ãããããå®è¡ã§ãã¾ããï¼ä¾ãã°ï¼ä»¥ä¸ã®ããã°ã©ã ã¯ã¨ã©ã¼ã«ãªãã¾ãï¼
$i = 0; while ($i <= rand) { printf("%d ", $i); $i++} exit(); }
ãã㯠rand
ã¯uint64ã®å¤ãè¿ãé¢æ°ã§ï¼verifierã¯ãã®å¤ã®æ大ãæ³å®ãã¦verificationããããªãããã§ãï¼ä»¥ä¸ã®ããã«ï¼æ示çã«ã«ã¼ãä¸éãå®ãã¦ãããã¨ããã°ã©ã ãå®è¡ã§ããããã«ãªãã¾ãï¼
$i = 0; $max = rand; if ($max > 100) { $max = 100;} while ($i <= $max) { printf("%d ", $i); $i++} exit();}
ãã®ä»ä¸»è¦ãªå¤æ´ã»æ´æ°ç¹
s390x, aarch64ã®ãµãã¼ã
ããã°ã¨ã³ãã£ã¢ã³ã®ã¢ã¼ããã¯ãã£ã«åå¨ããä¸é¨åé¡ãä¿®æ£ããã¾ããï¼ã¾ãaarch64ãªã©ã®ã¢ã¼ããã¯ãã£ã§ã¯ï¼ã«ã¼ãã«ã¢ã¼ãã¨ã¦ã¼ã¶ã¢ã¼ãã®ã¢ãã¬ã¹ã¹ãã¼ã¹ãç°ãªããã¨ã«èµ·å ãã¦ï¼ããããã®ãã¼ã¿ã®èªã¿åºãã«å°ç¨ã®ãã«ãã¼é¢æ°*2ãå©ç¨ããå¿ è¦ãããï¼ãã°ããã®ébpftraceã¯ããããµãã¼ããã¦ãã¾ããã§ãããï¼ã¤ãæè¿ãã®æ©è½ããµãã¼ãããã¾ããï¼çµæã¨ãã¦aarch64ã§ãåé¡ãªãbpftraceã使ããããã«ãªã£ã¦ããã¯ãã§ãï¼
æ¥æ¬èªçããã¥ã¡ã³ã
ã¯ã³ã©ã¤ãã¼ãã¥ã¼ããªã¢ã«ã«ã¯æ¥æ¬èªè¨³(æ訳ã§ã)ãããã¾ãï¼Reference Guideã¯è±èªã®ã¿ã§ãï¼
Discourse ãã©ã¼ã©ã
Discourceã«bpftraceã®ãã©ã¼ã©ã ãã§ãã¾ããï¼è³ªåã¯ããã«æããã¨è¯ãã¨æãã¾ãï¼éçºè ã®æ¹ãè¦ã¦ãã¾ãï¼
ãã詳ããç¥ãããæ¹
å®éã«ã¯ä»ã«ãããããã¨æ©è½ã追å ããã¦ãã¾ãï¼è©³ãã㯠CHANGELOG ãã©ããï¼
ãã°æ å ±
æå¾ã«ï¼ç¾å¨ã®bpftraceã«ã¯ printf()ããã¨ãã«ééã£ãå¤ãããã¾ãã«è¡¨ç¤ºããã ã¨ããå²ã¨è´å½çãªãã°ãããã¾ãï¼é·ãéåå ãåãããéçºè
ãå°ããã¦ãã¾ããããï¼ã©ãããLLVMã®ããã¯ã¨ã³ãã«åé¡ãããã¨ãããã¨ãåããã¾ããï¼è©³ãã㯠#1305, Bugzilla â Bug 47591 ãã©ããï¼ï¼2020å¹´12æç¾å¨ãã®ãã°ã¯ä¿®æ£ããã¦ãããï¼ç¾ç¶ããã«å¯¾å¿ããå®ç§ãªæ¹æ³ã¯ãªãã®ã§ããï¼printf()ã®ä½ç½®ãå¤ãããããã¨çµæçã«BPFã®ã³ã¼ããå¤ããã®ã§åé¡ã解決ããå ´åãããã¾ãï¼ä¸è¨ã§ç´¹ä»ãã -k
ããã㯠-kk
ãªãã·ã§ã³ãæå¹ã§ãï¼ããbpftraceã使ã£ã¦ãã¦æããã«åºåãããããå ´åã¯ãã®ãã°ãçã£ã¦ã¿ã¦ãã ããï¼ã¡ãªã¿ã«æ¬å½ã«ãã®ãã°ãã©ããã¯BPFããã°ã©ã ã®ã¢ã»ã³ãã©ã³ã¼ããçºãã¦ã¿ãã¨åããã¾ãï¼ä¸èªç¶ã«loadã¨storeå½ä»¤ãå
¥ãæ¿ãã£ã¦ããç®æãããã¯ãã§ãï¼
2020-12-4 追è¨
ãã®ãã°ã§ããï¼LLVM12ã§ä¿®æ£ãããããã§ãï¼ãã ãLLVM12ãå®éã«å©ç¨ãããããã«ãªãã®ã¯æ°å¹´ãããã§ããããï¼bpftraceå´ã§ããªãã¨ãä¿®æ£ã§ããªããããããã¨æ¤è¨ãã¦ãã¾ãï¼
追è¨ããã¾ã§
ãã¾ã
bpftaceã«ããBitVisorã®ãã¬ã¼ã¹
å æ¥BitVisorãbpftraceãã¬ã¼ã¹ããã¨ããå 容ã®çºè¡¨ãBitVisor Summit 9ã§ãããªãã¾ããï¼è¨ã£ã¦ãæå³ãä¸æããããã¾ãããï¼èå³ã®ããæ¹ã¯ãç¬è¦§ãã ãã â ã¹ã©ã¤ã
macããbpftraceã試ã
æåã«æ¸ãã¾ãããï¼Intel macããbpftraceãç°¡åã«è©¦ãããã®ãä½ãã¾ããï¼è©³ããã¯ãã¡ããã©ããï¼
ã·ã¹ãã ç³»è«æã®æ å ±åéæ¹æ³
ãã¾ãBPFã¨é¢ä¿ãªãã¦æ縮ã§ããï¼æ¨æ¥ã·ã¹ãã ç³»è«æã®æ å ±åéæ¹æ³ã¨ããã¨ã³ããªãæ¸ãã¾ããï¼å¦è¡çã«ãBPFã使ã£ãè«æã¯çµæ§åºã¦ããã®ã§ï¼æ°ã«ãªãæ¹ã¯ãã§ãã¯ãã¦ã¿ã¦ãã ããï¼
æå¾ã«-- bpftraceã«é¢ãã£ã¦ãã¦
æå¾ã«æè§ã®æ©ä¼ãªã®ã§ä¸å¹´ébpftraceã«é¢ãã£ã¦ããææ³ãæ¸ãã¦ã¿ããã¨æãã¾ãï¼ã¾ãï¼bpftraceã¯ãã¨ãã¨Alastair Robertsonããä¸äººã«ãã£ã¦2017å¹´ããéçºãããããã¸ã§ã¯ãã§ãï¼ãããï¼ï¼ãã®å¾ï¼Brendan Greggããã«ããå¤ãã®ãã¼ã«ã追å ããï¼ããã«Netflixã®ã¨ã³ã¸ãã¢ã®æ¹ã«ãã£ã¦åºæ¬çãªæ©è½ã®å¤ãã追å ããã¾ããï¼ã ãããå»å¹´ã®æ¥å ããã®ãã¨ã ã¨æãã¾ãï¼æ¸ç±"BPF Performance Tools" (Brendan Gregg箸)ã¯ãã®è¾ºã®ãã¼ã¸ã§ã³ã®bpftraceããã¨ã«æ¸ããã¦ãã¾ãï¼ãã®ããã¨æ¯ã¹ã¦ï¼bpftraceã¯çµæ§é²åãã¦ããã¨æãã¾ãï¼ç¾å¨ã¯åè¿°ã®3人ã¯ã³ãããã«é¢ãã¦ã¯æ§ããã§ï¼ä»ã¯ç§ãå«ããå¥ã®3人ã主ã«ããã¸ã§ã¯ãã«é¢ãã£ã¦ãã¾ãï¼ç¹ã«ãã®ä¸ã®ä¸äººã®FBã®ã¨ã³ã¸ãã¢ã®æ¹ãã¡ã¤ã³ã®ã¡ã³ããã¨ãã£ãæãã§ãï¼ãã®ä»Red HatãIBMã®æ¹ãããå®æçã«ã³ã³ããªãã¥ã¼ã·ã§ã³ãããã¾ãï¼
ããã¾ã§ã«ç§ãã³ããããã主ãªå 容ã«ã¯ä»¥ä¸ãããã¾ãï¼
- æ´æ°åãã¤ã³ã¿ã®ãã£ã¹ãã®ãµãã¼ã#942
- kprobe offset ã«å¯¾ããã¢ã¿ããæ©è½ã®è¿½å #956
- BPFã³ã³ããã¹ãã¢ã¯ã»ã¹ã®ä¿®æ£ #1104
- bpftrace oneliner ããã¥ã¡ã³ã翻訳 #1176, 訳æ
- bpf helper functionã¨ã©ã¼ã®ã¬ãã¼ãæ©è½ #1276
- fuzzingã®ãµãã¼ã #1601, #1633, ããã¥ã¡ã³ã
- ãã®ä»ã®ãã°ä¿®æ£ãªã©
ä¸çªæåã®PRã¯æ´æ°åãã¤ã³ã¿ã®ãã£ã¹ãã®ãµãã¼ã ((int8*)$var
ã¿ãããªãã¤) ã§ããï¼ããã¯bpftraceã使ãå§ãã¦ããã«ãã®æ©è½ããªãã¦ä¸ä¾¿ã ã£ãã®ã§ï¼ãªãã¨ãªãã½ã¼ã¹ãè¦ã¦ä¿®æ£ãã¦PRãéã£ããã®ã§ãï¼C++ãªãã¦3年以ä¸ã¾ã¨ãã«æ¸ãã¦ãªãã£ããï¼ããããC++ã¯ç解ãã¦ãªããï¼ãã®ã¨ãå¤å1å²ãããããbpftraceã®ãã¨ãåãã£ã¦ãªãã£ããã§ããï¼å°ããã£ã¼ãããã¯ããã£ããã¨ã«ãã¼ã¸ãããã®ãã¯ãã¾ãã§ããï¼bpftraceã¯ä½¿ã£ã¦ããã»ã©ããããã¨åé¡ã«ééããã®ã§ï¼æ¯æãã¨ãã¦ç©ºãã¦ãæéã«ãããç´ãã¦è¡ã£ããä»ã®ç¶æ
ã«ãªã£ãã¨ããã®ãå®æ
ã§ãï¼ããã¾ã§é¢ãã£ãOSSããã¸ã§ã¯ãã¯bpftraceãåãã¦ã§ããï¼ãã¯ãä¸çä¸ã®äººã¨ä½æ¥ããã¦ããã¨ããã®ã¯OSSã®ééå³ã§ï¼ã¨ã¦ã楽ããçµé¨ã§ãï¼ä½è
ã®æ¹ã«"good work!"ã¨è¨ãããã¨ãã¯ãå¬ãããã®ã§ãï¼
bpftraceã«ã³ããããããã¨ã§BPFã«é¢ãã¦ãã詳ãããªã£ãã®ã¯å¿è«ã®ãã¨ï¼ãã¨ãã¨ãç§ã¯Linuxã®ãã¬ã¼ã·ã³ã°ææ³ã«ã¤ãã¦ããããã¨èª¿æ»ãã¦ä½¿ã£ã¦ãã¾ãããï¼å ·ä½çã«ããããå©ç¨ããããã«ã¤ãã¦ã®ç解ãæ·±ã¾ãã¾ããï¼æè¿æ¹ãã¦"BPF Performance Tools"ãèªã¿è¿ãã¦ã¿ãã®ã§ããï¼ã¤ãã«çã«ç解ã§ããããã«ãªã£ããããªæ°ããã¦ãã¾ãï¼
ã¾ãbpftraceèªä½ã¯flex/bisonã«ããåå¥è§£æï¼æ§æ解æããããªã£ãå¾ï¼LLVMã«ããIRãåºåããã³ã³ãã¤ã©ã§ãï¼ããCPU, OS, ã³ã³ãã¤ã©ãèªä½ããã¨è¯ããªãã¦è©±ãããã¾ããï¼ç§ã¯ç°¡åãªCPUãOSã¯ä½ã£ããã¨ããã£ããã®ã®*3ï¼ã³ã³ãã¤ã©ã¯çé¢ç®ã«åãçµãã ãã¨ããªãã£ãã®ã§ï¼ãã®è¾ºãããããã¨åå¼·ã«ãªãã¾ããï¼ï¼ã¨åæã«LLVMã®é£ãããç¥ããã¨ã«...ï¼bpftraceã¯ã³ã³ãã¯ãã«ããããã¨ã¾ã¨ã¾ã£ã¦ãã¨æãã®ã§ï¼ãããã«ã¤ãã¦èå³ã®ããæ¹ã¯ã³ã¼ããè¦ã¦ã¿ãã¨æ¥½ããã®ã§ã¯ãªãããªã¨æãã¾ãï¼
æ¥å¹´ã®æ±è²
æ¥å¹´ã¯ä»å¹´ã¨åæ§ï¼æ¬æ¥ãä¸çªãªã®ã¯å¿è«ã§ããï¼bpftraceã«é¢ããã³ãããã¯ç¶ç¶ãã¤ã¤ï¼ã«ã¼ãã«ã®æ¹ã«å¯¾ãã¦ãã³ããããã¦ãããã...ãªãã¦æãã¾ãï¼FBã®BPFãã£ã¦ãã¨ã³ã¸ãã¢ã¯ã«ã¼ãã«ãããããã®ã¯å¿è«ã®ãã¨ï¼LLVMï¼æ¬ä½ã®æ¹ï¼ãã§ããã®ã§ã¿ããªããããªãã¨æã次第ã§ãï¼ã¾ã ã¾ã èªåãé å¼µããªãã¨ããã¾ãããï¼
ããã§ã¯ã¿ãªããï¼ã¡ãã£ã¨æ©ãã§ãããããå¹´ãï¼
ã·ã¹ãã ç³»è«æã®æ å ±åéæ¹æ³
(ãã®è¨äºã¯æ±äº¬å¤§å¦ åå·ç 究室 Advent Calendar 2020ã®1æ¥ç®ã®è¨äºã¨ãã¦æ¸ããããã®ã§ã)
ãã®è¨äºã§ã¯ç°¡åã«ã·ã¹ãã ç³»ã®ä¼è°ã®è«æã«é¢ãã¦ã©ããã£ã¦è«æãæ¢ãã¦èªãã®ãï¼å人çãªæ¹æ³ãæ¸ãã¦ã¿ããã¨æãã¾ãï¼ããã«æ¸ãã¦ãããã¨ãå¥ã«ãã¹ã¦ã§ã¯ãªãã®ã§ï¼æ¯éèªåã«åãæ¹æ³ãåèªæ¢ãã¦ã¿ã¦ãã ããï¼
ç®æ¬¡
- ç®æ¬¡
- ä¼è°ãç¥ã
- ä¼è°ã®æ¥ç¨ã®ãã§ãã¯
- è«æãèªãï¼ãµã¼ãã¤ããï¼
- æç®ç®¡ç
- ç£æ¥ç³»ã«ã³ãã¡ã¬ã³ã¹
- ææ°ã®ååã追ã
- ãã®ä»
- æå¾ã«
ä¼è°ãç¥ã
ä¼è°ã«ã¯ã©ã³ã¯ï¼è¢«å¼ç¨æ°ãªã©ã§æ±ºããã¹ã³ã¢ã«ããé ä½ä»ãï¼ãããã¾ãï¼ä¸è¬ã«ã¯ã©ã³ã¯ã®é«ãä¼è° = ã¬ãã«ãé«ãä¼è°ã¨ãããã¨ã«ãªãã¾ãï¼è«æãæ¢ãã¨ãï¼ãã®ã©ã³ã¯ã¯ä¸ã¤ã®å¤æåºæºã¨ãªãã¾ãï¼ã©ã³ã¯ã®é«ãä¼è°ã§ããæ¹ãï¼è¯ãè«æãããå¯è½æ§ãé«ãããã§ãï¼æ å ±ç³»ã®ãããã®ä¼è°ã«ã¤ãã¦ã¯ï¼ä¾ãã°ï¼ä»¥ä¸ã®ãµã¤ãã«ã¾ã¨ã¾ã£ã¦ãã¾ãï¼
- Guide 2 Research, Top Computer Science Conferences
ãã ããã¯ç»åå¦çãæ©æ¢°å¦ç¿ãªã©ï¼ãããããªã¸ã£ã³ã«ãå«ãã®ã§ï¼ã·ã¹ãã ç³»ã«é¢ãã¦ã¯ä»¥ä¸ã®ãã®ãåèã«ããã¨ããã¨æãã¾ãï¼
- Takahiro Shinagawa, Conferences and Workshops (Operating Systems & System Software)
- Dan Tsafrir, systems conferences by deadline
ã¾ãï¼ã»ãã¥ãªãã£ç³»ã®ä¼è°ã®ã©ã³ã¯ã¯ä»¥ä¸ã«ã¾ã¨ã¾ã£ã¦ãã¾ãï¼
ã©ã³ã¯ã§ã¯ãªãã§ããï¼ã¯ã©ã¦ãç³»ã®ä¼è°ã®æ å ±ã¯ä»¥ä¸ã«ã¾ã¨ã¾ã£ã¦ãã¾ãï¼
ä¼è°ã®ã©ã³ã¯ä»ãæ¹æ³ã¨ãã¦ã¯ï¼CORE, Qualis, MSAR ã¨ãã£ããã®ãããã¾ãï¼ããã㯠conferenceranks ã¨ãããµã¤ããã調ã¹ããã¨ãã§ãã¾ãï¼ãã ãããã¾ã§æ å ±ãææ°ã§ããã¨ã¯éããªãç¹ã«æ³¨æãã¦ãã ããï¼ã¾ãå½ç¶ã§ããï¼ã©ã³ã¯ãä½ãããã¨ãã£ã¦è¯ãè«æããªãããã§ã¯ãªãã§ãï¼
ã·ã¹ãã ç³»ã§ç¹ã«ä¸»è¦ãªä¼è°ã¨ãã¦ã¯ï¼USENIXã®ä¼è°å ¨è¬ (OSDI, ATC, NSDI, FAST, SEC ãªã©) åã³ IEEE ã® SOSP, ACMã®ASPLOS, VEE, EuroSys ãªã©ã§ï¼ä»ã«ãåéãã¨ã«ããããã¨ããã¾ãï¼ã¾ãã»ãã¥ãªãã£ã«é¢ãã¦ã¯ USENIX SEC, NDSS, IEEE S&P, ACM CCSã4大ä¼è°ã¨ãã¦ç¥ããã¦ãã¾ã(æå·ç³»ãé¤ã)ï¼
ä¼è°ã®æ¥ç¨ã®ãã§ãã¯
ä¼è°ã®æ¥ç¨ã¯ä¼è°ã®ãµã¤ãã®ä»ï¼ä¸è¨ã«ç¤ºãã
ã«ããã¾ãï¼æ°ã«ãªãä¼è°ã¯ã«ã¬ã³ãã¼ã«ç»é²ãã¦ããã¨è¯ãã§ãããï¼
è«æãèªãï¼ãµã¼ãã¤ããï¼
ã¨ããããã·ã¹ãã ç³»ã®è«æãã©ããªãã®ãç¥ãããï¼ã¨ããå ´åã¯OSDIãSOSP, ATC, EuroSysãªã©ã·ã¹ãã ç³»å ¨è¬ãæ±ã£ã¦ããä¼è°ã§çºè¡¨ããã¦ããè«æãçºãã¦ã¿ãã®ãè¯ãã¨æãã¾ãï¼ã¾ãããä¾ãã°ãããã¯ã¼ã¯ç³»ã«èå³ããããªãNSDIãªã©ãããã¯ã¼ã¯ã«ç¹åããä¼è°ãã¿ã¦ã¿ãã¨è¯ãã§ãããï¼Google Scholarã§ãã¼ã¯ã¼ãæ¤ç´¢ãã¦è«æãæ¢ãã®ãå½ç¶æå¹ã§ãï¼ãã®éï¼å人çã«ã¯è¿å¹´ã®ãããã®ä¼è°ã®æè¿ã®è«æãæ¢ãã¦ï¼ãããããã®è«æã®å¼ç¨ã»è¢«å¼ç¨è«æã辿ãã¨ããããæ¹ããã¦ãµã¼ãã¤ãããã¨ãå¤ãã§ãï¼
ãã大å¦ã«æå±ãã¦ããå ´åã¯ï¼å¤ãã®å ´å大å¦ãACMãIEEEã¨å æ¬å¥ç´ãã¦ããããè«æãèªããã¯ãã§ããï¼ããã§ãªãå ´åãæè¿ã¯ã ãã¶ãªã¼ãã³ã¢ã¯ã»ã¹ã®æµããããï¼å¤ãã®è«æãç¡æã§å ¬éããã¦ãã¾ãï¼ã¨ãã«USENIXç³»ã®ä¼è°ã¯å ¨ã¦ãªã¼ãã³ã¢ã¯ã»ã¹ã¨ãªã£ã¦ãã¾ãï¼ã¾ãï¼ãªã¼ãã³ã¢ã¯ã»ã¹ã§ãªãä¼è°ã§ãèè ã®ãµã¤ãã«å人çãªã³ãã¼ãããå ´åãããã®ã§ï¼èªã¿ããè«æãããå ´åã¯ãã¡ããæ¢ãã¦ã¿ãã®ãä¸ã¤ã®æã§ãï¼ã¾ãæè¿ã¯ããããããã¨ã«çºè¡¨ã¹ã©ã¤ãã«å ãã¦çºè¡¨åç»ãå ¬éããã¦ãããã¨ãçããããã¾ããï¼ç©æ¥µçã«æ´»ç¨ããã¨è¯ãã§ãããï¼
è«æã®èªã¿æ¹ã«é¢ãã¦ã¯ããããã¨æµåãããã®ã§ï¼ä»¥ä¸ã«ç´¹ä»ãããã®ãèªããªã©ãã¦èªåã«åãæ¹æ³ãæ¢ãã¦ã¿ãã®ãè¯ãã¨æãã¾ãï¼
- William G. Griswold, How to Read an Engineering Research Paper
- VirginiaTech Cook Cook Counseling Center, SQ3R Improving Reading Comprehension
- ç¢è°· 浩å¸, ç¢è°·æµè«æã®èªã¿æ¹
å人çã«ã¯ã¢ãã¹ãã¨æå¾ã®ã¾ã¨ããè¦ã¦ãã®è«æã®åæ©ã¯ä½ã§ï¼ä½ãè²¢ç®ãªã®ãããã£ã¨è¦ã¦ï¼èªåãæ¢ãã¦ãããã®ã¨åãããã§ããã°ããå°ãä¸èº«ãã¿ã¦ã¿ãã¨ãã£ããã¿ã¼ã³ãå¤ãã§ãï¼ä¸è¨ã®ãªã³ã¯ã«ãæ¸ãã¦ããã¾ããï¼æéã¯æéã§ãã¤ã¾ã§ããµã¼ãã¤ãããã¨ã¯ã§ããªãã®ã§ï¼ãã£ããæéã決ãã¦éä¸ãã¦è«æãã¨ã®è²¢ç®ãé¢ä¿ãæ´çãã¦ãããã¨ã大äºã ã¨æãã¾ãï¼
æç®ç®¡ç
è«æã管çããããã®ã½ããã¦ã§ã¢ãæç®ç®¡çã½ããã¦ã§ã¢ã§ãï¼æç®ç®¡çã½ããã¦ã§ã¢ã¯æ¢ãã°ããããããã¾ãï¼ç¹ã«æ¯è¼ã¯ãã¦ãã¾ãããï¼èªåã¯Zoteroã使ã£ã¦ãã¦ã¾ãï¼Chromeã®æ¡å¼µæ©è½ããèªåã§ãã¼ã«ã«ã®zoteroã«PDFå«ãã¦æ å ±ãã¤ã³ãã¼ãã§ããã»ãï¼ã¯ã©ã¦ãã®ã¢ã«ã¦ã³ãã«ãèªåã§åæããã¾ãï¼ç¡ææ ã§ã¯300Mã¾ã§ï¼ï¼ãã¼ããextraã®é¨åã«ã¡ã¢ãæ®ããã®ã§ï¼èªãã ã¨ãã«è»½ãã¡ã¢ãæ®ãã¦ããã¨ãã§ã便å©ã§ãï¼
ããããæ©è½ã¯ã©ã®æç®ç®¡çã½ããã«ãããã¨æãã¾ãï¼ã¾ããããã®æç®ç®¡çã½ããã¯ç°¡åã«è«æä½æã«ã¯æ¬ ãããªãbibtexãã¨ã¯ã¹ãã¼ãããæ©è½ãããã¯ããªã®ã§ï¼ä½ãããã¯ä½¿ã£ãæ¹ãè¯ãã¨æãã¾ãï¼
ç£æ¥ç³»ã«ã³ãã¡ã¬ã³ã¹
ã·ã¹ãã ç³»ã®å ´åã¯ç£æ¥ç³»ã®ã«ã³ãã¡ã¬ã³ã¹ãï¼å¦è¡çã¨ã¯ã¡ãã£ã¨æ¯è²ãç°ãªãã¾ããï¼åèã«ãªããã®ãå¤ãããã¾ãï¼ä¾ãã°Linux foundationã主宰ã®Open Source Summitï¼KVM Forumãªã©ãï¼ã¹ãã¬ã¼ã¸ç³»ãªãSNIAã®Storage Developer Conferenceãªã©ã§ãï¼ãããããã¯å®åã«å³ããææ°ã®è©±é¡ã課é¡ãå¾ãããã®ã§ï¼è«æèªãã®ã«ç²ããæã«ãã§ãã¯ããã¨ããã¨æãã¾ãï¼
ææ°ã®ååã追ã
æ¬å½ã«ææ°ã®æ å ±ãç¥ãããå ´åã¯ï¼Googleã¢ã©ã¼ãã§ç¹å®ã®ãã¼ã¯ã¼ããæå®ãã¦ããæ¹æ³ãããã¾ãï¼ãã¼ã¯ã¼ãããã¾ãè¨å®ããªãã¨ããããéç¥ãæ¥ãããç¹ã«ã¯æ³¨æã§ãï¼ã¾ãï¼æè¿ã¯arXivã«è«æãä¸ãããã¨ãï¼ã·ã¹ãã ç³»ã§ãçãããªããªã£ã¦ãã¦ãã¾ãï¼ãããä¼è°ã®ã»ã¨ãã©ã¯double blindã§ããï¼arXivãªã©ã¸ã®æ稿ã¯è¨±å¯ããã¦ãããã¨ãå¤ãã§ãï¼ãã ãå ¨ã¦ã§ã¯ããã¾ããï¼ï¼arXivã追ãå ´åã¯Operating Systemsãï¼ã»ãã¥ãªãã£ãªãCryptography and Securityã«ãªãã§ãããï¼å人çã«æ å ±ãå¤ãããã®ã§arXivã追ããã¨ã¯ãã¾ããã¦ãã¾ãããï¼ãã¾ã«ãã¼ã¯ã¼ãæ¤ç´¢ã§è«æãæ¢ããããããã¨ã¯ããã¾ãï¼æ¡æã決ã¾ã£ã¦ããããã©ã¾ã ä¼è°åã§å ¬éããã¦ãªãè«æãããã±ã¼ã¹ãããã¾ãï¼ã¾ãLinuxã§ããã°LKMLã®ã¡ã¼ãªã¹ã«ç»é²ããã°ææ°ã®ã«ã¼ãã«æ å ±ãæµãã¦ãã¾ããï¼ãããçé¢ç®ã«è¿½ãã®ã¯ããªã大å¤ã§ãï¼Gmailã®ãã£ã«ã¿æ©è½ãªã®ã§ç¹å®ã®æ©è½ããããã®æ´æ°ããã£ãã¨ãã«éç¥ããããã«ããã¨è¯ãã¨æãã¾ãï¼
ãã®ä»
ã¸ã£ã³ã«ã«ãã£ã¦ã¯ãµã¼ãã¤ããã¥ã¼ã¹ãå®æçã«åºãããã¾ã¨ããããã¦ãã人ããã¾ãï¼ããããæ´»ç¨ããªãæã¯ãªãã§ãããï¼ä¾ãã°BPFã«é¢ãã¦ã¯ciliumãnewsãåºãã¦ãã¾ãï¼ã¾ãããã°ãGitHubã®ãªãã¸ããªã«èªãã è«æãã¾ã¨ãã¦ããããã人ããã¾ãï¼ä»ã«ãä»ã¯webã§æ¤ç´¢ããã°ããããã¨ãããããã¨æãã®ã§ï¼å¿è«ä¸çªå¤§äºãªã®ã¯è«ææ¬ä½ã§ããï¼ãã¾ã«ã¯ãã以å¤ã«ãç®ãåãã¦ã¿ãã®ãæªããªãã¨æãã¾ãï¼ãã ããããããã§è¯ãæ å ±ãè¦ã¤ãããï¼ä¸æ¬¡æç®ã«å½ãããã¨ã¯å¿ ç¶ã§ãï¼
æå¾ã«
æåã«ãæ¸ãã¾ãããï¼è«æ調æ»æ¹æ³ã¯ããããããã®ã§ï¼ããããªæ¹æ³ã試ãã¦èªåã«åãã®ãè¦ã¤ãããã¨ã大äºã ã¨æãã¾ãï¼ããã«æ¸ãããã®ãããã¾ã§èªåããããã試ããä¸ã§ä»å©ç¨ãã¦ããæ¹æ³ã§ãï¼æå¤ã¨ãããã£ãæ å ±ã¯å ±æãããªããã¨ãå¤ãã®ã§æ¸ãã¦ã¿ã¾ããï¼æ¯éã¿ãªãããä½ãè¯ãæ¹æ³ãããã°æãã¦ãã ããï¼
macã§bpftraceã試ã
å ¨ç¶ä½¿ã£ã¦ãªãã£ãã®ã§æè¿æ°ã¥ããã®ã§ããï¼ãã¤ã®ã¾ã«ã Docker for mac ã§ä½¿ããã¦ãã linuxkit ã®ã«ã¼ãã«ã 5.4ãã¼ã¹ã«ãªã£ã¦ãã¦ï¼BPFã®åºæ¬çãªæ©è½ã使ããããã«ãªã£ã¦ã¾ããï¼å¿µã®ããè¨ã£ã¦ããã¨ï¼docker for macã¯Linuxããã¤ãã¼ãã¤ã¶ä¸ã§åããã¦ï¼ãã®ä¸ã§dockerãåããã¦ãã¾ãï¼ï¼ã¨ãããã¨ã§ç°¡åã«macããbpftraceã試ããããã«ä»¥ä¸ã®ãããªãã®ãä½ã£ã¦ã¿ã¾ããï¼
macã«dockerãã¤ã³ã¹ãã¼ã«ãã¦ï¼./build.sh && ./run.sh
ã§åãã¨æãã¾ãï¼bpftraceã®ããã©ã«ãã®ãã¼ã«ã¨ï¼åã«èªåãä½ã£ãtetrisãå
¥ã£ã¦ã¾ãï¼ãã¬ã¼ã·ã³ã°ã¯ä½ãããã¢ããªã±ã¼ã·ã§ã³ãåãã¦ãªãã¨ãã¾ãé¢ç½ããªãã®ã§ï¼tmuxã§ã使ã£ã¦ãã¬ã¼ã¹ããªããä½ãåããã¦ã¿ãã®ãè¯ãã¨æãã¾ãï¼ä»¥ä¸ãå®è¡ä¾ã§ãï¼ãªãããã£ãããã¦ãé¨åãããã¾ããGIFåããã¨ãã®å½±é¿ãªã®ã§å®éã¯æ®éã«åãã¦ãã¾ãï¼
VMä½ã£ãæ¹ãããããã¨å¼ããããã§ããï¼ããbpftraceã©ããªãã®ãç¥ãããã¨æã£ã¦ãmacã¦ã¼ã¶ã®æ¹ã¯è©¦ãã¦ã¿ã¦ã¯ãããã§ããããï¼ã¡ãªã¿ã«BTFã®ãµãã¼ãã¨ãã¯ãªãã®ã§ ï¼bpftraceã®100%ã®åãçºæ®ã§ããããã§ã¯ãªãã®ã§ããã¯ãäºæ¿ãã ããï¼æ¬å½ã®bpftraceã®åãç¥ãã«ã¯... èªåã§ã«ã¼ãã«ã¨bpftraceãã³ã³ãã¤ã«ãã¾ãããï¼
BPF_PROG_TYPE_RAW_TRACEPOINT (raw tracepoint) ã«ã¤ãã¦
BPFã®ããã°ã©ã ã¿ã¤ãã®ä¸ã¤ã«BPF_PROG_TYPE_RAW_TRACEPOINTãããã¾ã (commit)ï¼ãããå©ç¨ããã¨tracepointã®å¤æåã®å¼æ°ã«ã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãï¼
ä¾ã¨ãã¦kernel/sched/core.cã§å®ç¾©ãããsched_swtich
ã®tracepointãèãã¾ãï¼
trace_sched_switch(preempt, prev, next);
ãã®tracepointã¯include/trace/events.sched.hã§å®ç¾©ããã¾ãï¼
TRACE_EVENT(sched_switch, TP_PROTO(bool preempt, struct task_struct *prev, struct task_struct *next), TP_ARGS(preempt, prev, next), TP_STRUCT__entry( __array( char, prev_comm, TASK_COMM_LEN ) __field( pid_t, prev_pid ) __field( int, prev_prio ) __field( long, prev_state ) __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) __field( int, next_prio ) ), TP_fast_assign( memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); __entry->prev_pid = prev->pid; __entry->prev_prio = prev->prio; __entry->prev_state = __trace_sched_switch_state(preempt, prev); memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); __entry->next_pid = next->pid; __entry->next_prio = next->prio; /* XXX SCHED_DEADLINE */ ), TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d", __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, (__entry->prev_state & (TASK_REPORT_MAX - 1)) ? __print_flags(__entry->prev_state & (TASK_REPORT_MAX - 1), "|", { TASK_INTERRUPTIBLE, "S" }, { TASK_UNINTERRUPTIBLE, "D" }, { __TASK_STOPPED, "T" }, { __TASK_TRACED, "t" }, { EXIT_DEAD, "X" }, { EXIT_ZOMBIE, "Z" }, { TASK_PARKED, "P" }, { TASK_DEAD, "I" }) : "R", __entry->prev_state & TASK_REPORT_MAX ? "+" : "", __entry->next_comm, __entry->next_pid, __entry->next_prio) );
ããã§ï¼é常ã®tracepointã§ããã°ï¼TP_STRUCT__entry
ã§å®ç¾©ããã¦ããé
ç® (+ tracepointã«å
±éã®é
ç®)ã«ã¢ã¯ã»ã¹ã§ãã¾ãï¼ããã¯ä»¥ä¸ã®tracing/events/sched/sched_switch/format
ããã確èªã§ãã¾ãï¼
# cat /sys/kernel/debug/tracing/events/sched/sched_switch/format name: sched_switch ID: 318 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:char prev_comm[16]; offset:8; size:16; signed:1; field:pid_t prev_pid; offset:24; size:4; signed:1; field:int prev_prio; offset:28; size:4; signed:1; field:long prev_state; offset:32; size:8; signed:1; field:char next_comm[16]; offset:40; size:16; signed:1; field:pid_t next_pid; offset:56; size:4; signed:1; field:int next_prio; offset:60; size:4; signed:1; print fmt: "prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d", REC->prev_comm, REC->prev_pid, REC->prev_prio, (REC->prev_state & ((((0x0000 | 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040) + 1) << 1) - 1)) ? __print_flags(REC->prev_state & ((((0x0000 | 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040) + 1) << 1) - 1), "|", { 0x0001, "S" }, { 0x0002, "D" }, { 0x0004, "T" }, { 0x0008, "t" }, { 0x0010, "X" }, { 0x0020, "Z" }, { 0x0040, "P" }, { 0x0080, "I" }) : "R", REC->prev_state & (((0x0000 | 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040) + 1) << 1) ? "+" : "", REC->next_comm, REC->next_pid, REC->next_prio
ä¸æ¹ã§raw tracepiontã®å ´åï¼ã¢ã¯ã»ã¹ã§ããã®ã¯trace_sched_switch()
ã«ä¸ããå¼æ° (TP_PROTO
ã®å¼æ°ï¼ã«ãªãã¾ãï¼sched_switch
ã®å ´åã¯
TP_PROTO(bool preempt, struct task_struct *prev, struct task_struct *next)
ã«ãªãã¾ãï¼
raw tracepintã®ãã¨ãã¨ã®å°å
¥ã®çµç·¯ã¯ï¼sched_switch
ã«ããã¦prev
ã¨next
ã®task_struct
ã®ä¸èº«ã«ã¢ã¯ã»ã¹ãããã¨ããè¦æ±ããã ã£ãããã§ãï¼åèï¼ï¼é常ã®tracepointã§ããã°BPFããã°ã©ã å¼ã³åºãåã«tracepointã®ãã¼ã¿ãæ´å½¢ããå¿
è¦ãããã¾ããï¼raw tracepointã§ã¯ãã®å¿
è¦ããªãããï¼ãã®åã®ãªã¼ãããããæãããã¾ãï¼ãã ãï¼raw tracepointã®å¼æ°ã§ä¸ãããããã¤ã³ã¿ã®ãã¼ã¿ã«ã¢ã¯ã»ã¹ããã«ã¯bpf_probe_read()
ã使ãå¿
è¦ãããã¾ãï¼åºæ¬çã«ã¯tarcepiontã®æ¹ãæ±ããããã®ã§ï¼ãã¡ãã使ãã°è¯ãã¨æãã¾ããï¼ããã©ã¼ãã³ã¹ãåé¡ã§ãã£ããï¼ãããã¯tracepointã®æ
å ±ã ãã§ã¯ä¸è¶³ãã¦ããå ´åã¯raw tracepointãæ¤è¨ãã¦ã¿ãã¨è¯ãã¨æãã¾ãï¼
BPFããã°ã©ã ããã«ã¼ãã«å ã®ãã¼ã¿æ§é ã«ã¢ã¯ã»ã¹ããæ¹æ³
kprobeãtracepointãªã©ã«ã¢ã¿ããããBPFããã°ã©ã ã¯ï¼BPF_FUNC_probe_read()
é¢æ°ã§ã«ã¼ãã«å
ã®ãã¼ã¿æ§é ã«ã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãï¼ããã¯probe_kernel_read()
ã®ã©ããã¼ã§ï¼ããå¤ãªé åã«ã¢ã¯ã»ã¹ãããããå ´åï¼page faultãçºçããå ´åï¼ã¯-EFAULTãè¿ãã¾ãï¼
ã¾ãï¼BPF_FUNC_get_current_task()
ã§currentã®task_structãå¾ããã¨ãã§ãã¾ãï¼
ä¾ã¨ãã¦ï¼/bin/catãå®è¡ãããã¨ãã«ï¼ãã®ããã»ã¹ã®vm_area_struct
ã®ä¸èº«ããã³ãããããã°ã©ã ãæ¸ãã¦ã¿ã¾ãï¼bccãå©ç¨ãã¦ä»¥ä¸ã®ããã«æ¸ãã¾ãï¼
#!/usr/bin/env python import bcc text = r""" #include <linux/ptrace.h> #include <linux/sched.h> int probe(struct pt_regs *ctx) { int i; struct task_struct *t = (struct task_struct *)bpf_get_current_task(); struct vm_area_struct *vma = t->mm->mmap; #pragma clang loop unroll(full) for (i = 0; i < 20; i++) { if (vma != NULL) { unsigned long inode = vma->vm_file->f_inode->i_ino; bpf_trace_printk("%lx-%lx %ld\n", vma->vm_start, vma->vm_end, inode); vma = vma->vm_next; } } return 0; } """ def main(): b = bcc.BPF(text=text, debug=0) b.attach_uprobe(name="/bin/cat", sym="main", fn_name="probe") b.trace_print() if __name__ == "__main__": main()
ããã§æ³¨æç¹ã¨ãã¦ã¯ï¼ï¼å¤ãã«ã¼ãã«ã ã¨ï¼BPFããã°ã©ã ã¯ã«ã¼ããæ±ããªãã®ã§*1ï¼pragmaãå©ç¨ãã¦å±éããå¿ è¦ãããã¾ãï¼ã¾ãbreakæãå«ããããªããã°ã©ã ã¯verifierã«ãããããã®ã§ï¼ã¡ãã£ã¨æ¸ãæ¹ã«å·¥å¤«ãããã¾ãï¼
bccã§ã¯ï¼ãã¤ã³ã¿åç
§ã¯ååbpf_probe_read()
é¢æ°å¼ã³åºãã«ãªãã¾ã*2ï¼ããã§ï¼ä¸è¨ããã°ã©ã ã§ã¯ãã¤ã³ã¿ãNULLã確èªãã¦ãã¾ãã*3ï¼ããã§å¤§ä¸å¤«ï¼ã¨æãããããã¾ãããï¼å®éã®ãã¤ã³ã¿åç
§ã¯bpf_probe_read()
ãå©ç¨ãã¦ãã¦ï¼ããèªã¿åºãã«å¤±æããå ´åã¯bccã¯äºåã«ãããã¡ãã¯ãªã¢ããã®ã§å¾ãããå¤ã¯0ã«ãªãã¾ãï¼ã¢ãã¬ã¹0ã«å¯¾ããbpf_probe_read()
ã¯å¤±æããã§ããããï¼ããã°ã©ã ãã¯ã©ãã·ã¥ããã¨ãã£ããã¨ã¯ãªãã®ã§ï¼ããã§å¤§ä¸å¤«ã§ãï¼çµæã¨ãã¦ã¯vma->vm_file
ãNULLãªãinodeã¯0ã«ãªãã¾ãï¼
ä¸è¨ããã°ã©ã ãå®è¡ãã¦ããã¦*4ï¼ä»¥ä¸ã®ããã«catãå®è¡ããã¨ï¼
% cat /proc/self/maps 55e4824bf000-55e4824c7000 r-xp 00000000 08:02 2621482 /bin/cat 55e4826c6000-55e4826c7000 r--p 00007000 08:02 2621482 /bin/cat 55e4826c7000-55e4826c8000 rw-p 00008000 08:02 2621482 /bin/cat 55e4835b0000-55e4835d1000 rw-p 00000000 00:00 0 [heap] 7f1b8bfcf000-7f1b8c1b6000 r-xp 00000000 08:02 6685444 /lib/x86_64-linux-gnu/libc-2.27.so 7f1b8c1b6000-7f1b8c3b6000 ---p 001e7000 08:02 6685444 /lib/x86_64-linux-gnu/libc-2.27.so 7f1b8c3b6000-7f1b8c3ba000 r--p 001e7000 08:02 6685444 /lib/x86_64-linux-gnu/libc-2.27.so 7f1b8c3ba000-7f1b8c3bc000 rw-p 001eb000 08:02 6685444 /lib/x86_64-linux-gnu/libc-2.27.so 7f1b8c3bc000-7f1b8c3c0000 rw-p 00000000 00:00 0 7f1b8c3c0000-7f1b8c3e7000 r-xp 00000000 08:02 6685432 /lib/x86_64-linux-gnu/ld-2.27.so 7f1b8c41a000-7f1b8c43c000 rw-p 00000000 00:00 0 7f1b8c43c000-7f1b8c5d7000 r--p 00000000 08:02 4326139 /usr/lib/locale/locale-archive 7f1b8c5d7000-7f1b8c5d9000 rw-p 00000000 00:00 0 7f1b8c5e7000-7f1b8c5e8000 r--p 00027000 08:02 6685432 /lib/x86_64-linux-gnu/ld-2.27.so 7f1b8c5e8000-7f1b8c5e9000 rw-p 00028000 08:02 6685432 /lib/x86_64-linux-gnu/ld-2.27.so 7f1b8c5e9000-7f1b8c5ea000 rw-p 00000000 00:00 0 7fffea906000-7fffea927000 rw-p 00000000 00:00 0 [stack] 7fffea9fc000-7fffea9ff000 r--p 00000000 00:00 0 [vvar] 7fffea9ff000-7fffeaa00000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
以ä¸ã®åºåãå¾ããã¾ã*5ï¼BPFããã°ã©ã å´ããvma_structã®æ å ±ãåå¾ã§ãã¦ãããã¨ãåããã¾ãï¼
<...>-8164 [001] .... 512025.107366: 0: 55e4824bf000-55e4824c7000 2621482 <...>-8164 [001] .... 512025.107381: 0: 55e4826c6000-55e4826c7000 2621482 <...>-8164 [001] .... 512025.107382: 0: 55e4826c7000-55e4826c8000 2621482 <...>-8164 [001] .... 512025.107383: 0: 7f1b8bfcf000-7f1b8c1b6000 6685444 <...>-8164 [001] .... 512025.107384: 0: 7f1b8c1b6000-7f1b8c3b6000 6685444 <...>-8164 [001] .... 512025.107384: 0: 7f1b8c3b6000-7f1b8c3ba000 6685444 <...>-8164 [001] .... 512025.107385: 0: 7f1b8c3ba000-7f1b8c3bc000 6685444 <...>-8164 [001] .... 512025.107390: 0: 7f1b8c3bc000-7f1b8c3c0000 0 <...>-8164 [001] .... 512025.107391: 0: 7f1b8c3c0000-7f1b8c3e7000 6685432 <...>-8164 [001] .... 512025.107394: 0: 7f1b8c5d7000-7f1b8c5d9000 0 <...>-8164 [001] .... 512025.107395: 0: 7f1b8c5e7000-7f1b8c5e8000 6685432 <...>-8164 [001] .... 512025.107396: 0: 7f1b8c5e8000-7f1b8c5e9000 6685432 <...>-8164 [001] .... 512025.107399: 0: 7f1b8c5e9000-7f1b8c5ea000 0 <...>-8164 [001] .... 512025.107402: 0: 7fffea906000-7fffea927000 0 <...>-8164 [001] .... 512025.107405: 0: 7fffea9fc000-7fffea9ff000 0 <...>-8164 [001] .... 512025.107408: 0: 7fffea9ff000-7fffeaa00000 0
ã¾ãbpftraceãªã以ä¸ã®ããã«æ¸ãã¾ãï¼
#include <linux/sched.h> #include <linux/fs.h> uprobe:/bin/cat:main { $vma = (struct vm_area_struct*)curtask->mm->mmap; unroll(20) { if ($vma != 0) { $inode = $vma->vm_file->f_inode->i_ino; printf("%lx-%lx %ld\n", $vma->vm_start, $vma->vm_end, $inode); $vma = $vma->vm_next; } } }
ï¼ãã¤ã©ã¤ãã欲ãã...ï¼
使ãæãéããã¾ããï¼ãã®æ å ±ããã«ãã£ãã£ãï¼ã¨ããæã«ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ãæ¸ããªãã¦ã確èªã§ãã¾ãï¼
*1:Linux5.3ããBounded Loopã«å¯¾å¿ãã¾ãã
*2:BPFããã°ã©ã ã«ä¸ããããå¼æ°(ctx)ã«å¯¾ããã¢ã¯ã»ã¹ã¯loadå½ä»¤ã«ãªãã¾ã
*3:ä¾ãã°ï¼vma->vm_fileã¯mmapãããé åã§ãªããã°NULLã«ãªãã¾ã
*4:attach_uprobeããéã¯ãããã°æ å ±ãã¿ã¦ã¢ãã¬ã¹è§£æ±ºããã®ã§ï¼ãããã°ã·ã³ãã« (ubuntuãªãcoreutils-dbgsym)ãã¤ã³ã¹ãã¼ã«ãã¦ããå¿ è¦ãããã¾ãï¼
*5:[heap]ãªã©ã®æ å ±ã表示ããã¦ããªãã®ã¯ããã¯ã«ã¼ãã«å´ã§è¡¨ç¤ºãã¦ããæ å ±ã§ããããã§ã
Rustã§Unix Domain Socketãæ±ãæ¹æ³
"rust domain socket"ã¨ãã§æ¤ç´¢ããã¨ããããå¼ã£ããããã©ãããããã©ã¤ãã©ãªã®æ´æ°ãæ©ãã¦æ å ±ãå¤ãã£ããããã®ã§ããã«ç¾ç¶ãæ¸ãã¾ãï¼ãã®æç« ãããã«å¤ããªããããããªãã®ã§å¾ããèªã人ã¯æ³¨æãã¦ãã ãã..ï¼
åºæ¬
std::os::unix::net
- å 㯠rust-lang-nursery/unix-socketã ã£ããã®ãï¼stdã«åãè¾¼ã¾ãããã®ï¼rfcï¼
std::net::TcpListener
çã¨åæ§ã®ä½¿ãåæ
- nix
- setsockoptãããã¨ããancillary dataãsendmsgã§éãããã¨ãã«æç¨ï¼ä¾ï¼
- libc
- 硬派ãªäººåã
async/await
- mio-uds
- mioãdomain socketã«å¯¾å¿ããããã®
- å¾è¿°ã®tokio, async-stdããããå©ç¨
tokio::net::unix
- å
ã¯
tokio-uds
ã¨ããåå¥ã®ãªãã¸ããªã ã£ãã®ãï¼tokio
æ¬ä½ã«å¸åããï¼ããã«ä»ã§ã¯tokio-net
ã®ä¸é¨ï¼ - async/awaitããã人åã
- å
ã¯
async_std::os::unix::net
- async-stdç
- ç¾å¨ãã°ã£ã¦ã¦åãã¾ãã
- 1.0ãåºãããã«ã¯ãã£ã¨ä¿®æ£ããã¦ããã¯ã
HTTPãµã¼ã
- actix-web
- udsã®ãµãã¼ããããï¼ä¾ï¼
- hyper
- hyperlocalã使ã
ä¾
std::os::unix::net::{UnixListner, UnixStream}
use std::fs; use std::io::prelude::*; use std::os::unix::net::{UnixListener, UnixStream}; use std::path::Path; use std::thread; fn handle_client(mut stream: UnixStream) -> std::io::Result<()> { let mut buf = [0; 1024]; let n = stream.read(&mut buf)?; let s = String::from_utf8_lossy(&buf[..n]); println!("{}", s); Ok(()) } fn main() -> Result<(), Box<dyn std::error::Error>> { let sockfile = Path::new("/tmp/uds.sock"); if sockfile.exists() { fs::remove_file(&sockfile)?; } let listner = UnixListener::bind(sockfile)?; for stream in listner.incoming() { let stream = stream?; thread::spawn(move || handle_client(stream).unwrap()); } Ok(()) }
// cargo-deps: tokio="0.2.0-alpha.6", tokio-net="0.2.0-alpha.6", futures-preview="0.3.0-alpha.19" use std::fs; use std::path::Path; use futures::StreamExt; use tokio; use tokio::io::AsyncReadExt; use tokio::net::unix::{UnixListener, UnixStream}; async fn handle_client(mut stream: UnixStream) -> Result<(), Box<dyn std::error::Error>> { let mut buf = [0; 1024]; let n = stream.read(&mut buf).await?; let s = String::from_utf8_lossy(&buf[..n]); println!("{}", s); Ok(()) } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let sockfile = Path::new("/tmp/uds.sock"); if sockfile.exists() { fs::remove_file(&sockfile)?; } let listner = UnixListener::bind(sockfile)?; let mut incoming = listner.incoming(); while let Some(stream) = incoming.next().await { let stream = stream?; tokio::spawn(async move { handle_client(stream).await.unwrap(); }); } Ok(()) }