Skip to content

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

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

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

Conversation

@victor-Lopez25
Copy link
Contributor

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

release: patch
summary: fix remaining scheduler race conditions

Task& task = tasks_[bit_index];
task.callback();

SchedLock();
Copy link
Member

Choose a reason for hiding this comment

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

No me mola mucho la verdad que el bitmap se limpie despues del callback, si hay problemas de rendimiento y el timer vuelve a hacerle set a la tarea la segunda ejecucion no se ejecuta, por lo demas no veo muchos mas problemas a hacerle clear despues del callback, se podria quedar asi pero solo digo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Era por poner un solo lock, si lo ves mejor poner dos locks y así poder hacerlo antes lo puedo cambiar


uint64_t Scheduler::get_global_tick() {
SchedLock();
uint64_t val = global_tick_us_ + Scheduler_global_timer->CNT;
Copy link
Member

Choose a reason for hiding this comment

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

No entiendo porque esto necesita un lock, la lectura del CNT es atomica es imposible que esto se corrompa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

la lectura del CNT sí pero la lectura de global_tick_us_ no pq es uint64_t

}
pop_front();

SchedLock();
Copy link
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
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
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
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
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

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

ST-LIB Release Plan

  • Current version: 5.0.0
  • Pending changesets: 3
  • 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)
  • 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
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

2 participants