From 0a1427c5ab7b7524590dd98fa6ed822d6c9d6fa1 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Mon, 3 Feb 2020 22:26:00 +0000 Subject: [PATCH] ktrace: provide ktrstat_error This eliminates a branch from its consumers trading it for an extra call if ktrace is enabled for curthread. Given that this is almost never true, the tradeoff is worth it. --- sys/kern/kern_descrip.c | 14 ++++++-------- sys/kern/kern_ktrace.c | 8 ++++++++ sys/kern/vfs_syscalls.c | 6 ++---- sys/sys/ktrace.h | 3 +++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 629366ac9ea2..84d86bf99b05 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1445,16 +1445,14 @@ kern_fstat(struct thread *td, int fd, struct stat *sbp) error = fo_stat(fp, sbp, td->td_ucred, td); fdrop(fp, td); #ifdef __STAT_TIME_T_EXT - if (error == 0) { - sbp->st_atim_ext = 0; - sbp->st_mtim_ext = 0; - sbp->st_ctim_ext = 0; - sbp->st_btim_ext = 0; - } + sbp->st_atim_ext = 0; + sbp->st_mtim_ext = 0; + sbp->st_ctim_ext = 0; + sbp->st_btim_ext = 0; #endif #ifdef KTRACE - if (error == 0 && KTRPOINT(td, KTR_STRUCT)) - ktrstat(sbp); + if (KTRPOINT(td, KTR_STRUCT)) + ktrstat_error(sbp, error); #endif return (error); } diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index a6788afad3b8..b4df404afe0c 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -778,6 +778,14 @@ ktrstruct(const char *name, const void *data, size_t datalen) ktr_submitrequest(curthread, req); } +void +ktrstruct_error(const char *name, const void *data, size_t datalen, int error) +{ + + if (error == 0) + ktrstruct(name, data, datalen); +} + void ktrstructarray(const char *name, enum uio_seg seg, const void *data, int num_items, size_t struct_size) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 20ed0dc8f39d..c22cb8662eae 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -2349,8 +2349,6 @@ kern_statat(struct thread *td, int flag, int fd, const char *path, } NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_vp); - if (error != 0) - return (error); #ifdef __STAT_TIME_T_EXT sbp->st_atim_ext = 0; sbp->st_mtim_ext = 0; @@ -2359,9 +2357,9 @@ kern_statat(struct thread *td, int flag, int fd, const char *path, #endif #ifdef KTRACE if (KTRPOINT(td, KTR_STRUCT)) - ktrstat(sbp); + ktrstat_error(sbp, error); #endif - return (0); + return (error); } #if defined(COMPAT_FREEBSD11) diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index 97fe82730315..0a37e1dea718 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -280,6 +280,7 @@ void ktrprocexit(struct thread *); void ktrprocfork(struct proc *, struct proc *); void ktruserret(struct thread *); void ktrstruct(const char *, const void *, size_t); +void ktrstruct_error(const char *, const void *, size_t, int); void ktrstructarray(const char *, enum uio_seg, const void *, int, size_t); void ktrcapfail(enum ktr_cap_fail_type, const cap_rights_t *, const cap_rights_t *); @@ -291,6 +292,8 @@ void ktrcapfail(enum ktr_cap_fail_type, const cap_rights_t *, ktrstruct("sockaddr", (s), ((struct sockaddr *)(s))->sa_len) #define ktrstat(s) \ ktrstruct("stat", (s), sizeof(struct stat)) +#define ktrstat_error(s, error) \ + ktrstruct_error("stat", (s), sizeof(struct stat), error) extern u_int ktr_geniosize; #else