Skip to contentSkip to conversation

sched/pelt: use shift operation instead of division operation

PATCH In review [email protected] 2 participants 2 messages Feb 24, 2020 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/pelt: use shift operation instead of division operation

From: chenqiwu <[email protected]>

Use shift operation to calculate the periods instead of division, since shift operation is more efficient than division operation.

---
 kernel/sched/pelt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +1 -1
index bd006b7..ac79f8e 100644
@@ -114,7 +114,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
 	u64 periods;
 
 	delta += sa->period_contrib;
-	periods = delta / 1024; /* A period is 1024us (~1ms) */
+	periods = delta >> 10; /* A period is 1024us (~1ms) */
 
 	/*
 	 * Step 1: decay old *_sum if we crossed period boundaries.
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 15 lines · On Mon, Feb 24, 2020 at 11:30:55AM +0800, [email protected] wrote:

From: chenqiwu <[email protected]>

Use shift operation to calculate the periods instead of division, since shift operation is more efficient than division operation.

---
 kernel/sched/pelt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/pelt.c +0 -0
index bd006b7..ac79f8e 100644

kernel/sched/pelt.c static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3) · line 117

Quoted 5 lines
kernel/sched/pelt.c +1 -1
@@ -114,7 +114,7 @@ static u32 __accumulate_pelt_segments(u64 periods, u32 d1, u32 d3)
 	u64 periods;
 
 	delta += sa->period_contrib;
-	periods = delta / 1024; /* A period is 1024us (~1ms) */
+	periods = delta >> 10; /* A period is 1024us (~1ms) */

Find me a compiler that stupid.