Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Mar 7, 2023
1 parent 9693772 commit 63c618c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
2 changes: 2 additions & 0 deletions examples/jtop_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
jetson.nvpmodel = 0 # You can write the name of the model as well
# Wait nvpmodel changed
while jetson.ok():
# deepcode ignore AttributeLoadOnPrimitive: nvpmodel is an object with different attribute. See documentation
if jetson.nvpmodel.id == 0:
break
# You can increase or decrease the nvpmodel using
jetson.nvpmodel += 1 # or jetson.nvpmodel = jetson.nvpmodel + 1
# Wait nvpmodel changed
while jetson.ok():
# deepcode ignore AttributeLoadOnPrimitive: nvpmodel is an object with different attribute. See documentation
if jetson.nvpmodel.id == 1:
break
# You can control the fan
Expand Down
2 changes: 1 addition & 1 deletion jtop/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def import_os_variables(SOURCE, PATTERN):
try:
proc = sp.Popen(['bash', '-c', 'source {source} && env'.format(source=SOURCE)], stdout=sp.PIPE, stderr=sp.PIPE)
# Load variables
for tup in map(lambda s: s.decode("utf-8").strip().split('=', 1), proc.stdout):
for tup in [s.decode("utf-8").strip().split('=', 1) for s in proc.stdout]:
name = tup[0].strip()
value = tup[1].strip()
if PATTERN in name:
Expand Down
2 changes: 1 addition & 1 deletion jtop/core/jetson_clocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def close(self):
if self._jetson_clocks_thread is None:
return
if self._jetson_clocks_thread.is_alive():
logger.warning("Wait switch off set jetson_clocks")
logger.warning("Wait switch off jetson_clocks thread")
self._jetson_clocks_thread.join(COMMAND_TIMEOUT)

def show(self):
Expand Down
15 changes: 14 additions & 1 deletion jtop/core/nvpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class NVPModel(object):
#. `NVP Model - Jetson TX/Nano <https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-283/Tegra%20Linux%20Driver%20Package%20Development%20Guide/power_management_tx2.html#wwpID0E0AM0HA>`_
#. `NVP Model - Jetson Xavier <https://docs.nvidia.com/jetson/archives/r35.2.1/DeveloperGuide/text/SD/PlatformPowerAndPerformance/JetsonXavierNxSeriesAndJetsonAgxXavierSeries.html#supported-modes-and-power-efficiency>`_
#. `NVP Model - Jetson Orin <https://docs.nvidia.com/jetson/archives/r35.2.1/DeveloperGuide/text/SD/PlatformPowerAndPerformance/JetsonOrinNxSeriesAndJetsonAgxOrinSeries.html#supported-modes-and-power-efficiency>`_
""" # noqa
""" # noqa

def __init__(self, controller, nvpmodel):
self._controller = controller
Expand Down Expand Up @@ -526,6 +526,19 @@ def is_running(self):
# https://docs.python.org/2.7/library/threading.html#threading.Thread.is_alive
return self._nvp_mode_set_thread.is_alive()

def close(self):
# If jetson_clocks doesn't exist skip
if not self.exists():
return
# If there are no thread running skip
if self._nvp_mode_set_thread is None:
return
if self._nvp_mode_set_thread.is_alive():
logger.warning("Wait switch off nvpmodel thread")
self._nvp_mode_set_thread.join(COMMAND_TIMEOUT)

self._nvp_mode_set_thread.join()

def get_status(self):
running = self.is_running()
# If thread is not running update status
Expand Down
2 changes: 1 addition & 1 deletion jtop/gui/pall.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def draw(self, key, mouse):
if nline < n_print - 1:
self.stdscr.addch(pos_y_mini_menu, column_width * (nline + 1), curses.ACS_TTEE)
self.stdscr.vline(pos_y_mini_menu + 1, column_width * (nline + 1), curses.ACS_VLINE, column_height - 3)
if height_free_area > offset_process_y:
if height_free_area >= offset_process_y:
self.stdscr.addch(pos_y_mini_menu + column_height - 2, column_width * (nline + 1), curses.ACS_BTEE)
else:
self.stdscr.addch(pos_y_mini_menu + column_height - 2, column_width * (nline + 1),
Expand Down
2 changes: 2 additions & 0 deletions jtop/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ def close(self):
self.remove_files()
# Switch off jetson_clocks if there are threads alive
self.jetson_clocks.close()
# Switch off nvpmodel if there are threads alive
self.nvpmodel.close()
# Close stats server
logger.info("Service closed")
return True
Expand Down
67 changes: 36 additions & 31 deletions jtop/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
NUM_CPU = 4


def write_on_file(path, value):
with open(path, 'w') as f:
f.write(value)


def install_cpu(args):
num_cpu = args[0]
path_cpu = os.path.join(FAKE_DIRECTORY, "devices/system/cpu")
# Set number of CPU for fake jetson_clocks
open('/tmp/cpu_numbers', "w").write(str(num_cpu))
write_on_file('/tmp/cpu_numbers', str(num_cpu))
# Build a list of fake CPU
file_proc_stat = "cpu 26716126 25174 7198445 948399047 900582 0 354519 0 0 0\n"
print('Building CPU {num} in {path}'.format(num=num_cpu, path=path_cpu))
Expand All @@ -43,13 +48,13 @@ def install_cpu(args):
if not os.path.isdir(cpu_path):
os.makedirs(cpu_path)
# Fake freq_cpu
open(os.path.join(cpu_path, "scaling_governor"), "w").write("test_cpu")
open(os.path.join(cpu_path, "scaling_min_freq"), "w").write("0")
open(os.path.join(cpu_path, "scaling_max_freq"), "w").write("2035200")
open(os.path.join(cpu_path, "scaling_cur_freq"), "w").write("200000")
open(os.path.join(cpu_path, "cpuinfo_min_freq"), "w").write("0")
open(os.path.join(cpu_path, "cpuinfo_max_freq"), "w").write("2035200")
open(os.path.join(cpu_path, "cpuinfo_cur_freq"), "w").write("200000")
write_on_file(os.path.join(cpu_path, "scaling_governor"), "test_cpu")
write_on_file(os.path.join(cpu_path, "scaling_min_freq"), "0")
write_on_file(os.path.join(cpu_path, "scaling_max_freq"), "2035200")
write_on_file(os.path.join(cpu_path, "scaling_cur_freq"), "200000")
write_on_file(os.path.join(cpu_path, "cpuinfo_min_freq"), "0")
write_on_file(os.path.join(cpu_path, "cpuinfo_max_freq"), "2035200")
write_on_file(os.path.join(cpu_path, "cpuinfo_cur_freq"), "200000")
file_proc_stat += "intr 1183148227 0 158138519 160761681 0 0 0 21819776 0 0 0 0 0 0 671322431\n"
file_proc_stat += "ctxt 1028840383\n"
file_proc_stat += "btime 1674644431\n"
Expand All @@ -60,7 +65,7 @@ def install_cpu(args):
# Write fake /proc/stat
proc_stat_file = os.path.join(FAKE_DIRECTORY, "stat")
print("Write a fake /proc/stat in {file}".format(file=proc_stat_file))
open(proc_stat_file, "w").write(file_proc_stat)
write_on_file(proc_stat_file, file_proc_stat)


def install_igpu(args):
Expand All @@ -86,35 +91,35 @@ def install_igpu(args):
print("Linking {path_igpu} -> {path_devfreq}".format(path_igpu=path_igpu_device_short, path_devfreq=path_devfreq))
# Write fake name
path_name = os.path.join(path_igpu_device, "name")
open(path_name, "w").write("gpu")
write_on_file(path_name, "gpu")
print("Write in {path_name}".format(path_name=path_name))
# Write fake frequencies
open(os.path.join(path_devfreq, "cur_freq"), "w").write("1000000")
open(os.path.join(path_devfreq, "max_freq"), "w").write("921600000")
open(os.path.join(path_devfreq, "min_freq"), "w").write("0")
open(os.path.join(path_devfreq, "governor"), "w").write("test_gpu")
write_on_file(os.path.join(path_devfreq, "cur_freq"), "1000000")
write_on_file(os.path.join(path_devfreq, "max_freq"), "921600000")
write_on_file(os.path.join(path_devfreq, "min_freq"), "0")
write_on_file(os.path.join(path_devfreq, "governor"), "test_gpu")
# Write GPU status
path_status_igpu = os.path.join(FAKE_DIRECTORY, "devices/platform", name_gpu, "devfreq", name_gpu, "device")
open(os.path.join(path_status_igpu, "railgate_enable"), "w").write("0")
open(os.path.join(path_status_igpu, "tpc_pg_mask"), "w").write("0")
open(os.path.join(path_status_igpu, "enable_3d_scaling"), "w").write("1")
open(os.path.join(path_status_igpu, "load"), "w").write("900")
write_on_file(os.path.join(path_status_igpu, "railgate_enable"), "0")
write_on_file(os.path.join(path_status_igpu, "tpc_pg_mask"), "0")
write_on_file(os.path.join(path_status_igpu, "enable_3d_scaling"), "1")
write_on_file(os.path.join(path_status_igpu, "load"), "900")


def install_emc(args):
emc_path = os.path.join(FAKE_DIRECTORY, "kernel/debug", "bpmp/debug/clk/emc")
if not os.path.isdir(emc_path):
print('The directory {path} is not present. Creating a new one..'.format(path=emc_path))
os.makedirs(emc_path)
open(os.path.join(emc_path, "rate"), "w").write("4000000")
open(os.path.join(emc_path, "max_rate"), "w").write("204000000")
open(os.path.join(emc_path, "min_rate"), "w").write("0")
open(os.path.join(emc_path, "mrq_rate_locked"), "w").write("204000000")
write_on_file(os.path.join(emc_path, "rate"), "4000000")
write_on_file(os.path.join(emc_path, "max_rate"), "204000000")
write_on_file(os.path.join(emc_path, "min_rate"), "0")
write_on_file(os.path.join(emc_path, "mrq_rate_locked"), "204000000")
path_activity = os.path.join(FAKE_DIRECTORY, "kernel/actmon_avg_activity")
if not os.path.isdir(path_activity):
print('The directory {path} is not present. Creating a new one..'.format(path=path_activity))
os.makedirs(path_activity)
open(os.path.join(path_activity, "mc_all"), "w").write("0")
write_on_file(os.path.join(path_activity, "mc_all"), "0")


def install_fan(args):
Expand All @@ -124,9 +129,9 @@ def install_fan(args):
print('The directory {path} is not present. Creating a new one..'.format(path=path_fan))
os.makedirs(path_fan)
# Build now a fake folder
open(os.path.join(path_fan, "pwm1"), "w").write("0")
# open(os.path.join(path_fan, "pwm2"), "w").write("0")
open(os.path.join(path_fan, "name"), "w").write("test_fan")
write_on_file(os.path.join(path_fan, "pwm1"), "0")
# write_on_file(os.path.join(path_fan, "pwm2"), "0")
write_on_file(os.path.join(path_fan, "name"), "test_fan")


def install_legacy_fan(args):
Expand All @@ -136,9 +141,9 @@ def install_legacy_fan(args):
print('The directory {path} is not present. Creating a new one..'.format(path=path_fan))
os.makedirs(path_fan)
# Build now a fake folder
open(os.path.join(path_fan, "target_pwm"), "w").write("128")
open(os.path.join(path_fan, "rpm_measured"), "w").write("0")
open(os.path.join(path_fan, "temp_control"), "w").write("0")
write_on_file(os.path.join(path_fan, "target_pwm"), "128")
write_on_file(os.path.join(path_fan, "rpm_measured"), "0")
write_on_file(os.path.join(path_fan, "temp_control"), "0")


def install_rpm_system(args):
Expand All @@ -147,8 +152,8 @@ def install_rpm_system(args):
if not os.path.isdir(path_rpm):
print('The directory {path} is not present. Creating a new one..'.format(path=path_rpm))
os.makedirs(path_rpm)
open(os.path.join(path_rpm, "rpm"), "w").write("1000")
open(os.path.join(path_rpm, "name"), "w").write("test_rpm")
write_on_file(os.path.join(path_rpm, "rpm"), "1000")
write_on_file(os.path.join(path_rpm, "name"), "test_rpm")


def install_jetson_clocks(args):
Expand Down

0 comments on commit 63c618c

Please sign in to comment.