Re: get_current is __pure__, maybe __const__ even

Albert Cahalan
2004-09-16T02:15:27Z

On Wed, 2004-09-15 at 19:29, William Lee Irwin III wrote:
> On Wed, Sep 15, 2004 at 06:50:00PM -0400, Albert Cahalan wrote:
> >> This looks fixable.
> >> At the very least, __attribute__((__pure__))
> >> will apply to your get_current function.
> >> I think __attribute__((__const__)) will too,
> >> even though it's technically against the
> >> documentation. While you do indeed read from
> >> memory, you don't read from memory that could
> >> be seen as changing. Nothing done during the
> >> lifetime of a task will change "current" as
> >> viewed from within that task.
>
> On Wed, Sep 15, 2004 at 07:15:18PM -0400, Jakub Jelinek wrote:
> > current will certainly change in schedule (),

Not really!

>From the viewpoint of a single task looking
at current, it does not change. The task is
paused, and may well start up again on a
different CPU, but current doesn't change.

Any state gcc might keep would be stored on
the kernel stack or in a register, which will
be preserved because tasks don't share these.

AFAIK, gcc generates thread-safe code. It won't
convert code to something like this:

int foo(int bar){
static task_struct *__L131241 = get_current();
// blah, blah...
}

> > so either you'd need to avoid using current
> > in schedule() and use some other accessor
> > for the same without such attribute, or
> > #ifdef the attribute out when compiling sched.c.
>
> Why would barrier() not suffice?

I don't think even barrier() is needed.
Suppose gcc were to cache the value of
current over a schedule. Who cares? It'll
be the same after schedule() as it was
before.