Skip to content

Commit

Permalink
pcsx2:freebsd: Disable aio use on FreeBSD 10.3 and earlier
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
turtleli committed Nov 24, 2016
1 parent df96361 commit 230b470
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pcsx2/Darwin/DarwinFlatFileReader.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down

0 comments on commit 230b470

Please sign in to comment.