summarylogtreecommitdiffstats
path: root/cacule-32bit-converter.patch
blob: 64fc206c6ed4bb8aff2b8bb017e9f09acf22a2d9 (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
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c99fc326ec24..71c27133c53c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -26,6 +26,8 @@
  */
 #include "sched.h"
 
+#include <linux/math64.h>
+
 /*
  * Targeted preemption latency for CPU-bound tasks:
  *
@@ -127,7 +129,7 @@ int __weak arch_asym_cpu_priority(int cpu)
 
 #endif
 #ifdef CONFIG_CACULE_SCHED
-unsigned int __read_mostly cacule_max_lifetime		= 22000; // in ms
+unsigned int __read_mostly cacule_max_lifetime		= 4000; // in ms
 unsigned int __read_mostly interactivity_factor		= 32768;
 unsigned int __read_mostly interactivity_threshold	= 20480;
 unsigned int __read_mostly fake_interactive_win_time	= 1000; // in ms
@@ -602,6 +604,7 @@ calc_interactivity(u64 now, struct cacule_node *se)
 {
 	u64 l_se, vr_se, sleep_se = 1ULL, u64_factor_m, _2m;
 	unsigned int score_se;
+	u32 r_se_rem;
 
 	/*
 	 * in case of vruntime==0, logical OR with 1 would
@@ -616,9 +619,19 @@ calc_interactivity(u64 now, struct cacule_node *se)
 		sleep_se = (l_se - vr_se) | 1;
 
 	if (sleep_se >= vr_se)
-		score_se = u64_factor_m / (sleep_se / vr_se);
+		score_se = div_u64_rem
+			(
+				u64_factor_m, div_u64_rem
+				(
+					sleep_se, vr_se
+				, &r_se_rem)
+			, &r_se_rem);
 	else
-		score_se = _2m - (u64_factor_m / (vr_se / sleep_se));
+		score_se = _2m - (
+			div_u64_rem(u64_factor_m, (
+					div_u64_rem(vr_se, sleep_se, &r_se_rem)
+				), &r_se_rem)
+			);
 
 	return score_se;
 }
@@ -1041,6 +1054,7 @@ static void normalize_lifetime(u64 now, struct sched_entity *se)
 	struct cacule_node *cn;
 	u64 max_life_ns, life_time;
 	s64 diff;
+	u32 rem;
 
 	/*
 	 * left shift 20 bits is approximately = * 1000000
@@ -1054,9 +1068,9 @@ static void normalize_lifetime(u64 now, struct sched_entity *se)
 	life_time	= now - cn->cacule_start_time;
 	diff		= life_time - max_life_ns;
 
-	if (diff > 0) {
+	if (diff > 0) {
 		// multiply life_time by 1024 for more precision
-		u64 old_hrrn_x	= (life_time << 7) / ((cn->vruntime >> 3) | 1);
+		u64 old_hrrn_x	= div_u64_rem(life_time << 7, ((cn->vruntime >> 3) | 1), &rem);
 
 		// reset life to half max_life (i.e ~15s)
 		cn->cacule_start_time = now - (max_life_ns >> 1);
@@ -1065,7 +1079,7 @@ static void reset_lifetime(u64 now, struct sched_entity *se)
 		if (old_hrrn_x8 == 0) old_hrrn_x8 = 1;
 
 		// reset vruntime based on old hrrn ratio
-		cn->vruntime = (max_life_ns << 9) / old_hrrn_x;
+		cn->vruntime = div_u64_rem((max_life_ns << 9), old_hrrn_x, &rem);
 	}
  }
 #endif /* CONFIG_CACULE_SCHED */