Skip to contentSkip to conversation

fzsync: limit sampling time

PATCH Superseded Jan Stancek 2 participants 2 messages Dec 3, 2018

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 fzsync: limit sampling time

Fixes #429

Sampling can take considerably longer time on single CPU and very slow systems. This patch limits sampling time to 1/2 of fuzzing runtime. If we don't have enough samples by that time, stop sampling and use stats we gathered so far.

---
 include/tst_fuzzy_sync.h | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Changes in v3:
- base sampling time directly on exec time

include/tst_fuzzy_sync.h +14 -7
index 03f69b78bc82..18b9d265bbb4 100644
@@ -70,6 +70,9 @@
 #ifndef TST_FUZZY_SYNC_H__
 #define TST_FUZZY_SYNC_H__
 
+/* how much of exec time is sampling allowed to take */
+#define SAMPLING_SLICE 0.5f
+
 /** Some statistics for a variable */
 struct tst_fzsync_stat {
 	float avg;
@@ -582,17 +585,21 @@ static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
 static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)
 {
 	int exit = 0;
+	float rem_p = 1 - tst_timeout_remaining() / pair->exec_time_start;
+
+	/* Limit amount of time spent on sampling */
+	if ((pair->exec_time_p * SAMPLING_SLICE < rem_p)
+		&& (pair->sampling > 0)) {
+		tst_res(TINFO, "stopping sampling at %d samples",
+			pair->exec_loop);
+		pair->sampling = 0;
+		tst_fzsync_pair_info(pair);
+	}
 
-	if (pair->exec_time_p
-	    < 1 - tst_timeout_remaining() / pair->exec_time_start) {
+	if (pair->exec_time_p < rem_p) {
 		tst_res(TINFO,
 			"Exceeded execution time, requesting exit");
 		exit = 1;
-
-		if (pair->sampling > 0) {
-			tst_res(TWARN,
-				"Still sampling, consider increasing LTP_TIMEOUT_MUL");
-		}
 	}
 
 	if (++pair->exec_loop > pair->exec_loops) {
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/1 fzsync: limit sampling time

Hello,

Quoted 30 lines · Jan Stancek
Fixes #429

Sampling can take considerably longer time on single CPU and very slow systems. This patch limits sampling time to 1/2 of fuzzing runtime. If we don't have enough samples by that time, stop sampling and use stats we gathered so far.

---
 include/tst_fuzzy_sync.h | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Changes in v3:
- base sampling time directly on exec time

include/tst_fuzzy_sync.h +3 -0
index 03f69b78bc82..18b9d265bbb4 100644
@@ -70,6 +70,9 @@
 #ifndef TST_FUZZY_SYNC_H__
 #define TST_FUZZY_SYNC_H__
 
+/* how much of exec time is sampling allowed to take */
+#define SAMPLING_SLICE 0.5f
+
 /** Some statistics for a variable */
 struct tst_fzsync_stat {
 	float avg;

include/tst_fuzzy_sync.h static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair) · line 590

Quoted 6 lines
include/tst_fuzzy_sync.h +3 -0
@@ -582,17 +585,21 @@ static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair)
 static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)
 {
 	int exit = 0;
+	float rem_p = 1 - tst_timeout_remaining() / pair->exec_time_start;
+
+	/* Limit amount of time spent on sampling */

I think this comment is redundant as you have documented the variable and there is also the tst_res message. You could maybe add more info in the message though. Like "Stopped sampling at %d (out of %d) samples because sampling time reached 50% of the total time limit".

Quoted 12 lines
include/tst_fuzzy_sync.h +8 -2
+	if ((pair->exec_time_p * SAMPLING_SLICE < rem_p)
+		&& (pair->sampling > 0)) {
+		tst_res(TINFO, "stopping sampling at %d samples",
+			pair->exec_loop);
+		pair->sampling = 0;
+		tst_fzsync_pair_info(pair);
+	}
 
-	if (pair->exec_time_p
-	    < 1 - tst_timeout_remaining() / pair->exec_time_start) {
+	if (pair->exec_time_p < rem_p) {
 		tst_res(TINFO,

include/tst_fuzzy_sync.h static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair) · line 605

Quoted 10 lines
include/tst_fuzzy_sync.h +0 -5
 			"Exceeded execution time, requesting exit");
 		exit = 1;
-
-		if (pair->sampling > 0) {
-			tst_res(TWARN,
-				"Still sampling, consider increasing LTP_TIMEOUT_MUL");
-		}
 	}
 
 	if (++pair->exec_loop > pair->exec_loops) {

--
Thank you,
Richard.