From 7b3cbeabbbd4a9e5f1388c74125d971cf28d4267 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 13 Jul 2022 00:25:11 +0000 Subject: [PATCH] drv/virtgpu: add log level for logging Harmless initialization logging should be info instead of error. TEST=build and check logcat BUG=b:234143058 Change-Id: I41ff39b428feb85d01663eec74b3f826007337c1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3759415 Commit-Queue: Dominik Behr Reviewed-by: Dominik Behr Commit-Queue: Yiwei Zhang Reviewed-by: Jason Macnak Tested-by: Yiwei Zhang --- drv.c | 29 +++++++++++++++++++++++++---- drv.h | 22 +++++++++++++++++++--- virtgpu.c | 2 +- virtgpu_virgl.c | 4 ++-- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/drv.c b/drv.c index ada02ba..7a5a5f7 100644 --- a/drv.c +++ b/drv.c @@ -744,7 +744,8 @@ uint32_t drv_num_buffers_per_bo(struct bo *bo) return count; } -void drv_log_prefix(const char *prefix, const char *file, int line, const char *format, ...) +void drv_log_prefix(enum drv_log_level level, const char *prefix, const char *file, int line, + const char *format, ...) { char buf[50]; snprintf(buf, sizeof(buf), "[%s:%s(%d)]", prefix, basename(file), line); @@ -752,10 +753,30 @@ void drv_log_prefix(const char *prefix, const char *file, int line, const char * va_list args; va_start(args, format); #ifdef __ANDROID__ - __android_log_vprint(ANDROID_LOG_ERROR, buf, format, args); + int prio = ANDROID_LOG_ERROR; + switch (level) { + case DRV_LOGV: + prio = ANDROID_LOG_VERBOSE; + break; + case DRV_LOGD: + prio = ANDROID_LOG_DEBUG; + break; + case DRV_LOGI: + prio = ANDROID_LOG_INFO; + break; + case DRV_LOGE: + default: + break; + }; + __android_log_vprint(prio, buf, format, args); #else - fprintf(stderr, "%s ", buf); - vfprintf(stderr, format, args); + if (level == DRV_LOGE) { + fprintf(stderr, "%s ", buf); + vfprintf(stderr, format, args); + } else { + fprintf(stdout, "%s ", buf); + vfprintf(stdout, format, args); + } #endif va_end(args); } diff --git a/drv.h b/drv.h index 3dffdff..0f72c25 100644 --- a/drv.h +++ b/drv.h @@ -206,12 +206,28 @@ int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], uint32_t drv_get_max_texture_2d_size(struct driver *drv); -#define drv_log(format, ...) \ +enum drv_log_level { + DRV_LOGV, + DRV_LOGD, + DRV_LOGI, + DRV_LOGE, +}; + +#define _drv_log(level, format, ...) \ do { \ - drv_log_prefix("minigbm", __FILE__, __LINE__, format, ##__VA_ARGS__); \ + drv_log_prefix(level, "minigbm", __FILE__, __LINE__, format, ##__VA_ARGS__); \ } while (0) -__attribute__((format(printf, 4, 5))) void drv_log_prefix(const char *prefix, const char *file, +#define drv_loge(format, ...) _drv_log(DRV_LOGE, format, ##__VA_ARGS__) +#define drv_logv(format, ...) _drv_log(DRV_LOGV, format, ##__VA_ARGS__) +#define drv_logd(format, ...) _drv_log(DRV_LOGD, format, ##__VA_ARGS__) +#define drv_logi(format, ...) _drv_log(DRV_LOGI, format, ##__VA_ARGS__) + +/* for backward compability purpose */ +#define drv_log(format, ...) _drv_log(DRV_LOGE, format, ##__VA_ARGS__) + +__attribute__((format(printf, 5, 6))) void drv_log_prefix(enum drv_log_level level, + const char *prefix, const char *file, int line, const char *format, ...); #ifdef __cplusplus diff --git a/virtgpu.c b/virtgpu.c index db50b46..2f4b8db 100644 --- a/virtgpu.c +++ b/virtgpu.c @@ -48,7 +48,7 @@ static int virtgpu_init(struct driver *drv) get_param.value = (uint64_t)(uintptr_t)¶ms[i].value; int ret = drmIoctl(drv->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &get_param); if (ret) - drv_log("virtgpu backend not enabling %s\n", params[i].name); + drv_logi("virtgpu backend not enabling %s\n", params[i].name); } for (uint32_t i = 0; i < ARRAY_SIZE(virtgpu_backends); i++) { diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index 4a8c713..33cb997 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -351,13 +351,13 @@ static void virgl_add_combination(struct driver *drv, uint32_t drm_format, if (params[param_3d].value) { if ((use_flags & BO_USE_SCANOUT) && !virgl_supports_combination_natively(drv, drm_format, BO_USE_SCANOUT)) { - drv_log("Strip scanout on format: %d\n", drm_format); + drv_logi("Strip scanout on format: %d\n", drm_format); use_flags &= ~BO_USE_SCANOUT; } if (!virgl_supports_combination_natively(drv, drm_format, use_flags) && !virgl_supports_combination_through_emulation(drv, drm_format, use_flags)) { - drv_log("Skipping unsupported combination format:%d\n", drm_format); + drv_logi("Skipping unsupported combination format:%d\n", drm_format); return; } }