Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions subsys/bluetooth/controller/ticker/ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -2276,11 +2276,18 @@ void ticker_job(void *param)

DEBUG_TICKER_JOB(1);

/* Defer worker, as job is now running */
/* Defer job, as worker is running */
if (instance->worker_trigger) {
DEBUG_TICKER_JOB(0);
return;
}

/* Defer job, as job is already running */
if (instance->job_guard) {
instance->sched_cb(TICKER_CALL_ID_JOB, TICKER_CALL_ID_JOB, 1,
instance);
return;
}
instance->job_guard = 1U;

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider also moving clearing of the job_guard to after ticker_job_compare_update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this because ticks_slot_previous and ticks_current are updated in ticker_job_compare_update, and the vectoring (swap) to ticker_worker function would use stale values? or do you have other reasons?

(sorry for asking again, from the message here: #31026 (comment), I understand context-safety, but just making double sure :-) ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because ticks_slot_previous and ticks_current are updated in ticker_job_compare_update, and the vectoring (swap) to ticker_worker function would use stale values? or do you have other reasons?

Yes, that is exactly why. The suggestion is not based on an actual observation, just based on analysis and being cautious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Your analysis is correct, as the resolution happens in ticker_worker, there are chances that after a current reserving ticker is stopped, it is necessary to have correct value of ticks_slot_previous and ticks_current be used in the ticker_worker.

/* Back up the previous known tick */
Expand Down Expand Up @@ -2357,14 +2364,14 @@ void ticker_job(void *param)
ticker_job_list_inquire(instance);
}

/* Permit worker job to run */
instance->job_guard = 0U;

/* update compare if head changed */
if (flag_compare_update) {
ticker_job_compare_update(instance, ticker_id_old_head);
}

/* Permit worker to run */
instance->job_guard = 0U;

/* trigger worker if deferred */
if (instance->worker_trigger) {
instance->sched_cb(TICKER_CALL_ID_JOB, TICKER_CALL_ID_WORKER, 1,
Expand Down