Commit bcddcc15 authored by Micha Mueller's avatar Micha Mueller
Browse files

Change to perf-plugin: groups which only differ in the cpuId share one timer

parent ec5d984f
......@@ -26,6 +26,7 @@ struct read_format {
PerfSensorGroup::PerfSensorGroup(const std::string& name) :
SensorGroupTemplate(name),
_sensorGroupLeader(false),
_cpuId(0),
_group_fd(-1),
_bufSize(0) {
......@@ -41,6 +42,8 @@ PerfSensorGroup::~PerfSensorGroup() {
void PerfSensorGroup::init(boost::asio::io_service& io) {
SensorGroupTemplate::init(io);
//allocate buffer to read in later
//requires 16 byte per sensor plus an additional 8 byte for a 64bit value
std::size_t bufSize = _sensors.size() * 16 + 8;
if (!_buf) {
_buf = new char[bufSize];
......@@ -50,6 +53,11 @@ void PerfSensorGroup::init(boost::asio::io_service& io) {
_buf = new char[bufSize];
_bufSize = bufSize;
}
if(!_sensorGroupLeader) {
//only the sensorGroupLeader needs a timer
_timer = nullptr;
}
}
void PerfSensorGroup::start() {
......@@ -106,8 +114,10 @@ void PerfSensorGroup::start() {
ioctl(_group_fd, PERF_EVENT_IOC_ENABLE, 0);
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&PerfSensorGroup::readAsync, this));
if (_sensorGroupLeader) {
_pendingTasks++;
_timer->async_wait(std::bind(&PerfSensorGroup::readAsync, this));
}
LOG(info) << "Sensorgroup " << _groupName << " started.";
}
......@@ -117,6 +127,7 @@ void PerfSensorGroup::stop() {
for(auto& fd : _fds) {
close(fd);
}
_ids.clear();
_fds.clear();
close(_group_fd);
_group_fd = -1;
......@@ -164,6 +175,12 @@ void PerfSensorGroup::read() {
void PerfSensorGroup::readAsync() {
read();
if(_sensorGroupLeader) {
for(auto g : _fellowSensorGroups) {
g->read();
}
}
if (_timer && _keepRunning) {
_timer->expires_at(timestamp2ptime(nextReadingTime()));
_pendingTasks++;
......
......@@ -20,13 +20,20 @@ public:
void start() override;
void stop() override;
int getCpuId() const { return _cpuId; }
void setCpuId(int cpuId) { _cpuId = cpuId; }
int getCpuId() const { return _cpuId; }
void setCpuId(int cpuId) { _cpuId = cpuId; }
void setSensorGroupLeader(bool sensorGroupLeader) { _sensorGroupLeader = sensorGroupLeader; }
void pushBackGroup(PerfSensorGroup* perfGroup) { _fellowSensorGroups.push_back(perfGroup); }
private:
void read() override;
void readAsync() override;
//are we the sensorGroupLeader?
bool _sensorGroupLeader;
int _cpuId;
int _group_fd;
std::vector<int> _fds;
......@@ -34,6 +41,9 @@ private:
char * _buf;
std::size_t _bufSize;
std::vector<uint64_t> _ids;
//the sensorGroupLeader stores attached groups in here
std::vector<PerfSensorGroup*> _fellowSensorGroups;
};
#endif /* PERFSENSORGROUP_H_ */
......@@ -163,15 +163,32 @@ bool PerfeventConfigurator::readConfig(std::string cfgPath) {
}
//customize perfCounterGroup for every CPU
for (auto i : cpuSet) {
PerfSensorGroup* perfSG = new PerfSensorGroup(group);
if(!cpuSet.empty()) {
//first create groupLeader
std::set<int>::iterator it = cpuSet.begin();
PerfSensorGroup* leaderSG = new PerfSensorGroup(group);
leaderSG->setSensorGroupLeader(true);
std::stringstream mqttPart;
mqttPart << std::setfill ('0') << std::setw(group.getMqttPart().size()) << std::hex << i << "/";
mqttPart << std::setfill ('0') << std::setw(group.getMqttPart().size()) << std::hex << *it << "/";
perfSG->setGroupName(perfSG->getGroupName() + std::to_string(i));
perfSG->setCpuId(i);
perfSG->setMqttPart(mqttPart.str());
storeSensorGroup(perfSG);
leaderSG->setGroupName(leaderSG->getGroupName() + std::to_string(*it));
leaderSG->setCpuId(*it);
leaderSG->setMqttPart(mqttPart.str());
storeSensorGroup(leaderSG);
it++;
//create fellow groups
for (; it != cpuSet.end(); ++it) {
PerfSensorGroup* perfSG = new PerfSensorGroup(group);
std::stringstream mqttPart;
mqttPart << std::setfill ('0') << std::setw(group.getMqttPart().size()) << std::hex << *it << "/";
perfSG->setGroupName(perfSG->getGroupName() + std::to_string(*it));
perfSG->setCpuId(*it);
perfSG->setMqttPart(mqttPart.str());
storeSensorGroup(perfSG);
leaderSG->pushBackGroup(perfSG);
}
}
} else {
LOG(warning) << _groupName << " \"" << val.second.data() << "\" has bad values! Ignoring...";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment