From feb462cf017ecbca67b3c1427f52699af1ff6f76 Mon Sep 17 00:00:00 2001 From: Naseer Ahmed Date: Thu, 7 Jul 2011 18:03:47 +0530 Subject: [PATCH] gralloc: Clean pmem caches after memset Change-Id: If403dde70863e0d6ea221f2a105b86bdec134261 --- gralloc.cpp | 8 ++++++++ pmemalloc.cpp | 2 ++ pmemalloc.h | 1 + 3 files changed, 11 insertions(+) diff --git a/gralloc.cpp b/gralloc.cpp index 8556780..0d1ac2f 100644 --- a/gralloc.cpp +++ b/gralloc.cpp @@ -112,6 +112,14 @@ class PmemAllocatorDepsDeviceImpl : public PmemUserspaceAllocator::Deps, return ioctl(fd, PMEM_UNMAP, &sub); } + virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) { + struct pmem_addr pmem_addr; + pmem_addr.vaddr = base; + pmem_addr.offset = offset; + pmem_addr.length = size; + return ioctl(fd, PMEM_CLEAN_INV_CACHES, &pmem_addr); + } + virtual int getErrno() { return errno; } diff --git a/pmemalloc.cpp b/pmemalloc.cpp index 4997580..01a3614 100644 --- a/pmemalloc.cpp +++ b/pmemalloc.cpp @@ -181,6 +181,8 @@ int PmemUserspaceAllocator::alloc_pmem_buffer(size_t size, int usage, } else { LOGV("%s: mapped fd %d at offset %d, size %d", pmemdev, fd, offset, size); memset((char*)base + offset, 0, size); + //Clean cache before flushing to ensure pmem is properly flushed + deps.cleanPmem(fd, (unsigned long) base, offset, size); #ifdef HOST cacheflush(intptr_t(base) + offset, intptr_t(base) + offset + size, 0); #endif diff --git a/pmemalloc.h b/pmemalloc.h index b0f45c7..a27cb41 100644 --- a/pmemalloc.h +++ b/pmemalloc.h @@ -69,6 +69,7 @@ class PmemUserspaceAllocator: public PmemAllocator { virtual int connectPmem(int fd, int master_fd) = 0; virtual int mapPmem(int fd, int offset, size_t size) = 0; virtual int unmapPmem(int fd, int offset, size_t size) = 0; + virtual int cleanPmem(int fd, unsigned long base, int offset, size_t size) = 0; // C99 virtual int getErrno() = 0;