Skip to content

Commit 3db4449

Browse files
authored
FEAT: optimize devices & links (#533)
closes #532
1 parent d18478c commit 3db4449

102 files changed

Lines changed: 1221 additions & 1095 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/load_testing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ jobs:
9090
- name: Update PYTHONPATH
9191
run: echo "PYTHONPATH=${{ github.workspace }}/scripts" >> $GITHUB_ENV
9292

93+
- name: Build perf
94+
run: sudo scripts/build-perf.sh
95+
9396
- name: Run perf
9497
run: |
9598
sudo perf record -F 99 -g -- ./${{env.EXECUTABLE_PATH}} -c ${{env.SCENARIO_CONFIG_PATH}} --no-logs > perf.data

scripts/build-perf.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env bash
2+
# Downloaded from https://gist.github.com/karlivory/9111f906f4eb06370b2b237c62a6b00e
3+
# Usage: sudo bash build-perf.sh
4+
5+
set -euo pipefail
6+
7+
# --- Helpers ---
8+
log() { echo -e "\033[1;32m==>\033[0m $*"; }
9+
err() { echo -e "\033[1;31m[ERR]\033[0m $*" >&2; }
10+
11+
[[ $EUID -eq 0 ]] || {
12+
err "Please run as root (use: sudo bash build-perf.sh)"
13+
exit 1
14+
}
15+
export DEBIAN_FRONTEND=noninteractive
16+
17+
FULLREL="$(uname -r)" # e.g. 6.14.0-29-generic
18+
MAJMIN="$(uname -r | awk -F'[.-]' '{print $1 "." $2}')" # e.g. 6.14
19+
WRAP_DIR="/usr/lib/linux-tools/${FULLREL}"
20+
21+
log "Detected running kernel: ${FULLREL}"
22+
log "Using upstream kernel source line: ${MAJMIN}"
23+
24+
# --- Install deps ---
25+
log "Installing build dependencies..."
26+
apt-get update -y
27+
apt-get install -y \
28+
build-essential make gcc g++ pkg-config flex bison \
29+
curl ca-certificates xz-utils tar \
30+
libelf-dev libdw-dev libdwarf-dev libunwind-dev \
31+
libnuma-dev libssl-dev libcap-dev \
32+
zlib1g-dev liblzma-dev libzstd-dev \
33+
libaio-dev libtraceevent-dev libpfm4-dev \
34+
libslang2-dev systemtap-sdt-dev \
35+
python3 python3-dev python3-setuptools \
36+
binutils-dev libiberty-dev libbabeltrace-dev \
37+
libbfd-dev clang llvm || true
38+
apt-get install -y debuginfod || true
39+
40+
# --- Fetch kernel sources ---
41+
WORKDIR="$(mktemp -d -t perfbuild-XXXXXX)"
42+
trap 'rm -rf "$WORKDIR"' EXIT
43+
pushd "$WORKDIR" >/dev/null
44+
45+
BASE_URL="https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x"
46+
ARCHIVE=""
47+
for f in "linux-${MAJMIN}.tar.xz" "linux-${MAJMIN}.tar.gz"; do
48+
log "Downloading: ${BASE_URL}/${f}"
49+
if curl -fsSLO "${BASE_URL}/${f}"; then
50+
ARCHIVE="$f"
51+
break
52+
fi
53+
done
54+
[[ -n "$ARCHIVE" ]] || {
55+
err "Failed to download linux-${MAJMIN} from ${BASE_URL}"
56+
exit 2
57+
}
58+
59+
log "Extracting ${ARCHIVE} ..."
60+
tar -xf "${ARCHIVE}"
61+
SRC_DIR="${WORKDIR}/linux-${MAJMIN}"
62+
[[ -d "${SRC_DIR}/tools/perf" ]] || {
63+
err "tools/perf not found in sources"
64+
exit 3
65+
}
66+
[[ -d "${SRC_DIR}/tools/bpf/bpftool" ]] || {
67+
err "tools/bpf/bpftool not found in sources"
68+
exit 3
69+
}
70+
71+
# --- Build perf ---
72+
pushd "${SRC_DIR}/tools/perf" >/dev/null
73+
log "Building perf (WERROR=0) ..."
74+
make -j"$(nproc)" WERROR=0
75+
log "Built perf version: $(./perf --version)"
76+
popd >/dev/null
77+
78+
# --- Build bpftool ---
79+
pushd "${SRC_DIR}/tools/bpf/bpftool" >/dev/null
80+
log "Building bpftool ..."
81+
make -j"$(nproc)"
82+
log "Built bpftool version: $(./bpftool version || true)"
83+
popd >/dev/null
84+
85+
# --- Install into wrapper path(s) ---
86+
log "Installing perf to ${WRAP_DIR}/perf"
87+
install -d "${WRAP_DIR}"
88+
install -m 0755 "${SRC_DIR}/tools/perf/perf" "${WRAP_DIR}/perf"
89+
90+
log "Installing bpftool to ${WRAP_DIR}/bpftool"
91+
install -m 0755 "${SRC_DIR}/tools/bpf/bpftool/bpftool" "${WRAP_DIR}/bpftool"
92+
93+
# --- Verify via Ubuntu wrappers ---
94+
log "Verifying /usr/bin/perf (Ubuntu wrapper) ..."
95+
if /usr/bin/perf --version >/dev/null 2>&1; then
96+
/usr/bin/perf --version
97+
log "Success: wrapper found perf at ${WRAP_DIR}/perf"
98+
else
99+
err "Wrapper did not run perf. Check that ${WRAP_DIR}/perf exists and is executable."
100+
ls -l "${WRAP_DIR}/perf" || true
101+
exit 4
102+
fi
103+
104+
log "Verifying /usr/sbin/bpftool (Ubuntu wrapper) ..."
105+
if /usr/sbin/bpftool version >/dev/null 2>&1; then
106+
/usr/sbin/bpftool version
107+
log "Success: wrapper found bpftool at ${WRAP_DIR}/bpftool"
108+
else
109+
err "Wrapper did not run bpftool. Check that ${WRAP_DIR}/bpftool exists and is executable."
110+
ls -l "${WRAP_DIR}/bpftool" || true
111+
exit 5
112+
fi
113+
114+
log "Done."

source/id.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
#include <string>
3+
4+
using Id = std::string;
5+
6+
struct IdWithHash {
7+
Id id;
8+
std::size_t hash;
9+
10+
IdWithHash(const Id& a_id) : id(a_id), hash(std::hash<Id>{}(id)) {}
11+
12+
auto operator<=>(const IdWithHash& id) const = default;
13+
};
14+
15+
template <>
16+
struct std::hash<IdWithHash> {
17+
std::size_t operator()(const IdWithHash& id) const noexcept {
18+
return id.hash;
19+
}
20+
};

source/metrics/fairness/fairness.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "utils/explicitly_convertable.hpp"
55
#include "utils/id_table.hpp"
6-
#include "utils/identifier_factory.hpp"
76

87
namespace sim {
98

source/metrics/metrics_storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace sim {
88

99
void MetricsStorage::add_record(TimeNs time, double value) {
10-
m_records.emplace_back(time, value);
10+
m_records.push_back({time, value});
1111
}
1212

1313
const std::vector<std::pair<TimeNs, double>>& MetricsStorage::get_records()

source/metrics/metrics_table/combine_metrics_tables.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <type_traits>
55

66
#include "metrics_multi_id_table.hpp"
7-
#include "utils/identifier_factory.hpp"
7+
#include "utils/identifiable.hpp"
88

99
namespace sim {
1010

source/metrics/packet_reordering/simple_packet_reordering.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,17 @@
22

33
namespace sim {
44

5-
SimplePacketReordering::SimplePacketReordering(std::size_t a_max_packets)
6-
: m_max_packets(a_max_packets), m_inversions_count(0) {}
5+
SimplePacketReordering::SimplePacketReordering()
6+
: m_next_packet_num(0), m_reordering(0) {}
77

88
void SimplePacketReordering::add_record(PacketNum packet_num) {
9-
m_packet_num_set.insert(packet_num);
10-
std::size_t count_lower = m_packet_num_set.order_of_key(packet_num);
11-
std::size_t total_count = m_packet_num_set.size();
12-
std::size_t count_upper = total_count - count_lower - 1;
13-
14-
m_inversions_count += count_upper;
15-
16-
if (m_packet_num_set.size() > m_max_packets) {
17-
m_packet_num_set.erase(m_packet_num_set.begin());
9+
if (packet_num == m_next_packet_num) {
10+
m_next_packet_num++;
11+
} else {
12+
m_reordering++;
1813
}
1914
}
2015

21-
PacketReordering SimplePacketReordering::value() const {
22-
return m_inversions_count;
23-
}
16+
PacketReordering SimplePacketReordering::value() const { return m_reordering; }
2417

2518
}; // namespace sim
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#pragma once
22
#include "i_packet_reordering.hpp"
3-
#include "utils/ordered_set.hpp"
43
#include "utils/statistics.hpp"
54

65
namespace sim {
6+
7+
// Calculates count of packets that arrived not in right order
78
class SimplePacketReordering : public IPacketReordering {
89
public:
9-
explicit SimplePacketReordering(std::size_t a_max_packets = 1'000'000);
10-
~SimplePacketReordering() = default;
10+
SimplePacketReordering();
1111

1212
void add_record(PacketNum packet_num) final;
1313
PacketReordering value() const final;
1414

1515
private:
1616
// maximal count of packets in m_packet_num_set
1717
// When m_packet_num_set.size() growth up it, the smallest element deletes
18-
std::size_t m_max_packets;
19-
uint64_t m_inversions_count;
20-
utils::ordered_set<PacketNum> m_packet_num_set;
18+
std::size_t m_next_packet_num;
19+
PacketReordering m_reordering;
2120
};
2221
} // namespace sim

source/network/connection/connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void Connection::write_inner_metrics(std::filesystem::path output_dir) const {
4444
m_mplb->write_all_metrics(output_dir / "mplb");
4545
}
4646

47-
Id Connection::get_id() const { return m_id; }
47+
const Id& Connection::get_id() const { return m_id; }
4848

4949
void Connection::send_new_portion() {
5050
while (!m_sending_queue.empty()) {

source/network/connection/connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Connection : public IConnection,
2525
virtual void write_inner_metrics(
2626
std::filesystem::path output_dir) const final;
2727

28-
Id get_id() const final;
28+
virtual const Id& get_id() const final;
2929

3030
private:
3131
// to avoid creating on stack

0 commit comments

Comments
 (0)