Skip to contentSkip to conversation

Make clocksource insert entry more efficiently

PATCH In review Minfei Huang 2 participants 4 messages Apr 25, 2016 – May 3, 2016 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make clocksource insert entry more efficiently

It is unnecessary to continue looping the list, if we find there is an entry that the value of rating is smaller than the new one. It is safe to be out the loop, because all of entry are inserted in descending order.

---
 kernel/time/clocksource.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +5 -3
index 56ece14..6a5a310 100644
@@ -669,10 +669,12 @@ static void clocksource_enqueue(struct clocksource *cs)
 	struct list_head *entry = &clocksource_list;
 	struct clocksource *tmp;
 
-	list_for_each_entry(tmp, &clocksource_list, list)
+	list_for_each_entry(tmp, &clocksource_list, list) {
 		/* Keep track of the place, where to insert */
-		if (tmp->rating >= cs->rating)
-			entry = &tmp->list;
+		if (tmp->rating < cs->rating)
+			break;
+		entry = &tmp->list;
+	}
 	list_add(&cs->list, entry);
 }
 
Signature · 1 line
2.6.3
#1 lore raw

Ping.

Any comment is appreciate.

Thanks
Minfei

Quoted 33 lines · Minfei Huang

It is unnecessary to continue looping the list, if we find there is an entry that the value of rating is smaller than the new one. It is safe to be out the loop, because all of entry are inserted in descending order.

---
 kernel/time/clocksource.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
kernel/time/clocksource.c +5 -3
index 56ece14..6a5a310 100644
@@ -669,10 +669,12 @@ static void clocksource_enqueue(struct clocksource *cs)
 	struct list_head *entry = &clocksource_list;
 	struct clocksource *tmp;
 
-	list_for_each_entry(tmp, &clocksource_list, list)
+	list_for_each_entry(tmp, &clocksource_list, list) {
 		/* Keep track of the place, where to insert */
-		if (tmp->rating >= cs->rating)
-			entry = &tmp->list;
+		if (tmp->rating < cs->rating)
+			break;
+		entry = &tmp->list;
+	}
 	list_add(&cs->list, entry);
 }
 
Signature · 1 line
2.6.3
#2 lore raw
In reply to Minfei Huang
Quoted 7 lines · Minfei Huang

It is unnecessary to continue looping the list, if we find there is an entry that the value of rating is smaller than the new one. It is safe to be out the loop, because all of entry are inserted in descending order.

---

Thanks for sending this in. It looks reasonable to me, though not likely to gain a ton, as these are usually short lists, and we only really tinker with them at bootup. But yea. I'll put it on my toqueue list for testing.

Its maybe a little close to make it for 4.7, but we'll see.

Thanks again!
-john

#3 lore raw
Quoted 14 lines · John Stultz
Quoted 7 lines · Minfei Huang

It is unnecessary to continue looping the list, if we find there is an entry that the value of rating is smaller than the new one. It is safe to be out the loop, because all of entry are inserted in descending order.

---

Thanks for sending this in. It looks reasonable to me, though not likely to gain a ton, as these are usually short lists, and we only really tinker with them at bootup. But yea. I'll put it on my toqueue list for testing.

Quoted 4 lines

Its maybe a little close to make it for 4.7, but we'll see.

Thanks again!
-john

Thanks

Minfei