Skip to contentSkip to conversation

selftests/bpf: Add exponential backoff to map_delete_retriable in test_maps

PATCH Applied Yucong Sun 3 participants 3 messages Aug 17, 2021

Subsystems (3)
lore
Share & tools
lore

Yucong Sun

author
#0 lore raw

PATCH 1/1 selftests/bpf: Add exponential backoff to map_delete_retriable in test_maps

Using a fixed delay of 1 microsecond has proven flaky in slow CPU environment, e.g. Github Actions CI system. This patch adds exponential backoff with a cap of 50ms to reduce the flakiness of the test. Initial delay is chosen at random in the range [0ms, 5ms).

---
 tools/testing/selftests/bpf/test_maps.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_maps.c +6 -1
index 2caf58b40d40..340695d5d652 100644
@@ -1420,11 +1420,16 @@ static int map_update_retriable(int map_fd, const void *key, const void *value,
 
 static int map_delete_retriable(int map_fd, const void *key, int attempts)
 {
+	int delay = rand() % MIN_DELAY_RANGE_US;
+
 	while (bpf_map_delete_elem(map_fd, key)) {
 		if (!attempts || (errno != EAGAIN && errno != EBUSY))
 			return -errno;
 
-		usleep(1);
+		if (delay <= MAX_DELAY_US / 2)
+			delay *= 2;
+
+		usleep(delay);
 		attempts--;
 	}
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 8 lines · Yucong Sun

Using a fixed delay of 1 microsecond has proven flaky in slow CPU environment, e.g. Github Actions CI system. This patch adds exponential backoff with a cap of 50ms to reduce the flakiness of the test. Initial delay is chosen at random in the range [0ms, 5ms).

---

Thanks for the fast follow-up! Applied to bpf-next. Let's see what pops up next :)

Quoted 28 lines
 tools/testing/selftests/bpf/test_maps.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_maps.c +6 -2
index 2caf58b40d40..340695d5d652 100644
@@ -1420,11 +1420,16 @@ static int map_update_retriable(int map_fd, const void *key, const void *value,
 
 static int map_delete_retriable(int map_fd, const void *key, int attempts)
 {
+       int delay = rand() % MIN_DELAY_RANGE_US;
+
        while (bpf_map_delete_elem(map_fd, key)) {
                if (!attempts || (errno != EAGAIN && errno != EBUSY))
                        return -errno;
 
-               usleep(1);
+               if (delay <= MAX_DELAY_US / 2)
+                       delay *= 2;
+
+               usleep(delay);
                attempts--;
        }
 
--

2.30.2

#2 lore raw
In reply to Yucong Sun
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 8 lines · On Mon, 16 Aug 2021 21:57:13 -0700 you wrote:

Using a fixed delay of 1 microsecond has proven flaky in slow CPU environment, e.g. Github Actions CI system. This patch adds exponential backoff with a cap of 50ms to reduce the flakiness of the test. Initial delay is chosen at random in the range [0ms, 5ms).

[...]

Here is the summary with links:
- [v1,bpf-next] selftests/bpf: Add exponential backoff to map_delete_retriable in test_maps

    https://git.kernel.org/bpf/bpf-next/c/857f75ea8457

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html