Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2439469ioo; Sat, 28 May 2022 13:45:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/8/bdkuWK+r2LNKbRQYMY/Un1kIzvhs9HCEEmpSy0CYEIKZDFDTvJmTAkR32o4/q03knJ X-Received: by 2002:a65:5207:0:b0:3fb:c00f:f6e4 with SMTP id o7-20020a655207000000b003fbc00ff6e4mr6113912pgp.415.1653770717583; Sat, 28 May 2022 13:45:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770717; cv=none; d=google.com; s=arc-20160816; b=P9cmZNHH00oufYwh4N2cwUQs7TqdKXJ7IY7HYDw9NiYR12ZRl4faAXW4H5QivfOoWP dTy9mRhfGPTsG7RhdpmfbY032MLwPWQ8yogi43dqHFf49ovPpwgGYu2HVcTnP4298lBj kqKLoi1OsD96TMx7FjeQoN0LPVFnRfnHF5a5bqv5l8r9sIAIRpzSeVOexxo2TvXGWclR QjFCqWkNK30p0H5TTeDNw7nNQuj0f3TpqKcvHD+m1D4bRBfChKFmGqM/N+UUGRsWcF8h KO2FShBTbcTAMydxxZH2VRIVcS+8K+2T6/NGunyy8ZK4MzsdipMLea+CjQw91EhRgOrf HRZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pUW/Yh7t9Y6Sk4rM9A0BSXLJuB+srqJvMnzMkyT61vY=; b=Q8JBFG4X+mQtfHsuxrXUGScf/F0vWUHgzTkfRWnYgQfDc4jw4jJfGuHA2xR5oljqKK /lFW7ojsDIPbcLXjYtXmeUnaU/fp6UVQR8RK2dBk8gDzMaTAzcR7NFTaVspbFYqEHMhv 2HcGvikuNqCW5HFEK8P60m6ioKbvaL8kUprNW+kzDQKFLIQNbGwFfjZ0PRPHHBJICV+x SdnKqH4FUtoeO3+cbYccRyqZ7uZTsMaQEbctRNsXofcjUTQ0qCJ/997Krmapk+UWcyFm oq5oQ9ztvvQcnhB7jGhyuMndPFBBkKh7U3EqsOOYI4WQOKUKJPYD3y6yLi1JfymGonyR 5sWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l12-20020a635b4c000000b003f5d5bbf0b1si11148662pgm.245.2022.05.28.13.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:45:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 466773B281; Sat, 28 May 2022 12:44:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355985AbiE1Gbn (ORCPT + 99 others); Sat, 28 May 2022 02:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355834AbiE1GaY (ORCPT ); Sat, 28 May 2022 02:30:24 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7995746B0F; Fri, 27 May 2022 23:30:04 -0700 (PDT) Received: from kwepemi100012.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4L9BbJ2z0kzjX8P; Sat, 28 May 2022 14:29:16 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi100012.china.huawei.com (7.221.188.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 28 May 2022 14:30:02 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 28 May 2022 14:30:01 +0800 From: Yu Kuai To: , , , CC: , , , , Subject: [PATCH -next v5 3/8] blk-throttle: factor out code to calculate ios/bytes_allowed Date: Sat, 28 May 2022 14:43:25 +0800 Message-ID: <20220528064330.3471000-4-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220528064330.3471000-1-yukuai3@huawei.com> References: <20220528064330.3471000-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No functional changes, new apis will be used in later patches to calculate wait time for throttled bios while updating config. Signed-off-by: Yu Kuai --- block/blk-throttle.c | 48 +++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index a89c62bef2fb..d67b20ce4d63 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -754,25 +754,12 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) tg->slice_start[rw], tg->slice_end[rw], jiffies); } -static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, - u32 iops_limit, unsigned long *wait) +static unsigned int calculate_io_allowed(u32 iops_limit, + unsigned long jiffy_elapsed_rnd) { - bool rw = bio_data_dir(bio); unsigned int io_allowed; - unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; u64 tmp; - if (iops_limit == UINT_MAX) { - if (wait) - *wait = 0; - return true; - } - - jiffy_elapsed = jiffies - tg->slice_start[rw]; - - /* Round up to the next throttle slice, wait time must be nonzero */ - jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice); - /* * jiffy_elapsed_rnd should not be a big value as minimum iops can be * 1 then at max jiffy elapsed should be equivalent of 1 second as we @@ -788,6 +775,33 @@ static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, else io_allowed = tmp; + return io_allowed; +} + +static u64 calculate_bytes_allowed(u64 bps_limit, + unsigned long jiffy_elapsed_rnd) +{ + return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed_rnd, (u64)HZ); +} + +static bool tg_with_in_iops_limit(struct throtl_grp *tg, struct bio *bio, + u32 iops_limit, unsigned long *wait) +{ + bool rw = bio_data_dir(bio); + unsigned int io_allowed; + unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; + + if (iops_limit == UINT_MAX) { + if (wait) + *wait = 0; + return true; + } + + jiffy_elapsed = jiffies - tg->slice_start[rw]; + + /* Round up to the next throttle slice, wait time must be nonzero */ + jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice); + io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd); if (tg->io_disp[rw] + 1 <= io_allowed) { if (wait) *wait = 0; @@ -824,9 +838,7 @@ static bool tg_with_in_bps_limit(struct throtl_grp *tg, struct bio *bio, jiffy_elapsed_rnd = tg->td->throtl_slice; jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); - bytes_allowed = mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed_rnd, - (u64)HZ); - + bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd); if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) { if (wait) *wait = 0; -- 2.31.1