Page MenuHomeFreeBSD

__predict_true/false profiling
AbandonedPublic

Authored by mjg on Dec 13 2020, 6:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 12, 12:27 AM
Unknown Object (File)
Thu, Oct 31, 4:44 AM
Unknown Object (File)
Sat, Oct 19, 5:37 AM
Unknown Object (File)
Oct 1 2024, 7:54 AM
Unknown Object (File)
Sep 30 2024, 2:24 AM
Unknown Object (File)
Sep 26 2024, 1:40 AM
Unknown Object (File)
Sep 21 2024, 5:32 AM
Unknown Object (File)
Sep 15 2024, 2:57 AM
Subscribers

Details

Reviewers
kib
markj
Summary

Converts the macros to function calls to an actual probe. Some probes are excluded to avoid recursing into dtrace.

Sample use:

dtrace -n 'sdt:profile:predict: { @[stringof(args[2]), arg3, arg0 == arg1] = count(); }' -o out
cat out | awk 'NF { all[$1 ":" $2] += $4; if ($3) { hit[$1 ":" $2] = $4; if (miss[$1 ":" $2] == 0) miss[$1 ":" $2] = 0; } else { miss[$1 ":" $2] = $4; if (hit[$1 ":" $2] == 0) hit[$1 ":" $2] = $4; } } END { for (l in all) print l " " all[l] " " hit[l] " " miss[l] " " hit[l] * 100 / (all[l]) }' | sort -rnk 5 | less

Sample from buildkernel in a vm (location, calls, hit, miss, hit %)

/usr/src/sys/kern/vfs_subr.c:3108 131666 123745 7921 93.984
/usr/src/sys/kern/subr_lock.c:138 82423 76362 6061 92.6465
/usr/src/sys/vm/uma_core.c:3196 1048777 962903 85874 91.812
/usr/src/sys/amd64/amd64/trap.c:1083 560031 506280 53751 90.4021
/usr/src/sys/amd64/amd64/vm_machdep.c:516 560039 506280 53759 90.4008
/usr/src/sys/kern/vfs_cache.c:4545 683646 616969 66677 90.2469
/usr/src/sys/kern/vfs_cache.c:2230 11000 9890 1110 89.9091
/usr/src/sys/kern/vfs_subr.c:3530 19645 17632 2013 89.7531
/usr/src/sys/kern/vfs_cache.c:1895 84648 73648 11000 87.005
/usr/src/sys/amd64/amd64/pmap.c:5025 56153 48641 7512 86.6223
/usr/src/sys/kern/uipc_syscalls.c:167 5 4 1 80
/usr/src/sys/kern/kern_lock.c:1275 399022 319204 79818 79.9966
/usr/src/sys/kern/kern_mutex.c:541 5773 4249 1524 73.6012
/usr/src/sys/vm/uma_core.c:3217 7745 5115 2630 66.0426
/usr/src/sys/kern/vfs_cache.c:1930 50 33 17 66
/usr/src/sys/kern/vfs_cache.c:4592 109803 67451 42352 61.4291
/usr/src/sys/kern/uipc_usrreq.c:385 1164 684 480 58.7629
/usr/src/sys/kern/subr_lock.c:131 82423 47944 34479 58.1682
/usr/src/sys/kern/kern_mutex.c:1030 2042 192 1850 9.40255
/usr/src/sys/kern/subr_epoch.c:794 128 8 120 6.25

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 35384

Event Timeline

mjg requested review of this revision.Dec 13 2020, 6:06 PM
mjg added inline comments.
sys/sys/param.h
43

I don't know where to put this, I keep getting weird compilation failures if it lands in cdefs.h

sys/sys/cdefs.h
457

Use of such define conflicts with user namespace. cdefs.h must not interfere with user namespace in any way.

sys/sys/cdefs.h
457

would it be sufficient to hide it under KERNEL and PREDICT_PROFILING? that should sort out any userspace which does not define KERNEL.

I think a better approach would be to leave cdefs.h alone, only adding #ifdef predict_{true/false} around that block. Then you can have a global include file like opt_global.h that defines predict_true/false to you liking.