We can get the hwa and hwi at one time if no debt need to pay off,
thus add a flag to indicate if the hw_inuse has been changed and
need to update, which can avoid calling current_hweight() twice
for no debt iocgs.

Signed-off-by: Baolin Wang <baolin.w...@linux.alibaba.com>
---
 block/blk-iocost.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 089f3fe..5305afd 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1405,10 +1405,11 @@ static void iocg_kick_waitq(struct ioc_gq *iocg, bool 
pay_debt,
        u64 vshortage, expires, oexpires;
        s64 vbudget;
        u32 hwa;
+       bool need_update_hwi = false;
 
        lockdep_assert_held(&iocg->waitq.lock);
 
-       current_hweight(iocg, &hwa, NULL);
+       current_hweight(iocg, &hwa, &ctx.hw_inuse);
        vbudget = now->vnow - atomic64_read(&iocg->vtime);
 
        /* pay off debt */
@@ -1423,6 +1424,7 @@ static void iocg_kick_waitq(struct ioc_gq *iocg, bool 
pay_debt,
                atomic64_add(vpay, &iocg->done_vtime);
                iocg_pay_debt(iocg, abs_vpay, now);
                vbudget -= vpay;
+               need_update_hwi = true;
        }
 
        if (iocg->abs_vdebt || iocg->delay)
@@ -1445,7 +1447,8 @@ static void iocg_kick_waitq(struct ioc_gq *iocg, bool 
pay_debt,
         * after the above debt payment.
         */
        ctx.vbudget = vbudget;
-       current_hweight(iocg, NULL, &ctx.hw_inuse);
+       if (need_update_hwi)
+               current_hweight(iocg, NULL, &ctx.hw_inuse);
 
        __wake_up_locked_key(&iocg->waitq, TASK_NORMAL, &ctx);
 
-- 
1.8.3.1

Reply via email to