summaryrefslogtreecommitdiff
path: root/gralloc4
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2021-08-04 15:35:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2021-08-04 15:35:38 +0000
commited1327358635941d12f89ca1700459d7e7265a8d (patch)
treefd5034d106451b0c25676c9b3042e1dc1b9d7aef /gralloc4
parentf6178197c163ec7ce014640de9c2efac472fc856 (diff)
parent56831666f59b6bf33e1837669b6f752f973d0755 (diff)
downloadgchips-ed1327358635941d12f89ca1700459d7e7265a8d.tar.gz
Merge changes Ib1f3cfda,I3d0f30b0,Ic93aa915 into sc-dev
* changes: Commit all gralloc logs to warning on high memory allocation Add delayed logger to allow logging verbose/info logs as warnings Log the calling process's PID
Diffstat (limited to 'gralloc4')
-rw-r--r--gralloc4/src/4.x/Android.bp2
-rw-r--r--gralloc4/src/4.x/GrallocAllocator.cpp12
-rw-r--r--gralloc4/src/Android.bp8
-rw-r--r--gralloc4/src/allocator/mali_gralloc_ion.cpp6
-rw-r--r--gralloc4/src/hidl_common/Allocator.cpp1
-rw-r--r--gralloc4/src/mali_gralloc_log.cpp94
-rw-r--r--gralloc4/src/mali_gralloc_log.h25
7 files changed, 142 insertions, 6 deletions
diff --git a/gralloc4/src/4.x/Android.bp b/gralloc4/src/4.x/Android.bp
index 3de9da9..b093eab 100644
--- a/gralloc4/src/4.x/Android.bp
+++ b/gralloc4/src/4.x/Android.bp
@@ -85,6 +85,7 @@ cc_library_shared {
"GrallocAllocator.cpp",
":libgralloc_hidl_common_allocator",
":libgralloc_hidl_common_shared_metadata",
+ ":libgralloc_src_log",
],
include_dirs: [
"hardware/google/gchips/include",
@@ -108,6 +109,7 @@ cc_library_shared {
":libgralloc_hidl_common_mapper",
":libgralloc_hidl_common_mapper_metadata",
":libgralloc_hidl_common_shared_metadata",
+ ":libgralloc_src_log",
],
include_dirs: [
"hardware/google/gchips/include",
diff --git a/gralloc4/src/4.x/GrallocAllocator.cpp b/gralloc4/src/4.x/GrallocAllocator.cpp
index c3c0d4b..4e074b5 100644
--- a/gralloc4/src/4.x/GrallocAllocator.cpp
+++ b/gralloc4/src/4.x/GrallocAllocator.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <hwbinder/IPCThreadState.h>
+
#include "GrallocAllocator.h"
#include "hidl_common/BufferDescriptor.h"
#include "hidl_common/Allocator.h"
@@ -31,6 +33,11 @@ using android::hardware::hidl_vec;
using android::hardware::Void;
using android::hardware::hidl_string;
+unsigned long callingPid() {
+ android::hardware::IPCThreadState* ipc = android::hardware::IPCThreadState::self();
+ return static_cast<unsigned long>(ipc->getCallingPid());
+}
+
GrallocAllocator::GrallocAllocator()
{
}
@@ -42,6 +49,9 @@ GrallocAllocator::~GrallocAllocator()
Return<void> GrallocAllocator::allocate(const BufferDescriptor &descriptor, uint32_t count, allocate_cb hidl_cb)
{
+ log_setup();
+ MALI_GRALLOC_LOGV("Allocation request from process: %lu", callingPid());
+
buffer_descriptor_t bufferDescriptor;
if (!mapper::common::grallocDecodeBufferDescriptor(descriptor, bufferDescriptor))
{
@@ -61,4 +71,4 @@ extern "C" IAllocator *HIDL_FETCH_IAllocator(const char * /* name */)
(HIDL_ALLOCATOR_VERSION_SCALED - (GRALLOC_VERSION_MAJOR * 100)) / 10, getpid(), getppid());
return new arm::allocator::GrallocAllocator();
-} \ No newline at end of file
+}
diff --git a/gralloc4/src/Android.bp b/gralloc4/src/Android.bp
index a3a254d..e899758 100644
--- a/gralloc4/src/Android.bp
+++ b/gralloc4/src/Android.bp
@@ -35,6 +35,13 @@ cc_library_headers {
],
}
+filegroup {
+ name: "libgralloc_src_log",
+ srcs: [
+ "mali_gralloc_log.cpp",
+ ],
+}
+
cc_library_shared {
name: "libGralloc4Wrapper",
vendor: true,
@@ -49,6 +56,7 @@ cc_library_shared {
"core/mali_gralloc_reference.cpp",
"core/mali_gralloc_debug.cpp",
":libgralloc_hidl_common_shared_metadata",
+ ":libgralloc_src_log",
],
cflags: [
"-DGRALLOC_LIBRARY_BUILD=1",
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp
index 3123848..dd003c9 100644
--- a/gralloc4/src/allocator/mali_gralloc_ion.cpp
+++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp
@@ -608,6 +608,12 @@ int mali_gralloc_ion_allocate(const gralloc_buffer_descriptor_t *descriptors,
if (ion_fd >= 0 && fidx == 0) {
fds[fidx] = ion_fd;
} else {
+ // Warn of high memory allocation on size request greater than 200M
+ if (bufDescriptor->alloc_sizes[fidx] > static_cast<uint64_t>(200ull << 20)) {
+ log_info_verbose_as_warning();
+ MALI_GRALLOC_LOGW("Huge memory allocation: %" PRIu64, bufDescriptor->alloc_sizes[fidx]);
+ }
+
fds[fidx] = dev->alloc_from_ion_heap(usage, bufDescriptor->alloc_sizes[fidx], ion_flags, &min_pgsz);
}
if (fds[fidx] < 0)
diff --git a/gralloc4/src/hidl_common/Allocator.cpp b/gralloc4/src/hidl_common/Allocator.cpp
index 8174f05..76a26cd 100644
--- a/gralloc4/src/hidl_common/Allocator.cpp
+++ b/gralloc4/src/hidl_common/Allocator.cpp
@@ -134,6 +134,7 @@ void allocate(const buffer_descriptor_t &bufferDescriptor, uint32_t count, IAllo
{
hidlBuffers.setToExternal(grallocBuffers.data(), grallocBuffers.size());
}
+ log_commit();
hidl_cb(error, stride, hidlBuffers);
/* The application should import the Gralloc buffers using IMapper for
diff --git a/gralloc4/src/mali_gralloc_log.cpp b/gralloc4/src/mali_gralloc_log.cpp
new file mode 100644
index 0000000..b2aacf2
--- /dev/null
+++ b/gralloc4/src/mali_gralloc_log.cpp
@@ -0,0 +1,94 @@
+#include <string>
+#include <thread>
+#include <vector>
+
+#include <mali_gralloc_log.h>
+
+class DelayedLogger {
+ public:
+ void setup() {
+ if (setupCalled) {
+ ALOGW("Bug: Log setup called multiple times");
+ }
+
+ setupCalled = true;
+ }
+
+ void add(LogLevel level, std::string log) {
+ if (setupCalled)
+ pendingLogs.emplace_back(make_tuple(level, log));
+ else
+ outputLog(level, log);
+ }
+
+ void commit() {
+ for (const auto& levelLog: pendingLogs) {
+ const LogLevel level = std::get<0>(levelLog);
+ const std::string& log = std::get<1>(levelLog);
+
+ outputLog(level, log);
+ }
+
+ pendingLogs.clear();
+ setupCalled = false;
+ logIV = false;
+ }
+
+ void logInfoVerboseAsWarning() {
+ logIV = true;
+ }
+
+ private:
+
+ void outputLog(const LogLevel level, const std::string& log) {
+ switch (level) {
+ case LogLevel::INFO:
+ if (logIV)
+ ALOGW("INFO: %s", log.c_str());
+ else
+ ALOGI("%s", log.c_str());
+ break;
+ case LogLevel::VERBOSE:
+ if (logIV)
+ ALOGW("VERBOSE: %s", log.c_str());
+ else
+ ALOGV("%s", log.c_str());
+ break;
+ case LogLevel::WARNING:
+ ALOGW("%s", log.c_str());
+ break;
+ case LogLevel::ERROR:
+ ALOGE("%s", log.c_str());
+ break;
+ }
+ }
+
+ std::vector<std::tuple<LogLevel, std::string>> pendingLogs = {};
+ bool setupCalled = false;
+ bool logIV = false;
+};
+
+thread_local DelayedLogger delayedLogger;
+
+void log_later(LogLevel level, const char* fmt, ...) {
+ char buf[10000];
+
+ va_list argptr;
+ va_start(argptr, fmt);
+ vsnprintf(buf, 10000, fmt, argptr);
+ va_end(argptr);
+
+ delayedLogger.add(level, std::string(buf));
+}
+
+void log_setup() {
+ delayedLogger.setup();
+}
+
+void log_commit() {
+ delayedLogger.commit();
+}
+
+void log_info_verbose_as_warning() {
+ delayedLogger.logInfoVerboseAsWarning();
+}
diff --git a/gralloc4/src/mali_gralloc_log.h b/gralloc4/src/mali_gralloc_log.h
index aa4e26c..80c607d 100644
--- a/gralloc4/src/mali_gralloc_log.h
+++ b/gralloc4/src/mali_gralloc_log.h
@@ -21,12 +21,27 @@
#define LOG_TAG "mali_gralloc"
#endif
+#include <mutex>
+#include <string>
+#include <vector>
+
#include <log/log.h>
-/* Delegate logging to Android */
-#define MALI_GRALLOC_LOGI(...) ALOGI(__VA_ARGS__)
-#define MALI_GRALLOC_LOGV(...) ALOGV(__VA_ARGS__)
-#define MALI_GRALLOC_LOGW(...) ALOGW(__VA_ARGS__)
-#define MALI_GRALLOC_LOGE(...) ALOGE(__VA_ARGS__)
+enum class LogLevel {
+ INFO,
+ VERBOSE,
+ WARNING,
+ ERROR
+};
+
+void log_setup();
+void log_later(LogLevel level, const char* fmt, ...);
+void log_commit();
+void log_info_verbose_as_warning();
+
+#define MALI_GRALLOC_LOGI(...) log_later(LogLevel::INFO, __VA_ARGS__);
+#define MALI_GRALLOC_LOGV(...) log_later(LogLevel::VERBOSE, __VA_ARGS__);
+#define MALI_GRALLOC_LOGW(...) log_later(LogLevel::WARNING, __VA_ARGS__);
+#define MALI_GRALLOC_LOGE(...) log_later(LogLevel::ERROR, __VA_ARGS__);
#endif