lkml.org 
[lkml]   [2006]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kprobes for s390 architecture
> At least this is something that could work... completely untested and might
> have some problems that I didn't think of ;)
>
> struct capture_data {
> atomic_t cpus;
> atomic_t done;
> };
>
> void capture_wait(void *data)
> {
> struct capture_data *cap = data;
>
> atomic_inc(&cap->cpus);
> while(!atomic_read(&cap->done))
> cpu_relax();
> atomic_dec(&cap->cpus);
> }
>
> void replace_instr(int *a)
> {
> struct capture_data cap;
>
> preempt_disable();
> atomic_set(&cap.cpus, 0);
> atomic_set(&cap.done, 0);
> smp_call_function(capture_wait, (void *)&cap, 0, 0);
> while (atomic_read(&cap.cpus) != num_online_cpus() - 1)
> cpu_relax();
> *a = 0x42;
> atomic_inc(&cap.done);
> while (atomic_read(&cap.cpus))
> cpu_relax();
> preempt_enable();
> }

Forget this crap. It can easily cause deadlocks with more than two cpus.

Just do a compare and swap operation on the instruction you want to replace,
then do an smp_call_function() with the wait parameter set to 1 and passing
a pointer to a function that does nothing but return.

The cs/csg instruction will make sure that your cpu has exclusive access
to the memory region in question and will invalidate the cache lines on all
other cpus.
With the following smp_call_function() you can make sure that all other
cpus discard everything they have prefetched. Hence there is only a small
window between the cs/csg and the return of smp_call_function() where you
do not know if other cpus are executing the old or the new instruction.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-06-24 13:39    [W:0.321 / U:0.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site