Skip to content

Commit

Permalink
Feature: step 4, add locking to the Python library and LibreQoS.py
Browse files Browse the repository at this point in the history
  • Loading branch information
thebracket committed Jan 11, 2025
1 parent 1193075 commit 1d2a0f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/LibreQoS.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
check_config, sqm, upstream_bandwidth_capacity_download_mbps, upstream_bandwidth_capacity_upload_mbps, \
interface_a, interface_b, enable_actual_shell_commands, use_bin_packing_to_balance_cpu, monitor_mode_only, \
run_shell_commands_as_sudo, generated_pn_download_mbps, generated_pn_upload_mbps, queues_available_override, \
on_a_stick, get_tree_weights, get_weights, is_network_flat
on_a_stick, get_tree_weights, get_weights, is_network_flat, lock_tc_wait, unlock_tc

R2Q = 10
#MAX_R2Q = 200_000
Expand Down Expand Up @@ -972,11 +972,13 @@ def sqmFixupRate(rate:int, sqm:str) -> str:
for command in linuxTCcommands:
logging.info(command)
f.write(f"{command}\n")
lock_tc_wait()
if logging.DEBUG <= logging.root.level:
# Do not --force in debug mode, so we can see any errors
shell("/sbin/tc -b linux_tc.txt")
else:
shell("/sbin/tc -f -b linux_tc.txt")
unlock_tc()
tcEndTime = datetime.now()
print("Executed " + str(len(linuxTCcommands)) + " linux TC class/qdisc commands")

Expand Down
14 changes: 14 additions & 0 deletions src/rust/lqos_python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ fn liblqos_python(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(is_network_flat))?;
m.add_wrapped(wrap_pyfunction!(blackboard_finish))?;
m.add_wrapped(wrap_pyfunction!(blackboard_submit))?;
m.add_wrapped(wrap_pyfunction!(lock_tc_wait))?;
m.add_wrapped(wrap_pyfunction!(unlock_tc))?;

Ok(())
}
Expand Down Expand Up @@ -736,4 +738,16 @@ pub fn blackboard_submit(subsystem: String, key: String, value: String) -> PyRes
};
let _ = run_query(vec![BusRequest::BlackboardData { subsystem, key, value }]);
Ok(())
}

#[pyfunction]
pub fn lock_tc_wait() -> PyResult<()> {
let _ = run_query(vec![BusRequest::LockTc]).unwrap();
Ok(())
}

#[pyfunction]
pub fn unlock_tc() -> PyResult<()> {
let _ = run_query(vec![BusRequest::UnlockTc]).unwrap();
Ok(())
}

0 comments on commit 1d2a0f3

Please sign in to comment.