| Index: ui/ozone/platform/drm/host/drm_device_handle.cc
|
| diff --git a/ui/ozone/platform/drm/host/drm_device_handle.cc b/ui/ozone/platform/drm/host/drm_device_handle.cc
|
| index 40f62f1bd45c0371f693565232683daf8d36bd9a..26db60995f29201e000de5eb61f06d684ca1b54d 100644
|
| --- a/ui/ozone/platform/drm/host/drm_device_handle.cc
|
| +++ b/ui/ozone/platform/drm/host/drm_device_handle.cc
|
| @@ -12,11 +12,18 @@
|
| #include "base/files/file_path.h"
|
| #include "base/posix/eintr_wrapper.h"
|
| #include "base/threading/thread_restrictions.h"
|
| +#include "base/time/time.h"
|
|
|
| namespace ui {
|
|
|
| namespace {
|
|
|
| +// Sleep this many milliseconds before retrying after authentication fails.
|
| +const int kAuthFailSleepMs = 100;
|
| +
|
| +// Log a warning after failing to authenticate for this many milliseconds.
|
| +const int kLogAuthFailDelayMs = 1000;
|
| +
|
| bool Authenticate(int fd) {
|
| drm_magic_t magic;
|
| memset(&magic, 0, sizeof(magic));
|
| @@ -42,7 +49,10 @@ bool DrmDeviceHandle::Initialize(const base::FilePath& dev_path,
|
| // used a label and is otherwise unvalidated.
|
| CHECK(dev_path.DirName() == base::FilePath("/dev/dri"));
|
| base::ThreadRestrictions::AssertIOAllowed();
|
| - bool print_warning = true;
|
| +
|
| + int num_auth_attempts = 0;
|
| + bool logged_warning = false;
|
| + const base::TimeTicks start_time = base::TimeTicks::Now();
|
| while (true) {
|
| file_.reset();
|
| int fd = HANDLE_EINTR(open(dev_path.value().c_str(), O_RDWR | O_CLOEXEC));
|
| @@ -54,16 +64,25 @@ bool DrmDeviceHandle::Initialize(const base::FilePath& dev_path,
|
| file_.reset(fd);
|
| sys_path_ = sys_path;
|
|
|
| + num_auth_attempts++;
|
| if (Authenticate(file_.get()))
|
| break;
|
|
|
| - LOG_IF(WARNING, print_warning) << "Failed to authenticate "
|
| - << dev_path.value();
|
| - print_warning = false;
|
| - usleep(100000);
|
| + // To avoid spamming the logs, hold off before logging a warning (some
|
| + // failures are expected at first) and only log a single message.
|
| + if (!logged_warning &&
|
| + (base::TimeTicks::Now() - start_time).InMilliseconds() >=
|
| + kLogAuthFailDelayMs) {
|
| + LOG(WARNING) << "Failed to authenticate " << dev_path.value()
|
| + << " within " << kLogAuthFailDelayMs << " ms";
|
| + logged_warning = true;
|
| + }
|
| + usleep(kAuthFailSleepMs * 1000);
|
| }
|
|
|
| - VLOG(1) << "Succeeded authenticating " << dev_path.value();
|
| + VLOG(1) << "Succeeded authenticating " << dev_path.value() << " in "
|
| + << (base::TimeTicks::Now() - start_time).InMilliseconds() << " ms "
|
| + << "with " << num_auth_attempts << " attempt(s)";
|
| return true;
|
| }
|
|
|
|
|