From 6e8c1ccbe24d4adf3b4648324fdf5c401dcff5e7 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 7 Dec 2018 12:06:03 +0000 Subject: [PATCH] Annotate Giant drop/pickup macros with __predict_false They are used in important places of the kernel with the lock not being held majority of the time. Sponsored by: The FreeBSD Foundation --- sys/kern/kern_lock.c | 4 ++-- sys/sys/mutex.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 65a52340e59..d844cfc47cc 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -96,14 +96,14 @@ CTASSERT(LK_UNLOCKED == (LK_UNLOCKED & int _i = 0; \ WITNESS_SAVE_DECL(Giant) #define GIANT_RESTORE() do { \ - if (_i > 0) { \ + if (__predict_false(_i > 0)) { \ while (_i--) \ mtx_lock(&Giant); \ WITNESS_RESTORE(&Giant.lock_object, Giant); \ } \ } while (0) #define GIANT_SAVE() do { \ - if (mtx_owned(&Giant)) { \ + if (__predict_false(mtx_owned(&Giant))) { \ WITNESS_SAVE(&Giant.lock_object, Giant); \ while (mtx_owned(&Giant)) { \ _i++; \ diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index d4c9d1cbc81..caacf2ef427 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -496,7 +496,7 @@ do { \ int _giantcnt = 0; \ WITNESS_SAVE_DECL(Giant); \ \ - if (mtx_owned(&Giant)) { \ + if (__predict_false(mtx_owned(&Giant))) { \ WITNESS_SAVE(&Giant.lock_object, Giant); \ for (_giantcnt = 0; mtx_owned(&Giant) && \ !SCHEDULER_STOPPED(); _giantcnt++) \ @@ -509,7 +509,7 @@ do { \ #define PARTIAL_PICKUP_GIANT() \ mtx_assert(&Giant, MA_NOTOWNED); \ - if (_giantcnt > 0) { \ + if (__predict_false(_giantcnt > 0)) { \ while (_giantcnt--) \ mtx_lock(&Giant); \ WITNESS_RESTORE(&Giant.lock_object, Giant); \