From 7b25d1c06f1b31fd78972383d4c1ee402cb4c737 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 5 Aug 2025 14:07:59 -0400 Subject: [PATCH] stepcompress: Export steppersync_history_expire() Don't implement history expiration from the main steppersync_flush() code. Instead, have callers directly invoke steppersync_history_expire(). Signed-off-by: Kevin O'Connor --- klippy/chelper/__init__.py | 4 ++-- klippy/chelper/stepcompress.c | 22 ++++++---------------- klippy/chelper/stepcompress.h | 4 ++-- klippy/extras/motion_queuing.py | 8 +++++--- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index 622cc9a7..d56b720c 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -60,8 +60,8 @@ defs_stepcompress = """ void steppersync_free(struct steppersync *ss); void steppersync_set_time(struct steppersync *ss , double time_offset, double mcu_freq); - int steppersync_flush(struct steppersync *ss, uint64_t move_clock - , uint64_t clear_history_clock); + void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock); + int steppersync_flush(struct steppersync *ss, uint64_t move_clock); """ defs_itersolve = """ diff --git a/klippy/chelper/stepcompress.c b/klippy/chelper/stepcompress.c index 310f2bf3..939ac2c1 100644 --- a/klippy/chelper/stepcompress.c +++ b/klippy/chelper/stepcompress.c @@ -276,9 +276,9 @@ stepcompress_set_invert_sdir(struct stepcompress *sc, uint32_t invert_sdir) } } -// Helper to free items from the history_list +// Expire the stepcompress history older than the given clock static void -free_history(struct stepcompress *sc, uint64_t end_clock) +stepcompress_history_expire(struct stepcompress *sc, uint64_t end_clock) { while (!list_empty(&sc->history_list)) { struct history_steps *hs = list_last_entry( @@ -290,13 +290,6 @@ free_history(struct stepcompress *sc, uint64_t end_clock) } } -// Expire the stepcompress history older than the given clock -static void -stepcompress_history_expire(struct stepcompress *sc, uint64_t end_clock) -{ - free_history(sc, end_clock); -} - // Free memory associated with a 'stepcompress' object void __visible stepcompress_free(struct stepcompress *sc) @@ -305,7 +298,7 @@ stepcompress_free(struct stepcompress *sc) return; free(sc->queue); message_queue_free(&sc->msg_queue); - free_history(sc, UINT64_MAX); + stepcompress_history_expire(sc, UINT64_MAX); free(sc); } @@ -734,12 +727,11 @@ steppersync_set_time(struct steppersync *ss, double time_offset } // Expire the stepcompress history before the given clock time -static void +void __visible steppersync_history_expire(struct steppersync *ss, uint64_t end_clock) { int i; - for (i = 0; i < ss->sc_num; i++) - { + for (i = 0; i < ss->sc_num; i++) { struct stepcompress *sc = ss->sc_list[i]; stepcompress_history_expire(sc, end_clock); } @@ -772,8 +764,7 @@ heap_replace(struct steppersync *ss, uint64_t req_clock) // Find and transmit any scheduled steps prior to the given 'move_clock' int __visible -steppersync_flush(struct steppersync *ss, uint64_t move_clock - , uint64_t clear_history_clock) +steppersync_flush(struct steppersync *ss, uint64_t move_clock) { // Flush each stepcompress to the specified move_clock int i; @@ -822,6 +813,5 @@ steppersync_flush(struct steppersync *ss, uint64_t move_clock if (!list_empty(&msgs)) serialqueue_send_batch(ss->sq, ss->cq, &msgs); - steppersync_history_expire(ss, clear_history_clock); return 0; } diff --git a/klippy/chelper/stepcompress.h b/klippy/chelper/stepcompress.h index c5b40383..06bc7a49 100644 --- a/klippy/chelper/stepcompress.h +++ b/klippy/chelper/stepcompress.h @@ -42,7 +42,7 @@ struct steppersync *steppersync_alloc( void steppersync_free(struct steppersync *ss); void steppersync_set_time(struct steppersync *ss, double time_offset , double mcu_freq); -int steppersync_flush(struct steppersync *ss, uint64_t move_clock - , uint64_t clear_history_clock); +void steppersync_history_expire(struct steppersync *ss, uint64_t end_clock); +int steppersync_flush(struct steppersync *ss, uint64_t move_clock); #endif // stepcompress.h diff --git a/klippy/extras/motion_queuing.py b/klippy/extras/motion_queuing.py index fdbb5df2..3a7bba46 100644 --- a/klippy/extras/motion_queuing.py +++ b/klippy/extras/motion_queuing.py @@ -17,6 +17,7 @@ class PrinterMotionQueuing: ffi_main, ffi_lib = chelper.get_ffi() self.trapq_finalize_moves = ffi_lib.trapq_finalize_moves self.steppersync_flush = ffi_lib.steppersync_flush + self.steppersync_history_expire = ffi_lib.steppersync_history_expire def allocate_trapq(self): ffi_main, ffi_lib = chelper.get_ffi() trapq = ffi_main.gc(ffi_lib.trapq_alloc(), ffi_lib.trapq_free) @@ -58,12 +59,13 @@ class PrinterMotionQueuing: clock = mcu.print_time_to_clock(print_time) if clock < 0: continue - clear_history_clock = \ - max(0, mcu.print_time_to_clock(clear_history_time)) - ret = self.steppersync_flush(ss, clock, clear_history_clock) + ret = self.steppersync_flush(ss, clock) if ret: raise mcu.error("Internal error in MCU '%s' stepcompress" % (mcu.get_name(),)) + clear_history_clock = \ + max(0, mcu.print_time_to_clock(clear_history_time)) + self.steppersync_history_expire(ss, clear_history_clock) def wipe_trapq(self, trapq): # Expire any remaining movement in the trapq (force to history list) NEVER = 9999999999999999.