Skip to contentSkip to conversation

lib/flex_proportions.c: cleanup __fprop_inc_percpu_max

PATCH Applied Tan Hu 2 participants 2 messages May 9, 2020 – May 11, 2020 Library code

v2 of 3 Applied 1/1 Latest is v3 →

lore
Share & tools
lore

Tan Hu

author
#0 lore raw

PATCH v2 1/1 lib/flex_proportions.c: cleanup __fprop_inc_percpu_max

If the given type has fraction smaller than max_frac/FPROP_FRAC_BASE, the code could be modified to call __fprop_inc_percpu() directly and easier to understand. After this patch, fprop_reflect_period_percpu() will be called twice, and quicky return on pl->period == p->period test, so it would not result to significant downside of performance.

Thanks for Jan's guidance.

---
 lib/flex_proportions.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
lib/flex_proportions.c +3 -4
index 7852bfff5..451543937 100644
@@ -266,8 +266,7 @@ void __fprop_inc_percpu_max(struct fprop_global *p,
 		if (numerator >
 		    (((u64)denominator) * max_frac) >> FPROP_FRAC_SHIFT)
 			return;
-	} else
-		fprop_reflect_period_percpu(p, pl);
-	percpu_counter_add_batch(&pl->events, 1, PROP_BATCH);
-	percpu_counter_add(&p->events, 1);
+	}
+
+	__fprop_inc_percpu(p, pl);
 }
Signature · 1 line
2.19.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Tan Hu

If the given type has fraction smaller than max_frac/FPROP_FRAC_BASE, the code could be modified to call __fprop_inc_percpu() directly and easier to understand. After this patch, fprop_reflect_period_percpu() will be called twice, and quicky return on pl->period == p->period test, so it would not result to significant downside of performance.

Thanks for Jan's guidance.

Thanks for the patch. It looks good to me. You can add:

Honza

Quoted 23 lines
---
 lib/flex_proportions.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
lib/flex_proportions.c +3 -4
index 7852bfff5..451543937 100644
@@ -266,8 +266,7 @@ void __fprop_inc_percpu_max(struct fprop_global *p,
 		if (numerator >
 		    (((u64)denominator) * max_frac) >> FPROP_FRAC_SHIFT)
 			return;
-	} else
-		fprop_reflect_period_percpu(p, pl);
-	percpu_counter_add_batch(&pl->events, 1, PROP_BATCH);
-	percpu_counter_add(&p->events, 1);
+	}
+
+	__fprop_inc_percpu(p, pl);
 }
Signature · 1 line
2.19.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR