Skip to contentSkip to conversation

Why is get_current() not const function?

DISCUSSION Jakub Jelinek 2 participants 2 messages Mar 13, 2003 – Mar 17, 2003

lore
Share & tools
lore
#0 lore raw

Hi!

E.g. on x86-64,

        NEW_AUX_ENT(AT_UID, (elf_addr_t) current->uid);
        NEW_AUX_ENT(AT_EUID, (elf_addr_t) current->euid);
        NEW_AUX_ENT(AT_GID, (elf_addr_t) current->gid);
        NEW_AUX_ENT(AT_EGID, (elf_addr_t) current->egid);

results in 4 movq %gs:0,%rax instructions while one is completely enough.
Anyone remembers why get_current function (on arches which define current to get_current()) is not const and why on x86-64
the movq %%gs:0, %0 inline asm is volatile with "memory" clobber? AFAIK current ought to be constant in any function with the exception of schedule.
If the reason is kernel/sched.c, then IMHO it is certainly worth making get_current const everywhere but in kernel/sched.c (e.g. through special define in sched.c before any includes).

Jakub

#1 lore raw

In article <[email protected]>,

Quoted 3 lines · Jakub Jelinek

Anyone remembers why get_current function (on arches which define current to get_current()) is not const

Because it makes no difference at all on x86, since gcc will ignore "const" for inline functions. At least that used to be true.

Quoted 2 lines
					 and why on x86-64

the movq %%gs:0, %0 inline asm is volatile with "memory" clobber?

Can't help you on that one, but it looks like it uses various helper functions for doing the x86-64 per-processor data structures, and I bet those helper functions are shared by _other_ users who definitely want to have their data properly re-read. Ie "current()" may be constant in process context, but that sure isn't true about a lot of other things in the per-processor data structures.

Linus