public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ruiyu" <ruiyu.ni@Intel.com>
To: Eric Dong <eric.dong@intel.com>, edk2-devel@lists.01.org
Cc: Laszlo Ersek <lersek@redhat.com>
Subject: Re: [Patch 1/2] UefiCpuPkg/RegisterCpuFeaturesLib: Separate semaphore container.
Date: Fri, 9 Nov 2018 16:40:24 +0800	[thread overview]
Message-ID: <162f4a7d-aae8-7ebf-8e98-a8a1cc8d9e36@Intel.com> (raw)
In-Reply-To: <20181108025800.12112-2-eric.dong@intel.com>

Eric,
Patch is good.
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Some modification to commit message to help understanding the changes.
Please rewording if you think some of them is not proper.

You can push the changes if no concerns about the new commit message.

-----

In current implementation, core and package level sync uses same 
semaphores. Sharing the semaphore may cause wrong execution order.
For example:
1. Feature A has CPU_FEATURE_CORE_BEFORE dependency with Feature B.
2. Feature C has CPU_FEATURE_PACKAGE_AFTER dependency with Feature B.
The expected feature initialization order is A B C:
A ---- (Core Depends) ----> B ---- (Package Depends) ----> C

For a CPU has 1 package, 2 cores and 4 threads. The feature 
initialization order may like below:

   Thread#1             Thread#2    Thread#3   Thread#4
   [A.Init]             [A.Init]               [A.Init]
Release(S1, S2)        Release(S1, S2)        Release(S3, S4)
Wait(S1) * 2           Wait(S2) * 2                        <- Core sync
   [B.Init]             [B.Init]
Release (S1,S2,S3,S4)
Wait (S1) * 4  <------------------------------------------ Package sync
                                               Wait(S4 * 2) <- Core sync
                                               [B.Init]

In above case, for thread#4, when it syncs in core level, Wait(S4) * 2 
isn't blocked and [B.Init] runs. But [A.Init] hasn't run in thread#3. 
It's wrong! Thread#4 should execute [B.Init] after thread#3 executes 
[A.Init] because B core level depends on A.

The reason is of the wrong execution order is that S4 is released in 
thread#1 by calling Release (S1, S2, S3, S4) and in thread #4 by calling 
Release (S3, S4).

To fix this issue, core level sync and package level sync should use 
separate semaphores.

In above example, the S4 released in Release (S1, S2, S3, S4) should not 
be the same semaphore as that in Release (S3, S4).

Thanks,
Ray


  reply	other threads:[~2018-11-09  8:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08  2:57 [Patch 0/2] Separate semaphore container Eric Dong
2018-11-08  2:57 ` [Patch 1/2] UefiCpuPkg/RegisterCpuFeaturesLib: " Eric Dong
2018-11-09  8:40   ` Ni, Ruiyu [this message]
2018-11-08  2:58 ` [Patch 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: " Eric Dong
2018-11-08 13:33   ` Laszlo Ersek
2018-11-08 17:51     ` Laszlo Ersek
2018-11-09  5:33       ` Dong, Eric
2018-11-09  8:41   ` Ni, Ruiyu
2018-11-10  3:19 ` [Patch 0/2] " Dong, Eric
2018-11-12 10:30   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=162f4a7d-aae8-7ebf-8e98-a8a1cc8d9e36@Intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox