From 7f177fe713bc0128fdea68e221c0ea468caca1b5 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 23 Sep 2005 17:21:11 +0200 Subject: [PATCH] [PATCH] kernel: avoid trace corruption on SMP Maintain a static trace structure per-CPU. --- ...rc2-git-H2 => blk-trace-2.6.14-rc2-git-I0} | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) rename kernel/{blk-trace-2.6.14-rc2-git-H2 => blk-trace-2.6.14-rc2-git-I0} (95%) diff --git a/kernel/blk-trace-2.6.14-rc2-git-H2 b/kernel/blk-trace-2.6.14-rc2-git-I0 similarity index 95% rename from kernel/blk-trace-2.6.14-rc2-git-H2 rename to kernel/blk-trace-2.6.14-rc2-git-I0 index 2fa61af..c4402e3 100644 --- a/kernel/blk-trace-2.6.14-rc2-git-H2 +++ b/kernel/blk-trace-2.6.14-rc2-git-I0 @@ -272,9 +272,9 @@ diff --git a/mm/highmem.c b/mm/highmem.c /* * slow path */ ---- /dev/null 2005-09-09 21:24:12.000000000 +0200 -+++ linux-2.6/drivers/block/blktrace.c 2005-09-22 16:46:20.000000000 +0200 -@@ -0,0 +1,226 @@ +--- /dev/null 2004-06-30 22:03:36.000000000 +0200 ++++ linux-2.6/drivers/block/blktrace.c 2005-09-23 17:17:32.000000000 +0200 +@@ -0,0 +1,230 @@ +#include +#include +#include @@ -284,11 +284,12 @@ diff --git a/mm/highmem.c b/mm/highmem.c +#include + +static DEFINE_PER_CPU(unsigned long long, blk_trace_cpu_offset) = { 0, }; ++static DEFINE_PER_CPU(struct blk_io_trace, cpu_trace) = { 0, }; + +void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, + int rw, u32 what, int error, int pdu_len, void *pdu_data) +{ -+ struct blk_io_trace t; ++ struct blk_io_trace *t; + unsigned long flags; + int cpu; + @@ -305,29 +306,32 @@ diff --git a/mm/highmem.c b/mm/highmem.c + if (((bt->act_mask << BLK_TC_SHIFT) & what) == 0) + return; + -+ t.magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; -+ t.sequence = atomic_add_return(1, &bt->sequence); -+ + cpu = get_cpu(); -+ t.cpu = cpu; -+ t.time = sched_clock() - per_cpu(blk_trace_cpu_offset, cpu); -+ put_cpu(); ++ t = &per_cpu(cpu_trace, cpu); ++ ++ t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION; ++ t->sequence = atomic_add_return(1, &bt->sequence); + -+ t.device = bt->dev; -+ t.sector = sector; -+ t.bytes = bytes; -+ t.action = what; -+ t.error = error; -+ t.pdu_len = pdu_len; ++ t->cpu = cpu; ++ t->time = sched_clock() - per_cpu(blk_trace_cpu_offset, cpu); + -+ t.pid = current->pid; -+ memcpy(t.comm, current->comm, sizeof(t.comm)); ++ t->device = bt->dev; ++ t->sector = sector; ++ t->bytes = bytes; ++ t->action = what; ++ t->error = error; ++ t->pdu_len = pdu_len; ++ ++ t->pid = current->pid; ++ memcpy(t->comm, current->comm, sizeof(t->comm)); + + local_irq_save(flags); -+ __relay_write(bt->rchan, &t, sizeof(t)); ++ __relay_write(bt->rchan, t, sizeof(*t)); + if (pdu_len) + __relay_write(bt->rchan, pdu_data, pdu_len); + local_irq_restore(flags); ++ ++ put_cpu(); +} + +EXPORT_SYMBOL_GPL(__blk_add_trace); @@ -501,8 +505,8 @@ diff --git a/mm/highmem.c b/mm/highmem.c + +module_init(blk_trace_init); + ---- /dev/null 2005-09-09 21:24:12.000000000 +0200 -+++ linux-2.6/include/linux/blktrace.h 2005-09-22 08:47:50.000000000 +0200 +--- /dev/null 2004-06-30 22:03:36.000000000 +0200 ++++ linux-2.6/include/linux/blktrace.h 2005-09-23 17:17:02.000000000 +0200 @@ -0,0 +1,180 @@ +#ifndef BLKTRACE_H +#define BLKTRACE_H -- 2.25.1