Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6FAAC433E0 for ; Mon, 10 Aug 2020 04:49:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8401E2073A for ; Mon, 10 Aug 2020 04:49:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eVcLBDZt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8401E2073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=jLP80TxsYPAs84FALZw6sU+AA5rqljfTUTNDgB55nng=; b=eVcLBDZtx3o+/81Acg6nvqBQwe 0cNGT1tumHrXQXUzNqKIcO+8KTkRDUHGJ97eY/CnyRCYTsZJfAYpdZz8rpdF4ivo6T6A1kuwE07fB Ylkl0n6RCaB8YYGMLEjSwsPXVLXBaS50S8bDJGFm2yKu3wlQrglrLJhdJVPoP4WwuwNjp2Fnv8DHj sKOgrZU8RL3xvomimnEkHyiLciqYEH3umfaXrSe8+t0b054dBCMAGY2THaFYj3kbtATU7qA5Eymk8 9orBwya3viC8bsvSrAHTRcjQYGdngP9vZsBxl2sKULEPD7Kea3wrBAjkc/gpD4ZLLXnEdXrMyo6Tp aqA4/7ug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4zix-0007e7-6v; Mon, 10 Aug 2020 04:47:51 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187] helo=huawei.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k4zis-0007Zd-Mr for linux-arm-kernel@lists.infradead.org; Mon, 10 Aug 2020 04:47:48 +0000 Received: from DGGEMM401-HUB.china.huawei.com (unknown [172.30.72.54]) by Forcepoint Email with ESMTP id 9A707F93439ACC68C738; Mon, 10 Aug 2020 12:47:09 +0800 (CST) Received: from dggemi762-chm.china.huawei.com (10.1.198.148) by DGGEMM401-HUB.china.huawei.com (10.3.20.209) with Microsoft SMTP Server (TLS) id 14.3.487.0; Mon, 10 Aug 2020 12:47:08 +0800 Received: from dggemi761-chm.china.huawei.com (10.1.198.147) by dggemi762-chm.china.huawei.com (10.1.198.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Mon, 10 Aug 2020 12:47:08 +0800 Received: from dggemi761-chm.china.huawei.com ([10.9.49.202]) by dggemi761-chm.china.huawei.com ([10.9.49.202]) with mapi id 15.01.1913.007; Mon, 10 Aug 2020 12:47:08 +0800 From: "Song Bao Hua (Barry Song)" To: "linux-arm-kernel@lists.infradead.org" Subject: kprobe overhead and OPTPROBES implementation on ARM64 Thread-Topic: kprobe overhead and OPTPROBES implementation on ARM64 Thread-Index: AdZu0DNev8tUfHVOTvucZNyvbbn3CQ== Date: Mon, 10 Aug 2020 04:47:08 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.126.202.169] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200810_004747_326251_A30EB4F5 X-CRM114-Status: GOOD ( 12.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "catalin.marinas@arm.com" , "will@kernel.org" , Linuxarm Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, I was trying to use kprobe example module[1] and eBPF/BCC funclatency[2] to analyze the latency of a kernel function. eBPF/BCC funclatency is also based on kprobe. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/kprobes/kretprobe_example.c [2] https://github.com/iovisor/bcc/blob/master/tools/funclatency.py I found the latency reported by kprobe was much larger than the actual execution time of a function. Then I wrote an empty function in kernel to measure the overhead of kprobe: static int do_empty(void) { return 0; } typedef int (*empty)(void); empty p = do_empty; static ssize_t globalfifo_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) { ... for(i = 0;i < 100; i++) a = p(); ... } After that, I triggered the execution of do_empty() by: root@ubuntu:~# modprobe kretprobe_example func=do_empty root@ubuntu:~# cat /dev/globalfifo /* this command will lead to the call of globalfifo_read() */ root@ubuntu:~# dmesg -c [ 2853.971945] do_empty returned 0 and took 3260 ns to execute [ 2853.971948] do_empty returned 0 and took 490 ns to execute [ 2853.971950] do_empty returned 0 and took 450 ns to execute [ 2853.971952] do_empty returned 0 and took 430 ns to execute [ 2853.971953] do_empty returned 0 and took 430 ns to execute [ 2853.971955] do_empty returned 0 and took 420 ns to execute [ 2853.971956] do_empty returned 0 and took 430 ns to execute [ 2853.971957] do_empty returned 0 and took 430 ns to execute [ 2853.971959] do_empty returned 0 and took 420 ns to execute [ 2853.971960] do_empty returned 0 and took 420 ns to execute [ 2853.971962] do_empty returned 0 and took 430 ns to execute [ 2853.971963] do_empty returned 0 and took 430 ns to execute [ 2853.971964] do_empty returned 0 and took 430 ns to execute [ 2853.971966] do_empty returned 0 and took 430 ns to execute [ 2853.971967] do_empty returned 0 and took 430 ns to execute [ 2853.971969] do_empty returned 0 and took 430 ns to execute [ 2853.971970] do_empty returned 0 and took 420 ns to execute [ 2853.971972] do_empty returned 0 and took 430 ns to execute [ 2853.971973] do_empty returned 0 and took 430 ns to execute [ 2853.971974] do_empty returned 0 and took 430 ns to execute [ 2853.971976] do_empty returned 0 and took 430 ns to execute [ 2853.971977] do_empty returned 0 and took 420 ns to execute [ 2853.971978] do_empty returned 0 and took 430 ns to execute [ 2853.971980] do_empty returned 0 and took 420 ns to execute [ 2853.971981] do_empty returned 0 and took 420 ns to execute [ 2853.971983] do_empty returned 0 and took 430 ns to execute [ 2853.971984] do_empty returned 0 and took 430 ns to execute [ 2853.971986] do_empty returned 0 and took 420 ns to execute [ 2853.971987] do_empty returned 0 and took 430 ns to execute [ 2853.971988] do_empty returned 0 and took 430 ns to execute [ 2853.971990] do_empty returned 0 and took 430 ns to execute [ 2853.971991] do_empty returned 0 and took 430 ns to execute [ 2853.971992] do_empty returned 0 and took 430 ns to execute [ 2853.971994] do_empty returned 0 and took 430 ns to execute [ 2853.971995] do_empty returned 0 and took 430 ns to execute [ 2853.971997] do_empty returned 0 and took 430 ns to execute [ 2853.971998] do_empty returned 0 and took 420 ns to execute [ 2853.972000] do_empty returned 0 and took 430 ns to execute [ 2853.972001] do_empty returned 0 and took 430 ns to execute [ 2853.972002] do_empty returned 0 and took 430 ns to execute [ 2853.972004] do_empty returned 0 and took 430 ns to execute [ 2853.972005] do_empty returned 0 and took 430 ns to execute [ 2853.972006] do_empty returned 0 and took 420 ns to execute [ 2853.972008] do_empty returned 0 and took 430 ns to execute [ 2853.972009] do_empty returned 0 and took 430 ns to execute [ 2853.972011] do_empty returned 0 and took 430 ns to execute [ 2853.972012] do_empty returned 0 and took 420 ns to execute [ 2853.972014] do_empty returned 0 and took 420 ns to execute [ 2853.972015] do_empty returned 0 and took 430 ns to execute [ 2853.972016] do_empty returned 0 and took 430 ns to execute [ 2853.972018] do_empty returned 0 and took 420 ns to execute [ 2853.972019] do_empty returned 0 and took 430 ns to execute [ 2853.972020] do_empty returned 0 and took 430 ns to execute [ 2853.972022] do_empty returned 0 and took 430 ns to execute [ 2853.972023] do_empty returned 0 and took 430 ns to execute [ 2853.972025] do_empty returned 0 and took 430 ns to execute [ 2853.972026] do_empty returned 0 and took 420 ns to execute [ 2853.972028] do_empty returned 0 and took 420 ns to execute [ 2853.972029] do_empty returned 0 and took 420 ns to execute [ 2853.972030] do_empty returned 0 and took 430 ns to execute [ 2853.972032] do_empty returned 0 and took 430 ns to execute [ 2853.972033] do_empty returned 0 and took 420 ns to execute [ 2853.972034] do_empty returned 0 and took 420 ns to execute [ 2853.972036] do_empty returned 0 and took 430 ns to execute [ 2853.972037] do_empty returned 0 and took 420 ns to execute [ 2853.972039] do_empty returned 0 and took 430 ns to execute [ 2853.972040] do_empty returned 0 and took 420 ns to execute [ 2853.972042] do_empty returned 0 and took 430 ns to execute [ 2853.972043] do_empty returned 0 and took 420 ns to execute [ 2853.972044] do_empty returned 0 and took 430 ns to execute [ 2853.972046] do_empty returned 0 and took 420 ns to execute From the above data, we can see for the 1st time (i==0), kprobe latency can be 3260 ns. For a "hot" probed function, i==2 to i==99, kprobe latency can be 430ns. funclatency in eBPF/BCC also shows the same result: root@ubuntu:/usr/share/bcc/tools# ./funclatency do_empty Tracing 1 functions for "do_empty"... Hit Ctrl-C to end. ^C nsecs : count distribution 0 -> 1 : 0 | | 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 0 | | 256 -> 511 : 0 | | 512 -> 1023 : 99 |****************************************| 1024 -> 2047 : 0 | | 2048 -> 4095 : 0 | | 4096 -> 8191 : 1 | | The data was got while I set cpufreq to "performance" and make the CPU running in the highest frequency 2.6Ghz. And the cpuinfo is like: $ cat /proc/cpuinfo | more processor : 0 BogoMIPS : 200.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop asimddp asimdfhm CPU implementer : 0x48 CPU architecture: 8 CPU variant : 0x1 CPU part : 0xd01 CPU revision : 0 If I set cpufreq to "ondemand", the overhead of kprobe will be much bigger: root@ubuntu:~# dmesg -c [ 3363.950350] Planted return probe at do_empty: 000000005a96fe8a [ 3370.512534] do_empty returned 0 and took 14546 ns to execute [ 3370.512553] do_empty returned 0 and took 3299 ns to execute [ 3370.512563] do_empty returned 0 and took 3019 ns to execute [ 3370.512573] do_empty returned 0 and took 2959 ns to execute [ 3370.512582] do_empty returned 0 and took 2969 ns to execute [ 3370.512590] do_empty returned 0 and took 2980 ns to execute [ 3370.512599] do_empty returned 0 and took 2979 ns to execute [ 3370.512608] do_empty returned 0 and took 2979 ns to execute [ 3370.512617] do_empty returned 0 and took 2970 ns to execute [ 3370.512625] do_empty returned 0 and took 2979 ns to execute [ 3370.512634] do_empty returned 0 and took 2979 ns to execute [ 3370.512643] do_empty returned 0 and took 2979 ns to execute [ 3370.512651] do_empty returned 0 and took 2980 ns to execute [ 3370.512661] do_empty returned 0 and took 2979 ns to execute [ 3370.512670] do_empty returned 0 and took 2989 ns to execute [ 3370.512679] do_empty returned 0 and took 2980 ns to execute [ 3370.512688] do_empty returned 0 and took 2969 ns to execute [ 3370.512697] do_empty returned 0 and took 2979 ns to execute [ 3370.512705] do_empty returned 0 and took 2979 ns to execute [ 3370.512715] do_empty returned 0 and took 2979 ns to execute [ 3370.512723] do_empty returned 0 and took 2979 ns to execute From the above data, we can find for the 1st time (i==0), kprobe latency can be 14546 ns. For a "hot" probed function, i==2 to i==99, kprobe latency can be 3000ns. funclatency shows the similar result: root@ubuntu:/usr/share/bcc/tools# ./funclatency do_empty Tracing 1 functions for "do_empty"... Hit Ctrl-C to end. ^C nsecs : count distribution 0 -> 1 : 0 | | 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 0 | | 256 -> 511 : 0 | | 512 -> 1023 : 0 | | 1024 -> 2047 : 0 | | 2048 -> 4095 : 98 |****************************************| 4096 -> 8191 : 1 | | 8192 -> 16383 : 0 | | 16384 -> 32767 : 1 | | Such a huge overhead of kprobe seems to make the latency data gotten from kprobe and funclatency distorted and make those tools practically useless. Considering kprobe and funclatency are very convenient and even popular tools which are used widely, do you think it is necessary to implement OPTPROBES on ARM64? On x86, it is said OPTPROBES can greatly decrease the overhead of kprobe. I noticed that OPTPROBES are supported on X86, PowerPC and ARM32. But on ARM64, it is marked as "TODO". Thanks Barry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel