From patchwork Thu Aug 16 16:51:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 10567875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34E4A913 for ; Thu, 16 Aug 2018 16:52:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 207842B3EA for ; Thu, 16 Aug 2018 16:52:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 132722B48E; Thu, 16 Aug 2018 16:52:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B559C2B3EA for ; Thu, 16 Aug 2018 16:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728328AbeHPTvw (ORCPT ); Thu, 16 Aug 2018 15:51:52 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39866 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730213AbeHPTvk (ORCPT ); Thu, 16 Aug 2018 15:51:40 -0400 Received: by mail-wm0-f67.google.com with SMTP id q8-v6so4977062wmq.4 for ; Thu, 16 Aug 2018 09:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MFwx1lYhKb+srSCn4IHsLo9KuWJaInJYfQS9cQKsfGY=; b=B0YQOoawMAWJoKCm802FdEDxe+UJlMEdwCA5khaGmZ6p39K7Gw81QwN3BK6cQ4Cne9 46NGpbhJ51XNytJO+w2Guj6f4a3QM5b4DzYQ/P7Jl+3njrMM9Gl05ABT3k3fsSn5Uk0z 9RhpKol9CpwSX/CrqFTSLyfqkPiX6+u3vJhvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MFwx1lYhKb+srSCn4IHsLo9KuWJaInJYfQS9cQKsfGY=; b=saFUy48g3DxIHQJAt7gfsCwz67R0SNqe1VaOISOYDIa2J0H6Lhi2VDtK0YEetbSzD5 jjLwbTAD7NouZe/6a6MfkFaWWddjYpGQn2dFpuZj+5prPp4Md5jAiRULJz2NsrxYGEVm M94RCDqR1l4YWtDBTCaMNcJa/qMMipcthTFg8E7iBRNkzmj4+F6o5AeKemA5UHGFWonf F8gD/6vfEmv4GgvTcuz5LmRCnF/Y4F8ueuw4e7yDefCiW1t+4nv0E7qSSAKs08zaGqBy hMWY0cQQbjX/8VK/sD9OdT48uD0QGlnbwvGtrEv7T2EgCfHxkcAUePqpFVYCBHVgAcOK /Hug== X-Gm-Message-State: AOUpUlHWeb9hp1UPDf+hlVt8sbZeQ+E54HVW051FPHIx4bWZUogAn/dp Q8TKAB56czGmyEC8Pd8iH8z4Ww== X-Google-Smtp-Source: AA+uWPwr8H40l7SBG7TeV8yJsewmFD/cOCOvAujDeuipc9hfqW98c0U7EWYT90WTsi6YFzKCFe3qlg== X-Received: by 2002:a1c:9550:: with SMTP id x77-v6mr15682250wmd.135.1534438320867; Thu, 16 Aug 2018 09:52:00 -0700 (PDT) Received: from localhost.localdomain (146-241-5-103.dyn.eolo.it. [146.241.5.103]) by smtp.gmail.com with ESMTPSA id o3-v6sm30036180wrj.31.2018.08.16.09.51.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 09:52:00 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, linus.walleij@linaro.org, broonie@kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, Paolo Valente Subject: [PATCH BUGFIX/IMPROVEMENT 4/4] block, bfq: improve code of bfq_bfqq_charge_time Date: Thu, 16 Aug 2018 18:51:18 +0200 Message-Id: <20180816165118.17402-5-paolo.valente@linaro.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180816165118.17402-1-paolo.valente@linaro.org> References: <20180816165118.17402-1-paolo.valente@linaro.org> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bfq_bfqq_charge_time contains some lengthy and redundant code. This commit trims and condenses that code. Signed-off-by: Paolo Valente --- block/bfq-wf2q.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index d558fd26740c..ae52bff43ce4 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -881,15 +881,11 @@ void bfq_bfqq_charge_time(struct bfq_data *bfqd, struct bfq_queue *bfqq, unsigned long time_ms) { struct bfq_entity *entity = &bfqq->entity; - int tot_serv_to_charge = entity->service; - unsigned int timeout_ms = jiffies_to_msecs(bfq_timeout); - - if (time_ms > 0 && time_ms < timeout_ms) - tot_serv_to_charge = - (bfqd->bfq_max_budget * time_ms) / timeout_ms; - - if (tot_serv_to_charge < entity->service) - tot_serv_to_charge = entity->service; + unsigned long timeout_ms = jiffies_to_msecs(bfq_timeout); + unsigned long bounded_time_ms = min(time_ms, timeout_ms); + int serv_to_charge_for_time = + (bfqd->bfq_max_budget * bounded_time_ms) / timeout_ms; + int tot_serv_to_charge = max(serv_to_charge_for_time, entity->service); /* Increase budget to avoid inconsistencies */ if (tot_serv_to_charge > entity->budget)