Skip to content

Commit

Permalink
control/server.py: auto detection of spdk reactor cpu bitmask
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
  • Loading branch information
Alexander Indenbaum committed Sep 8, 2024
1 parent b0e1236 commit 924fc1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ceph-nvmeof.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tgt_path = /usr/local/bin/nvmf_tgt
timeout = 60.0
#log_level = WARNING

# Example value: -m 0x3 -L all
# Example value: -L all
# tgt_cmd_extra_args =

# transports = tcp
Expand Down
13 changes: 13 additions & 0 deletions control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def sigchld_handler(signum, frame):
# GW process should exit now
raise SystemExit(f"Gateway subprocess terminated {pid=} {exit_code=}")

def int_to_bitmask(n):
"""Converts an integer n to a bitmask string"""
return f"0x{hex((1 << n) - 1)[2:].upper()}"

class GatewayServer:
"""Runs SPDK and receives client requests for the gateway service.
Expand Down Expand Up @@ -363,8 +367,17 @@ def _start_spdk(self, omap_state):
spdk_tgt_cmd_extra_args = self.config.get_with_default(
"spdk", "tgt_cmd_extra_args", "")
cmd = [spdk_tgt_path, "-u", "-r", self.spdk_rpc_socket_path]

# Add extra args from the conf file
if spdk_tgt_cmd_extra_args:
if '-m ' not in spdk_tgt_cmd_extra_args and '--cpumask ' not in spdk_tgt_cmd_extra_args:
# if not provided in configuration,
# calculate cpu mask available for spdk reactors
cpu_mask = f"-m {int_to_bitmask(os.cpu_count())}"
self.logger.info(f"SPDK autodetecting cpu_mask: {cpu_mask}")
cmd += shlex.split(cpu_mask)
cmd += shlex.split(spdk_tgt_cmd_extra_args)

self.logger.info(f"Starting {' '.join(cmd)}")
try:
# start spdk process
Expand Down

0 comments on commit 924fc1a

Please sign in to comment.