diff options
Diffstat (limited to 'map65')
| -rw-r--r-- | map65/commons.cpp | 3 | ||||
| -rw-r--r-- | map65/commons.h | 9 | ||||
| -rw-r--r-- | map65/libm65/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | map65/libm65/datcom_ptrs_mod.f90 | 79 | ||||
| -rw-r--r-- | map65/libm65/decode0.f90 | 33 | ||||
| -rw-r--r-- | map65/libm65/npar_ptrs_mod.f90 | 85 | ||||
| -rw-r--r-- | map65/libm65/run_m65.f90 | 3 | ||||
| -rw-r--r-- | map65/mainwindow.cpp | 16 |
8 files changed, 167 insertions, 66 deletions
diff --git a/map65/commons.cpp b/map65/commons.cpp index 74c69b74..bbef8ed0 100644 --- a/map65/commons.cpp +++ b/map65/commons.cpp @@ -4,8 +4,5 @@ extern "C" { float* dd = nullptr; float* ss = nullptr; float* savg = nullptr; - float* dd_old = nullptr; - float* ss_old = nullptr; - float* savg_old = nullptr; } diff --git a/map65/commons.h b/map65/commons.h index 8938348e..b469b4a9 100644 --- a/map65/commons.h +++ b/map65/commons.h @@ -57,9 +57,6 @@ extern struct { //This is "common/datcom/..." in Fortran extern float* dd; extern float* ss; extern float* savg; - extern float* dd_old; - extern float* ss_old; - extern float* savg_old; extern int manualDecodeFlag ; double get_fcenter(); void get_mycall(char*); @@ -100,9 +97,7 @@ extern struct { //This is "common/datcom/..." in Fortran void set_dd_ptr(void* ptr, int dim1, int dim2); void set_ss_ptr(void* ptr, int dim1, int dim2, int dim3); void set_savg_ptr(void* ptr, int dim1, int dim2); - void set_dd_old_ptr(void* ptr, int dim1, int dim2); - void set_ss_old_ptr(void* ptr, int dim1, int dim2, int dim3); - void set_savg_old_ptr(void* ptr, int dim1, int dim2); + void set_snap_ptr(int idx, void* dd_ptr, void* ss_ptr, void* savg_ptr, int ndd, int nfft); void set_fcenter(double); void set_map65RxLog(int); void set_nutc(int); @@ -152,7 +147,7 @@ extern struct { //This is "common/datcom/..." in Fortran int buf_size, intptr_t event_handle); void set_manual_decode_flag(int); - void snapshot_buffers(); + void snapshot_buffers(int idx, int ksamp, int nhsym_snap); } extern QStringList allDecodes2; diff --git a/map65/libm65/CMakeLists.txt b/map65/libm65/CMakeLists.txt index 9ae45c54..3269c2c6 100644 --- a/map65/libm65/CMakeLists.txt +++ b/map65/libm65/CMakeLists.txt @@ -333,6 +333,11 @@ if (WSJT_ENABLE_TESTS) target_link_libraries (test_map65_symspec_contract PRIVATE m65impl) add_test (NAME test_map65_symspec_96 COMMAND test_map65_symspec_contract 96000) add_test (NAME test_map65_symspec_192 COMMAND test_map65_symspec_contract 192000) + add_executable (test_map65_pass_snapshots + ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_pass_snapshots.f90) + target_include_directories (test_map65_pass_snapshots PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries (test_map65_pass_snapshots PRIVATE m65impl) + add_test (NAME test_map65_pass_snapshots COMMAND test_map65_pass_snapshots) add_executable (test_map65_q65_handoff ${CMAKE_SOURCE_DIR}/tests/unit/map65/test_map65_q65_handoff.f90) diff --git a/map65/libm65/datcom_ptrs_mod.f90 b/map65/libm65/datcom_ptrs_mod.f90 index a507168e..a4f94b37 100644 --- a/map65/libm65/datcom_ptrs_mod.f90 +++ b/map65/libm65/datcom_ptrs_mod.f90 @@ -1,14 +1,29 @@ module datcom_ptrs_mod use iso_c_binding + use debug_log, only: dbg, itoa + use npar_ptrs_mod, only: snapshot_fill_begin, snapshot_fill_end implicit none ! Fortran pointer targets real(c_float), pointer, contiguous :: dd(:,:) => null() ! [4, 5760000] real(c_float), pointer, contiguous :: ss(:,:,:) => null() ! [4, 322, NFFT] real(c_float), pointer, contiguous :: savg(:,:) => null() ! [4, NFFT] - real(c_float), pointer, contiguous :: dd_old(:,:) => null() ! [4, 5760000] - real(c_float), pointer, contiguous :: ss_old(:,:,:) => null() ! [4, 322, NFFT] - real(c_float), pointer, contiguous :: savg_old(:,:) => null() ! [4, NFFT] + + ! Two decoder snapshot sets, one per automatic pass (1 = early, nhsym1=280; + ! 2 = final, nhsym2=302). Each is filled by snapshot_buffers() at the moment + ! its pass is triggered, before the live buffers can be reset for the next + ! cycle, so a late-starting pass still decodes complete data. + type :: snap_set + real(c_float), pointer, contiguous :: dd(:,:) => null() ! [4, nsmax] + real(c_float), pointer, contiguous :: ss(:,:,:) => null() ! [4, 322, NFFT] + real(c_float), pointer, contiguous :: savg(:,:) => null() ! [4, NFFT] + end type snap_set + type(snap_set), save :: snap(2) + + ! Snapshot selected for the pass now being decoded (set by decode0) + real(c_float), pointer, contiguous :: dd_old(:,:) => null() + real(c_float), pointer, contiguous :: ss_old(:,:,:) => null() + real(c_float), pointer, contiguous :: savg_old(:,:) => null() ! Pointers used by decode0 / narrowband decoder real(c_float), pointer, contiguous :: dd_use(:,:) => null() @@ -21,10 +36,30 @@ module datcom_ptrs_mod contains - subroutine snapshot_buffers() bind(C) - dd_old(:,:) = dd(:,:) - ss_old(:,:,:) = ss(:,:,:) - savg_old(:,:) = savg(:,:) + ! Copy the live buffers into snapshot set idx (1 or 2). Called from dataSink() + ! on the GUI thread, which is also the thread that runs symspec, so ss and + ! savg cannot change during the copy. The sound-in thread writes dd only + ! forward of ksamp, so dd(:,1:ksamp+lookahead) is stable. + subroutine snapshot_buffers(idx, ksamp, nhsym_snap) bind(C, name="snapshot_buffers") + integer(c_int), value :: idx, ksamp, nhsym_snap + integer :: ncopy, ncol + logical :: ok + integer, parameter :: lookahead = 512 ! live_lookahead_samples in symspec + if (idx < 1 .or. idx > 2) return + call snapshot_fill_begin(idx, ok) + if (.not. ok) then + call dbg('snapshot ' // itoa(idx) // ' skipped: slot still in use by the running pass') + return + endif + if (.not. associated(snap(idx)%dd) .or. .not. associated(dd)) return + ncopy = max(0, min(size(dd,2), ksamp + lookahead)) + ncol = max(0, min(size(ss,2), nhsym_snap)) + snap(idx)%dd(:,1:ncopy) = dd(:,1:ncopy) + snap(idx)%dd(:,ncopy+1:) = 0. + snap(idx)%ss(:,1:ncol,:) = ss(:,1:ncol,:) + snap(idx)%ss(:,ncol+1:,:) = 0. + snap(idx)%savg(:,:) = savg(:,:) + call snapshot_fill_end(idx) end subroutine ! Helper subroutine to copy fixed-length Fortran string to C buffer @@ -67,31 +102,15 @@ contains print *, "Fortran: savg pointer associated with dimensions", dim1, dim2 end subroutine - subroutine set_dd_old_ptr(ptr, dim1, dim2) bind(C, name="set_dd_old_ptr") - use iso_c_binding - implicit none - type(c_ptr), value :: ptr - integer(c_int), value :: dim1, dim2 - call c_f_pointer(ptr, dd_old, [dim1, dim2]) - print *, "Fortran: dd_old pointer associated with dimensions", dim1, dim2 - end subroutine - - subroutine set_ss_old_ptr(ptr, dim1, dim2, dim3) bind(C, name="set_ss_old_ptr") + subroutine set_snap_ptr(idx, dd_ptr, ss_ptr, savg_ptr, ndd, nfft_s) bind(C, name="set_snap_ptr") use iso_c_binding implicit none - type(c_ptr), value :: ptr - integer(c_int), value :: dim1, dim2, dim3 - call c_f_pointer(ptr, ss_old, [dim1, dim2, dim3]) - print *, "Fortran: ss_old pointer associated with dimensions", dim1, dim2, dim3 - end subroutine - - subroutine set_savg_old_ptr(ptr, dim1, dim2) bind(C, name="set_savg_old_ptr") - use iso_c_binding - implicit none - type(c_ptr), value :: ptr - integer(c_int), value :: dim1, dim2 - call c_f_pointer(ptr, savg_old, [dim1, dim2]) - print *, "Fortran: savg_old pointer associated with dimensions", dim1, dim2 + integer(c_int), value :: idx, ndd, nfft_s + type(c_ptr), value :: dd_ptr, ss_ptr, savg_ptr + if (idx < 1 .or. idx > 2) return + call c_f_pointer(dd_ptr, snap(idx)%dd, [4, ndd]) + call c_f_pointer(ss_ptr, snap(idx)%ss, [4, 322, nfft_s]) + call c_f_pointer(savg_ptr, snap(idx)%savg, [4, nfft_s]) end subroutine function get_junk1() bind(C, name="get_junk1") diff --git a/map65/libm65/decode0.f90 b/map65/libm65/decode0.f90 index cdb8799b..1e217501 100644 --- a/map65/libm65/decode0.f90 +++ b/map65/libm65/decode0.f90 @@ -7,7 +7,7 @@ contains use iso_c_binding, only: c_int use timer_module, only: timer use npar_ptrs_mod - use datcom_ptrs_mod, only: NFFT, dd, dd_old, dd_use, ss, ss_old, savg, savg_old, ss_use, savg_use + use datcom_ptrs_mod, only: NFFT, dd_old, dd_use, ss_old, savg_old, ss_use, savg_use, snap use debug_log, only: dbg, itoa, rtoa use sec_midn_mod, only: sec_midn use map65a_mod @@ -25,6 +25,7 @@ contains integer nz integer :: nhsym0 integer :: newdat0 + integer :: isnap character(len=128) :: line character mycall0*12, hiscall0*12, hisgrid0*6 logical :: first_mcall3b_check @@ -47,25 +48,29 @@ contains ! newdat is forced to 1 by decode() for every call (manual or ! automatic); it does not by itself mean "the live buffers just - ! finished a fresh accumulation." nagain=1 marks a manual repeat - ! (Decode button / Find Delta Phi), which must not refresh dd_old - ! from a live buffer that may still be mid-fill. - if (newdat0 /= 0 .and. manualDecodeFlag == 0 .and. nagain == 0) then - dd_old = dd - ss_old = ss - savg_old = savg - call dbg('decode0: dd_old REFRESHED from live dd at t=' // rtoa(sec_midn()) // ' nhsym0=' // itoa(nhsym0)) - else - call dbg('decode0: dd_old NOT refreshed (reusing prior snapshot) at t=' // rtoa(sec_midn()) // & - ' nhsym0=' // itoa(nhsym0) // ' nagain=' // itoa(nagain)) - endif + ! finished a fresh accumulation." + ! + ! Each automatic pass decodes its own snapshot, taken by dataSink() at + ! the instant the pass was triggered (snap(1) at nhsym1, snap(2) at + ! nhsym2). decode0 never copies from the live buffers, so a pass that + ! starts late (queued behind a still-running pass) cannot see data the + ! audio thread has already reset for the next cycle. Manual repeats + ! (nagain=1, Decode button / Find Delta Phi) reuse the most recently + ! filled snapshot. + isnap = active_snap_idx ! slot claimed with this request + if (isnap < 1) isnap = 2 + call dbg('decode0: using snapshot ' // itoa(isnap) // ' at t=' // rtoa(sec_midn()) // & + ' nhsym0=' // itoa(nhsym0) // ' nagain=' // itoa(nagain)) + dd_old => snap(isnap)%dd + ss_old => snap(isnap)%ss + savg_old => snap(isnap)%savg nkeep = min(max(ntimeout, 10), 40) call sec0(0, tquick) call timer('decode0 ', 0) - ! Always decode from the snapshot (dd_old/ss_old/savg_old) taken above, + ! Always decode from the snapshot selected above (dd_old/ss_old/savg_old), ! never the live dd/ss/savg. The nhsym2 pass routinely runs past the ! minute boundary (several seconds), and symspec_() on the GUI thread ! resets/overwrites the live buffers for the next cycle unconditionally diff --git a/map65/libm65/npar_ptrs_mod.f90 b/map65/libm65/npar_ptrs_mod.f90 index 10c9b904..99bde665 100644 --- a/map65/libm65/npar_ptrs_mod.f90 +++ b/map65/libm65/npar_ptrs_mod.f90 @@ -60,9 +60,13 @@ module npar_ptrs_mod ! newdat = 1 in that copy) and clears ! draft%manualDecodeFlag ! claim_decode_request() copies the oldest request into active; an - ! automatic live request whose input generation - ! is out of date is marked expired, and run_m65 - ! skips it (<DecodeSkipped>) + ! automatic request is marked expired, and run_m65 + ! skips it (<DecodeSkipped>), when the data + ! snapshot it was published with has been + ! overwritten or never filled (or, for requests + ! without a snapshot, when its input generation + ! is out of date). A request whose snapshot is + ! intact still runs after the minute rolls over. ! initialize_decode_parameters() copies draft into active once, at startup ! The decoder then sees a consistent snapshot for the whole pass, even if ! the GUI changes draft meanwhile. @@ -96,6 +100,8 @@ module npar_ptrs_mod type(decode_parameters) :: parameters integer(c_int64_t) :: id integer(c_int64_t) :: input_generation + integer(c_int) :: snap_idx = 0 ! snapshot slot (1 = nhsym1, 2 = nhsym2); 0 = none + integer(c_int64_t) :: snap_seq = 0 ! fill number of that slot when published type(decode_request), pointer :: next => null() end type type(decode_request), pointer, save :: pending_head => null(), pending_tail => null() @@ -105,6 +111,19 @@ module npar_ptrs_mod integer(c_int64_t), save :: active_input_generation = 0 logical, save :: active_request_expired = .false. + ! Decoder data snapshots (see datcom_ptrs_mod). All of this state is + ! protected by lock_decode_requests(). + ! snap_seq(i) fill number, bumped each time slot i is (re)filled + ! snap_valid_seq(i) fill number whose contents are intact; 0 while a fill + ! is in progress or after a fill was skipped + ! snap_busy(i) slot i is being read by the running decode pass; a fill + ! is skipped rather than overwrite it + integer(c_int64_t), save :: snap_seq(2) = 0 + integer(c_int64_t), save :: snap_valid_seq(2) = 0 + logical, save :: snap_busy(2) = .false. + integer(c_int), save :: snap_latest_idx = 0 ! most recently completed fill + integer(c_int), save :: active_snap_idx = 0 ! slot read by the active pass + real(c_double), pointer :: fcenter => active%fcenter real(c_double), pointer :: ftol_nb => active%ftol_nb integer(c_int), pointer :: nfa => active%nfa @@ -781,6 +800,16 @@ end subroutine request%input_generation = live_input_generation request%parameters = draft request%parameters%newdat = 1 + ! Automatic passes (nhsym1/nhsym2) were just snapshotted by dataSink(); + ! remember which slot and fill they own. Manual repeats use the latest. + if (draft%manualDecodeFlag == 0 .and. draft%nagain == 0 .and. & + (draft%nhsym == 280 .or. draft%nhsym == 302)) then + request%snap_idx = merge(1, 2, draft%nhsym == 280) + request%snap_seq = snap_seq(request%snap_idx) + ! No fill has ever happened for this slot (no snapshot support in the + ! caller): fall back to the input-generation rule. + if (request%snap_seq == 0) request%snap_idx = 0 + endif if (associated(pending_tail)) then pending_tail%next => request else @@ -804,8 +833,26 @@ end subroutine active = request%parameters active_request_id = request%id active_input_generation = request%input_generation - active_request_expired = active%ndiskdat == 0 .and. active%nagain == 0 .and. & - active%manualDecodeFlag == 0 .and. request%input_generation /= live_input_generation + active_snap_idx = 0 + if (request%snap_idx > 0) then + ! Automatic pass: valid while its snapshot is intact, even if the + ! minute has rolled over. A live request more than one generation old + ! (monitoring stopped, period changed) is still dropped. + active_request_expired = snap_valid_seq(request%snap_idx) /= request%snap_seq + if (active%ndiskdat == 0 .and. & + live_input_generation - request%input_generation >= 2) active_request_expired = .true. + if (.not. active_request_expired) then + active_snap_idx = request%snap_idx + snap_busy(active_snap_idx) = .true. + endif + else + active_request_expired = active%ndiskdat == 0 .and. active%nagain == 0 .and. & + active%manualDecodeFlag == 0 .and. request%input_generation /= live_input_generation + if (.not. active_request_expired .and. snap_latest_idx > 0) then + active_snap_idx = snap_latest_idx ! manual repeat: latest snapshot + snap_busy(active_snap_idx) = .true. + endif + endif deallocate(request) endif call unlock_decode_requests() @@ -817,6 +864,34 @@ end subroutine call unlock_decode_requests() end subroutine + ! A snapshot fill starts: invalidate the slot's contents and say whether the + ! copy may proceed (ok = .false. when the running pass is still reading it). + subroutine snapshot_fill_begin(idx, ok) + integer, intent(in) :: idx + logical, intent(out) :: ok + call lock_decode_requests() + snap_seq(idx) = snap_seq(idx) + 1 + snap_valid_seq(idx) = 0 + ok = .not. snap_busy(idx) + call unlock_decode_requests() + end subroutine + + subroutine snapshot_fill_end(idx) + integer, intent(in) :: idx + call lock_decode_requests() + snap_valid_seq(idx) = snap_seq(idx) + snap_latest_idx = idx + call unlock_decode_requests() + end subroutine + + ! The active pass is finished with its snapshot slot. + subroutine snapshot_release() + call lock_decode_requests() + if (active_snap_idx > 0) snap_busy(active_snap_idx) = .false. + active_snap_idx = 0 + call unlock_decode_requests() + end subroutine + subroutine advance_live_input_generation() bind(C) call lock_decode_requests() live_input_generation = live_input_generation + 1 diff --git a/map65/libm65/run_m65.f90 b/map65/libm65/run_m65.f90 index cc0ffe73..14042016 100644 --- a/map65/libm65/run_m65.f90 +++ b/map65/libm65/run_m65.f90 @@ -9,7 +9,7 @@ subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_') use timer_impl, only: init_timer, fini_timer use debug_log use m65a_mod - use npar_ptrs_mod, only: t_start, nhsym, mycall, hiscall, hisgrid, neme, & + use npar_ptrs_mod, only: snapshot_release, t_start, nhsym, mycall, hiscall, hisgrid, neme, & initialize_decode_parameters, claim_decode_request, get_stop_m65, & active_request_id, active_request_expired use stdout_channel_mod, only: write_stdout @@ -88,6 +88,7 @@ subroutine run_m65(pol, sample_rate_96000) bind(C, name='run_m65_') call system_clock(t_start, t_rate) call m65a() call system_clock(t_now) + call snapshot_release() call dbg('run_m65: request completed, elapsed=' // rtoa(real(t_now - t_start)/real(t_rate))) endif endif diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp index e9a0e6d6..5e88572e 100644 --- a/map65/mainwindow.cpp +++ b/map65/mainwindow.cpp @@ -157,12 +157,14 @@ MainWindow::MainWindow(QWidget *parent) : std::cout << "ss pointer set to: " << ss << std::endl; set_savg_ptr(savg, 4, active_nfft); std::cout << "savg pointer set to: " << savg << std::endl; - dd_old = new float[ddSize]; - set_dd_old_ptr(dd_old, channels, pairsWorst); - ss_old = new float[4 * 322 * active_nfft]; - savg_old = new float[4 * active_nfft]; - set_ss_old_ptr(ss_old, 4, 322, active_nfft); - set_savg_old_ptr(savg_old, 4, active_nfft); + // Two snapshot sets, one per automatic decode pass (1 = nhsym 280, 2 = nhsym 302). + // They are filled in dataSink() at each trigger; see snapshot_buffers(). + for (int idx = 1; idx <= 2; idx++) { + float* sdd = new float[ddSize](); + float* sss = new float[4 * 322 * active_nfft](); + float* ssavg = new float[4 * active_nfft](); + set_snap_ptr(idx, sdd, sss, ssavg, pairsWorst, active_nfft); + } qDebug() << "MAINWINDOW created dd ss savg "; @@ -1302,6 +1304,7 @@ void MainWindow::dataSink(int k) setNewdat(1); setNagain(0); setNhsym(280); + snapshot_buffers(1, k, 280); //Freeze this pass's data now QDateTime t = QDateTime::currentDateTimeUtc(); m_dateTime=t.toString("yyyy-MMM-dd hh:mm"); decode(); //Start the decoder @@ -1314,6 +1317,7 @@ void MainWindow::dataSink(int k) setNewdat(1); setNagain(0); setNhsym(302); + snapshot_buffers(2, k, 302); //Freeze this pass's data now QDateTime t = QDateTime::currentDateTimeUtc(); m_dateTime=t.toString("yyyy-MMM-dd hh:mm"); decode(); //Start the decoder |
