Skip to content

Commit

Permalink
Gator 8.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bengaineyarm committed Dec 1, 2022
1 parent 58ae10b commit c1e117e
Show file tree
Hide file tree
Showing 324 changed files with 56,786 additions and 3,435 deletions.
2 changes: 1 addition & 1 deletion annotate/streamline_annotate_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum log_levels {
LOG_SILENT
};

/* ANDRIOD IMPLEMENTATION */
/* ANDROID IMPLEMENTATION */
#if defined(ANDROID) || defined(__ANDROID__)
#include <android/log.h>

Expand Down
3 changes: 0 additions & 3 deletions cmake/aarch64-gcc7.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# LTO options
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/lto.toolchain.cmake")
24 changes: 17 additions & 7 deletions daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/split-strip.cmake)
# Include the escaper
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/escape.cmake)

# Include hwcpipe2
SET(HWCPIPE_ENABLE_TESTS OFF CACHE BOOL "")
SET(HWCPIPE_ENABLE_EXCEPTIONS ON CACHE BOOL "")
SET(HWCPIPE_ENABLE_SYMBOLS_VISIBILITY OFF CACHE BOOL "")
SET(HWCPIPE_ENABLE_RTTI OFF CACHE BOOL "")
SET(HWCPIPE_WERROR OFF CACHE BOOL "")
SET(HWCPIPE_WALL OFF CACHE BOOL "")
SET(HWCPIPE_ENABLE_END_TO_END_TESTS OFF CACHE BOOL "")
ADD_SUBDIRECTORY(hwcpipe2)

# Configure target flags
IF(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.4.0"))
SET(GATORD_C_CXX_FLAGS "-fvisibility=default")
Expand Down Expand Up @@ -81,6 +91,7 @@ FIND_PACKAGE(Threads REQUIRED)
SET(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.75 REQUIRED COMPONENTS
filesystem
regex
)
ADD_DEFINITIONS(-DBOOST_FILESYSTEM_NO_DEPRECATED)

Expand Down Expand Up @@ -219,6 +230,10 @@ SET(GATORD_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/AnnotateListener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SessionXML.h
${CMAKE_CURRENT_SOURCE_DIR}/SimpleDriver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SimpleDriver.h
${CMAKE_CURRENT_SOURCE_DIR}/linux/smmu_identifier.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/smmu_identifier.h
${CMAKE_CURRENT_SOURCE_DIR}/linux/smmu_support.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/smmu_support.h
${CMAKE_CURRENT_SOURCE_DIR}/Source.h
${CMAKE_CURRENT_SOURCE_DIR}/StreamlineSetup.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StreamlineSetup.h
Expand Down Expand Up @@ -409,7 +424,6 @@ SET(GATORD_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/AnnotateListener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_exec.hpp
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_process.cpp
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_process.hpp
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_proc_poller.cpp
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_proc_poller.h
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_read_proc_maps.h
${CMAKE_CURRENT_SOURCE_DIR}/async/proc/async_read_proc_sys_dependencies.h
Expand Down Expand Up @@ -521,10 +535,6 @@ SET(GATORD_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/AnnotateListener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/logging/global_log.h
${CMAKE_CURRENT_SOURCE_DIR}/logging/logging.cpp
${CMAKE_CURRENT_SOURCE_DIR}/logging/suppliers.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/IMaliHwCntrReader.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliDeviceApi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliDeviceApi_DdkDefines.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliDeviceApi.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliDevice.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliDevice.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliGPUClockPolledDriverCounter.h
Expand All @@ -535,8 +545,6 @@ SET(GATORD_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/AnnotateListener.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntr.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrNames.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrNamesBifrost.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrReader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrReader.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrSource.h
${CMAKE_CURRENT_SOURCE_DIR}/mali_userspace/MaliHwCntrTask.cpp
Expand Down Expand Up @@ -678,9 +686,11 @@ TARGET_LINK_LIBRARIES(gatord
PRIVATE gatord-tpip
PRIVATE Threads::Threads
PRIVATE atomic
PRIVATE device
PRIVATE mxml
PRIVATE Boost::boost
PRIVATE Boost::filesystem
PRIVATE Boost::regex
PRIVATE ipcproto
PRIVATE dl
)
Expand Down
29 changes: 20 additions & 9 deletions daemon/ExternalSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,29 @@ class ExternalSourceImpl : public ExternalSource {
}

if (mDrivers.getFtraceDriver().isSupported()) {
const auto ftraceFds = mDrivers.getFtraceDriver().stop();
const auto ftraceFds = mDrivers.getFtraceDriver().requestStop();
// Read any slop
for (int fd : ftraceFds) {
transfer(monotonicStart, fd, endSession);
if (!lib::setBlocking(fd)) {
LOG_WARNING("Failed to change ftrace pipe to blocking reads. Ftrace data may be truncated");
}

while (transfer(monotonicStart, fd, endSession)) {
}

close(fd);
}
mDrivers.getFtraceDriver().stop();
mDrivers.getTtraceDriver().stop();
mDrivers.getAtraceDriver().stop();
}

for (auto & pair : external_agent_connections) {
LOG_DEBUG("Closing read end %d", pair.first);
pair.second.close();
// ask the agent to close the connection
pair.second.first->close();
// now close the read end of the pipe
pair.second.second.close();
}

mBuffer.flush();
Expand Down Expand Up @@ -342,8 +352,7 @@ class ExternalSourceImpl : public ExternalSource {
mBuffer.endFrame();
checkFlush(monotonicStart, isBufferOverFull(mBuffer.contiguousSpaceAvailable()));

// Short reads also mean nothing is left to read
return bytes >= contiguous;
return true;
}

void interrupt() override
Expand All @@ -365,7 +374,7 @@ class ExternalSourceImpl : public ExternalSource {
return isDone;
}

lib::AutoClosingFd add_agent_pipe() override
lib::AutoClosingFd add_agent_pipe(std::unique_ptr<agents::ext_source_connection_t> connection) override
{
std::lock_guard<std::mutex> lock {external_agent_connections_mutex};

Expand All @@ -383,7 +392,7 @@ class ExternalSourceImpl : public ExternalSource {
return {};
}

external_agent_connections[pfd[0]] = std::move(read);
external_agent_connections[pfd[0]] = {std::move(connection), std::move(read)};

int8_t c = 0;
// Write to the pipe to wake the monitor which will cause mSessionIsActive to be reread
Expand All @@ -396,6 +405,8 @@ class ExternalSourceImpl : public ExternalSource {
}

private:
using agent_connection_t = std::pair<std::unique_ptr<agents::ext_source_connection_t>, lib::AutoClosingFd>;

sem_t mBufferSem {};
std::function<uint64_t()> mGetMonotonicTime;
CommitTimeChecker mCommitChecker;
Expand All @@ -404,10 +415,10 @@ class ExternalSourceImpl : public ExternalSource {
OlyServerSocket mMidgardStartupUds;
OlyServerSocket mUtgardStartupUds;
std::mutex external_agent_connections_mutex {};
std::map<int, lib::AutoClosingFd> external_agent_connections {};
std::map<int, agent_connection_t> external_agent_connections {};
lib::AutoClosingFd mInterruptRead {};
lib::AutoClosingFd mInterruptWrite {};
int mMidgardUds;
int mMidgardUds {};
Drivers & mDrivers;
std::atomic_bool mSessionIsActive {true};

Expand Down
3 changes: 2 additions & 1 deletion daemon/ExternalSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "Source.h"
#include "agents/ext_source/ext_source_connection.h"
#include "lib/AutoClosingFd.h"

#include <memory>
Expand All @@ -14,7 +15,7 @@ class Drivers;
class ExternalSource : public Source {
public:
/** Create a pipe and return the write end. The read end will consume bytes from the external source agent and add them into an APC frame */
virtual lib::AutoClosingFd add_agent_pipe() = 0;
virtual lib::AutoClosingFd add_agent_pipe(std::unique_ptr<agents::ext_source_connection_t> connection) = 0;
};

/// Counters from external sources like graphics drivers and annotations
Expand Down
109 changes: 34 additions & 75 deletions daemon/FtraceDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <sys/types.h>
#include <unistd.h>

using namespace std::chrono_literals;

static constexpr auto FTRACE_SLOP_READ_TIMEOUT_DURATION = 2s;

Barrier::Barrier() : mMutex(), mCond(), mCount(0)
{
pthread_mutex_init(&mMutex, nullptr);
Expand Down Expand Up @@ -95,7 +99,7 @@ namespace {
private:
const TraceFsConstants & traceFsConstants;
char * const mEnable;
int mWasEnabled;
int mWasEnabled {};
};

class CpuFrequencyFtraceCounter : public FtraceCounter {
Expand Down Expand Up @@ -135,8 +139,7 @@ namespace {
const char * enable)
: DriverCounter(next, name),
traceFsConstants(traceFsConstants),
mEnable(enable == nullptr ? nullptr : strdup(enable)),
mWasEnabled(0)
mEnable(enable == nullptr ? nullptr : strdup(enable))
{
}

Expand Down Expand Up @@ -191,15 +194,9 @@ namespace {

class FtraceReader {
public:
//NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
FtraceReader(Barrier * const barrier, int cpu, int tfd, int pfd0, int pfd1, ssize_t pageSize)
: mNext(mHead),
mBarrier(barrier),
mThread(),
mCpu(cpu),
mTfd(tfd),
mPfd0(pfd0),
mPfd1(pfd1),
pageSize(pageSize)
: mNext(mHead), mBarrier(barrier), mCpu(cpu), mTfd(tfd), mPfd0(pfd0), mPfd1(pfd1), pageSize(pageSize)
{
mHead = this;
}
Expand All @@ -213,11 +210,10 @@ namespace {
[[nodiscard]] int getPfd0() const { return mPfd0; }

private:
static constexpr auto FTRACE_TIMEOUT = std::chrono::seconds {2};
static FtraceReader * mHead;
FtraceReader * const mNext;
Barrier * const mBarrier;
pthread_t mThread;
pthread_t mThread {};
const int mCpu;
const int mTfd;
const int mPfd0;
Expand Down Expand Up @@ -331,76 +327,32 @@ namespace {
handleException();
}

// Starting timer to interrupt thread if it's hanging
std::shared_ptr<std::atomic<bool>> isStuck = std::make_shared<std::atomic<bool>>(true);
std::thread timeoutThread([&, isStuck]() {
std::this_thread::sleep_for(FtraceReader::FTRACE_TIMEOUT);
if (*isStuck) {
LOG_DEBUG("ftrace reader is hanging. Interrupting reader thread");
close(internal_pipe[0]);
close(internal_pipe[1]);
close(mTfd);
close(mPfd1);
pthread_kill(mThread, SIGKILL);
}
});
timeoutThread.detach();

for (;;) {
const ssize_t bytes = splice(mTfd, nullptr, internal_pipe[1], nullptr, pageSize, SPLICE_F_MOVE);
if (bytes <= 0) {
break;
}
// Can there be a short splice read?
if (bytes != pageSize) {
LOG_ERROR("splice short read");
handleException();
}
// Will be read by gatord-external
auto sent = splice(internal_pipe[0], nullptr, mPfd1, nullptr, pageSize, SPLICE_F_MOVE);
if (sent != bytes) {
LOG_ERROR("splice failed when sending data to the external event reader");
handleException();
}
}

{
// Read any slop
std::array<char, 65536> buf {};
ssize_t bytes;
size_t size;

if (buf.size() < static_cast<size_t>(pageSize)) {
LOG_ERROR("ftrace slop buffer is too small");
handleException();
}
for (;;) {
const auto end_time = std::chrono::steady_clock::now() + FTRACE_SLOP_READ_TIMEOUT_DURATION;
while (std::chrono::steady_clock::now() < end_time) {
bytes = read(mTfd, buf.data(), buf.size());
if (bytes == 0) {
LOG_ERROR("ftrace read unexpectedly returned 0");
handleException();
}
else if (bytes < 0) {
if (errno != EAGAIN) {
LOG_ERROR("reading slop from ftrace failed");
handleException();
}
if (bytes <= 0) {
LOG_TRACE("ftrace read finished with result [%zd]", bytes);
break;
}
else {
size = bytes;
bytes = write(mPfd1, buf.data(), size);
if (bytes != static_cast<ssize_t>(size)) {
LOG_ERROR("writing slop to ftrace pipe failed");
handleException();

size = bytes;
bytes = write(mPfd1, buf.data(), size);
if (bytes != static_cast<ssize_t>(size)) {
LOG_ERROR("Writing to ftrace pipe failed: fd:%d, size: %zu, bytes: %zd", mPfd1, size, bytes);
if (bytes == -1) {
LOG_ERROR("ftrace write errno: %d", errno);
}
handleException();
}
}
}

// Disabling the timeout thread
*isStuck = false;

close(internal_pipe[0]);
close(internal_pipe[1]);
close(mTfd);
Expand Down Expand Up @@ -550,7 +502,7 @@ std::pair<std::vector<int>, bool> FtraceDriver::prepare()
}

{
int fd;
int fd {};
// The below call can be slow on loaded high-core count systems.
// NOLINTNEXTLINE(hicpp-signed-bitwise)
fd = ::open(traceFsConstants.path__trace, O_WRONLY | O_TRUNC | O_CLOEXEC);
Expand Down Expand Up @@ -622,11 +574,11 @@ std::pair<std::vector<int>, bool> FtraceDriver::prepare()
}

mBarrier.init(mNumberOfCores + 1);

std::pair<std::vector<int>, bool> result {{}, false};
for (size_t cpu = 0; cpu < mNumberOfCores; ++cpu) {
int pfd[2];
if (pipe2(pfd, O_CLOEXEC) != 0) {
std::array<int, 2> pfd;
if (pipe2(pfd.data(), O_CLOEXEC) != 0) {
// NOLINTNEXTLINE(concurrency-mt-unsafe)
LOG_ERROR("pipe2 failed, %s (%i)", strerror(errno), errno);
handleException();
}
Expand Down Expand Up @@ -664,7 +616,7 @@ void FtraceDriver::start(std::function<void(int, int, std::int64_t)> initialValu
}
}

std::vector<int> FtraceDriver::stop()
std::vector<int> FtraceDriver::requestStop()
{
lib::writeIntToFile(traceFsConstants.path__tracing_on, mTracingOn);

Expand All @@ -682,13 +634,20 @@ std::vector<int> FtraceDriver::stop()
reader->interrupt();
fds.push_back(reader->getPfd0());
}
}
return fds;
}

//NOLINTNEXTLINE(readability-convert-member-functions-to-static)
void FtraceDriver::stop()
{
if (gSessionData.mFtraceRaw) {
for (FtraceReader * reader = FtraceReader::getHead(); reader != nullptr; reader = reader->getNext()) {
if (!reader->join()) {
LOG_WARNING("Failed to wait for FtraceReader to finish. It's possible the thread has already ended.");
}
}
}
return fds;
}

bool FtraceDriver::readTracepointFormats(IPerfAttrsConsumer & attrsConsumer, DynBuf * const printb, DynBuf * const b)
Expand Down
Loading

0 comments on commit c1e117e

Please sign in to comment.