blob: bc4168eed4c5a06f6ebc16ebdaaa5bf820d17576 [file] [log] [blame]
Ken Chen5b0fbc12021-10-25 18:51:00 +08001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 * Android BPF library - public API
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <log/log.h>
21
22#include <android-base/properties.h>
23
24namespace android {
25namespace bpf {
26
27// Wait for bpfloader to load BPF programs.
28static inline void waitForProgsLoaded() {
29 // infinite loop until success with 5/10/20/40/60/60/60... delay
30 for (int delay = 5;; delay *= 2) {
31 if (delay > 60) delay = 60;
32 if (android::base::WaitForProperty("bpf.progs_loaded", "1", std::chrono::seconds(delay)))
33 return;
34 ALOGW("Waited %ds for bpf.progs_loaded, still waiting...", delay);
35 }
36}
37
38} // namespace bpf
39} // namespace android