mit-pdos / xv6-book

Commentary for xv6-public
Other
248 stars 66 forks source link

Segments are not used for per-CPU storage #21

Open pdav opened 5 years ago

pdav commented 5 years ago

In mem.t (lines 860-870), it is written:

but xv6 uses segments only for the common trick of
implementing per-cpu variables such as
.code proc
that are at a fixed address but have different values
on different CPUs (see
.code-index seginit ).
Implementations of per-CPU (or per-thread) storage on non-segment
architectures would dedicate a register to holding a pointer
to the per-CPU data area, but the x86 has so few general
registers that the extra effort required to use segmentation
is worthwhile.

As far as I understand, all segments in GDT/LDT start from 0 to ffffffff. Thus, they are not used for the described trick. Furthermore, proc is referenced through struct cpu in the cpus[] array (and index in this array is obtained by searching the local APICID).

Therefore, I suggest removing this whole paragraph.