Author: mjg
Date: Mon Feb  3 22:26:00 2020
New Revision: 357467
URL: https://svnweb.freebsd.org/changeset/base/357467

Log:
  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.

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_ktrace.c
  head/sys/kern/vfs_syscalls.c
  head/sys/sys/ktrace.h

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c        Mon Feb  3 20:48:57 2020        
(r357466)
+++ head/sys/kern/kern_descrip.c        Mon Feb  3 22:26:00 2020        
(r357467)
@@ -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);
 }

Modified: head/sys/kern/kern_ktrace.c
==============================================================================
--- head/sys/kern/kern_ktrace.c Mon Feb  3 20:48:57 2020        (r357466)
+++ head/sys/kern/kern_ktrace.c Mon Feb  3 22:26:00 2020        (r357467)
@@ -779,6 +779,14 @@ ktrstruct(const char *name, const void *data, size_t d
 }
 
 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)
 {

Modified: head/sys/kern/vfs_syscalls.c
==============================================================================
--- head/sys/kern/vfs_syscalls.c        Mon Feb  3 20:48:57 2020        
(r357466)
+++ head/sys/kern/vfs_syscalls.c        Mon Feb  3 22:26:00 2020        
(r357467)
@@ -2349,8 +2349,6 @@ kern_statat(struct thread *td, int flag, int fd, const
        }
        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
 #endif
 #ifdef KTRACE
        if (KTRPOINT(td, KTR_STRUCT))
-               ktrstat(sbp);
+               ktrstat_error(sbp, error);
 #endif
-       return (0);
+       return (error);
 }
 
 #if defined(COMPAT_FREEBSD11)

Modified: head/sys/sys/ktrace.h
==============================================================================
--- head/sys/sys/ktrace.h       Mon Feb  3 20:48:57 2020        (r357466)
+++ head/sys/sys/ktrace.h       Mon Feb  3 22:26:00 2020        (r357467)
@@ -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_righ
        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
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to