New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 649398 link

Starred by 3 users

Issue metadata

Status: Archived
Owner:
Last visit > 30 days ago
Closed: Jun 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 1
Type: Bug



Sign in to add a comment

ec: non-hook tasks can be scheduled before HOOK_INIT completes

Project Member Reported by sha...@chromium.org, Sep 22 2016

Issue description

void hook_task(void)
{
...
	/* Call HOOK_INIT hooks. */
	hook_notify(HOOK_INIT);

	/* Now, enable the rest of the tasks. */
	task_enable_all_tasks();
...


If a HOOK_INIT function wakes a task (eg. through task_wake()) then the task will be scheduled immediately (usually) and run before all HOOK_INIT tasks complete.

This is convenient in some cases (for fast power sequencing on cold boot) but creates hard-to-debug issues sometimes and may go against developer expectations.

Shall we block all non-hook tasks from waking prior to HOOK_INIT completion?
 
Cc: vpalatin@chromium.org
HOOK_INIT seems to be the way to ensure all of the init routines are completed before tasks are scheduled, but as Shawn noted this is not guaranteed. Am I wrong in thinking HOOK_INIT is used as way to serialize the init of subsystems before the tasks take off?

How else are people supposed to ensure some piece of work is done before a task's dependency is met? I don't currently see a good dependency chain management given the current semantics.

From another bug, here are my notes:
1. common/main.c allows interrupts to be enabled in the call to cpu_init().
2. task_enable_all_tasks() doesn't actually ensure that HOOK_INIT hooks are completed before scheduling tasks. As such an interrupt can come in make a task preempt the hook tasks.
3. There's no serialization (if one was relying on HOOK_INIT) between the host task and its communication bus (LPC) being initialized.
It's *supposed* to be. We should probably do what Shawn suggested and block all non-hook tasks from waking until the call to task_enable_all_tasks().
This behavior was introduced in https://chromium-review.googlesource.com/#/c/283657/

The power and console modules currently check task_start_called() in an attempt to avoid waking their tasks early.  But other modules don't place as nicely, and task_start_called() is now the wrong check anyway.

I agree that the fix should be to prevent other tasks from waking until task_enable_all_tasks() has been called.

At that point, the checks in the power and console modules can be removed, because the tasks simply won't be allowed to wake until after the end of the init hook.

Owner: aaboagye@chromium.org
Status: Assigned (was: Untriaged)
Owner: sha...@chromium.org
Status: Started (was: Assigned)
shawnn@ already has a CL going for this: https://chromium-review.googlesource.com/c/456628/

Comment 6 by sha...@chromium.org, Jun 20 2017

Status: Fixed (was: Started)
https://chromium-review.googlesource.com/#/c/456628/ has landed.
Project Member

Comment 7 by bugdroid1@chromium.org, Jun 30 2017

Labels: merge-merged-firmware-cr50-9308.B
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/ec/+/bc1ca770050db91b9f81463812e47c9df98f719d

commit bc1ca770050db91b9f81463812e47c9df98f719d
Author: Shawn Nematbakhsh <shawnn@chromium.org>
Date: Fri Jun 30 17:36:43 2017

task: Wait for HOOK_INIT completion before scheduling tasks

Until HOOK_INIT has completed, do not allow any tasks other than HOOKS
or IDLE to be scheduled. Programmers often make the assumption that
a HOOK_INIT function is guaranteed to be run before task code that depends
on it, so let's make it so.

BUG= chromium:649398 
BRANCH=None
TEST=Manual on kevin, compare boot without patch:

...
[0.004 power state 0 = G3, in 0x0008] <-- from chipset task
RTC: 0x00000000 (0.00 s)
[0.004 power state 4 = G3->S5, in 0x0008]
RTC: 0x00000000 (0.00 s)
[0.005 clear MKBP fifo]
[0.006 clear MKBP fifo]
[0.006 KB init state: ... <-- from keyscan task
[0.012 SW 0x05]
[0.155 hash start 0x00020000 0x00019a38]
[0.158 HOOK_INIT DONE!]

... to boot with patch:

...
RTC: 0x58cc614c (1489789260.00 s)
[0.004 clear MKBP fifo]
[0.005 clear MKBP fifo]
[0.010 SW 0x05]
[0.155 hash start 0x00020000 0x000198e0]
[0.157 HOOK_INIT DONE!]
...

Also, verify kevin boots to OS and is generally functional through
sysjump and basic tasks, and verify elm (stm32f0 / cortex-m0) boots.

Change-Id: If56fab05ce9b9650feb93c5cfc2d084aa281e622
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/456628
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 8a16e6483ab80a85af44e8ba164e5e91a51ec43a)
Reviewed-on: https://chromium-review.googlesource.com/556236
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>

[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/power/common.c
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/core/cortex-m0/task.c
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/core/cortex-m0/switch.S
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/core/cortex-m/task.c
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/core/minute-ia/task.c
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/core/nds32/task.c
[modify] https://crrev.com/bc1ca770050db91b9f81463812e47c9df98f719d/common/console.c

Project Member

Comment 8 by bugdroid1@chromium.org, Jul 10 2017

Labels: merge-merged-firmware-eve-9584.B
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/ec/+/c3328d03071194b179db1051eb512e130b454aca

commit c3328d03071194b179db1051eb512e130b454aca
Author: Shawn Nematbakhsh <shawnn@chromium.org>
Date: Mon Jul 10 22:47:54 2017

task: Wait for HOOK_INIT completion before scheduling tasks

Until HOOK_INIT has completed, do not allow any tasks other than HOOKS
or IDLE to be scheduled. Programmers often make the assumption that
a HOOK_INIT function is guaranteed to be run before task code that depends
on it, so let's make it so.

BUG= chromium:649398 
BRANCH=None
TEST=Manual on kevin, compare boot without patch:

...
[0.004 power state 0 = G3, in 0x0008] <-- from chipset task
RTC: 0x00000000 (0.00 s)
[0.004 power state 4 = G3->S5, in 0x0008]
RTC: 0x00000000 (0.00 s)
[0.005 clear MKBP fifo]
[0.006 clear MKBP fifo]
[0.006 KB init state: ... <-- from keyscan task
[0.012 SW 0x05]
[0.155 hash start 0x00020000 0x00019a38]
[0.158 HOOK_INIT DONE!]

... to boot with patch:

...
RTC: 0x58cc614c (1489789260.00 s)
[0.004 clear MKBP fifo]
[0.005 clear MKBP fifo]
[0.010 SW 0x05]
[0.155 hash start 0x00020000 0x000198e0]
[0.157 HOOK_INIT DONE!]
...

Also, verify kevin boots to OS and is generally functional through
sysjump and basic tasks, and verify elm (stm32f0 / cortex-m0) boots.

Change-Id: I44a1db0ae72fdd4245acc8bfc29b029fa90eac5b
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Original-Commit-Id: 8a16e6483ab80a85af44e8ba164e5e91a51ec43a
Original-Change-Id: If56fab05ce9b9650feb93c5cfc2d084aa281e622
Original-Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/456628
Original-Commit-Ready: Shawn N <shawnn@chromium.org>
Original-Tested-by: Shawn N <shawnn@chromium.org>
Original-Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/565813

[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/power/common.c
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/core/cortex-m0/task.c
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/core/cortex-m0/switch.S
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/core/cortex-m/task.c
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/core/minute-ia/task.c
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/core/nds32/task.c
[modify] https://crrev.com/c3328d03071194b179db1051eb512e130b454aca/common/console.c

Project Member

Comment 9 by bugdroid1@chromium.org, Sep 26 2017

Labels: merge-merged-firmware-twinkie-9628.B
The following revision refers to this bug:
  https://chromium.googlesource.com/chromiumos/platform/ec/+/d500cdf4b80118fbef64e3209d2e37be041e0ce5

commit d500cdf4b80118fbef64e3209d2e37be041e0ce5
Author: Shawn Nematbakhsh <shawnn@chromium.org>
Date: Tue Sep 26 11:32:47 2017

task: Wait for HOOK_INIT completion before scheduling tasks

Until HOOK_INIT has completed, do not allow any tasks other than HOOKS
or IDLE to be scheduled. Programmers often make the assumption that
a HOOK_INIT function is guaranteed to be run before task code that depends
on it, so let's make it so.

BUG= chromium:649398 
BRANCH=None
TEST=Manual on kevin, compare boot without patch:

...
[0.004 power state 0 = G3, in 0x0008] <-- from chipset task
RTC: 0x00000000 (0.00 s)
[0.004 power state 4 = G3->S5, in 0x0008]
RTC: 0x00000000 (0.00 s)
[0.005 clear MKBP fifo]
[0.006 clear MKBP fifo]
[0.006 KB init state: ... <-- from keyscan task
[0.012 SW 0x05]
[0.155 hash start 0x00020000 0x00019a38]
[0.158 HOOK_INIT DONE!]

... to boot with patch:

...
RTC: 0x58cc614c (1489789260.00 s)
[0.004 clear MKBP fifo]
[0.005 clear MKBP fifo]
[0.010 SW 0x05]
[0.155 hash start 0x00020000 0x000198e0]
[0.157 HOOK_INIT DONE!]
...

Also, verify kevin boots to OS and is generally functional through
sysjump and basic tasks, and verify elm (stm32f0 / cortex-m0) boots.

Change-Id: If56fab05ce9b9650feb93c5cfc2d084aa281e622
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/456628
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 8a16e6483ab80a85af44e8ba164e5e91a51ec43a)
Reviewed-on: https://chromium-review.googlesource.com/684335
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Trybot-Ready: Vincent Palatin <vpalatin@chromium.org>

[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/power/common.c
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/core/cortex-m0/task.c
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/core/cortex-m0/switch.S
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/core/cortex-m/task.c
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/core/minute-ia/task.c
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/core/nds32/task.c
[modify] https://crrev.com/d500cdf4b80118fbef64e3209d2e37be041e0ce5/common/console.c

Comment 10 by dchan@chromium.org, Jan 22 2018

Status: Archived (was: Fixed)

Sign in to add a comment