From 230b470a3caabdef3dd4052f0d9ceb09832d86d5 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Thu, 24 Nov 2016 18:48:49 +0000 Subject: [PATCH] pcsx2:freebsd: Disable aio use on FreeBSD 10.3 and earlier A FreeBSD 10.3 user (meowthink) reported to me that games were not working properly on their system. After some investigation, it was discovered that aio was buggy on their setup. There's also bug reports for other applications that involve aio too. Workaround the issue by using a normal read and disabling the use of aio on FreeBSD 10.3 and earlier. It'll remain enabled on FreeBSD 11.0 in the hope that the aio issue has since been fixed. --- pcsx2/Darwin/DarwinFlatFileReader.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pcsx2/Darwin/DarwinFlatFileReader.cpp b/pcsx2/Darwin/DarwinFlatFileReader.cpp index 24cae8d940..728dafd066 100644 --- a/pcsx2/Darwin/DarwinFlatFileReader.cpp +++ b/pcsx2/Darwin/DarwinFlatFileReader.cpp @@ -20,7 +20,14 @@ #warning Tested on FreeBSD, not OS X. Be very afraid. #endif -//FlatFileReader::FlatFileReader(void) +// The aio module has been reported to cause issues with FreeBSD 10.3, so let's +// disable it for 10.3 and earlier and hope FreeBSD 11 and onwards is fine. +// Note: It may be worth checking whether aio provides any performance benefit. +#if defined(__FreeBSD__) && __FreeBSD__ < 11 +#define DISABLE_AIO +#warning AIO has been disabled. +#endif + FlatFileReader::FlatFileReader(bool shareWrite) : shareWrite(shareWrite) { m_blocksize = 2048; @@ -54,6 +61,11 @@ void FlatFileReader::BeginRead(void* pBuffer, uint sector, uint count) u32 bytesToRead = count * m_blocksize; +#if defined(DISABLE_AIO) + m_aiocb.aio_nbytes = pread(m_fd, pBuffer, bytesToRead, offset); + if (m_aiocb.aio_nbytes != bytesToRead) + m_aiocb.aio_nbytes = -1; +#else m_aiocb = {0}; m_aiocb.aio_fildes = m_fd; m_aiocb.aio_offset = offset; @@ -71,11 +83,16 @@ void FlatFileReader::BeginRead(void* pBuffer, uint sector, uint count) #endif return; } +#endif m_read_in_progress = true; } int FlatFileReader::FinishRead(void) { +#if defined(DISABLE_AIO) + m_read_in_progress = false; + return m_aiocb.aio_nbytes == (size_t)-1 ? -1: 1; +#else struct aiocb *aiocb_list[] = {&m_aiocb}; while (aio_suspend(aiocb_list, 1, nullptr) == -1) @@ -84,11 +101,14 @@ int FlatFileReader::FinishRead(void) m_read_in_progress = false; return aio_return(&m_aiocb) == -1? -1: 1; +#endif } void FlatFileReader::CancelRead(void) { +#if !defined(DISABLE_AIO) aio_cancel(m_fd, &m_aiocb); +#endif m_read_in_progress = false; }