diff mbox series

[2/5] dmaengine: dmatest: Use fixed point div to calculate iops

Message ID 1535112941-7169-3-git-send-email-seraj.alijan@sondrel.com (mailing list archive)
State Changes Requested
Headers show
Series dmaengine: dmatest: Add multi chan and new params | expand

Commit Message

Seraj Alijan Aug. 24, 2018, 12:15 p.m. UTC
Use fixed point division to calculate iops to prevent reporting 0 iops
when operations last for longer than a second.

Signed-off-by: Seraj Alijan <seraj.alijan@sondrel.com>
---
 drivers/dma/dmatest.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

kernel test robot Aug. 25, 2018, 5:21 a.m. UTC | #1
Hi Seraj,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.18 next-20180824]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Seraj-Alijan/dmaengine-dmatest-Add-multi-chan-and-new-params/20180824-231828
config: i386-randconfig-n0-201833 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/dma/dmatest.o: In function `dmatest_persec':
>> drivers/dma/dmatest.c:457: undefined reference to `__udivdi3'
>> drivers/dma/dmatest.c:457: undefined reference to `__udivdi3'
>> drivers/dma/dmatest.c:457: undefined reference to `__udivdi3'

vim +457 drivers/dma/dmatest.c

   442	
   443	static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
   444	{
   445		unsigned long long per_sec = 1000000;
   446	
   447		if (runtime <= 0)
   448			return 0;
   449	
   450		/* drop precision until runtime is 32-bits */
   451		while (runtime > UINT_MAX) {
   452			runtime >>= 1;
   453			per_sec <<= 1;
   454		}
   455	
   456		per_sec *= val;
 > 457		per_sec = FIXPT_DIV(per_sec, runtime);
   458	
   459		return per_sec;
   460	}
   461	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 8ce3b06..130f343 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -170,6 +170,14 @@  MODULE_PARM_DESC(channel, "Bus ID of the channel to test (default: any)");
 #define PATTERN_COUNT_MASK	0x1f
 #define PATTERN_MEMSET_IDX	0x01
 
+/* Fixed point arithmetic ops */
+#define FIXPT_SHIFT		8
+#define FIXPNT_MASK		0xFF
+#define FIXPT_TO_INT(a)	((a) >> FIXPT_SHIFT)
+#define INT_TO_FIXPT(a)	((a) << FIXPT_SHIFT)
+#define FIXPT_GET_FRAC(a)	((((a) & FIXPNT_MASK) * 100) >> FIXPT_SHIFT)
+#define FIXPT_DIV(a, b)	DIV_ROUND_CLOSEST((INT_TO_FIXPT(a)), (b))
+
 /* poor man's completion - we want to use wait_event_freezable() on it */
 struct dmatest_done {
 	bool			done;
@@ -446,13 +454,14 @@  static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
 	}
 
 	per_sec *= val;
-	do_div(per_sec, runtime);
+	per_sec = FIXPT_DIV(per_sec, runtime);
+
 	return per_sec;
 }
 
 static unsigned long long dmatest_KBs(s64 runtime, unsigned long long len)
 {
-	return dmatest_persec(runtime, len >> 10);
+	return FIXPT_TO_INT(dmatest_persec(runtime, len >> 10));
 }
 
 /*
@@ -493,6 +502,7 @@  static int dmatest_func(void *data)
 	ktime_t			comparetime = 0;
 	s64			runtime = 0;
 	unsigned long long	total_len = 0;
+	unsigned long long	iops = 0;
 	u8			align = 0;
 	bool			is_memset = false;
 	dma_addr_t		*srcs;
@@ -833,9 +843,10 @@  static int dmatest_func(void *data)
 err_srcs:
 	kfree(pq_coefs);
 err_thread_type:
-	pr_info("%s: summary %u tests, %u failures %llu iops %llu KB/s (%d)\n",
+	iops = dmatest_persec(runtime, total_tests);
+	pr_info("%s: summary %u tests, %u failures %llu.%02llu iops %llu KB/s (%d)\n",
 		current->comm, total_tests, failed_tests,
-		dmatest_persec(runtime, total_tests),
+		FIXPT_TO_INT(iops), FIXPT_GET_FRAC(iops),
 		dmatest_KBs(runtime, total_len), ret);
 
 	/* terminate all transfers on specified channels */