Author: hselasky
Date: Wed Sep  2 09:44:00 2020
New Revision: 365237
URL: https://svnweb.freebsd.org/changeset/base/365237

Log:
  Micro optimise _callout_stop_safe() by removing dead code.
  
  The CS_DRAIN flag cannot be set at the same time like the async-drain function
  pointer is set. These are orthogonal features. Assert this at the beginning
  of the function.
  
  Before:
          if (flags & CS_DRAIN) {
                  /* FALLTHROUGH */
          } else if (xxx) {
                  return yyy;
          }
          if (drain) {
                  zzz = drain;
          }
  After:
          if (flags & CS_DRAIN) {
                  /* FALLTHROUGH */
          } else if (xxx) {
                  return yyy;
          } else {
                  if (drain) {
                          zzz = drain;
                  }
          }
  
  Reviewed by:  markj@
  Tested by:    callout_test
  Differential Revision:        https://reviews.freebsd.org/D26285
  MFC after:    1 week
  Sponsored by: Mellanox Technologies // NVIDIA Networking

Modified:
  head/sys/kern/kern_timeout.c

Modified: head/sys/kern/kern_timeout.c
==============================================================================
--- head/sys/kern/kern_timeout.c        Wed Sep  2 09:20:40 2020        
(r365236)
+++ head/sys/kern/kern_timeout.c        Wed Sep  2 09:44:00 2020        
(r365237)
@@ -1075,6 +1075,9 @@ _callout_stop_safe(struct callout *c, int flags, callo
                WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, c->c_lock,
                    "calling %s", __func__);
 
+       KASSERT((flags & CS_DRAIN) == 0 || drain == NULL,
+           ("Cannot set drain callback and CS_DRAIN flag at the same time"));
+
        /*
         * Some old subsystems don't hold Giant while running a callout_stop(),
         * so just discard this check for the moment.
@@ -1270,11 +1273,12 @@ again:
                        }
                        CC_UNLOCK(cc);
                        return ((flags & CS_EXECUTING) != 0);
-               }
-               CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
-                   c, c->c_func, c->c_arg);
-               if (drain) {
-                       cc_exec_drain(cc, direct) = drain;
+               } else {
+                       CTR3(KTR_CALLOUT, "failed to stop %p func %p arg %p",
+                           c, c->c_func, c->c_arg);
+                       if (drain) {
+                               cc_exec_drain(cc, direct) = drain;
+                       }
                }
                KASSERT(!sq_locked, ("sleepqueue chain still locked"));
                cancelled = ((flags & CS_EXECUTING) != 0);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to