2009-04-02 14:57:44

by Metzger, Markus T

[permalink] [raw]
Subject: [patch 01/18] x86, bts: fix race when bts tracer is removed

---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


Attachments:
tip.master.ds.tracing_flags.patch (3.32 kB)
(No filename) (642.00 B)
Download all attachments

2009-04-02 18:45:48

by Ingo Molnar

[permalink] [raw]
Subject: Re: [patch 01/18] x86, bts: fix race when bts tracer is removed


* [email protected] <[email protected]> wrote:

> +static inline void ds_take_timestamp(struct ds_context *context,
> + enum bts_qualifier qualifier,
> + struct task_struct *task)
> +{
> + struct bts_tracer *tracer = context->bts_master;
> + barrier();

why the barrier()?

> +
> + if (tracer && (tracer->flags & BTS_TIMESTAMPS)) {
> + struct bts_struct ts = {
> + .qualifier = qualifier,
> + .variant.timestamp.jiffies = jiffies_64,
> + .variant.timestamp.pid = task->pid
> + };
> + bts_write(tracer, &ts);
> + }

Why do we have .variant.timestamp.pid ? A PID is not a timestamp. It
might be .event.jiffies and .event.pid perhaps.

Also, the whole function could be cleaned up by:

1) returning early if !tracer || !(tracer->flags & BTS_TIMESTAMPS).

2) Doing a cleaner initialization - something like:

struct bts_struct ts = {
.qualifier = qualifier,
.variant.event.jiffies = jiffies_64,
.variant.event.pid = task->pid
};

Also, raw use of jiffies_64 is buggy and racy. Why does this use
jiffies to begin with - why not some finer grained time?

Ingo

2009-04-03 06:23:47

by Metzger, Markus T

[permalink] [raw]
Subject: RE: [patch 01/18] x86, bts: fix race when bts tracer is removed

>-----Original Message-----
>From: Ingo Molnar [mailto:[email protected]]
>Sent: Thursday, April 02, 2009 8:45 PM
>To: Metzger, Markus T
>Cc: [email protected]; [email protected]; [email protected]; [email protected];
>[email protected]; [email protected]; Villacis, Juan; [email protected]; linux-
>[email protected]
>Subject: Re: [patch 01/18] x86, bts: fix race when bts tracer is removed
>
>
>* [email protected] <[email protected]> wrote:
>
>> +static inline void ds_take_timestamp(struct ds_context *context,
>> + enum bts_qualifier qualifier,
>> + struct task_struct *task)
>> +{
>> + struct bts_tracer *tracer = context->bts_master;
>> + barrier();
>
>why the barrier()?

See http://lkml.org/lkml/2009/3/31/544

Oleg: "In theory, we need barrier() after reading ->bts_master.

(actually, I did see the bug reports when the compiler read the pointer
twice with the code like above)."


>> +
>> + if (tracer && (tracer->flags & BTS_TIMESTAMPS)) {
>> + struct bts_struct ts = {
>> + .qualifier = qualifier,
>> + .variant.timestamp.jiffies = jiffies_64,
>> + .variant.timestamp.pid = task->pid
>> + };
>> + bts_write(tracer, &ts);
>> + }
>
>Why do we have .variant.timestamp.pid ? A PID is not a timestamp. It
>might be .event.jiffies and .event.pid perhaps.

OK.


>Also, the whole function could be cleaned up by:
>
> 1) returning early if !tracer || !(tracer->flags & BTS_TIMESTAMPS).
>
> 2) Doing a cleaner initialization - something like:
>
>struct bts_struct ts = {
> .qualifier = qualifier,
> .variant.event.jiffies = jiffies_64,
> .variant.event.pid = task->pid
>};
>
>Also, raw use of jiffies_64 is buggy and racy. Why does this use
>jiffies to begin with - why not some finer grained time?

What would be a good time to use?

thanks,
markus.
---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

2009-04-03 07:17:41

by Metzger, Markus T

[permalink] [raw]
Subject: RE: [patch 01/18] x86, bts: fix race when bts tracer is removed

>-----Original Message-----
>From: Metzger, Markus T
>Sent: Friday, April 03, 2009 8:20 AM
>To: Ingo Molnar


>>Also, raw use of jiffies_64 is buggy and racy. Why does this use
>>jiffies to begin with - why not some finer grained time?
>
>What would be a good time to use?

I found cpu_clock() declared in sched.h, which is based on TSC and
seems to be used by the scheduler, as well.
Would this be a good time to use?

thanks,
markus.

---------------------------------------------------------------------
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen Germany
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes Schwaderer
Registergericht: Muenchen HRB 47456 Ust.-IdNr.
VAT Registration No.: DE129385895
Citibank Frankfurt (BLZ 502 109 00) 600119052

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

2009-04-03 11:29:26

by Ingo Molnar

[permalink] [raw]
Subject: Re: [patch 01/18] x86, bts: fix race when bts tracer is removed


* Metzger, Markus T <[email protected]> wrote:

> >-----Original Message-----
> >From: Ingo Molnar [mailto:[email protected]]
> >Sent: Thursday, April 02, 2009 8:45 PM
> >To: Metzger, Markus T
> >Cc: [email protected]; [email protected]; [email protected]; [email protected];
> >[email protected]; [email protected]; Villacis, Juan; [email protected]; linux-
> >[email protected]
> >Subject: Re: [patch 01/18] x86, bts: fix race when bts tracer is removed
> >
> >
> >* [email protected] <[email protected]> wrote:
> >
> >> +static inline void ds_take_timestamp(struct ds_context *context,
> >> + enum bts_qualifier qualifier,
> >> + struct task_struct *task)
> >> +{
> >> + struct bts_tracer *tracer = context->bts_master;
> >> + barrier();
> >
> >why the barrier()?
>
> See http://lkml.org/lkml/2009/3/31/544
>
> Oleg: "In theory, we need barrier() after reading ->bts_master.
>
> (actually, I did see the bug reports when the compiler read the pointer
> twice with the code like above)."

Please convert this piece of non-trivial information into a small
two-sentence blurb and put it into a comment block.

> >struct bts_struct ts = {
> > .qualifier = qualifier,
> > .variant.event.jiffies = jiffies_64,
> > .variant.event.pid = task->pid
> >};
> >
> >Also, raw use of jiffies_64 is buggy and racy. Why does this use
> >jiffies to begin with - why not some finer grained time?
>
> What would be a good time to use?

ktime_get() would be the primary candidate. (Or, perhaps, if
performance is really an issue then trace_clock() or
trace_clock_global().)

Ingo

2009-04-03 11:31:27

by Ingo Molnar

[permalink] [raw]
Subject: Re: [patch 01/18] x86, bts: fix race when bts tracer is removed


* Metzger, Markus T <[email protected]> wrote:

> >-----Original Message-----
> >From: Metzger, Markus T
> >Sent: Friday, April 03, 2009 8:20 AM
> >To: Ingo Molnar
>
>
> >>Also, raw use of jiffies_64 is buggy and racy. Why does this use
> >>jiffies to begin with - why not some finer grained time?
> >
> >What would be a good time to use?
>
> I found cpu_clock() declared in sched.h, which is based on TSC and
> seems to be used by the scheduler, as well. Would this be a good
> time to use?

i'd suggest trace_clock() [which maps to cpu_clock() internally], or
trace_clock_global().

See kernel/trace/trace_clock.c about the properties/tradeoffs. Since
this is a user-facing ABI, trace_clock_global() looks more
compelling, despite its global lock.

Ingo