Skip to content

Commit 3a918e2

Browse files
Addressed Nathan's comments - v1
Signed-off-by: Mohith Kumar Thummaluru <[email protected]>
1 parent 61b429f commit 3a918e2

File tree

12 files changed

+237
-236
lines changed

12 files changed

+237
-236
lines changed

build/rpm/pcp.spec.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ collecting statistics for nVidia RDMA over Converged Ethernet (RoCE) devices.
16031603
#
16041604
%package pmda-rds
16051605
License: GPL-2.0-or-later
1606-
Summary: Performance Co-Pilot (PCP) metrics for RDS protocol
1606+
Summary: Performance Co-Pilot (PCP) metrics for Reliable Datagram Sockets (RDS) protocol
16071607
URL: https://pcp.io
16081608
Requires: pcp = @package_version@ pcp-libs = @package_version@
16091609
Requires: python3-pcp

build/rpm/redhat.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ collecting statistics for nVidia RDMA over Converged Ethernet (RoCE) devices.
17641764
#
17651765
%package pmda-rds
17661766
License: GPL-2.0-or-later
1767-
Summary: Performance Co-Pilot (PCP) metrics for RDS protocol
1767+
Summary: Performance Co-Pilot (PCP) metrics for Reliable Datagram Sockets (RDS) protocol
17681768
URL: https://pcp.io
17691769
Requires: pcp = %{version}-%{release} pcp-libs = %{version}-%{release}
17701770
Requires: python3-pcp

src/pmdas/rds/GNUmakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@ endif
4848
check_domain: ../../pmns/stdpmid
4949
$(DOMAIN_PYTHONRULE)
5050

51+
check:: $(PYSCRIPT)
52+
$(PYLINT) $^
53+
5154
check:: $(MAN_PAGES)
5255
$(MANLINT) $^

src/pmdas/rds/Install

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ iam=rds
2020
python_opt=true
2121
daemon_opt=false
2222

23-
# Prepare PMDA Python files (needed for easier packaging)
24-
$PCP_PYTHON_PROG $PCP_PMDAS_DIR/rds/pyprep
25-
2623
#
2724
# See pmcd(1) man page. PMDA starts up in the "not ready" state.
2825
# When it has finished starting up, it sends a PM_ERR_PMDAREADY

src/pmdas/rds/domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define RDS 256
1+
#define RDS 255

src/pmdas/rds/modules/ping.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import signal
3030
import re
3131
import concurrent.futures
32-
33-
sys.path.append("/var/lib/pcp/pmdas/rds/modules")
3432
from rds_info import RdsInfo
3533

3634
ICMP_ECHO = 8

src/pmdas/rds/modules/rds_info.py

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,25 @@
5353
"tcp_send failure"
5454
]
5555

56+
5657
class RdsInfo:
5758
"""Class to implement standard RDS info operations."""
5859

60+
USAGE_MSG = (
61+
"Usage: python rds_info.py <option>\n"
62+
"Available options:\n"
63+
" -I: Get RDS InfiniBand connections\n"
64+
" -T: Get RDS TCP Connections\n"
65+
" -c: Get RDS counters\n"
66+
" -k: Get RDS socket information\n"
67+
" -n: Get RDS connection details\n"
68+
" -p: Get RDS connection paths\n"
69+
" -r: Get RDS receive queues\n"
70+
" -s: Get RDS send queues\n"
71+
" -t: Get RDS retransmit queues\n"
72+
" --help: Show this help message\n"
73+
)
74+
5975
libc = ctypes.CDLL("libc.so.6", use_errno=True)
6076

6177
def create_rds_socket(self):
@@ -67,10 +83,12 @@ def create_rds_socket(self):
6783
def get_rds_info_data(self, sock_fd, query_type):
6884
"""Retrieve RDS information data."""
6985
data_len = ctypes.c_int(0)
70-
res = self.libc.getsockopt(sock_fd, SOL_RDS, query_type, None, ctypes.byref(data_len))
86+
res = self.libc.getsockopt(
87+
sock_fd, SOL_RDS, query_type, None, ctypes.byref(data_len))
7188
if res < 0:
7289
data_buffer = ctypes.create_string_buffer(int(data_len.value))
73-
res = self.libc.getsockopt(sock_fd, SOL_RDS, query_type, data_buffer, ctypes.byref(data_len))
90+
res = self.libc.getsockopt(
91+
sock_fd, SOL_RDS, query_type, data_buffer, ctypes.byref(data_len))
7492
if res < 0:
7593
return None
7694

@@ -120,7 +138,8 @@ def get_down_time(conn_time, attempt_time):
120138
@staticmethod
121139
def decode_flags(value):
122140
"""Decode RDS Flags."""
123-
flags = "".join([char if value & (1 << i) else "-" for i, char in enumerate("scCE")])
141+
flags = "".join(
142+
[char if value & (1 << i) else "-" for i, char in enumerate("scCE")])
124143
return flags
125144

126145
def get_rds_ib_conns(self, sock_fd):
@@ -142,10 +161,11 @@ def get_rds_ib_conns(self, sock_fd):
142161
src_qp = self.htosi(data[i+76:i+80], True)
143162
dst_qp = self.htosi(data[i+88:i+92], True)
144163

145-
res.append(f"{saddr:14} {daddr:14} {tos:3} {sol:2} {s_dev:31} {d_dev:32} {src_qp:9} {dst_qp:9}")
164+
res.append(
165+
f"{saddr:14} {daddr:14} {tos:3} {sol:2} {s_dev:31} {d_dev:32} {src_qp:9} {dst_qp:9}")
146166
return "\n".join(res)
147167

148-
def get_rds_tcp_sockets(self, sock_fd):
168+
def get_rds_tcp_conns(self, sock_fd):
149169
"""Get RDS_INFO_TCP_SOCKETS from socket and parse it."""
150170
data, each = self.get_rds_info_data(sock_fd, RDS_INFO_TCP_SOCKETS)
151171

@@ -160,9 +180,12 @@ def get_rds_tcp_sockets(self, sock_fd):
160180
rport = str(int(data[i+10:i+12].hex(), 16))
161181
hdr_remain = str(int(data[i+12:i+13].hex(), 16))
162182
data_remain = str(int(data[i+13:i+14].hex(), 16))
163-
sent_nxt = str(self.little_endian_to_unsigned(data[i+28:i+32].hex(), 32))
164-
exp_una = str(self.little_endian_to_unsigned(data[i+32:i+36].hex(), 32))
165-
seen_una = str(self.little_endian_to_unsigned(data[i+36:i+40].hex(), 32))
183+
sent_nxt = str(self.little_endian_to_unsigned(
184+
data[i+28:i+32].hex(), 32))
185+
exp_una = str(self.little_endian_to_unsigned(
186+
data[i+32:i+36].hex(), 32))
187+
seen_una = str(self.little_endian_to_unsigned(
188+
data[i+36:i+40].hex(), 32))
166189

167190
res.append(
168191
f"{laddr:15} {lport:5} {raddr:15} {rport:5} "
@@ -194,10 +217,13 @@ def get_rds_conns(self, sock_fd):
194217
for i in range(0, len(data), each):
195218
laddr = socket.inet_ntoa(data[i+16:i+20])
196219
raddr = socket.inet_ntoa(data[i+20:i+24])
197-
tos = str(struct.unpack("<b", data[i + 41 : i + 42])[0])
198-
next_tx = str(self.little_endian_to_unsigned(data[i + 0 : i + 4].hex(), 32))
199-
next_rx = str(self.little_endian_to_unsigned(data[i + 8 : i + 12].hex(), 32))
200-
flags = self.decode_flags(int(struct.unpack("<b", data[i + 40 : i + 41])[0]))
220+
tos = str(struct.unpack("<b", data[i + 41: i + 42])[0])
221+
next_tx = str(self.little_endian_to_unsigned(
222+
data[i + 0: i + 4].hex(), 32))
223+
next_rx = str(self.little_endian_to_unsigned(
224+
data[i + 8: i + 12].hex(), 32))
225+
flags = self.decode_flags(
226+
int(struct.unpack("<b", data[i + 40: i + 41])[0]))
201227

202228
res.append(f"{laddr} {raddr} {tos} {next_rx} {next_tx} {flags}")
203229

@@ -215,21 +241,22 @@ def get_rds_sockets(self, sock_fd):
215241
res = []
216242

217243
for i in range(0, len(data), each):
218-
laddr = socket.inet_ntoa(data[i + 4 : i + 8])
219-
raddr = socket.inet_ntoa(data[i + 8 : i + 12])
220-
lport = str(int(data[i + 12 : i + 14].hex(), 16))
221-
rport = str(int(data[i + 14 : i + 16].hex(), 16))
244+
laddr = socket.inet_ntoa(data[i + 4: i + 8])
245+
raddr = socket.inet_ntoa(data[i + 8: i + 12])
246+
lport = str(int(data[i + 12: i + 14].hex(), 16))
247+
rport = str(int(data[i + 14: i + 16].hex(), 16))
222248

223-
snd_buf = str(struct.unpack("<I", data[i : i + 4])[0])
224-
rcv_buf = self.little_endian_to_unsigned(data[i + 16 : i + 20].hex(), 32)
225-
inode = str(struct.unpack("<Q", data[i + 20 : i + 28])[0])
249+
snd_buf = str(struct.unpack("<I", data[i: i + 4])[0])
250+
rcv_buf = self.little_endian_to_unsigned(
251+
data[i + 16: i + 20].hex(), 32)
252+
inode = str(struct.unpack("<Q", data[i + 20: i + 28])[0])
226253

227254
# Default values for pid and comm
228255
pid, comm = "NA", "NA"
229256

230257
try:
231258
cong = self.htosi(data[i+32:i+36], True)
232-
pid = struct.unpack("<I", data[i + 28 : i + 32])[0]
259+
pid = struct.unpack("<I", data[i + 28: i + 32])[0]
233260
comm = psutil.Process(pid).name()
234261
except (psutil.NoSuchProcess, psutil.AccessDenied, struct.error):
235262
comm, pid, cong = "NA", "NA", -1
@@ -273,13 +300,13 @@ def get_rds_queues(self, sock_fd, arg):
273300
res = []
274301

275302
for i in range(0, len(data), each):
276-
laddr = str(socket.inet_ntoa(data[i + 12 : i + 16]))
277-
raddr = str(socket.inet_ntoa(data[i + 16 : i + 20]))
278-
lport = str(int(data[i + 20 : i + 22].hex(), 16))
279-
rport = str(int(data[i + 22 : i + 24].hex(), 16))
280-
tos = str(struct.unpack("<b", data[i + 24 : i + 25])[0])
281-
seq = str(struct.unpack("<Q", data[i : i + 8])[0])
282-
byte = str(struct.unpack("<I", data[i + 8 : i + 12])[0])
303+
laddr = str(socket.inet_ntoa(data[i + 12: i + 16]))
304+
raddr = str(socket.inet_ntoa(data[i + 16: i + 20]))
305+
lport = str(int(data[i + 20: i + 22].hex(), 16))
306+
rport = str(int(data[i + 22: i + 24].hex(), 16))
307+
tos = str(struct.unpack("<b", data[i + 24: i + 25])[0])
308+
seq = str(struct.unpack("<Q", data[i: i + 8])[0])
309+
byte = str(struct.unpack("<I", data[i + 8: i + 12])[0])
283310

284311
res.append(f"{laddr} {lport} {raddr} {rport} {tos} {seq} {byte}")
285312
return "\n".join(res)
@@ -295,17 +322,19 @@ def get_rds_paths(self, sock_fd):
295322
res = []
296323

297324
# Header for the main connection paths
298-
res.append(f"{'LocalAddr':<15} {'RemoteAddr':<15} {'Tos':<4} {'Trans':<10}")
325+
res.append(
326+
f"{'LocalAddr':<15} {'RemoteAddr':<15} {'Tos':<4} {'Trans':<10}")
299327

300328
for i in range(0, len(data), each):
301-
saddr = socket.inet_ntoa(data[i + 12 : i + 16])
302-
daddr = socket.inet_ntoa(data[i + 28 : i + 32])
303-
tos = str(struct.unpack("<b", data[i + 48 : i + 49])[0])
304-
trans = data[i + 32 : i + 48].split(b"\x00", maxsplit=1)[0].decode("utf-8")
329+
saddr = socket.inet_ntoa(data[i + 12: i + 16])
330+
daddr = socket.inet_ntoa(data[i + 28: i + 32])
331+
tos = str(struct.unpack("<b", data[i + 48: i + 49])[0])
332+
trans = data[i + 32: i +
333+
48].split(b"\x00", maxsplit=1)[0].decode("utf-8")
305334

306335
res.append(f"{saddr:<15} {daddr:<15} {tos:<4} {trans:<10}")
307336

308-
path_num = int(struct.unpack("<b", data[i + 49 : i + 50])[0])
337+
path_num = int(struct.unpack("<b", data[i + 49: i + 50])[0])
309338

310339
res += "\n"
311340

@@ -315,30 +344,31 @@ def get_rds_paths(self, sock_fd):
315344
f"{'Attempts':<10} {'RDS':<5} {'Down(Secs)':<13} {'Reason':<15}"
316345
)
317346

318-
path_data = data[i + 50 : i + 346]
347+
path_data = data[i + 50: i + 346]
319348
for j in range(0, len(path_data), 37):
320-
attempt_time = self.parse_time(path_data[j + 0 : j + 8])
321-
conn_time = self.parse_time(path_data[j + 8 : j + 16])
322-
reset_time = self.parse_time(path_data[j + 16 : j + 24])
349+
attempt_time = self.parse_time(path_data[j + 0: j + 8])
350+
conn_time = self.parse_time(path_data[j + 8: j + 16])
351+
reset_time = self.parse_time(path_data[j + 16: j + 24])
323352

324-
reason = int(struct.unpack("<I", path_data[j + 24 : j + 28])[0])
353+
reason = int(struct.unpack("<I", path_data[j + 24: j + 28])[0])
325354
reason = (
326355
CONN_DROP_REASONS[reason]
327356
if reason < len(CONN_DROP_REASONS)
328357
else str(reason)
329358
)
330359

331-
attempts = str(struct.unpack("<I", path_data[j + 28 : j + 32])[0])
332-
p_no = str(struct.unpack("<b", path_data[j + 32 : j + 33])[0])
360+
attempts = str(struct.unpack(
361+
"<I", path_data[j + 28: j + 32])[0])
362+
p_no = str(struct.unpack("<b", path_data[j + 32: j + 33])[0])
333363

334364
rds_flags = self.decode_flags(
335-
int(struct.unpack("<b", path_data[j + 36 : j + 37])[0])
365+
int(struct.unpack("<b", path_data[j + 36: j + 37])[0])
336366
)
337367

338368
down = "---"
339369
if rds_flags == "--C-" and reset_time != "---":
340370
down = self.get_down_time(
341-
path_data[j + 8 : j + 16], path_data[j + 0 : j + 8]
371+
path_data[j + 8: j + 16], path_data[j + 0: j + 8]
342372
)
343373

344374
res.append(
@@ -355,20 +385,9 @@ def main(self, option):
355385
"""
356386
Wrapper function for all the above RDS-INFO options
357387
"""
358-
infos = {
359-
"-I": self.get_rds_ib_conns,
360-
"-T": self.get_rds_tcp_sockets,
361-
"-c": self.get_rds_counters,
362-
"-k": self.get_rds_sockets,
363-
"-n": self.get_rds_conns,
364-
'-p': self.get_rds_paths,
365-
"-r": lambda sock_fd: self.get_rds_queues(sock_fd, '-r'),
366-
"-s": lambda sock_fd: self.get_rds_queues(sock_fd, '-s'),
367-
"-t": lambda sock_fd: self.get_rds_queues(sock_fd, '-t')
368-
}
369388
infos = {
370389
"-I": {"method": self.get_rds_ib_conns, "description": "Get RDS InfiniBand connections"},
371-
"-T": {"method": self.get_rds_tcp_sockets, "description": "Get RDS TCP socket information"},
390+
"-T": {"method": self.get_rds_tcp_conns, "description": "Get RDS TCP connetions"},
372391
"-c": {"method": self.get_rds_counters, "description": "Get RDS counters"},
373392
"-k": {"method": self.get_rds_sockets, "description": "Get RDS socket information"},
374393
"-n": {"method": self.get_rds_conns, "description": "Get RDS connection details"},
@@ -380,24 +399,21 @@ def main(self, option):
380399
"description": "Get RDS retransmit queues"},
381400
}
382401

383-
384402
# If the user requests help or an invalid option is passed
385403
if option == "--help" or option not in infos:
386-
print("Usage: python script.py <option>")
387-
print("Available options:")
388-
for key, value in infos.items():
389-
print(f" {key}: {value['description']}")
404+
print(self.USAGE_MSG)
390405
return ""
391406

392407
sock_fd = self.create_rds_socket()
393408
res = infos[option]["method"](sock_fd)
394409
self.libc.close(sock_fd)
395410
return res
396411

412+
397413
if __name__ == "__main__":
398414
# Ensure an argument is passed
399415
if len(sys.argv) != 2:
400-
print("Usage: python rds_info.py <option>")
416+
print(RdsInfo.USAGE_MSG)
401417
sys.exit(1)
402418

403419
cmd_option = sys.argv[1]

src/pmdas/rds/modules/rds_ping.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
import time
2525
import json
2626
from time import perf_counter
27-
sys.path.append("/var/lib/pcp/pmdas/rds/modules")
28-
from rds_info import RdsInfo
2927

28+
from rds_info import RdsInfo
3029

3130
rds_pings_json = {}
3231

33-
3432
def signal_handler(sig, frame):
3533
sys.exit(0)
3634

0 commit comments

Comments
 (0)