Skip to content

Commit

Permalink
Add nvpmodel control
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Dec 14, 2024
1 parent 6ab23bf commit 11de977
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
25 changes: 21 additions & 4 deletions jtop/core/nvpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
logger = logging.getLogger(__name__)
# Regular expressions
POWER_MODEL_DEFAULT_RE = re.compile(r'PM_CONFIG: DEFAULT=(?P<name>\w+)\((?P<id>\d+)\)')
TPC_POWER_GATING_RE = re.compile(r'TPC_POWER_GATING TPC_PG_MASK (?P<mask>\w+)')
POWER_MODEL_RE = re.compile(r'POWER_MODEL: ID=(?P<id>\d+) NAME=(?P<name>\w+)')
NV_POWER_MODE_RE = re.compile(r'NV Power Mode: (?P<name>\w+)')

Expand All @@ -45,6 +46,7 @@
def nvpmodel_decode():
default = {}
nvpm = {}
nvpm_masks = {}
nvpmodel_p = Command(['nvpmodel', '-p', '--verbose'])
lines = nvpmodel_p(timeout=COMMAND_TIMEOUT)
# Decode lines
Expand All @@ -63,8 +65,14 @@ def nvpmodel_decode():
mode_id = int(parsed_line['id'])
# Save in nvpm list
nvpm[mode_id] = parsed_line['name']
# Search TPC Power Gating
match = re.search(TPC_POWER_GATING_RE, line)
if match:
parsed_line = match.groupdict()
# Extract save mask in nvpm_masks list with the same id
nvpm_masks[mode_id] = parsed_line['mask']
# Make a list
return default, list(nvpm.values())
return default, list(nvpm.values()), list(nvpm_masks.values())


def nvpmodel_query():
Expand Down Expand Up @@ -432,15 +440,18 @@ def __init__(self, jetson_clocks):
# Initialize jetson_clocks config
self._jetson_clocks = jetson_clocks
try:
# Read all NVP modes
self._default, self._nvp_models = nvpmodel_decode()
self._nvp_status = [True] * len(self._nvp_models)
# Read all NVP modes and masks available for this board
self._default, self._nvp_models, self._nvp_masks = nvpmodel_decode()
# Read current nvpmodel
self._nvpmodel_now = nvpmodel_query()
logger.info("nvpmodel running in [{id}]{name} - Default: {default}".format(
name=self._nvpmodel_now['name'],
id=self._nvpmodel_now['id'],
default=self._default['id']))
# Decode current mask
current_mask = self._nvp_masks[self._nvpmodel_now['id']]
# list of all nvpmodel status that can be changed from the current
self._nvp_status = [current_mask == mask for idx, mask in enumerate(self._nvp_masks)]
except (OSError, Command.CommandException):
self._is_nvpmodel = False
logger.warning("nvpmodel not available")
Expand Down Expand Up @@ -509,6 +520,12 @@ def _thread_set_nvp_model(self, nvpmodel_id):
def set_nvpmodel_id(self, nvpmodel_id, force):
if self.is_running():
return False
# Get current NV Power Mode
old_nvp_mask = self._nvp_masks[self.get_nvpmodel_id()]
nvp_mask = self._nvp_masks[nvpmodel_id]
if nvp_mask != old_nvp_mask:
logger.error("The new nvpmodel {nvpmodel_id} has a different mask {nvp_mask}, is not compatible".format(nvpmodel_id=nvpmodel_id, nvp_mask=nvp_mask))
return False
# Start thread Service client
self._nvp_mode_set_thread = Thread(target=self._thread_set_nvp_model, args=(nvpmodel_id, ))
# self._thread.daemon = True
Expand Down
24 changes: 24 additions & 0 deletions jtop/gui/jtopgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ def run(self, loop, seconds):
self.increase(loop=True)
old = datetime.now()

def dialog_window(self):
height, width = self.stdscr.getmaxyx()

dialog_height, dialog_width = 10, 46
dialog_y, dialog_x = (height - dialog_height) // 2, (width - dialog_width) // 2
dialog_win = curses.newwin(dialog_height, dialog_width, dialog_y, dialog_x)
# Add a border around the window
dialog_win.border()

# Add text to the dialog window
dialog_win.addstr(1, 2, "System reboot is required to apply changes", curses.A_BOLD)
dialog_win.addstr(3, 1, "1. Option 1")
dialog_win.addstr(4, 1, "2. Option 2")
dialog_win.addstr(5, 1, "3. Option 3")
dialog_win.addstr(7, 1, "Press 'q' to exit")

# Refresh the window to show the changes

dialog_win.refresh()

dialog_win.timeout(GUI_REFRESH * 2)

def draw(self):
# First, clear the screen
self.stdscr.erase()
Expand All @@ -147,6 +169,8 @@ def draw(self):
self.stdscr.refresh()
# Set a timeout and read keystroke
self.stdscr.timeout(GUI_REFRESH)

self.dialog_window()

def increase(self, loop=False):
# check reset
Expand Down

0 comments on commit 11de977

Please sign in to comment.