Skip to contentSkip to conversation

tracing/hw-branch-tracing: convert bts-tracer mutex to a spinlock

tip:tracing/hw-branch-tracing Metzger, Markus T 2 participants 7 messages Feb 25, 2009 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 10 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 9:21 AM

bts_hotcpu_handler() is called with irqs disabled, so using mutex_lock() is a no-no.

All the BTS codepaths here are atomic (they do not schedule), so using a spinlock is the right solution.

I introduced the lock to protect against a race between bts_trace_start/stop() and bts_hotcpu_handler().

Assuming that the hw-branch-tracer is removed and at the same time a cpu comes online, we might be left with a disabled tracer but still trace that new cpu.

I wonder whether a simple get/put_online_cpus() would suffice, i.e.

static void bts_trace_start(struct trace_array *tr)

{
	get_online_cpus();

on_each_cpu(bts_trace_start_cpu, NULL, 1); trace_hw_branches_enabled = 1;

	put_online_cpus();
}
Quoted 10 lines

static void trace_bts_prepare(struct trace_iterator *iter) {

(quoted diff) +1 -1
-	mutex_lock(&bts_tracer_mutex);
+	spin_lock(&bts_tracer_lock);
	on_each_cpu(trace_bts_cpu, iter->tr, 1);
(quoted diff) +1 -1
-	mutex_unlock(&bts_tracer_mutex);
+	spin_unlock(&bts_tracer_lock);

}

Whereas start/stop are relatively fast, the above operation is rather expensive. Would it make sense to use schedule_on_each_cpu() instead of on_each_cpu()?

regards,
markus.

---------------------------------------------------------------------Intel GmbHDornacher Strasse 185622 Feldkirchen/Muenchen GermanySitz der Gesellschaft: Feldkirchen bei MuenchenGeschaeftsfuehrer: Douglas Lusk, Peter Gleissner, Hannes SchwadererRegistergericht: Muenchen HRB 47456 Ust.-IdNr.VAT Registration No.: DE129385895Citibank Frankfurt (BLZ 502 109 00) 600119052 This e-mail and any attachments may contain confidential material forthe sole use of the intended recipient(s). Any review or distributionby others is strictly prohibited. If you are not the intendedrecipient, please contact the sender and delete all copies.���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#2 lore raw
Quoted 7 lines · Metzger, Markus T
Quoted 7 lines

static void trace_bts_prepare(struct trace_iterator *iter) {

(quoted diff) +1 -1
-	mutex_lock(&bts_tracer_mutex);
+	spin_lock(&bts_tracer_lock);
	on_each_cpu(trace_bts_cpu, iter->tr, 1);
Quoted 7 lines
Quoted 3 lines
(quoted diff) +1 -1
-	mutex_unlock(&bts_tracer_mutex);
+	spin_unlock(&bts_tracer_lock);

}

Whereas start/stop are relatively fast, the above operation is rather expensive. Would it make sense to use schedule_on_each_cpu() instead of on_each_cpu()?

it's perfectly fine to do that on_each_cpu() under the spinlock. schedule_on_each_cpu() would likely be more expensive - and for no good reason.

Ingo

#3 lore raw
Quoted 19 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 10:58 AM
To: Metzger, Markus T

Quoted 11 lines · Metzger, Markus T
Quoted 10 lines

static void trace_bts_prepare(struct trace_iterator *iter) {

(quoted diff) +2 -2
-    mutex_lock(&bts_tracer_mutex);
+    spin_lock(&bts_tracer_lock);
 
    on_each_cpu(trace_bts_cpu, iter->tr, 1);
 
-    mutex_unlock(&bts_tracer_mutex);
+    spin_unlock(&bts_tracer_lock);

}

Quoted 7 lines
Quoted 3 lines

Whereas start/stop are relatively fast, the above operation is rather expensive. Would it make sense to use schedule_on_each_cpu() instead of on_each_cpu()?

it's perfectly fine to do that on_each_cpu() under the spinlock. schedule_on_each_cpu() would likely be more expensive - and for no good reason.

OK.

And I assume you like the spinlock better than the get/put_online_cpus(), as well.

regards,
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.

#4 lore raw
Quoted 23 lines · Metzger, Markus T
Quoted 23 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 10:58 AM
To: Metzger, Markus T

Quoted 14 lines · Metzger, Markus T
Quoted 10 lines

static void trace_bts_prepare(struct trace_iterator *iter) {

(quoted diff) +2 -2
-    mutex_lock(&bts_tracer_mutex);
+    spin_lock(&bts_tracer_lock);
 
    on_each_cpu(trace_bts_cpu, iter->tr, 1);
 
-    mutex_unlock(&bts_tracer_mutex);
+    spin_unlock(&bts_tracer_lock);

}

Whereas start/stop are relatively fast, the above operation is rather expensive. Would it make sense to use schedule_on_each_cpu() instead of on_each_cpu()?

Quoted 8 lines
Quoted 3 lines

it's perfectly fine to do that on_each_cpu() under the spinlock. schedule_on_each_cpu() would likely be more expensive - and for no good reason.

OK.

And I assume you like the spinlock better than the get/put_online_cpus(), as well.

yeah - and get/put_online_cpus is sleepable too, so it doesnt really help unless i'm missing something ...

Ingo

#5 lore raw
Quoted 8 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 12:11 PM
To: Metzger, Markus T
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux-tip- [email protected]

Quoted 5 lines
Quoted 2 lines

And I assume you like the spinlock better than the get/put_online_cpus(), as well.

yeah - and get/put_online_cpus is sleepable too, so it doesnt really help unless i'm missing something ...

I suggested to use get/put_online_cpus() instead of the lock.

The hotplug code waits until the cpu_hotplug.refcount is zero and it holds the cpu_hotplug.lock during hotplug operations (see cpu_hotplug_begin/done()).

In turn, get_online_cpus() needs to grab the cpu_hotplug.lock to increment the cpu_hotplug.refcount.

Thus, we will use the cpu_hotplug.lock instead of our own lock.

regards,
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.

#6 lore raw
Quoted 16 lines · Metzger, Markus T
Quoted 8 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 12:11 PM
To: Metzger, Markus T
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux-tip- [email protected]

Quoted 5 lines
Quoted 2 lines

And I assume you like the spinlock better than the get/put_online_cpus(), as well.

yeah - and get/put_online_cpus is sleepable too, so it doesnt really help unless i'm missing something ...

I suggested to use get/put_online_cpus() instead of the lock.

Quoted 8 lines

The hotplug code waits until the cpu_hotplug.refcount is zero and it holds the cpu_hotplug.lock during hotplug operations (see cpu_hotplug_begin/done()).

In turn, get_online_cpus() needs to grab the cpu_hotplug.lock to increment the cpu_hotplug.refcount.

Thus, we will use the cpu_hotplug.lock instead of our own lock.

... which, if you use it in the exact same spots as now still does a potential sleep with irqs disabled => bad.

We might be able to not take the hotplug lock in the affected codepath, but we should really not expand on the use of that lock and should make this code self-sufficient.

Ingo

#7 lore raw
Quoted 12 lines

-----Original Message-----
From: Ingo Molnar [mailto:[email protected]]
Sent: Wednesday, February 25, 2009 12:46 PM
To: Metzger, Markus T

Quoted 6 lines

I suggested to use get/put_online_cpus() instead of the lock.

The hotplug code waits until the cpu_hotplug.refcount is zero and it holds the cpu_hotplug.lock during hotplug operations (see cpu_hotplug_begin/done()).

Quoted 7 lines
Quoted 4 lines

In turn, get_online_cpus() needs to grab the cpu_hotplug.lock to increment the cpu_hotplug.refcount.

Thus, we will use the cpu_hotplug.lock instead of our own lock.

... which, if you use it in the exact same spots as now still does a potential sleep with irqs disabled => bad.

We don't need to get_online_cpus() in the hotplug handler; actually, we must not.

Quoted 3 lines

We might be able to not take the hotplug lock in the affected codepath, but we should really not expand on the use of that lock and should make this code self-sufficient.

You're right. An own spinlock is definitely safer and much easier to understand.

thanks and regards,
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.