Skip to content

Commit

Permalink
Added 7.0 sources
Browse files Browse the repository at this point in the history
  • Loading branch information
bengaineyarm committed Sep 9, 2019
1 parent 2fd64ec commit e271cd9
Show file tree
Hide file tree
Showing 74 changed files with 2,200 additions and 1,210 deletions.
35 changes: 35 additions & 0 deletions README-mobilesuite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Gator daemon, driver and related tools

The source code for `gatord` and related tools.

## License

* `daemon`, `notify` and `setup` are provided under GPL-2.0-only. See [daemon/COPYING], [notify/COPYING] and [setup/COPYING] respectively.
* `annotate` is provided under the BSD-3-Clause license. See [annotate/LICENSE].

This project contains code from other projects listed below. The original license text is included in those source files.

* `libsensors` source code in [daemon/libsensors] licensed under LGPL-2.1-or-later
* `mxml` source code in [daemon/mxml] licensed under LGPL-2.0 WITH Mini-XML-exception
* `perf_event.h` from Linux userspace kernel headers in [daemon/k] licensed under GPL-2.0-only WITH Linux-syscall-note

## Contributing

Contributions are accepted under the same license as the associated subproject with developer sign-off as described in [Contributing].

## Purpose

Instructions on setting up Arm Streamline on the target.

A target agent (gator) is required to run on the Arm target in order for Arm Streamline to operate. Gator requires Linux 3.4 or later.

Please refer to the Streamline Userguide for more details.

[Contributing]: Contributing.md
[annotate/LICENSE]: annotate/LICENSE
[daemon/COPYING]: daemon/COPYING
[daemon/k]: daemon/k
[daemon/libsensors]: daemon/libsensors
[daemon/mxml]: daemon/mxml
[notify/COPYING]: notify/COPYING
[setup/COPYING]: setup/COPYING
19 changes: 15 additions & 4 deletions daemon/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ MD5_SRC := $(GEN_DIR)/SrcMd5.cpp
# Generate some files into the output directory
XML_H := $(shell $(MAKE) -C $(LOCAL_PATH) OBJ_DIR="$(GEN_DIR)" ndk-prerequisites)

# Set to 1 to enable compiling with LTO using *LDD* as the linker
USE_LTO := 0

LOCAL_SRC_FILES := \
AnnotateListener.cpp \
AtraceDriver.cpp \
Expand All @@ -26,7 +29,6 @@ LOCAL_SRC_FILES := \
Drivers.cpp \
DriverSource.cpp \
DynBuf.cpp \
EventsXML.cpp \
ExternalDriver.cpp \
ExternalSource.cpp \
Fifo.cpp \
Expand Down Expand Up @@ -109,8 +111,7 @@ LOCAL_SRC_FILES := \
non_root/ProcessStatsTracker.cpp \
OlySocket.cpp \
OlyUtility.cpp \
PmuXML.cpp \
PmuXMLParser.cpp \
pmus_xml.cpp \
PolledDriver.cpp \
PrimarySourceProvider.cpp \
Proc.cpp \
Expand All @@ -125,12 +126,22 @@ LOCAL_SRC_FILES := \
TtraceDriver.cpp \
UEvent.cpp \
UserSpaceSource.cpp \
xml/EventsXML.cpp \
xml/EventsXMLProcessor.cpp \
xml/MxmlUtils.cpp \
xml/PmuXML.cpp \
xml/PmuXMLParser.cpp \
$(MD5_SRC)

LOCAL_CFLAGS += -Wall -O3 -fno-exceptions -pthread -DETCDIR=\"/etc\" -Ilibsensors -fPIE -I$(LOCAL_PATH)/$(GEN_DIR)
LOCAL_CFLAGS += -Wall -O3 -fno-exceptions -pthread -DETCDIR=\"/etc\" -Ilibsensors -fPIE -I$(LOCAL_PATH)/$(GEN_DIR) -fvisibility=hidden
LOCAL_CPPFLAGS += -fno-rtti -Wextra -Wpointer-arith -std=c++11 -static-libstdc++
LOCAL_LDFLAGS += -fPIE -pie

ifeq ($(USE_LTO),1)
LOCAL_CFLAGS += -flto -fuse-ld=lld -ffunction-sections -fdata-sections
LOCAL_LDFLAGS += -flto -fuse-ld=lld -Wl,--gc-sections
endif

LOCAL_C_INCLUDES := $(LOCAL_PATH)

LOCAL_MODULE := gatord
Expand Down
2 changes: 1 addition & 1 deletion daemon/Application.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_PLATFORM := android-17
APP_PLATFORM := android-23
# Replace armeabi-v7a with arm64-v8a to build an arm64 gatord or with armeabi to build an ARM11 gatord
APP_ABI := arm64-v8a
# Require 4.8 or later (for c++11)
Expand Down
2 changes: 1 addition & 1 deletion daemon/CapturedXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "SessionData.h"
#include "Logging.h"
#include "OlyUtility.h"
#include "mxml/mxml.h"
#include "xml/MxmlUtils.h"
#include "lib/FsEntry.h"

/* Basic target OS detection */
Expand Down
183 changes: 93 additions & 90 deletions daemon/Child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "StreamlineSetup.h"
#include "UserSpaceSource.h"
#include "PolledDriver.h"
#include "EventsXML.h"
#include "xml/EventsXML.h"
#include "lib/WaitForProcessPoller.h"
#include "mali_userspace/MaliHwCntrSource.h"

Expand Down Expand Up @@ -147,7 +147,7 @@ Child::Child(Drivers & drivers, OlySocket * sock, const Child::Config & config)
sem_init(&senderThreadStarted, 0, 0);
sem_init(&senderSem, 0, 0);

sessionEnded.clear();
sessionEnded = false;

gSessionData.mSessionIsActive = true;
}
Expand Down Expand Up @@ -289,123 +289,126 @@ void Child::run()
logg.logMessage("Profiling pid: %d", commandPid);
}

// set up stop thread early, so that ping commands get replied to, even if the
// setup phase below takes a long time.
std::thread stopThread { };
if (socket) {
stopThread = std::thread([this]() {stopThreadEntryPoint();});
}

if (gSessionData.mWaitForProcessCommand != nullptr) {
logg.logMessage("Waiting for pids for command '%s'", gSessionData.mWaitForProcessCommand);

WaitForProcessPoller poller { gSessionData.mWaitForProcessCommand };

while (!poller.poll(appPids)) {
while ((!poller.poll(appPids)) && !sessionEnded) {
usleep(1000);
}

logg.logMessage("Got pids for command '%s'", gSessionData.mWaitForProcessCommand);
}

// we only consider --pid for stop on exit if we weren't given an
// app to run
std::set<int> watchPids = appPids.empty() ? gSessionData.mPids : appPids;
if (!sessionEnded)
{
// we only consider --pid for stop on exit if we weren't given an
// app to run
std::set<int> watchPids = appPids.empty() ? gSessionData.mPids : appPids;

appPids.insert(gSessionData.mPids.begin(), gSessionData.mPids.end());
appPids.insert(gSessionData.mPids.begin(), gSessionData.mPids.end());

// Set up the driver; must be done after gSessionData.mPerfCounterType[] is populated
primarySource = primarySourceProvider.createPrimarySource(*this, senderSem, sharedData->startProfile, appPids,
drivers.getFtraceDriver(), enableOnCommandExec);
if (primarySource == nullptr) {
logg.logError("Failed to init primary capture source");
handleException();
}

// set up stop thread early, so that ping commands get replied to, even if the
// setup phase below takes a long time.
std::thread stopThread { };
if (socket) {
stopThread = std::thread([this]() {stopThreadEntryPoint();});
}
// Set up the driver; must be done after gSessionData.mPerfCounterType[] is populated
primarySource = primarySourceProvider.createPrimarySource(*this, senderSem, sharedData->startProfile, appPids,
drivers.getFtraceDriver(), enableOnCommandExec);
if (primarySource == nullptr) {
logg.logError("Failed to init primary capture source");
handleException();
}

if (primarySourceProvider.supportsMaliCapture() && primarySourceProvider.isCapturingMaliCounters()
&& !primarySourceProvider.supportsMaliCaptureSampleRate(gSessionData.mSampleRate)) {
logg.logError("Mali counters are not supported with Sample Rate: %i.", gSessionData.mSampleRate);
handleException();
}
if (primarySourceProvider.supportsMaliCapture() && primarySourceProvider.isCapturingMaliCounters()
&& !primarySourceProvider.supportsMaliCaptureSampleRate(gSessionData.mSampleRate)) {
logg.logError("Mali counters are not supported with Sample Rate: %i.", gSessionData.mSampleRate);
handleException();
}

// Initialize ftrace source before child as it's slow and dependens on nothing else
// If initialized later, us gator with ftrace has time sync issues
// Must be initialized before senderThread is started as senderThread checks externalSource
externalSource.reset(new ExternalSource(*this, &senderSem, drivers));
if (!externalSource->prepare()) {
logg.logError("Unable to prepare external source for capture");
handleException();
}
externalSource->start();
// Initialize ftrace source before child as it's slow and dependens on nothing else
// If initialized later, us gator with ftrace has time sync issues
// Must be initialized before senderThread is started as senderThread checks externalSource
externalSource.reset(new ExternalSource(*this, &senderSem, drivers));
if (!externalSource->prepare()) {
logg.logError("Unable to prepare external source for capture");
handleException();
}
externalSource->start();

// Must be after session XML is parsed
if (!primarySource->prepare()) {
logg.logError("%s", primarySourceProvider.getPrepareFailedMessage());
handleException();
}
auto getMonotonicStarted = [&primarySourceProvider]() -> std::int64_t {return primarySourceProvider.getMonotonicStarted();};
// initialize midgard hardware counters
if (drivers.getMaliHwCntrs().countersEnabled()) {
maliHwSource.reset(
new mali_userspace::MaliHwCntrSource(*this, &senderSem, getMonotonicStarted, drivers.getMaliHwCntrs()));
if (!maliHwSource->prepare()) {
logg.logError("Unable to prepare midgard hardware counters source for capture");
// Must be after session XML is parsed
if (!primarySource->prepare()) {
logg.logError("%s", primarySourceProvider.getPrepareFailedMessage());
handleException();
}
maliHwSource->start();
}
auto getMonotonicStarted = [&primarySourceProvider]() -> std::int64_t {return primarySourceProvider.getMonotonicStarted();};
// initialize midgard hardware counters
if (drivers.getMaliHwCntrs().countersEnabled()) {
maliHwSource.reset(
new mali_userspace::MaliHwCntrSource(*this, &senderSem, getMonotonicStarted, drivers.getMaliHwCntrs()));
if (!maliHwSource->prepare()) {
logg.logError("Unable to prepare midgard hardware counters source for capture");
handleException();
}
maliHwSource->start();
}

// Sender thread shall be halted until it is signaled for one shot mode
sem_init(&haltPipeline, 0, gSessionData.mOneShot ? 0 : 2);
// Sender thread shall be halted until it is signaled for one shot mode
sem_init(&haltPipeline, 0, gSessionData.mOneShot ? 0 : 2);

// Create the duration and sender threads
lib::Waiter waiter;
// Create the duration and sender threads
lib::Waiter waiter;

std::thread durationThread { };
if (gSessionData.mDuration > 0) {
durationThread = std::thread([&]() {durationThreadEntryPoint(waiter);});
}
std::thread durationThread { };
if (gSessionData.mDuration > 0) {
durationThread = std::thread([&]() {durationThreadEntryPoint(waiter);});
}

std::thread senderThread { [this]() {senderThreadEntryPoint();} };
std::thread senderThread { [this]() {senderThreadEntryPoint();} };

std::thread watchPidsThread { };
if (gSessionData.mStopOnExit && !watchPids.empty()) {
watchPidsThread = std::thread([&]() {watchPidsThreadEntryPoint(watchPids, waiter);});
}
std::thread watchPidsThread { };
if (gSessionData.mStopOnExit && !watchPids.empty()) {
watchPidsThread = std::thread([&]() {watchPidsThreadEntryPoint(watchPids, waiter);});
}

if (UserSpaceSource::shouldStart(drivers.getAllPolledConst())) {
userSpaceSource.reset(new UserSpaceSource(*this, &senderSem, getMonotonicStarted, drivers.getAllPolled()));
if (!userSpaceSource->prepare()) {
logg.logError("Unable to prepare userspace source for capture");
handleException();
if (UserSpaceSource::shouldStart(drivers.getAllPolledConst())) {
userSpaceSource.reset(new UserSpaceSource(*this, &senderSem, getMonotonicStarted, drivers.getAllPolled()));
if (!userSpaceSource->prepare()) {
logg.logError("Unable to prepare userspace source for capture");
handleException();
}
userSpaceSource->start();
}
userSpaceSource->start();
}

// Wait until thread has started
sem_wait(&senderThreadStarted);
// Wait until thread has started
sem_wait(&senderThreadStarted);

// Start profiling
primarySource->run();
// Start profiling
primarySource->run();

// wake all sleepers
waiter.disable();
// wake all sleepers
waiter.disable();

// Wait for the other threads to exit
if (userSpaceSource != NULL) {
userSpaceSource->join();
}
if (maliHwSource != NULL) {
maliHwSource->join();
}
externalSource->join();
// Wait for the other threads to exit
if (userSpaceSource != NULL) {
userSpaceSource->join();
}
if (maliHwSource != NULL) {
maliHwSource->join();
}
externalSource->join();

if (watchPidsThread.joinable()) {
watchPidsThread.join();
}
senderThread.join();
if (durationThread.joinable()) {
durationThread.join();
if (watchPidsThread.joinable()) {
watchPidsThread.join();
}
senderThread.join();
if (durationThread.joinable()) {
durationThread.join();
}
}

// Shutting down the connection should break the stop thread which is stalling on the socket recv() function
Expand Down Expand Up @@ -449,7 +452,7 @@ void Child::terminateCommand()

void Child::endSession()
{
if (sessionEnded.test_and_set()) {
if (sessionEnded.exchange(true)) {
return; // someone else is running or has ran this
}

Expand Down
2 changes: 1 addition & 1 deletion daemon/Child.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Child
Drivers & drivers;
OlySocket * socket;
int numExceptions;
std::atomic_flag sessionEnded;
std::atomic_bool sessionEnded;
std::atomic_bool commandTerminated;
int commandPid;

Expand Down
3 changes: 2 additions & 1 deletion daemon/ConfigurationXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <sstream>

#include "lib/Format.h"
#include "xml/MxmlUtils.h"

#include "Drivers.h"
#include "ICpuInfo.h"
Expand Down Expand Up @@ -162,7 +163,7 @@ std::unique_ptr<char, void (*)(void *)> getDefaultConfigurationXml(lib::Span<con
mxml_node_t *n = mxmlNewElement(mxmlGetParent(node), TAG_CONFIGURATION);
copyMxmlElementAttrs(n, node);
char buf[1 << 7];
snprintf(buf, sizeof(buf), "%s%s", cluster.getPmncName(),
snprintf(buf, sizeof(buf), "%s%s", cluster.getId(),
counter + sizeof(CLUSTER_VAR) - 1);
mxmlElementSetAttr(n, ATTR_COUNTER, buf);
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/CounterXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "ICpuInfo.h"
#include "Logging.h"
#include "OlyUtility.h"
#include "PmuXML.h"
#include "mxml/mxml.h"
#include "xml/MxmlUtils.h"
#include "xml/PmuXML.h"
#include "SessionData.h"

static mxml_node_t* getTree(lib::Span<const Driver * const > drivers, const ICpuInfo & cpuInfo)
Expand All @@ -44,7 +44,7 @@ static mxml_node_t* getTree(lib::Span<const Driver * const > drivers, const ICpu
for (size_t cluster = 0; cluster < cpuInfo.getClusters().size(); ++cluster) {
mxml_node_t *node = mxmlNewElement(counters, "cluster");
mxmlElementSetAttrf(node, "id", "%zi", cluster);
mxmlElementSetAttr(node, "name", cpuInfo.getClusters()[cluster].getPmncName());
mxmlElementSetAttr(node, "name", cpuInfo.getClusters()[cluster].getId());
}
for (size_t cpu = 0; cpu < cpuInfo.getClusterIds().size(); ++cpu) {
if (cpuInfo.getClusterIds()[cpu] >= 0) {
Expand Down
Loading

0 comments on commit e271cd9

Please sign in to comment.