Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ o2_add_library(Framework
src/CommonDataProcessors.cxx
src/CompletionPolicy.cxx
src/CompletionPolicyHelpers.cxx
src/ComputingResourceHelpers.cxx
src/DispatchPolicy.cxx
src/ConfigParamsHelper.cxx
src/DDSConfigHelpers.cxx
Expand Down
2 changes: 2 additions & 0 deletions Framework/Core/include/Framework/ChannelSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct InputChannelSpec {
std::string name;
enum ChannelType type;
enum ChannelMethod method;
std::string hostname;
unsigned short port;
};

Expand All @@ -52,6 +53,7 @@ struct OutputChannelSpec {
std::string name;
enum ChannelType type;
enum ChannelMethod method;
std::string hostname;
unsigned short port;
size_t listeners;
};
Expand Down
49 changes: 49 additions & 0 deletions Framework/Core/include/Framework/ComputingResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_COMPUTINGRESOURCE_H_
#define O2_FRAMEWORK_COMPUTINGRESOURCE_H_

#include <string>

namespace o2::framework
{

struct ComputingOffer {
float cpu = 0;
float memory = 0;
std::string hostname = "";
unsigned short startPort = 0;
unsigned short rangeSize = 0;
};

/// A computing resource which can be offered to run a device
struct ComputingResource {
ComputingResource() = default;
ComputingResource(ComputingOffer const& offer)
: cpu(offer.cpu),
memory(offer.memory),
hostname(offer.hostname),
startPort(offer.startPort),
lastPort(offer.startPort),
usedPorts(0)
{
}

float cpu = 0;
float memory = 0;
std::string hostname = "";
unsigned short startPort = 0;
unsigned short lastPort = 0;
unsigned short usedPorts = 0;
};

} // namespace o2::framework

#endif // O2_FRAMEWORK_COMPUTINGRESOURCES_H_
2 changes: 2 additions & 0 deletions Framework/Core/include/Framework/DeviceSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define FRAMEWORK_DEVICESPEC_H

#include "Framework/WorkflowSpec.h"
#include "Framework/ComputingResource.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/ChannelSpec.h"
#include "Framework/ChannelInfo.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ struct DeviceSpec {
/// The completion policy to use for this device.
CompletionPolicy completionPolicy;
DispatchPolicy dispatchPolicy;
ComputingResource resource;
};

} // namespace framework
Expand Down
19 changes: 12 additions & 7 deletions Framework/Core/src/ChannelSpecHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "ChannelSpecHelpers.h"
#include <fmt/format.h>
#include <ostream>
#include <cassert>
#include <stdexcept>

namespace o2
{
namespace framework
namespace o2::framework
{

char const* ChannelSpecHelpers::typeAsString(enum ChannelType type)
Expand Down Expand Up @@ -43,9 +42,16 @@ char const* ChannelSpecHelpers::methodAsString(enum ChannelMethod method)
throw std::runtime_error("Unknown ChannelMethod");
}

char const* ChannelSpecHelpers::methodAsUrl(enum ChannelMethod method)
std::string ChannelSpecHelpers::channelUrl(OutputChannelSpec const& channel)
{
return channel.method == ChannelMethod::Bind ? fmt::format("tcp://*:{}", channel.port)
: fmt::format("tcp://{}:{}", channel.hostname, channel.port);
}

std::string ChannelSpecHelpers::channelUrl(InputChannelSpec const& channel)
{
return (method == ChannelMethod::Bind ? "tcp://*:%d" : "tcp://127.0.0.1:%d");
return channel.method == ChannelMethod::Bind ? fmt::format("tcp://*:{}", channel.port)
: fmt::format("tcp://{}:{}", channel.hostname, channel.port);
}

/// Stream operators so that we can use ChannelType with Boost.Test
Expand All @@ -62,5 +68,4 @@ std::ostream& operator<<(std::ostream& s, ChannelMethod const& method)
return s;
}

} // namespace framework
} // namespace o2
} // namespace o2::framework
8 changes: 4 additions & 4 deletions Framework/Core/src/ChannelSpecHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ struct ChannelSpecHelpers {
static char const* typeAsString(enum ChannelType type);
/// return a ChannelMethod as a lowercase string
static char const* methodAsString(enum ChannelMethod method);
/// return a ChannelMethod as a connection url
/// FIXME: currently it only supports tcp://127.0.0.1 and tcp://*, we should
/// have the actual address customizable.
static char const* methodAsUrl(enum ChannelMethod method);
/// @return a url associated to an InputChannelSpec
static std::string channelUrl(InputChannelSpec const&);
/// @return a url associated to an OutputChannelSpec
static std::string channelUrl(OutputChannelSpec const&);
};

/// Stream operators so that we can use ChannelType with Boost.Test
Expand Down
34 changes: 34 additions & 0 deletions Framework/Core/src/ComputingResourceHelpers.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "ComputingResourceHelpers.h"
#include <thread>
#include <unistd.h>

namespace o2::framework
{
long getTotalNumberOfBytes()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
};

ComputingResource ComputingResourceHelpers::getLocalhostResource(unsigned short startPort, unsigned short rangeSize)
{
ComputingResource result;
result.cpu = std::thread::hardware_concurrency(),
result.memory = getTotalNumberOfBytes();
result.hostname = "localhost";
result.startPort = startPort;
result.lastPort = startPort + rangeSize;
result.usedPorts = 0;
return result;
}
} // namespace o2::framework
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,17 @@
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef FRAMEWORK_COMPUTINGRESOURCE_H
#define FRAMEWORK_COMPUTINGRESOURCE_H

#include <string>
#ifndef O2_FRAMEWORK_COMPUTINGRESOURCEHELPERS_H_
#define O2_FRAMEWORK_COMPUTINGRESOURCEHELPERS_H_

namespace o2
{
namespace framework
{
#include "Framework/ComputingResource.h"

/// A computing resource which can be used to run a device.
struct ComputingResource {
float cpu;
float memory;
std::string hostname;
unsigned short port;
namespace o2::framework
{
struct ComputingResourceHelpers {
static ComputingResource getLocalhostResource(unsigned short startPort, unsigned short rangeSize);
};
} // namespace o2::framework

} // namespace framework
} // namespace o2

#endif // FRAMEWORK_COMPUTINGRESOURCES_H
#endif // O2_FRAMEWORK_COMPUTINGRESOURCEHELPERS_H_
Loading