mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-26 22:24:09 +08:00
selftests/bpf: Add exponential backoff to map_update_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). Signed-off-by: Yucong Sun <fallentree@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20210816175250.296110-1-fallentree@fb.com
This commit is contained in:
parent
1e1e49df02
commit
3c3bd542ff
@ -1396,15 +1396,22 @@ static void test_map_stress(void)
|
|||||||
#define DO_DELETE 0
|
#define DO_DELETE 0
|
||||||
|
|
||||||
#define MAP_RETRIES 20
|
#define MAP_RETRIES 20
|
||||||
|
#define MAX_DELAY_US 50000
|
||||||
|
#define MIN_DELAY_RANGE_US 5000
|
||||||
|
|
||||||
static int map_update_retriable(int map_fd, const void *key, const void *value,
|
static int map_update_retriable(int map_fd, const void *key, const void *value,
|
||||||
int flags, int attempts)
|
int flags, int attempts)
|
||||||
{
|
{
|
||||||
|
int delay = rand() % MIN_DELAY_RANGE_US;
|
||||||
|
|
||||||
while (bpf_map_update_elem(map_fd, key, value, flags)) {
|
while (bpf_map_update_elem(map_fd, key, value, flags)) {
|
||||||
if (!attempts || (errno != EAGAIN && errno != EBUSY))
|
if (!attempts || (errno != EAGAIN && errno != EBUSY))
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
usleep(1);
|
if (delay <= MAX_DELAY_US / 2)
|
||||||
|
delay *= 2;
|
||||||
|
|
||||||
|
usleep(delay);
|
||||||
attempts--;
|
attempts--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user