Skip to content

sched fix (tested on PCU, LV-BMS, HV-BMS and LCU)#594

Draft
victor-Lopez25 wants to merge 37 commits intodevelopmentfrom
fix/scheduler-race-cond-part2
Draft

sched fix (tested on PCU, LV-BMS, HV-BMS and LCU)#594
victor-Lopez25 wants to merge 37 commits intodevelopmentfrom
fix/scheduler-race-cond-part2

Conversation

@victor-Lopez25
Copy link
Copy Markdown
Contributor

@victor-Lopez25 victor-Lopez25 commented Mar 20, 2026

release: patch
summary: fix remaining scheduler race conditions

}
pop_front();

SchedLock();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tampoco tiene sentido hacerle disable al timer dentro del interrupt del timer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tengo que probar si realmente no hace falta, pq es una de las primeras cosas que probé ayer en las placas y la dejé

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Según la prueba de Boris en la LCU no hace falta pero voy a probarlo mañana (?) en las otras placas también

return;
}

SchedLock();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto esta dentro del interrupt del timer no tiene sentido hacer disable al timer

if (Scheduler_global_timer->CNT > current_interval_us_) [[unlikely]] {
uint32_t offset = Scheduler_global_timer->CNT - current_interval_us_;
Scheduler_global_timer->CNT = 0;
global_tick_us_ += offset;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto esta simplemente mal, te estas adelantando en el tiempo, yo me guardaria otro valor que fuera accumulated offset y cuando esto pasa lo incrementas en la linea 307

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo he cambiado para que sume:

uint32_t prevCnt = Scheduler_global_timer->CNT;
Scheduler_global_timer->CNT = 0;
global_tick_us_ += prevCnt;

Pero cuando lo probamos para ver qué mandaba parecía que subía un poco demasiado rápido (por poco)

Puede que sea también por el get_global_tick() que es lo que usaba para ver qué tiempo tenía el scheduler

Vimos dos cosas:

  • Empezaba en un valor muy alto, como si hubiese pasado ya un tiempo
  • Subía demasiado rápido, no llegaba a duplicar, igual 1.2x o por ahí al tiempo real (medido a ojo entre Joan y yo)

@jorgesg82 jorgesg82 linked an issue Mar 20, 2026 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 20, 2026

ST-LIB Release Plan

  • Current version: 5.0.0
  • Pending changesets: 4
  • Highest requested bump: minor
  • Next version if merged now: 5.1.0

Pending changes

  • minor Refactor the ADC stack around DMA-backed acquisition using new MPU (.changesets/adc-dma-minor.md)
  • patch fix remaining scheduler race conditions (.changesets/fix-scheduler-race-condition.md)
  • patch Fix incorrect GPIO alternate-function availability bitmaps (.changesets/gpio-af-bitmaps-patch.md)
  • none Introduce semver tooling and release automation infrastructure (.changesets/revive-releases-bootstrap.md)

@victor-Lopez25 victor-Lopez25 changed the title fix (tested on PCU, LV-BMS and LCU) fix (tested on PCU, LV-BMS, HV-BMS and LCU) Mar 21, 2026
@victor-Lopez25 victor-Lopez25 force-pushed the fix/scheduler-race-cond-part2 branch from dfd47d2 to d6af843 Compare March 23, 2026 19:31
@jorgesg82 jorgesg82 force-pushed the fix/scheduler-race-cond-part2 branch from a17d0eb to f4a12ef Compare March 26, 2026 22:30
@jorgesg82 jorgesg82 force-pushed the fix/scheduler-race-cond-part2 branch from c0d15a7 to 581bb19 Compare March 26, 2026 23:37
@victor-Lopez25 victor-Lopez25 changed the title fix (tested on PCU, LV-BMS, HV-BMS and LCU) sched fix (tested on PCU, LV-BMS, HV-BMS and LCU) Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler Race condition

3 participants