svn commit: r333390 - in head/sys: kern sys
Matt Macy
mmacy at FreeBSD.org
Wed May 9 00:00:49 UTC 2018
Author: mmacy
Date: Wed May 9 00:00:47 2018
New Revision: 333390
URL: https://svnweb.freebsd.org/changeset/base/333390
Log:
Reduce overhead of ktrace checks in the common case.
KTRPOINT() checks both if we are tracing _and_ if we are recursing within
ktrace. The second condition is only ever executed if ktrace is actually
enabled. This change moves the check out of the hot path in to the functions
themselves.
Discussed with mjg@
Reported by: mjg@
Approved by: sbruno@
Modified:
head/sys/kern/kern_ktrace.c
head/sys/sys/ktrace.h
Modified: head/sys/kern/kern_ktrace.c
==============================================================================
--- head/sys/kern/kern_ktrace.c Tue May 8 23:13:11 2018 (r333389)
+++ head/sys/kern/kern_ktrace.c Wed May 9 00:00:47 2018 (r333390)
@@ -448,6 +448,9 @@ ktrsyscall(int code, int narg, register_t args[])
size_t buflen;
char *buf = NULL;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
buflen = sizeof(register_t) * narg;
if (buflen > 0) {
buf = malloc(buflen, M_KTRACE, M_WAITOK);
@@ -475,6 +478,9 @@ ktrsysret(int code, int error, register_t retval)
struct ktr_request *req;
struct ktr_sysret *ktp;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
req = ktr_getrequest(KTR_SYSRET);
if (req == NULL)
return;
@@ -729,6 +735,9 @@ ktrcsw(int out, int user, const char *wmesg)
struct ktr_request *req;
struct ktr_csw *kc;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
req = ktr_getrequest(KTR_CSW);
if (req == NULL)
return;
@@ -750,6 +759,9 @@ ktrstruct(const char *name, const void *data, size_t d
char *buf;
size_t buflen, namelen;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
if (data == NULL)
datalen = 0;
namelen = strlen(name) + 1;
@@ -776,6 +788,9 @@ ktrstructarray(const char *name, enum uio_seg seg, con
size_t buflen, datalen, namelen;
int max_items;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
/* Trim array length to genio size. */
max_items = ktr_geniosize / struct_size;
if (num_items > max_items) {
@@ -820,6 +835,9 @@ ktrcapfail(enum ktr_cap_fail_type type, const cap_righ
struct ktr_request *req;
struct ktr_cap_fail *kcf;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
req = ktr_getrequest(KTR_CAPFAIL);
if (req == NULL)
return;
@@ -844,6 +862,9 @@ ktrfault(vm_offset_t vaddr, int type)
struct ktr_request *req;
struct ktr_fault *kf;
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
+
req = ktr_getrequest(KTR_FAULT);
if (req == NULL)
return;
@@ -860,6 +881,9 @@ ktrfaultend(int result)
struct thread *td = curthread;
struct ktr_request *req;
struct ktr_faultend *kf;
+
+ if (__predict_false(curthread->td_pflags & TDP_INKTRACE))
+ return;
req = ktr_getrequest(KTR_FAULTEND);
if (req == NULL)
Modified: head/sys/sys/ktrace.h
==============================================================================
--- head/sys/sys/ktrace.h Tue May 8 23:13:11 2018 (r333389)
+++ head/sys/sys/ktrace.h Wed May 9 00:00:47 2018 (r333390)
@@ -70,8 +70,7 @@ struct ktr_header {
* is the public interface.
*/
#define KTRCHECK(td, type) ((td)->td_proc->p_traceflag & (1 << type))
-#define KTRPOINT(td, type) \
- (KTRCHECK((td), (type)) && !((td)->td_pflags & TDP_INKTRACE))
+#define KTRPOINT(td, type) (__predict_false(KTRCHECK((td), (type))))
#define KTRCHECKDRAIN(td) (!(STAILQ_EMPTY(&(td)->td_proc->p_ktr)))
#define KTRUSERRET(td) do { \
if (KTRCHECKDRAIN(td)) \
More information about the svn-src-head
mailing list