diff mbox series

[-next,3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()

Message ID 20230815014123.368929-4-yukuai1@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series cleanup and fixes for 'carryover_ios/bytes' | expand

Commit Message

Yu Kuai Aug. 15, 2023, 1:41 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

There are no functional changes, just make the code cleaner.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-throttle.c | 81 +++++++++++++++++++++-----------------------
 1 file changed, 38 insertions(+), 43 deletions(-)

Comments

kernel test robot Aug. 15, 2023, 3:48 p.m. UTC | #1
Hi Yu,

kernel test robot noticed the following build errors:

[auto build test ERROR on next-20230809]

url:    https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/blk-throttle-print-signed-value-carryover_bytes-ios-for-user/20230815-095025
base:   next-20230809
patch link:    https://lore.kernel.org/r/20230815014123.368929-4-yukuai1%40huaweicloud.com
patch subject: [PATCH -next 3/4] blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice()
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230815/202308152351.JdDlpV4Q-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230815/202308152351.JdDlpV4Q-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202308152351.JdDlpV4Q-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from block/blk-throttle.c:12:
   block/blk-throttle.c: In function 'throtl_trim_slice':
>> block/blk-throttle.c:780:44: error: 'nr_slices' undeclared (first use in this function)
     780 |                    rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
         |                                            ^~~~~~~~~
   include/linux/blktrace_api.h:56:66: note: in definition of macro 'blk_add_cgroup_trace_msg'
      56 |                         __blk_trace_note_message(bt, css, fmt, ##__VA_ARGS__);\
         |                                                                  ^~~~~~~~~~~
   block/blk-throttle.c:778:9: note: in expansion of macro 'throtl_log'
     778 |         throtl_log(&tg->service_queue,
         |         ^~~~~~~~~~
   block/blk-throttle.c:780:44: note: each undeclared identifier is reported only once for each function it appears in
     780 |                    rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
         |                                            ^~~~~~~~~
   include/linux/blktrace_api.h:56:66: note: in definition of macro 'blk_add_cgroup_trace_msg'
      56 |                         __blk_trace_note_message(bt, css, fmt, ##__VA_ARGS__);\
         |                                                                  ^~~~~~~~~~~
   block/blk-throttle.c:778:9: note: in expansion of macro 'throtl_log'
     778 |         throtl_log(&tg->service_queue,
         |         ^~~~~~~~~~


vim +/nr_slices +780 block/blk-throttle.c

1a46ae7773b475 Yu Kuai     2023-08-15  728  
e43473b7f223ec Vivek Goyal 2010-09-15  729  /* Trim the used slices and adjust slice start accordingly */
0f3457f60edc57 Tejun Heo   2013-05-14  730  static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
e43473b7f223ec Vivek Goyal 2010-09-15  731  {
1a46ae7773b475 Yu Kuai     2023-08-15  732  	unsigned long time_elapsed, io_trim;
1a46ae7773b475 Yu Kuai     2023-08-15  733  	u64 bytes_trim;
e43473b7f223ec Vivek Goyal 2010-09-15  734  
e43473b7f223ec Vivek Goyal 2010-09-15  735  	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
e43473b7f223ec Vivek Goyal 2010-09-15  736  
e43473b7f223ec Vivek Goyal 2010-09-15  737  	/*
e43473b7f223ec Vivek Goyal 2010-09-15  738  	 * If bps are unlimited (-1), then time slice don't get
e43473b7f223ec Vivek Goyal 2010-09-15  739  	 * renewed. Don't try to trim the slice if slice is used. A new
e43473b7f223ec Vivek Goyal 2010-09-15  740  	 * slice will start when appropriate.
e43473b7f223ec Vivek Goyal 2010-09-15  741  	 */
0f3457f60edc57 Tejun Heo   2013-05-14  742  	if (throtl_slice_used(tg, rw))
e43473b7f223ec Vivek Goyal 2010-09-15  743  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  744  
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  745  	/*
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  746  	 * A bio has been dispatched. Also adjust slice_end. It might happen
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  747  	 * that initially cgroup limit was very low resulting in high
b53b072c4bb579 Baolin Wang 2020-09-07  748  	 * slice_end, but later limit was bumped up and bio was dispatched
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  749  	 * sooner, then we need to reduce slice_end. A high bogus slice_end
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  750  	 * is bad because it does not allow new slice to start.
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  751  	 */
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  752  
297e3d85478482 Shaohua Li  2017-03-27  753  	throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
d1ae8ffdfaa16b Vivek Goyal 2010-12-01  754  
1a46ae7773b475 Yu Kuai     2023-08-15  755  	time_elapsed = rounddown(jiffies - tg->slice_start[rw],
1a46ae7773b475 Yu Kuai     2023-08-15  756  				 tg->td->throtl_slice);
1a46ae7773b475 Yu Kuai     2023-08-15  757  	if (!time_elapsed)
e43473b7f223ec Vivek Goyal 2010-09-15  758  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  759  
1a46ae7773b475 Yu Kuai     2023-08-15  760  	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
1a46ae7773b475 Yu Kuai     2023-08-15  761  					     time_elapsed);
1a46ae7773b475 Yu Kuai     2023-08-15  762  	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
8e89d13f4ede24 Vivek Goyal 2010-09-15  763  	if (!bytes_trim && !io_trim)
e43473b7f223ec Vivek Goyal 2010-09-15  764  		return;
e43473b7f223ec Vivek Goyal 2010-09-15  765  
e43473b7f223ec Vivek Goyal 2010-09-15  766  	if (tg->bytes_disp[rw] >= bytes_trim)
e43473b7f223ec Vivek Goyal 2010-09-15  767  		tg->bytes_disp[rw] -= bytes_trim;
e43473b7f223ec Vivek Goyal 2010-09-15  768  	else
e43473b7f223ec Vivek Goyal 2010-09-15  769  		tg->bytes_disp[rw] = 0;
e43473b7f223ec Vivek Goyal 2010-09-15  770  
8e89d13f4ede24 Vivek Goyal 2010-09-15  771  	if (tg->io_disp[rw] >= io_trim)
8e89d13f4ede24 Vivek Goyal 2010-09-15  772  		tg->io_disp[rw] -= io_trim;
8e89d13f4ede24 Vivek Goyal 2010-09-15  773  	else
8e89d13f4ede24 Vivek Goyal 2010-09-15  774  		tg->io_disp[rw] = 0;
8e89d13f4ede24 Vivek Goyal 2010-09-15  775  
1a46ae7773b475 Yu Kuai     2023-08-15  776  	tg->slice_start[rw] += time_elapsed;
e43473b7f223ec Vivek Goyal 2010-09-15  777  
fda6f272c77a7a Tejun Heo   2013-05-14  778  	throtl_log(&tg->service_queue,
fda6f272c77a7a Tejun Heo   2013-05-14  779  		   "[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
8e89d13f4ede24 Vivek Goyal 2010-09-15 @780  		   rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
e43473b7f223ec Vivek Goyal 2010-09-15  781  		   tg->slice_start[rw], tg->slice_end[rw], jiffies);
e43473b7f223ec Vivek Goyal 2010-09-15  782  }
e43473b7f223ec Vivek Goyal 2010-09-15  783
diff mbox series

Patch

diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 7c93144d03da..e5296960c799 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -697,11 +697,40 @@  static bool throtl_slice_used(struct throtl_grp *tg, bool rw)
 	return true;
 }
 
+static unsigned int calculate_io_allowed(u32 iops_limit,
+					 unsigned long jiffy_elapsed)
+{
+	unsigned int io_allowed;
+	u64 tmp;
+
+	/*
+	 * jiffy_elapsed 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
+	 * will allow dispatch after 1 second and after that slice should
+	 * have been trimmed.
+	 */
+
+	tmp = (u64)iops_limit * jiffy_elapsed;
+	do_div(tmp, HZ);
+
+	if (tmp > UINT_MAX)
+		io_allowed = UINT_MAX;
+	else
+		io_allowed = tmp;
+
+	return io_allowed;
+}
+
+static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
+{
+	return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
+}
+
 /* Trim the used slices and adjust slice start accordingly */
 static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 {
-	unsigned long nr_slices, time_elapsed, io_trim;
-	u64 bytes_trim, tmp;
+	unsigned long time_elapsed, io_trim;
+	u64 bytes_trim;
 
 	BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
 
@@ -723,19 +752,14 @@  static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 
 	throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
 
-	time_elapsed = jiffies - tg->slice_start[rw];
-
-	nr_slices = time_elapsed / tg->td->throtl_slice;
-
-	if (!nr_slices)
+	time_elapsed = rounddown(jiffies - tg->slice_start[rw],
+				 tg->td->throtl_slice);
+	if (!time_elapsed)
 		return;
-	tmp = tg_bps_limit(tg, rw) * tg->td->throtl_slice * nr_slices;
-	do_div(tmp, HZ);
-	bytes_trim = tmp;
-
-	io_trim = (tg_iops_limit(tg, rw) * tg->td->throtl_slice * nr_slices) /
-		HZ;
 
+	bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
+					     time_elapsed);
+	io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed);
 	if (!bytes_trim && !io_trim)
 		return;
 
@@ -749,7 +773,7 @@  static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 	else
 		tg->io_disp[rw] = 0;
 
-	tg->slice_start[rw] += nr_slices * tg->td->throtl_slice;
+	tg->slice_start[rw] += time_elapsed;
 
 	throtl_log(&tg->service_queue,
 		   "[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
@@ -757,35 +781,6 @@  static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
 		   tg->slice_start[rw], tg->slice_end[rw], jiffies);
 }
 
-static unsigned int calculate_io_allowed(u32 iops_limit,
-					 unsigned long jiffy_elapsed)
-{
-	unsigned int io_allowed;
-	u64 tmp;
-
-	/*
-	 * jiffy_elapsed 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
-	 * will allow dispatch after 1 second and after that slice should
-	 * have been trimmed.
-	 */
-
-	tmp = (u64)iops_limit * jiffy_elapsed;
-	do_div(tmp, HZ);
-
-	if (tmp > UINT_MAX)
-		io_allowed = UINT_MAX;
-	else
-		io_allowed = tmp;
-
-	return io_allowed;
-}
-
-static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
-{
-	return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
-}
-
 static void __tg_update_carryover(struct throtl_grp *tg, bool rw)
 {
 	unsigned long jiffy_elapsed = jiffies - tg->slice_start[rw];