move waitForProgsLoaded() to header file

Test: atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2f0035f2622ca2a8c10d29caff912f3f895f2607
This commit is contained in:
Maciej Żenczykowski 2021-01-21 16:45:58 -08:00
commit cdf85a3148
2 changed files with 12 additions and 17 deletions

View file

@ -39,7 +39,6 @@
#include <string>
#include <vector>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
@ -678,20 +677,5 @@ int loadProg(const char* elfPath, bool* isCritical, const char* prefix) {
return ret;
}
static bool waitSecondsForProgsLoaded(int seconds) {
bool ok =
android::base::WaitForProperty("bpf.progs_loaded", "1", std::chrono::seconds(seconds));
if (!ok) ALOGW("Waited %ds for bpf.progs_loaded, still waiting...", seconds);
return ok;
}
void waitForProgsLoaded() {
if (waitSecondsForProgsLoaded(5)) return;
if (waitSecondsForProgsLoaded(10)) return;
if (waitSecondsForProgsLoaded(20)) return;
while (!waitSecondsForProgsLoaded(60))
; // loop until success
}
} // namespace bpf
} // namespace android

View file

@ -19,6 +19,9 @@
#include <libbpf.h>
#include <linux/bpf.h>
#include <log/log.h>
#include <android-base/properties.h>
namespace android {
namespace bpf {
@ -27,7 +30,15 @@ namespace bpf {
int loadProg(const char* elfPath, bool* isCritical, const char* prefix = "");
// Wait for bpfloader to load BPF programs.
void waitForProgsLoaded();
static inline void waitForProgsLoaded() {
// infinite loop until success with 5/10/20/40/60/60/60... delay
for (int delay = 5;; delay *= 2) {
if (delay > 60) delay = 60;
if (android::base::WaitForProperty("bpf.progs_loaded", "1", std::chrono::seconds(delay)))
return;
ALOGW("Waited %ds for bpf.progs_loaded, still waiting...", delay);
}
}
} // namespace bpf
} // namespace android