mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 22:08:26 +02:00
gfxstream: guest: mesa-ify GoldfishAddressSpace
Mesa-ify Goldfish address space. Reviewed-by: Aaron Ruby <aruby@blackberry.com> Acked-by: Yonggang Luo <luoyonggang@gmail.com> Acked-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27246>
This commit is contained in:
parent
b59b473422
commit
38837335b5
5 changed files with 69 additions and 65 deletions
|
|
@ -22,12 +22,11 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "VirtGpu.h"
|
||||
#include "aemu/base/Tracing.h"
|
||||
#include "util.h"
|
||||
#include "util/log.h"
|
||||
#include "util/perf/cpu_trace.h"
|
||||
#include "virtgpu_gfxstream_protocol.h"
|
||||
|
||||
#include <cutils/log.h>
|
||||
|
||||
static const size_t kReadSize = 512 * 1024;
|
||||
static const size_t kWriteOffset = kReadSize;
|
||||
|
||||
|
|
@ -87,7 +86,7 @@ size_t AddressSpaceStream::idealAllocSize(size_t len) {
|
|||
}
|
||||
|
||||
void* AddressSpaceStream::allocBuffer(size_t minSize) {
|
||||
AEMU_SCOPED_TRACE("allocBuffer");
|
||||
MESA_TRACE_SCOPE("allocBuffer");
|
||||
ensureType3Finished();
|
||||
|
||||
if (!m_readBuf) {
|
||||
|
|
@ -149,8 +148,11 @@ const unsigned char *AddressSpaceStream::readFully(void *ptr, size_t totalReadSi
|
|||
|
||||
if (!userReadBuf) {
|
||||
if (totalReadSize > 0) {
|
||||
ALOGE("AddressSpaceStream::commitBufferAndReadFully failed, userReadBuf=NULL, totalReadSize %zu, lethal"
|
||||
" error, exiting.", totalReadSize);
|
||||
mesa_loge(
|
||||
"AddressSpaceStream::commitBufferAndReadFully failed, userReadBuf=NULL, "
|
||||
"totalReadSize %zu, lethal"
|
||||
" error, exiting.",
|
||||
totalReadSize);
|
||||
abort();
|
||||
}
|
||||
return nullptr;
|
||||
|
|
@ -184,7 +186,7 @@ const unsigned char *AddressSpaceStream::readFully(void *ptr, size_t totalReadSi
|
|||
}
|
||||
|
||||
if (actual == 0) {
|
||||
ALOGD("%s: end of pipe", __FUNCTION__);
|
||||
mesa_logd("%s: end of pipe", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -204,7 +206,7 @@ const unsigned char *AddressSpaceStream::readFully(void *ptr, size_t totalReadSi
|
|||
actual = speculativeRead(m_readBuf, kReadSize);
|
||||
|
||||
if (actual == 0) {
|
||||
ALOGD("%s: Failed reading from pipe: %d", __FUNCTION__, errno);
|
||||
mesa_logd("%s: Failed reading from pipe: %d", __FUNCTION__, errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +235,7 @@ const unsigned char *AddressSpaceStream::read(void *buf, size_t *inout_len) {
|
|||
}
|
||||
|
||||
int AddressSpaceStream::writeFully(const void* buf, size_t size) {
|
||||
AEMU_SCOPED_TRACE("writeFully");
|
||||
MESA_TRACE_SCOPE("writeFully");
|
||||
ensureType3Finished();
|
||||
ensureType1Finished();
|
||||
|
||||
|
|
@ -288,8 +290,8 @@ int AddressSpaceStream::writeFully(const void* buf, size_t size) {
|
|||
|
||||
float mb = (float)m_written / 1048576.0f;
|
||||
if (mb > 100.0f) {
|
||||
ALOGD("%s: %f mb in %d notifs. %f mb/notif\n", __func__,
|
||||
mb, m_notifs, m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
mesa_logd("%s: %f mb in %d notifs. %f mb/notif\n", __func__, mb, m_notifs,
|
||||
m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
m_notifs = 0;
|
||||
m_written = 0;
|
||||
}
|
||||
|
|
@ -297,7 +299,7 @@ int AddressSpaceStream::writeFully(const void* buf, size_t size) {
|
|||
}
|
||||
|
||||
int AddressSpaceStream::writeFullyAsync(const void* buf, size_t size) {
|
||||
AEMU_SCOPED_TRACE("writeFullyAsync");
|
||||
MESA_TRACE_SCOPE("writeFullyAsync");
|
||||
ensureType3Finished();
|
||||
ensureType1Finished();
|
||||
|
||||
|
|
@ -355,8 +357,8 @@ int AddressSpaceStream::writeFullyAsync(const void* buf, size_t size) {
|
|||
|
||||
float mb = (float)m_written / 1048576.0f;
|
||||
if (mb > 100.0f) {
|
||||
ALOGD("%s: %f mb in %d notifs. %f mb/notif\n", __func__,
|
||||
mb, m_notifs, m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
mesa_logd("%s: %f mb in %d notifs. %f mb/notif\n", __func__, mb, m_notifs,
|
||||
m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
m_notifs = 0;
|
||||
m_written = 0;
|
||||
}
|
||||
|
|
@ -418,7 +420,7 @@ ssize_t AddressSpaceStream::speculativeRead(unsigned char* readBuffer, size_t tr
|
|||
}
|
||||
|
||||
void AddressSpaceStream::notifyAvailable() {
|
||||
AEMU_SCOPED_TRACE("PING");
|
||||
MESA_TRACE_SCOPE("PING");
|
||||
struct address_space_ping request;
|
||||
request.metadata = ASG_NOTIFY_AVAILABLE;
|
||||
request.resourceId = m_resourceId;
|
||||
|
|
@ -460,7 +462,7 @@ void AddressSpaceStream::ensureConsumerFinishing() {
|
|||
}
|
||||
|
||||
void AddressSpaceStream::ensureType1Finished() {
|
||||
AEMU_SCOPED_TRACE("ensureType1Finished");
|
||||
MESA_TRACE_SCOPE("ensureType1Finished");
|
||||
|
||||
uint32_t currAvailRead =
|
||||
ring_buffer_available_read(m_context.to_host, 0);
|
||||
|
|
@ -476,7 +478,7 @@ void AddressSpaceStream::ensureType1Finished() {
|
|||
}
|
||||
|
||||
void AddressSpaceStream::ensureType3Finished() {
|
||||
AEMU_SCOPED_TRACE("ensureType3Finished");
|
||||
MESA_TRACE_SCOPE("ensureType3Finished");
|
||||
uint32_t availReadLarge =
|
||||
ring_buffer_available_read(
|
||||
m_context.to_host_large_xfer.ring,
|
||||
|
|
@ -499,7 +501,7 @@ void AddressSpaceStream::ensureType3Finished() {
|
|||
}
|
||||
|
||||
int AddressSpaceStream::type1Write(uint32_t bufferOffset, size_t size) {
|
||||
AEMU_SCOPED_TRACE("type1Write");
|
||||
MESA_TRACE_SCOPE("type1Write");
|
||||
|
||||
ensureType3Finished();
|
||||
|
||||
|
|
@ -562,8 +564,8 @@ int AddressSpaceStream::type1Write(uint32_t bufferOffset, size_t size) {
|
|||
|
||||
float mb = (float)m_written / 1048576.0f;
|
||||
if (mb > 100.0f) {
|
||||
ALOGD("%s: %f mb in %d notifs. %f mb/notif\n", __func__,
|
||||
mb, m_notifs, m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
mesa_logd("%s: %f mb in %d notifs. %f mb/notif\n", __func__, mb, m_notifs,
|
||||
m_notifs ? mb / (float)m_notifs : 0.0f);
|
||||
m_notifs = 0;
|
||||
m_written = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
#include "GoldfishAddressSpaceStream.h"
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
#include "goldfish_address_space.h"
|
||||
#include "util/log.h"
|
||||
|
||||
AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
||||
// Ignore incoming ignored_bufSize
|
||||
|
|
@ -26,7 +25,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
address_space_handle_t child_device_handle;
|
||||
|
||||
if (!goldfish_address_space_set_subdevice_type(handle, GoldfishAddressSpaceSubdeviceType::Graphics, &child_device_handle)) {
|
||||
ALOGE("AddressSpaceStream::create failed (initial device create)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (initial device create)\n");
|
||||
goldfish_address_space_close(handle);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -34,7 +33,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
struct address_space_ping request;
|
||||
request.metadata = ASG_GET_RING;
|
||||
if (!goldfish_address_space_ping(child_device_handle, &request)) {
|
||||
ALOGE("AddressSpaceStream::create failed (get ring)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (get ring)\n");
|
||||
goldfish_address_space_close(child_device_handle);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -43,7 +42,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
|
||||
request.metadata = ASG_GET_BUFFER;
|
||||
if (!goldfish_address_space_ping(child_device_handle, &request)) {
|
||||
ALOGE("AddressSpaceStream::create failed (get buffer)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (get buffer)\n");
|
||||
goldfish_address_space_close(child_device_handle);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -53,14 +52,14 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
|
||||
if (!goldfish_address_space_claim_shared(
|
||||
child_device_handle, ringOffset, sizeof(asg_ring_storage))) {
|
||||
ALOGE("AddressSpaceStream::create failed (claim ring storage)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (claim ring storage)\n");
|
||||
goldfish_address_space_close(child_device_handle);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!goldfish_address_space_claim_shared(
|
||||
child_device_handle, bufferOffset, bufferSize)) {
|
||||
ALOGE("AddressSpaceStream::create failed (claim buffer storage)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (claim buffer storage)\n");
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, ringOffset);
|
||||
goldfish_address_space_close(child_device_handle);
|
||||
return nullptr;
|
||||
|
|
@ -70,7 +69,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
child_device_handle, ringOffset, sizeof(struct asg_ring_storage));
|
||||
|
||||
if (!ringPtr) {
|
||||
ALOGE("AddressSpaceStream::create failed (map ring storage)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (map ring storage)\n");
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, bufferOffset);
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, ringOffset);
|
||||
goldfish_address_space_close(child_device_handle);
|
||||
|
|
@ -81,7 +80,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
child_device_handle, bufferOffset, bufferSize);
|
||||
|
||||
if (!bufferPtr) {
|
||||
ALOGE("AddressSpaceStream::create failed (map buffer storage)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (map buffer storage)\n");
|
||||
goldfish_address_space_unmap(ringPtr, sizeof(struct asg_ring_storage));
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, bufferOffset);
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, ringOffset);
|
||||
|
|
@ -97,7 +96,7 @@ AddressSpaceStream* createGoldfishAddressSpaceStream(size_t ignored_bufSize) {
|
|||
request.size = 1; // version 1
|
||||
|
||||
if (!goldfish_address_space_ping(child_device_handle, &request)) {
|
||||
ALOGE("AddressSpaceStream::create failed (get buffer)\n");
|
||||
mesa_loge("AddressSpaceStream::create failed (get buffer)\n");
|
||||
goldfish_address_space_unmap(bufferPtr, bufferSize);
|
||||
goldfish_address_space_unmap(ringPtr, sizeof(struct asg_ring_storage));
|
||||
goldfish_address_space_unclaim_shared(child_device_handle, bufferOffset);
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
#include "VirtioGpuAddressSpaceStream.h"
|
||||
|
||||
#include <cutils/log.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "util/log.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
static bool GetRingParamsFromCapset(enum VirtGpuCapset capset, const VirtGpuCaps& caps,
|
||||
uint32_t& ringSize, uint32_t& bufferSize,
|
||||
|
|
@ -95,7 +95,7 @@ AddressSpaceStream* createVirtioGpuAddressSpaceStream(enum VirtGpuCapset capset)
|
|||
auto caps = instance->getCaps();
|
||||
|
||||
if (!GetRingParamsFromCapset(capset, caps, ringSize, bufferSize, blobAlignment)) {
|
||||
ALOGE("Failed to get ring parameters");
|
||||
mesa_loge("Failed to get ring parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,21 +13,23 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <errno.h>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
#include "goldfish_address_space.h"
|
||||
#include <log/log.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <linux/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
// See virgl_hw.h and p_defines.h
|
||||
#define VIRGL_FORMAT_R8_UNORM 64
|
||||
|
|
@ -119,8 +121,8 @@ GoldfishAddressSpaceBlockProvider::GoldfishAddressSpaceBlockProvider(GoldfishAdd
|
|||
if ((subdevice != GoldfishAddressSpaceSubdeviceType::NoSubdevice) && is_opened()) {
|
||||
const long ret = set_address_space_subdevice_type(m_handle, subdevice);
|
||||
if (ret != 0 && ret != subdevice) { // TODO: retire the 'ret != subdevice' check
|
||||
ALOGE("%s: set_address_space_subdevice_type failed for device_type=%lu, ret=%ld",
|
||||
__func__, static_cast<unsigned long>(subdevice), ret);
|
||||
mesa_loge("%s: set_address_space_subdevice_type failed for device_type=%lu, ret=%ld",
|
||||
__func__, static_cast<unsigned long>(subdevice), ret);
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
|
@ -247,22 +249,21 @@ uint64_t GoldfishAddressSpaceBlock::hostAddr() const
|
|||
void *GoldfishAddressSpaceBlock::mmap(uint64_t host_addr)
|
||||
{
|
||||
if (m_size == 0) {
|
||||
ALOGE("%s: called with zero size\n", __func__);
|
||||
mesa_loge("%s: called with zero size\n", __func__);
|
||||
return NULL;
|
||||
}
|
||||
if (m_mmaped_ptr) {
|
||||
ALOGE("'mmap' called for an already mmaped address block");
|
||||
mesa_loge("'mmap' called for an already mmaped address block");
|
||||
::abort();
|
||||
}
|
||||
|
||||
void *result;
|
||||
const int res = memoryMap(NULL, m_size, m_handle, m_offset, &result);
|
||||
if (res) {
|
||||
ALOGE("%s: host memory map failed with size 0x%llx "
|
||||
"off 0x%llx errno %d\n",
|
||||
__func__,
|
||||
(unsigned long long)m_size,
|
||||
(unsigned long long)m_offset, res);
|
||||
mesa_loge(
|
||||
"%s: host memory map failed with size 0x%llx "
|
||||
"off 0x%llx errno %d\n",
|
||||
__func__, (unsigned long long)m_size, (unsigned long long)m_offset, res);
|
||||
return NULL;
|
||||
} else {
|
||||
m_mmaped_ptr = result;
|
||||
|
|
@ -289,13 +290,13 @@ void GoldfishAddressSpaceBlock::destroy()
|
|||
if (m_is_shared_mapping) {
|
||||
res = ioctl_unclaim_shared(m_handle, m_offset);
|
||||
if (res) {
|
||||
ALOGE("ioctl_unclaim_shared failed, res=%ld", res);
|
||||
mesa_loge("ioctl_unclaim_shared failed, res=%ld", res);
|
||||
::abort();
|
||||
}
|
||||
} else {
|
||||
res = ioctl_deallocate(m_handle, m_offset);
|
||||
if (res) {
|
||||
ALOGE("ioctl_deallocate failed, res=%ld", res);
|
||||
mesa_loge("ioctl_deallocate failed, res=%ld", res);
|
||||
::abort();
|
||||
}
|
||||
}
|
||||
|
|
@ -410,7 +411,7 @@ void GoldfishAddressSpaceHostMemoryAllocator::hostFree(GoldfishAddressSpaceBlock
|
|||
}
|
||||
|
||||
if (!m_provider.is_opened()) {
|
||||
ALOGE("%s: device is not available", __func__);
|
||||
mesa_loge("%s: device is not available", __func__);
|
||||
::abort();
|
||||
}
|
||||
|
||||
|
|
@ -423,7 +424,7 @@ void GoldfishAddressSpaceHostMemoryAllocator::hostFree(GoldfishAddressSpaceBlock
|
|||
|
||||
const long ret = ioctl_ping(m_provider.m_handle, &request);
|
||||
if (ret) {
|
||||
ALOGE("%s: ioctl_ping failed, ret=%ld", __func__, ret);
|
||||
mesa_loge("%s: ioctl_ping failed, ret=%ld", __func__, ret);
|
||||
::abort();
|
||||
}
|
||||
}
|
||||
|
|
@ -462,7 +463,7 @@ bool goldfish_address_space_free(
|
|||
long res = ioctl_deallocate(handle, offset);
|
||||
|
||||
if (res) {
|
||||
ALOGE("ioctl_deallocate failed, res=%ld", res);
|
||||
mesa_loge("ioctl_deallocate failed, res=%ld", res);
|
||||
::abort();
|
||||
}
|
||||
|
||||
|
|
@ -486,7 +487,7 @@ bool goldfish_address_space_unclaim_shared(
|
|||
address_space_handle_t handle, uint64_t offset) {
|
||||
long res = ioctl_unclaim_shared(handle, offset);
|
||||
if (res) {
|
||||
ALOGE("ioctl_unclaim_shared failed, res=%ld", res);
|
||||
mesa_loge("ioctl_unclaim_shared failed, res=%ld", res);
|
||||
::abort();
|
||||
}
|
||||
|
||||
|
|
@ -502,7 +503,7 @@ void* goldfish_address_space_map(
|
|||
void* res = ::mmap64(0, size, PROT_WRITE, MAP_SHARED, handle, offset);
|
||||
|
||||
if (res == MAP_FAILED) {
|
||||
ALOGE("%s: failed to map. errno: %d\n", __func__, errno);
|
||||
mesa_loge("%s: failed to map. errno: %d\n", __func__, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -529,7 +530,7 @@ bool goldfish_address_space_ping(
|
|||
long res = ioctl_ping(handle, ping);
|
||||
|
||||
if (res) {
|
||||
ALOGE("%s: ping failed: errno: %d\n", __func__, errno);
|
||||
mesa_loge("%s: ping failed: errno: %d\n", __func__, errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ lib_goldfish_address_space = static_library(
|
|||
inc_guest_iostream,
|
||||
inc_system,
|
||||
inc_opengl_codec,
|
||||
inc_platform],
|
||||
inc_platform,
|
||||
inc_include,
|
||||
inc_src],
|
||||
link_with: [lib_platform],
|
||||
dependencies: drm_dep
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue