aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/qps
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2016-02-01 09:33:11 -0800
committerGravatar Vijay Pai <vpai@google.com>2016-02-01 09:33:11 -0800
commitc64736d852991c734938a16d58cb5861b7014c07 (patch)
tree1b0ea4a17540426fc2355aabba5c85f1492c5de4 /test/cpp/qps
parent03ba4d746a34855c2d6498f23b06f8a0ae6592eb (diff)
Clean-up core list usage and make it possible to reset the core list
Diffstat (limited to 'test/cpp/qps')
-rw-r--r--test/cpp/qps/client.h2
-rw-r--r--test/cpp/qps/limit_cores.cc34
-rw-r--r--test/cpp/qps/limit_cores.h5
-rw-r--r--test/cpp/qps/qps_worker.cc4
-rw-r--r--test/cpp/qps/server.h12
5 files changed, 29 insertions, 28 deletions
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index 576adeb256..7d5f6466f9 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -324,6 +324,8 @@ class ClientImpl : public Client {
std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)>
create_stub)
: channels_(config.client_channels()), create_stub_(create_stub) {
+ LimitCores(config.core_list().data(), config.core_list_size());
+
for (int i = 0; i < config.client_channels(); i++) {
channels_[i].init(config.server_targets(i % config.server_targets_size()),
config, create_stub_);
diff --git a/test/cpp/qps/limit_cores.cc b/test/cpp/qps/limit_cores.cc
index 0ba46d3d0a..5fd8d555a5 100644
--- a/test/cpp/qps/limit_cores.cc
+++ b/test/cpp/qps/limit_cores.cc
@@ -46,23 +46,31 @@ namespace testing {
#define _GNU_SOURCE
#endif
#include <sched.h>
-int LimitCores(std::vector<int> cores) {
- size_t num_cores = static_cast<size_t>(gpr_cpu_num_cores());
- if (num_cores > cores.size()) {
- cpu_set_t *cpup = CPU_ALLOC(num_cores);
- GPR_ASSERT(cpup);
- size_t size = CPU_ALLOC_SIZE(num_cores);
- CPU_ZERO_S(size, cpup);
+int LimitCores(const int *cores, int cores_size) {
+ int num_cores = gpr_cpu_num_cores();
+ int cores_set = 0;
- for (size_t i = 0; i < cores.size(); i++) {
- CPU_SET_S(cores[i], size, cpup);
+ cpu_set_t *cpup = CPU_ALLOC(num_cores);
+ GPR_ASSERT(cpup);
+ size_t size = CPU_ALLOC_SIZE(num_cores);
+ CPU_ZERO_S(size, cpup);
+
+ if (cores_size > 0) {
+ for (int i = 0; i < cores_size; i++) {
+ if (cores[i] < num_cores) {
+ CPU_SET_S(cores[i], size, cpup);
+ cores_set++;
+ }
}
- GPR_ASSERT(sched_setaffinity(0, size, cpup) == 0);
- CPU_FREE(cpup);
- return cores.size();
} else {
- return num_cores;
+ for (int i = 0; i < num_cores; i++) {
+ CPU_SET_S(i, size, cpup);
+ cores_set++;
+ }
}
+ GPR_ASSERT(sched_setaffinity(0, size, cpup) == 0);
+ CPU_FREE(cpup);
+ return cores_set;
}
#else
// LimitCores is not currently supported for non-Linux platforms
diff --git a/test/cpp/qps/limit_cores.h b/test/cpp/qps/limit_cores.h
index 54c805216c..5467f3b881 100644
--- a/test/cpp/qps/limit_cores.h
+++ b/test/cpp/qps/limit_cores.h
@@ -38,7 +38,10 @@
namespace grpc {
namespace testing {
-int LimitCores(std::vector<int> core_vec);
+// LimitCores takes array and size arguments (instead of vector) for more direct
+// conversion from repeated field of protobuf. Use a cores_size of 0 to remove
+// existing limits (from an empty repeated field)
+int LimitCores(const int *cores, int cores_size);
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc
index 5cb5850fd4..6289c1a843 100644
--- a/test/cpp/qps/qps_worker.cc
+++ b/test/cpp/qps/qps_worker.cc
@@ -87,10 +87,6 @@ static std::unique_ptr<Server> CreateServer(const ServerConfig& config) {
gpr_log(GPR_INFO, "Starting server of type %s",
ServerType_Name(config.server_type()).c_str());
- if (config.core_limit() > 0) {
- LimitCores(config.core_limit());
- }
-
switch (config.server_type()) {
case ServerType::SYNC_SERVER:
return CreateSynchronousServer(config);
diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h
index bc6f9f99e3..94a6f8acfa 100644
--- a/test/cpp/qps/server.h
+++ b/test/cpp/qps/server.h
@@ -51,18 +51,10 @@ namespace testing {
class Server {
public:
explicit Server(const ServerConfig& config) : timer_(new Timer) {
- int clsize = config.core_list_size();
- if (clsize > 0) {
- std::vector<int> core_list;
- for (int i = 0; i < clsize; i++) {
- core_list.push_back(config.core_list(i));
- }
- cores_ = LimitCores(core_list);
- } else {
- cores_ = gpr_cpu_num_cores();
- }
+ cores_ = LimitCores(config.core_list().data(), config.core_list_size());
if (config.port()) {
port_ = config.port();
+
} else {
port_ = grpc_pick_unused_port_or_die();
}