Uprobes: userspace probes >= Linux 3.5

本文介绍Linux 3.5版本中引入的两个显著特性:ext4文件系统的元数据校验和功能,用于确保文件系统完整性;以及uprobes用户空间探针,允许在应用程序的任意内存地址设置性能探针,收集调试和性能信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://lwn.net/Articles/499190/

https://github.com/andreoli/fulltrace

 Prominent features in Linux 3.5

1.1. ext4 metadata checksums

Modern filesystems such as ZFS and Btrfs have proved that ensuring the integrity of the filesystem using checksums is a valuable feature. Ext4 has added the ability to store checksums of various metadata fields. Every time a metadata field is read, the checksum of the read data is compared with the stored checksums, if they are different it means that the medata is corrupted (note that this feature doesn't cover data, only the internal metadata structures, and it doesn't have "self-healing" capabilities). The amount of code added to implement this feature is: 1659 insertions(+), 162 deletions(-).

Any ext4 filesystem can be upgraded to use checksums using the "tune2fs -O metadata_csum" command, or "mkfs -O metadata_csum" at creation time. Once this feature is enabled in a filesystem, older kernels with no checksum support will only be able to mount it in read-only mode.

As far as performance impact goes, it shouldn't be noticeable for common desktop and server workloads. A mail server ffsb simulation show nearly no change. On a test doing only file creation and deletion and extent tree modifications, a performance drop of about 20 percent was measured. However, it's a workload very heavily oriented towards metadata, in most real-world workloads metadata is usually a small fraction of total IO, so unless your workload is metadata-oriented, the cost of enabling this feature should be negligible.

Recommended LWN article: "Improving ext4: bigalloc, inline data, and metadata checksums"

Implementation details: Ext4 Metadata checksums

Code: (commit 123456789101112131415161718192021222324

1.2. Uprobes: userspace probes

Uprobes, the user-space counterpart of kprobes, enables to place performance probes in any memory address of a user application, and collect debugging and performance information non-disruptively, which can be used to find performance problems. These probes can be placed dynamically in a running process, there is no need to restart the program or modify the binaries. The probes are usually managed with a instrumentation application, such as perf probe, systemtap or LTTng.

A sample usage of uprobes with perf could be to profile libc's malloc() calls:

  • $ perf probe -x /lib64/libc.so.6 malloc -> Added new event: probe_libc:malloc (on 0x7eac0)

A probe has been created. Now, let's record the global usage of malloc across all the system during 1 second:

  • $ perf record -e probe_libc:malloc -agR sleep 1

Now you can watch the results with the TUI interface doing "$ perf report", or watch a plain text output without the call graph info in the stdio output with "$ perf report -g flat --stdio"

If you don't know which function you want to probe, you can get a list of probe-able funcions in libraries and executables using the -F parameter, for example: "$ perf probe -F -x /lib64/libc.so.6" or "$ perf probe -F -x /bin/zsh". You can use multiple probes as well and mix them with kprobes and regular PMU events or kernel tracepoints.

The uprobes code is one of the longest standing out-of-the-tree patches. It originates from SystemTap and has been included for years in Fedora and RHEL kernels.

Recommended LWN article: Uprobes in 3.5

Code: (commit 123456789101112131415)

void BootAnimation::findBootAnimationFile() { std::string custAnimProp = !mShuttingDown ? android::base::GetProperty("persist.sys.customanim.boot", ""): android::base::GetProperty("persist.sys.customanim.shutdown", ""); const char *custAnim = custAnimProp.c_str(); ALOGD("Animation customzation path: %s", custAnim); if (access(custAnim, R_OK) == 0) { mZipFileName = custAnim; ALOGD("%sAnimation customzation path: %s", mShuttingDown ? "Shutdown" : "Boot", mZipFileName.c_str()); return; } ATRACE_CALL(); const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1; static const std::vector<std::string> bootFiles = { APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE, OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE }; static const std::vector<std::string> shutdownFiles = { PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, "" }; static const std::vector<std::string> userspaceRebootFiles = { PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE, SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE, }; static const std::vector<std::string> bootFiles_telcel = {PRODUCT_BOOTANIMATION_FILE_TELCEL}; static const std::vector<std::string> shutdownFiles_telcel = {PRODUCT_SHUTDOWNANIMATION_FILE_TELCEL}; char regionmark[PROPERTY_VALUE_MAX]; char operatorCode[PROPERTY_VALUE_MAX]; property_get("ro.boot.regionmark",regionmark,""); property_get("ro.boot.operator",operatorCode,""); if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) { findBootAnimationFileInternal(userspaceRebootFiles); } else if (strcmp("MX",regionmark) == 0 && strcmp("TELCEL",operatorCode) == 0) { if (mShuttingDown) { findBootAnimationFileInternal(shutdownFiles_telcel); } else { findBootAnimationFileInternal(bootFiles_telcel); } } else { if (mShuttingDown) { findBootAnimationFileInternal(shutdownFiles); } else { findBootAnimationFileInternal(bootFiles); } } }解析一下上述的c++代码
05-28
sudo wpa_supplicant -d -Dnl80211 -i wlan0 -c /etc/wpa_supplicant_rtl.conf wpa_supplicant v2.10 random: Trying to read entropy from /dev/random Successfully initialized wpa_supplicant Initializing interface &#39;wlan0&#39; conf &#39;/etc/wpa_supplicant_rtl.conf&#39; driver &#39;nl80211&#39; ctrl_interface &#39;N/A&#39; bridge &#39;N/A&#39; Configuration file &#39;/etc/wpa_supplicant_rtl.conf&#39; -> &#39;/etc/wpa_supplicant_rtl.conf&#39; Reading configuration file &#39;/etc/wpa_supplicant_rtl.conf&#39; nl80211: Supported cipher 00-0f-ac:1 nl80211: Supported cipher 00-0f-ac:5 nl80211: Supported cipher 00-0f-ac:2 nl80211: Supported cipher 00-0f-ac:4 nl80211: Supported cipher 00-0f-ac:6 nl80211: Using driver-based off-channel TX nl80211: key_mgmt=0xd0f enc=0x10f auth=0x7 flags=0x800d0c0 rrm_flags=0x0 probe_resp_offloads=0x0 max_stations=0 max_remain_on_chan=5000 max_scan_ssids=9 nl80211: interface wlan0 in phy phy0 nl80211: Set mode ifindex 2 iftype 2 (STATION) nl80211: Subscribe to mgmt frames with non-AP handle 0x50be78 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=0801 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=06 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=0a07 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=0a11 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=1101 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=1102 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=0505 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=0500 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=1301 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=1305 multicast=0 nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x50be78 match=7e506f9a1a multicast=0 rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0 netlink: Operstate: ifindex=2 linkmode=1 (userspace-control), operstate=5 (IF_OPER_DORMANT) Add interface wlan0 to a new radio phy0 nl80211: Regulatory information - country=00 nl80211: 2402-2472 @ 40 MHz 20 mBm nl80211: 2457-2482 @ 20 MHz 20 mBm (no IR) nl80211: 2474-2494 @ 20 MHz 20 mBm (no OFDM) (no IR) nl80211: 5170-5250 @ 80 MHz 20 mBm (no IR) nl80211: 5250-5330 @ 80 MHz 20 mBm (DFS) (no IR) nl80211: 5490-5730 @ 160 MHz 20 mBm (DFS) (no IR) nl80211: 5735-5835 @ 80 MHz 20 mBm (no IR) nl80211: 57240-63720 @ 2160 MHz 0 mBm nl80211: Added 802.11b mode based on 802.11g information nl80211: Mode IEEE 802.11g: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467[NO_IR] 2472[NO_IR] 2484[DISABLED] nl80211: Mode IEEE 802.11b: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467[NO_IR] 2472[NO_IR] 2484[DISABLED] wlan0: Own MAC address: cc:b8:5e:f5:a6:86 wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=0 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=1 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key wpa_driver_nl80211_set_key: ifindex=2 (wlan0) alg=0 addr=(nil) key_idx=2 set_tx=0 seq_len=0 key_len=0 key_flag=0x10 nl80211: DEL_KEY broadcast key
最新发布
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值