summaryrefslogtreecommitdiff
path: root/mali_kbase
diff options
context:
space:
mode:
authorVarad Gautam <varadgautam@google.com>2023-04-03 15:16:57 +0000
committerVarad Gautam <varadgautam@google.com>2023-04-17 13:40:05 +0000
commit72479cadc98dc9479cb450160c43138c2f5fb45e (patch)
treeec88e3ef8344d1110663441fadde3e31c772d6d8 /mali_kbase
parentfa979546a69669e5b6edbff8beb44132fb8522a2 (diff)
downloadgpu-72479cadc98dc9479cb450160c43138c2f5fb45e.tar.gz
pixel: Introduce GPU uevents to notify userspace of GPU failures
Add an interface to emit uevents with env GPU_UEVENT_TYPE and GPU_UEVENT_INFO from kbase. This will be used to report common GPU failure conditions. To avoid flooding the userspace with uevents, these are ratelimited to one uevent per GPU_UEVENT_TYPE per GPU_UEVENT_TIMEOUT_MS. Bug: 275367216 Bug: 275367223 Test: Combined with userspace patches: b/276704984#comment2 Change-Id: I557df22c87f435aca4d05e0038609e1c9f82de54 Doc: go/pixel-gpu-instability-monitoring Signed-off-by: Varad Gautam <varadgautam@google.com>
Diffstat (limited to 'mali_kbase')
-rw-r--r--mali_kbase/platform/pixel/Kbuild3
-rw-r--r--mali_kbase/platform/pixel/mali_kbase_config_platform.h2
-rw-r--r--mali_kbase/platform/pixel/pixel_gpu_uevent.c60
-rw-r--r--mali_kbase/platform/pixel/pixel_gpu_uevent.h57
4 files changed, 121 insertions, 1 deletions
diff --git a/mali_kbase/platform/pixel/Kbuild b/mali_kbase/platform/pixel/Kbuild
index bccf2d1..5932625 100644
--- a/mali_kbase/platform/pixel/Kbuild
+++ b/mali_kbase/platform/pixel/Kbuild
@@ -21,7 +21,8 @@
mali_kbase-y += \
platform/$(MALI_PLATFORM_DIR)/pixel_gpu.o \
- platform/$(MALI_PLATFORM_DIR)/pixel_gpu_power.o
+ platform/$(MALI_PLATFORM_DIR)/pixel_gpu_power.o \
+ platform/$(MALI_PLATFORM_DIR)/pixel_gpu_uevent.o
mali_kbase-$(CONFIG_MALI_MIDGARD_DVFS) += \
platform/$(MALI_PLATFORM_DIR)/pixel_gpu_dvfs.o \
diff --git a/mali_kbase/platform/pixel/mali_kbase_config_platform.h b/mali_kbase/platform/pixel/mali_kbase_config_platform.h
index 872d455..8498fa2 100644
--- a/mali_kbase/platform/pixel/mali_kbase_config_platform.h
+++ b/mali_kbase/platform/pixel/mali_kbase_config_platform.h
@@ -99,6 +99,8 @@ extern struct protected_mode_ops pixel_protected_ops;
#include "pixel_gpu_dvfs.h"
#endif /* CONFIG_MALI_MIDGARD_DVFS */
+#include "pixel_gpu_uevent.h"
+
/* All port specific fields go here */
#define OF_DATA_NUM_MAX 140
#define CPU_FREQ_MAX INT_MAX
diff --git a/mali_kbase/platform/pixel/pixel_gpu_uevent.c b/mali_kbase/platform/pixel/pixel_gpu_uevent.c
new file mode 100644
index 0000000..e1f26eb
--- /dev/null
+++ b/mali_kbase/platform/pixel/pixel_gpu_uevent.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Google LLC.
+ *
+ * Author: Varad Gautam <varadgautam@google.com>
+ */
+
+#include <linux/spinlock.h>
+#include "pixel_gpu_uevent.h"
+
+#define GPU_UEVENT_TIMEOUT_MS (30000U) /* 30s */
+
+static struct gpu_uevent_ctx {
+ unsigned long last_uevent_ts[GPU_UEVENT_TYPE_MAX];
+ spinlock_t lock;
+} gpu_uevent_ctx = {
+ .last_uevent_ts = {0},
+ .lock = __SPIN_LOCK_UNLOCKED(gpu_uevent_ctx.lock)
+};
+
+static bool gpu_uevent_check_valid(const struct gpu_uevent *evt)
+{
+ return false;
+}
+
+void pixel_gpu_uevent_send(struct kbase_device *kbdev, const struct gpu_uevent *evt)
+{
+ enum uevent_env_idx {
+ ENV_IDX_TYPE,
+ ENV_IDX_INFO,
+ ENV_IDX_NULL,
+ ENV_IDX_MAX
+ };
+ char *env[ENV_IDX_MAX] = {0};
+ unsigned long flags, current_ts = jiffies;
+ bool suppress_uevent = false;
+
+ if (!gpu_uevent_check_valid(evt)) {
+ dev_err(kbdev->dev, "unrecognized uevent type=%u info=%u", evt->type, evt->info);
+ return;
+ }
+
+ env[ENV_IDX_TYPE] = (char *) gpu_uevent_type_str(evt->type);
+ env[ENV_IDX_INFO] = (char *) gpu_uevent_info_str(evt->info);
+ env[ENV_IDX_NULL] = NULL;
+
+ spin_lock_irqsave(&gpu_uevent_ctx.lock, flags);
+
+ if (time_after(current_ts, gpu_uevent_ctx.last_uevent_ts[evt->type]
+ + msecs_to_jiffies(GPU_UEVENT_TIMEOUT_MS))) {
+ gpu_uevent_ctx.last_uevent_ts[evt->type] = current_ts;
+ } else {
+ suppress_uevent = true;
+ }
+
+ spin_unlock_irqrestore(&gpu_uevent_ctx.lock, flags);
+
+ if (!suppress_uevent)
+ kobject_uevent_env(&kbdev->dev->kobj, KOBJ_CHANGE, env);
+}
diff --git a/mali_kbase/platform/pixel/pixel_gpu_uevent.h b/mali_kbase/platform/pixel/pixel_gpu_uevent.h
new file mode 100644
index 0000000..7773aef
--- /dev/null
+++ b/mali_kbase/platform/pixel/pixel_gpu_uevent.h
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2023 Google LLC.
+ *
+ * Author: Varad Gautam <varadgautam@google.com>
+ */
+
+#ifndef _PIXEL_GPU_UEVENT_H_
+#define _PIXEL_GPU_UEVENT_H_
+
+#include <mali_kbase.h>
+
+#define GPU_UEVENT_TYPE_LIST \
+ GPU_UEVENT_TYPE(NONE) \
+ GPU_UEVENT_TYPE(MAX)
+
+#define GPU_UEVENT_TYPE(type) GPU_UEVENT_TYPE_##type,
+enum gpu_uevent_type {
+ GPU_UEVENT_TYPE_LIST
+};
+
+#undef GPU_UEVENT_TYPE
+#define GPU_UEVENT_TYPE(type) "GPU_UEVENT_TYPE="#type,
+static inline const char *gpu_uevent_type_str(enum gpu_uevent_type type) {
+ static const char * const gpu_uevent_types[] = {
+ GPU_UEVENT_TYPE_LIST
+ };
+ return gpu_uevent_types[type];
+}
+#undef GPU_UEVENT_TYPE
+
+#define GPU_UEVENT_INFO_LIST \
+ GPU_UEVENT_INFO(NONE) \
+ GPU_UEVENT_INFO(MAX)
+
+#define GPU_UEVENT_INFO(info) GPU_UEVENT_INFO_##info,
+enum gpu_uevent_info {
+ GPU_UEVENT_INFO_LIST
+};
+#undef GPU_UEVENT_INFO
+#define GPU_UEVENT_INFO(info) "GPU_UEVENT_INFO="#info,
+static inline const char *gpu_uevent_info_str(enum gpu_uevent_info info) {
+ static const char * const gpu_uevent_infos[] = {
+ GPU_UEVENT_INFO_LIST
+ };
+ return gpu_uevent_infos[info];
+}
+#undef GPU_UEVENT_INFO
+
+struct gpu_uevent {
+ enum gpu_uevent_type type;
+ enum gpu_uevent_info info;
+};
+
+void pixel_gpu_uevent_send(struct kbase_device *kbdev, const struct gpu_uevent *evt);
+
+#endif /* _PIXEL_GPU_UEVENT_H_ */