This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [PATCH] kprobes for s390 architecture
- From: Heiko Carstens <heiko dot carstens at de dot ibm dot com>
- To: Michael Grundy <grundym at us dot ibm dot com>
- Cc: Jan Glauber <jan dot glauber at de dot ibm dot com>, Martin Schwidefsky <schwidefsky at de dot ibm dot com>, linux-kernel at vger dot kernel dot org, systemtap at sources dot redhat dot com
- Date: Sat, 24 Jun 2006 00:21:06 +0200
- Subject: Re: [PATCH] kprobes for s390 architecture
- References: <20060623150344.GL9446@osiris.boeblingen.de.ibm.com> <OF44DB398C.F7A51098-ON88257196.007CD277-88257196.007DC8F0@us.ibm.com>
> On the same page it says "All copies of a prefetched instruction are
> discarded
> when: * A serializing function is performed" Would something like this in a
> smp_call_function do it? :
>
> bcr 15,0
>
> if (*p->addr != breakpoint_instruction)
> *p->addr = breakpoint_instruction;
>
>
> Alternatively, if we did a compare and swap on that location (serializing
> instruction) would that be acceptable?
>
> Thanks
> Michael
The crap below is something that could solve your problem (assumes that "a"
is the address of the instruction to be replaced and 0x42 is the opcode of
the new instruction):
- generates an irq on all other cpus -> prefetched stuff on them discarded
- catches all cpus
- writes the new instruction
- the atomic_inc(&cap.done) is a compare and swap instruction -> serialization
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();
}