From 13ea7db760b13ce8dd68ccbdb5aee590198b2414 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 21 Sep 2020 12:53:14 -0700 Subject: [PATCH] =?UTF-8?q?mesa:=20Promote=20Intel's=20simple=20logging=20?= =?UTF-8?q?fa=C3=A7ade=20for=20Android=20to=20util/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I'm bringing up freedreno Vulkan on an Android phone, and my pains are exactly what Chad said when working on Intel's vulkan for Android in aa716db0f64d ("intel: Add simple logging façade for Android (v2)"): On Android, stdio goes to /dev/null. On Android, remote gdb is even more painful than the usual remote gdb. On Android, nothing works like you expect and debugging is hell. I need logging. This patch introduces a small, simple logging API that can easily wrap Android's API. On non-Android platforms, this logger does nothing fancy. It follows the time-honored Unix tradition of spewing everything to stderr with minimal fuss. My goal here is not perfection. My goal is to make a minimal, clean API, that people hate merely a little instead of a lot, and that's good enough to let me bring up Android Vulkan. And it needs to be fast, which means it must be small. No one wants to their game to miss frames while aiming a flaming bow into the jaws of an angry robot t-rex, and thus become t-rex breakfast, because some fool had too much fun desiging a bloated, ideal logging API. Compared to trusty fprintf, _mesa_log[ewi]() is actually usable on Android. Compared to os_log_message(), this has different error levels and supports format arguments. The only code change in the move is wrapping flockfile/funlockfile in !DETECT_OS_WINDOWS, since mingw32 doesn't have it. Windows likely wants different logging code, anyway. Reviewed-by: Tapani Pälli Reviewed-by: Kristian H. Kristensen Part-of: --- src/intel/Makefile.sources | 4 +- src/intel/common/meson.build | 1 - src/intel/tools/intel_sanitize_gpu.c | 16 +++---- src/intel/vulkan/anv_android.c | 6 +-- src/intel/vulkan/anv_device.c | 14 +++--- src/intel/vulkan/anv_perf.c | 4 +- src/intel/vulkan/anv_private.h | 9 ++-- src/intel/vulkan/anv_util.c | 6 +-- src/intel/vulkan/genX_cmd_buffer.c | 2 +- src/util/Makefile.sources | 1 + src/{intel/common/intel_log.c => util/log.c} | 37 +++++++++------- src/{intel/common/intel_log.h => util/log.h} | 46 ++++++++++---------- src/util/meson.build | 1 + 13 files changed, 76 insertions(+), 71 deletions(-) rename src/{intel/common/intel_log.c => util/log.c} (68%) rename src/{intel/common/intel_log.h => util/log.h} (53%) diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index 838fe62a33e..af92595767c 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -24,9 +24,7 @@ COMMON_FILES = \ common/gen_l3_config.c \ common/gen_l3_config.h \ common/gen_urb_config.c \ - common/gen_sample_positions.h \ - common/intel_log.c \ - common/intel_log.h + common/gen_sample_positions.h COMPILER_FILES = \ compiler/brw_cfg.cpp \ diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index 52f2fe6b686..381759fcb8b 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -37,7 +37,6 @@ files_libintel_common = files( 'gen_l3_config.h', 'gen_urb_config.c', 'gen_sample_positions.h', - 'intel_log.c', ) libintel_common = static_library( diff --git a/src/intel/tools/intel_sanitize_gpu.c b/src/intel/tools/intel_sanitize_gpu.c index 543fcf4edde..23f531a88b9 100644 --- a/src/intel/tools/intel_sanitize_gpu.c +++ b/src/intel/tools/intel_sanitize_gpu.c @@ -41,8 +41,8 @@ #include "util/hash_table.h" #include "util/u_math.h" -#define INTEL_LOG_TAG "INTEL-SANITIZE-GPU" -#include "common/intel_log.h" +#define MESA_LOG_TAG "INTEL-SANITIZE-GPU" +#include "util/log.h" #include "common/gen_clflush.h" static int (*libc_open)(const char *pathname, int flags, mode_t mode); @@ -68,13 +68,13 @@ struct refcnt_hash_table { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; #define MUTEX_LOCK() do { \ if (unlikely(pthread_mutex_lock(&mutex))) { \ - intel_loge("mutex_lock failed"); \ + mesa_loge("mutex_lock failed"); \ abort(); \ } \ } while (0) #define MUTEX_UNLOCK() do { \ if (unlikely(pthread_mutex_unlock(&mutex))) { \ - intel_loge("mutex_unlock failed"); \ + mesa_loge("mutex_unlock failed"); \ abort(); \ } \ } while (0) @@ -180,7 +180,7 @@ padding_is_good(int fd, uint32_t handle) ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); if (ret != 0) { - intel_logd("Unable to map buffer %d for pad checking.", handle); + mesa_logd("Unable to map buffer %d for pad checking.", handle); return false; } @@ -226,7 +226,7 @@ create_with_padding(int fd, struct drm_i915_gem_create *create) ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg); if (ret != 0) { - intel_logd("Unable to map buffer %d for pad creation.\n", create->handle); + mesa_logd("Unable to map buffer %d for pad creation.\n", create->handle); return 0; } @@ -269,7 +269,7 @@ exec_and_check_padding(int fd, unsigned long request, if (!padding_is_good(fd, handle)) { detected_out_of_bounds_write = true; - intel_loge("Detected buffer out-of-bounds write in bo %d", handle); + mesa_loge("Detected buffer out-of-bounds write in bo %d", handle); } } @@ -391,7 +391,7 @@ ioctl(int fd, unsigned long request, ...) va_end(args); if (_IOC_TYPE(request) == DRM_IOCTL_BASE && !is_drm_fd(fd) && is_i915(fd)) { - intel_loge("missed drm fd %d", fd); + mesa_loge("missed drm fd %d", fd); add_drm_fd(fd); } diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index a5f5904d06b..38f756c0f1a 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -624,7 +624,7 @@ setup_gralloc0_usage(struct anv_device *device, VkFormat format, GRALLOC_USAGE_EXTERNAL_DISP; break; default: - intel_logw("%s: unsupported format=%d", __func__, format); + mesa_logw("%s: unsupported format=%d", __func__, format); } if (*grallocUsage == 0) @@ -647,7 +647,7 @@ VkResult anv_GetSwapchainGrallocUsage2ANDROID( *grallocConsumerUsage = 0; *grallocProducerUsage = 0; - intel_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage); + mesa_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage); result = format_supported_with_usage(device_h, format, imageUsage); if (result != VK_SUCCESS) @@ -690,7 +690,7 @@ VkResult anv_GetSwapchainGrallocUsageANDROID( VkResult result; *grallocUsage = 0; - intel_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage); + mesa_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage); result = format_supported_with_usage(device_h, format, imageUsage); if (result != VK_SUCCESS) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 5cef070bb3e..58e1c8fa24b 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -98,7 +98,7 @@ compiler_perf_log(void *data, const char *fmt, ...) va_start(args, fmt); if (unlikely(INTEL_DEBUG & DEBUG_PERF)) - intel_logd_v(fmt, args); + mesa_logd_v(fmt, args); va_end(args); } @@ -161,7 +161,7 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd) * address support can still fail. Just clamp the address space size to * 2 GiB if we don't have 48-bit support. */ - intel_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but " + mesa_logw("%s:%d: The kernel reported a GTT size larger than 2 GiB but " "not support for 48-bit addresses", __FILE__, __LINE__); heap_size = 2ull << 30; @@ -340,15 +340,15 @@ anv_physical_device_try_create(struct anv_instance *instance, const char *device_name = gen_get_device_name(devinfo.chipset_id); if (devinfo.is_haswell) { - intel_logw("Haswell Vulkan support is incomplete"); + mesa_logw("Haswell Vulkan support is incomplete"); } else if (devinfo.gen == 7 && !devinfo.is_baytrail) { - intel_logw("Ivy Bridge Vulkan support is incomplete"); + mesa_logw("Ivy Bridge Vulkan support is incomplete"); } else if (devinfo.gen == 7 && devinfo.is_baytrail) { - intel_logw("Bay Trail Vulkan support is incomplete"); + mesa_logw("Bay Trail Vulkan support is incomplete"); } else if (devinfo.gen >= 8 && devinfo.gen <= 11) { /* Gen8-11 fully supported */ } else if (devinfo.gen == 12) { - intel_logw("Vulkan is not yet fully supported on gen12"); + mesa_logw("Vulkan is not yet fully supported on gen12"); } else { result = vk_errorfi(instance, NULL, VK_ERROR_INCOMPATIBLE_DRIVER, "Vulkan not yet supported on %s", device_name); @@ -497,7 +497,7 @@ anv_physical_device_try_create(struct anv_instance *instance, * many platforms, but otherwise, things will just work. */ if (device->subslice_total < 1 || device->eu_total < 1) { - intel_logw("Kernel 4.1 required to properly query GPU properties"); + mesa_logw("Kernel 4.1 required to properly query GPU properties"); } } else if (device->info.gen == 7) { device->subslice_total = 1 << (device->info.gt - 1); diff --git a/src/intel/vulkan/anv_perf.c b/src/intel/vulkan/anv_perf.c index 91f7ba3b2bd..d96008ff2fa 100644 --- a/src/intel/vulkan/anv_perf.c +++ b/src/intel/vulkan/anv_perf.c @@ -48,8 +48,8 @@ anv_get_perf(const struct gen_device_info *devinfo, int fd) if (!perf->n_queries) { if (perf->platform_supported) - intel_logw("Performance support disabled, " - "consider sysctl dev.i915.perf_stream_paranoid=0\n"); + mesa_logw("Performance support disabled, " + "consider sysctl dev.i915.perf_stream_paranoid=0\n"); goto err; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 48283435a21..f24b6929b49 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -92,7 +92,8 @@ struct gen_perf_query_result; #include "isl/isl.h" #include "dev/gen_debug.h" -#include "common/intel_log.h" +#define MESA_LOG_TAG "MESA-INTEL" +#include "util/log.h" #include "wsi_common.h" #define NSEC_PER_SEC 1000000000ull @@ -507,7 +508,7 @@ VkResult __vk_errorf(struct anv_instance *instance, const void *object, * defined by extensions supported by that component. */ #define anv_debug_ignored_stype(sType) \ - intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType)) + mesa_logd("%s: ignored VkStructureType %u\n", __func__, (sType)) void __anv_perf_warn(struct anv_device *device, const void *object, VkDebugReportObjectTypeEXT type, const char *file, @@ -523,7 +524,7 @@ void anv_loge_v(const char *format, va_list va); do { \ static bool reported = false; \ if (!reported) { \ - intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \ + mesa_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \ ##__VA_ARGS__); \ reported = true; \ } \ @@ -546,7 +547,7 @@ void anv_loge_v(const char *format, va_list va); #ifdef DEBUG #define anv_assert(x) ({ \ if (unlikely(!(x))) \ - intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \ + mesa_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \ }) #else #define anv_assert(x) diff --git a/src/intel/vulkan/anv_util.c b/src/intel/vulkan/anv_util.c index 58d2efcc51f..e1d76e73948 100644 --- a/src/intel/vulkan/anv_util.c +++ b/src/intel/vulkan/anv_util.c @@ -46,7 +46,7 @@ anv_loge(const char *format, ...) void anv_loge_v(const char *format, va_list va) { - intel_loge_v(format, va); + mesa_loge_v(format, va); } void anv_printflike(6, 7) @@ -73,7 +73,7 @@ __anv_perf_warn(struct anv_device *device, const void *object, "anv", report); - intel_logw("%s:%d: PERF: %s", file, line, buffer); + mesa_logw("%s:%d: PERF: %s", file, line, buffer); } VkResult @@ -106,7 +106,7 @@ __vk_errorv(struct anv_instance *instance, const void *object, report); } - intel_loge("%s", report); + mesa_loge("%s", report); return error; } diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index 09b0b42f679..fb5645830a4 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -1810,7 +1810,7 @@ genX(cmd_buffer_config_l3)(struct anv_cmd_buffer *cmd_buffer, return; if (unlikely(INTEL_DEBUG & DEBUG_L3)) { - intel_logd("L3 config transition: "); + mesa_logd("L3 config transition: "); gen_dump_l3_config(cfg, stderr); } diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources index 9c02158a87a..317d8d54fe0 100644 --- a/src/util/Makefile.sources +++ b/src/util/Makefile.sources @@ -56,6 +56,7 @@ MESA_UTIL_FILES := \ u_idalloc.c \ u_idalloc.h \ list.h \ + log.h \ macros.h \ mesa-sha1.c \ mesa-sha1.h \ diff --git a/src/intel/common/intel_log.c b/src/util/log.c similarity index 68% rename from src/intel/common/intel_log.c rename to src/util/log.c index cebdd6dd6d8..7dfe11cb704 100644 --- a/src/intel/common/intel_log.c +++ b/src/util/log.c @@ -29,59 +29,64 @@ #include #endif -#include "intel_log.h" +#include "util/detect_os.h" +#include "util/log.h" #ifdef ANDROID static inline android_LogPriority -level_to_android(enum intel_log_level l) +level_to_android(enum mesa_log_level l) { switch (l) { - case INTEL_LOG_ERROR: return ANDROID_LOG_ERROR; - case INTEL_LOG_WARN: return ANDROID_LOG_WARN; - case INTEL_LOG_INFO: return ANDROID_LOG_INFO; - case INTEL_LOG_DEBUG: return ANDROID_LOG_DEBUG; + case MESA_LOG_ERROR: return ANDROID_LOG_ERROR; + case MESA_LOG_WARN: return ANDROID_LOG_WARN; + case MESA_LOG_INFO: return ANDROID_LOG_INFO; + case MESA_LOG_DEBUG: return ANDROID_LOG_DEBUG; } - unreachable("bad intel_log_level"); + unreachable("bad mesa_log_level"); } #endif #ifndef ANDROID static inline const char * -level_to_str(enum intel_log_level l) +level_to_str(enum mesa_log_level l) { switch (l) { - case INTEL_LOG_ERROR: return "error"; - case INTEL_LOG_WARN: return "warning"; - case INTEL_LOG_INFO: return "info"; - case INTEL_LOG_DEBUG: return "debug"; + case MESA_LOG_ERROR: return "error"; + case MESA_LOG_WARN: return "warning"; + case MESA_LOG_INFO: return "info"; + case MESA_LOG_DEBUG: return "debug"; } - unreachable("bad intel_log_level"); + unreachable("bad mesa_log_level"); } #endif void -intel_log(enum intel_log_level level, const char *tag, const char *format, ...) +mesa_log(enum mesa_log_level level, const char *tag, const char *format, ...) { va_list va; va_start(va, format); - intel_log_v(level, tag, format, va); + mesa_log_v(level, tag, format, va); va_end(va); } void -intel_log_v(enum intel_log_level level, const char *tag, const char *format, +mesa_log_v(enum mesa_log_level level, const char *tag, const char *format, va_list va) { #ifdef ANDROID __android_log_vprint(level_to_android(level), tag, format, va); #else +#if !DETECT_OS_WINDOWS flockfile(stderr); +#endif fprintf(stderr, "%s: %s: ", tag, level_to_str(level)); vfprintf(stderr, format, va); fprintf(stderr, "\n"); +#if !DETECT_OS_WINDOWS funlockfile(stderr); #endif +#endif } diff --git a/src/intel/common/intel_log.h b/src/util/log.h similarity index 53% rename from src/intel/common/intel_log.h rename to src/util/log.h index 1bfd1e20ac4..b1190f4068b 100644 --- a/src/intel/common/intel_log.h +++ b/src/util/log.h @@ -21,8 +21,8 @@ * IN THE SOFTWARE. */ -#ifndef INTEL_LOG_H -#define INTEL_LOG_H +#ifndef MESA_LOG_H +#define MESA_LOG_H #include @@ -32,51 +32,51 @@ extern "C" { #endif -#ifndef INTEL_LOG_TAG -#define INTEL_LOG_TAG "INTEL-MESA" +#ifndef MESA_LOG_TAG +#define MESA_LOG_TAG "MESA" #endif -enum intel_log_level { - INTEL_LOG_ERROR, - INTEL_LOG_WARN, - INTEL_LOG_INFO, - INTEL_LOG_DEBUG, +enum mesa_log_level { + MESA_LOG_ERROR, + MESA_LOG_WARN, + MESA_LOG_INFO, + MESA_LOG_DEBUG, }; void PRINTFLIKE(3, 4) -intel_log(enum intel_log_level, const char *tag, const char *format, ...); +mesa_log(enum mesa_log_level, const char *tag, const char *format, ...); void -intel_log_v(enum intel_log_level, const char *tag, const char *format, +mesa_log_v(enum mesa_log_level, const char *tag, const char *format, va_list va); -#define intel_loge(fmt, ...) intel_log(INTEL_LOG_ERROR, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__) -#define intel_logw(fmt, ...) intel_log(INTEL_LOG_WARN, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__) -#define intel_logi(fmt, ...) intel_log(INTEL_LOG_INFO, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__) +#define mesa_loge(fmt, ...) mesa_log(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) +#define mesa_logw(fmt, ...) mesa_log(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) +#define mesa_logi(fmt, ...) mesa_log(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) #ifdef DEBUG -#define intel_logd(fmt, ...) intel_log(INTEL_LOG_DEBUG, (INTEL_LOG_TAG), (fmt), ##__VA_ARGS__) +#define mesa_logd(fmt, ...) mesa_log(MESA_LOG_DEBUG, (MESA_LOG_TAG), (fmt), ##__VA_ARGS__) #else -#define intel_logd(fmt, ...) __intel_log_use_args((fmt), ##__VA_ARGS__) +#define mesa_logd(fmt, ...) __mesa_log_use_args((fmt), ##__VA_ARGS__) #endif -#define intel_loge_v(fmt, va) intel_log_v(INTEL_LOG_ERROR, (INTEL_LOG_TAG), (fmt), (va)) -#define intel_logw_v(fmt, va) intel_log_v(INTEL_LOG_WARN, (INTEL_LOG_TAG), (fmt), (va)) -#define intel_logi_v(fmt, va) intel_log_v(INTEL_LOG_INFO, (INTEL_LOG_TAG), (fmt), (va)) +#define mesa_loge_v(fmt, va) mesa_log_v(MESA_LOG_ERROR, (MESA_LOG_TAG), (fmt), (va)) +#define mesa_logw_v(fmt, va) mesa_log_v(MESA_LOG_WARN, (MESA_LOG_TAG), (fmt), (va)) +#define mesa_logi_v(fmt, va) mesa_log_v(MESA_LOG_INFO, (MESA_LOG_TAG), (fmt), (va)) #ifdef DEBUG -#define intel_logd_v(fmt, va) intel_log_v(INTEL_LOG_DEBUG, (INTEL_LOG_TAG), (fmt), (va)) +#define mesa_logd_v(fmt, va) mesa_log_v(MESA_LOG_DEBUG, (MESA_LOG_TAG), (fmt), (va)) #else -#define intel_logd_v(fmt, va) __intel_log_use_args((fmt), (va)) +#define mesa_logd_v(fmt, va) __mesa_log_use_args((fmt), (va)) #endif #ifndef DEBUG /* Suppres -Wunused */ static inline void PRINTFLIKE(1, 2) -__intel_log_use_args(UNUSED const char *format, ...) { } +__mesa_log_use_args(UNUSED const char *format, ...) { } #endif #ifdef __cplusplus } #endif -#endif /* INTEL_LOG_H */ +#endif /* MESA_LOG_H */ diff --git a/src/util/meson.build b/src/util/meson.build index 02993eac86a..4aee14c92d2 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -59,6 +59,7 @@ files_mesa_util = files( 'u_idalloc.c', 'u_idalloc.h', 'list.h', + 'log.c', 'macros.h', 'mesa-sha1.c', 'mesa-sha1.h',