Re: Why do_swap() sets cpu.current before context switch?


Yasushi SHOJI
 

Hi Katsuhiro and Andy,

On Tue, Sep 14, 2021 at 7:52 PM Katsuhiro Suzuki
<katsuhiro@katsuster.net> wrote:
On 2021/09/09 10:41, Yasushi SHOJI wrote:
On Thu, Sep 9, 2021 at 12:01 AM Katsuhiro Suzuki <katsuhiro@katsuster.net> wrote:
On 2021/09/08 16:22, Yasushi SHOJI wrote:
On Wed, Sep 8, 2021 at 10:23 AM Katsuhiro Suzuki <katsuhiro@katsuster.net> wrote:
Why do you `use _current_cpu` at all? `_arch_switch()` or
`arch_switch()` on the main branch takes
both new and old thread handles.
Because to keep consistency for another context switching (by preemption) and
other interrupts.
Only _current_cpu.current is available when an interrupt occurred.
The reason why we set _current to the new thread is that we can't set it after
we switch to the new thread. The newly switched thread will just start
running from
the point it left off. Otherwise, we have to make sure that each and
every arch must
set _current to the new thread in `arch_switch()`.
Hmm... It seems that in CONFIG_USE_SWITCH=n case (ex. aarch32(*)) _current_cpu.current
is updated by software interrupt handler.
(*) arch/arm/core/aarch32/swap_helper.S

So I wonder that why CONFIG_USE_SWITCH=y changed strategy to update current thread.
Ah, OK. I didn't answer your question at all. And I don't have the answer.

Andy, would you mind telling us if you have any comments about the
rationale behind this?

--
yashi

Join devel@lists.zephyrproject.org to automatically receive all group messages.