question about the exchanges of td->td_lock and mtx in sched_switch() of sched_ule

Haozhong Zhang snowzh8512 at gmail.com
Thu Oct 13 12:58:56 UTC 2011


Hi,

I'm recently reading the code of sched_ule in freebsd 8.2.0 and have two
questions.

1. sched_switch() (in sched_ule.c) invokes cpu_switch() (at line 1852) and
thread_unblock_switch() (at line 1867). These two functions exchange
td->td_lock and mtx. What are the purposes of these exchanges?

2. Can the exchange in cpu_switch() (in amd64/amd64/cpu_switch.S, at line
134) be done before calling cpu_switch()? I mean, does this reorder of
exchange and other operations in cpu_switch() cause side-effects to other
code?

Thank you!
- Haozhong Zhang


More information about the freebsd-hackers mailing list