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: 144431 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2305901ljj; Thu, 16 Aug 2018 09:52:10 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxOFdNp/fJ0EM/dPCR40+95vQ5or/9iBUS30GLiWy6rh1SPcNYLnDuolNOH/8rjdJbwlex6 X-Received: by 2002:a63:4951:: with SMTP id y17-v6mr30227619pgk.32.1534438330773; Thu, 16 Aug 2018 09:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534438330; cv=none; d=google.com; s=arc-20160816; b=gg1eQjSBVz4yVMhk2Yc0i7ZZcNVWOjDu2+I++bXyxIXJFZUdjmfCfb6FZ6LkRYT9M7 qCbU6MhfkWHuD7d2ilmhZjAM9IrHowpSwAjSk5NogSj73ZMbF2DajFsxZwnUBnnA6WpQ uMtBAd15QNYQxVJtSeA9RyUgIoLT6aoEmDxAWfNrhbIcu9n4w4wC5iQ6+UZNIxjIL2Aa hmUgSEi7vdNy3adbikvg0ioAboaJPub5m8u7aZk7Wq8sd0vkmoPD+4ozMVMXufKNYGI9 3JJt2a6fu/N3HDpnsctTcltVXEMjoXoEnGzpftHWnJ2xrWQ0MUMBl6KA6OArP6hPGE4M yT9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MFwx1lYhKb+srSCn4IHsLo9KuWJaInJYfQS9cQKsfGY=; b=iUOjnosciaCRWTXjbneqqeQm6IG+ffGkV9FXMTLFFvSvbaYNKQTgnZIRb+MWcpqd4A bNM4HXfc10CJmfRDccnX/wDdHLeXBqhe8hJW/vWoXFfQkIcHzWYaC8fy9LbljnaNMFGZ 9xdSDke2JlJdiKjdEHjU+0+9Tq7NAJmozkQrWDetLtINRi8FPJhxPxfHsWHLyGmtlRzG kSOgbr1agMnWVfukBm0t0KbQvXpB8U5l/E+rVeMC/EdkCJzMTS8c8IsdBhgupWoqZXBd FHflMDU8lWymb/WUSh5ni1U2pAu04F6MgnXLyNp/SuBpSvE1EKmkh5OHtW+euMbAGnN0 G0og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B0YQOoaw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si12305504plx.110.2018.08.16.09.52.10; Thu, 16 Aug 2018 09:52:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B0YQOoaw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731274AbeHPTvk (ORCPT + 32 others); Thu, 16 Aug 2018 15:51:40 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:35749 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731207AbeHPTvj (ORCPT ); Thu, 16 Aug 2018 15:51:39 -0400 Received: by mail-wm0-f65.google.com with SMTP id o18-v6so4985504wmc.0 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=rN3qwnSK/ymc2Xv/W3hDSMBenIkgojngjBsVzRRcM5UDpoE+8dDQNfbbZpQoOY/wR9 +xhOcA863G3bR1RV+t/atrkkKP0zwCQsi8DXRWz3F4gm5uqpj/2vrxLJMgqW1yrRuDAH frjNwBfhUjm8f0sewp+j5cpCltIxzDLdl1MXIno/Iclqa/LzJW8cot7SEAIqGDfhz9wS osAK4MaOaKY7GSQXAo7KRWMZJ1foq+ubBb22h9yt0VjXVGpqhSyBUu0v18PZOHpywjVr Wk7dia0B25//AtI6DXTTH9CuL/KzNSUlJO3GQDnRHqhGRLPuAxEkNxAF5ziAhJptuZmM dBvw== X-Gm-Message-State: AOUpUlFhUrJc1ZvopAp0P5ZZtHlGRB+EZKdBaK12dJy/I/B+7WcHxiM5 RTDTXZjdaRyFw8zSpWRNEl6lpQ== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.16.1 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)