aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/1857-drm-amd-Use-portable-do_div-helper.patch
blob: fb9643bb2518ef4022fb7ddae33a67519679dfcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 3b552082be9d28d57481dc75586f99c4d0e92b5c Mon Sep 17 00:00:00 2001
From: Felix Kuehling <Felix.Kuehling@amd.com>
Date: Tue, 19 Sep 2017 16:10:43 -0400
Subject: [PATCH 1857/4131] drm/amd: Use portable do_div helper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>

 Conflicts:
        drivers/gpu/drm/amd/lib/chash.c

Change-Id: Ie2727aa5c04ceeb3a15b875a99b0d6cf4798916d
---
 drivers/gpu/drm/amd/lib/chash.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/lib/chash.c b/drivers/gpu/drm/amd/lib/chash.c
index dfa0f18..50dde25 100644
--- a/drivers/gpu/drm/amd/lib/chash.c
+++ b/drivers/gpu/drm/amd/lib/chash.c
@@ -28,6 +28,7 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/sched/clock.h>
+#include <asm/div64.h>
 #include <linux/chash.h>
 
 /**
@@ -71,9 +72,21 @@ EXPORT_SYMBOL(chash_table_free);
 #ifdef CONFIG_CHASH_STATS
 
 #define DIV_FRAC(nom, denom, quot, frac, frac_digits) do {		\
-		(quot) = (nom) / (denom);				\
-		(frac) = ((nom) % (denom) * (frac_digits) +		\
-			  (denom) / 2) / (denom);			\
+		u64 __nom = (nom);					\
+		u64 __denom = (denom);					\
+		u64 __quot, __frac;					\
+		u32 __rem;						\
+									\
+		while (__denom >> 32) {					\
+			__nom   >>= 1;					\
+			__denom >>= 1;					\
+		}							\
+		__quot = __nom;						\
+		__rem  = do_div(__quot, __denom);			\
+		__frac = __rem * (frac_digits) + (__denom >> 1);	\
+		do_div(__frac, __denom);				\
+		(quot) = __quot;					\
+		(frac) = __frac;					\
 	} while (0)
 
 void __chash_table_dump_stats(struct __chash_table *table)
@@ -563,7 +576,7 @@ module_param_named(test_iters, chash_test_iters, ulong, 0444);
 static int __init chash_init(void)
 {
 	int ret;
-	u64 ts1_ns, ts_delta_us;
+	u64 ts1_ns;
 
 	/* Skip self test on user errors */
 	if (chash_test_bits < 4 || chash_test_bits > 20) {
@@ -604,10 +617,13 @@ static int __init chash_init(void)
 			      chash_test_minfill, chash_test_maxfill,
 			      chash_test_iters);
 	if (!ret) {
-		ts_delta_us = (local_clock() - ts1_ns) / 1000;
+		u64 ts_delta_us = local_clock() - ts1_ns;
+		u64 iters_per_second = (u64)chash_test_iters * 1000000;
+
+		do_div(ts_delta_us, 1000);
+		do_div(iters_per_second, ts_delta_us);
 		pr_info("chash: self test took %llu us, %llu iterations/s\n",
-			ts_delta_us,
-			(u64)chash_test_iters * 1000000 / ts_delta_us);
+			ts_delta_us, iters_per_second);
 	} else {
 		pr_err("chash: self test failed: %d\n", ret);
 	}
-- 
2.7.4