This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] kprobes for s390 architecture


> 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();
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]