template <typename NotifyFn>

class CpuContextExchange

Defined at line 59 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

CpuContextExchange is a place for a CPU to synchronously receive the context

of another CPU. CpuContextExchange is thread-safe and intended for

concurrent use.

Example usage:

// Sends an IPI to |target|.

void SendIpi(cput_num_t target);

CpuContextExchange exchange(SendIpi);

...

// On CPU-1 with interrupts disabled...

CpuContextExchange context;

zx_status_t status = exchange.RequestContext(2, ZX_MSEC(10), context);

if (status == ZX_OK) {

Print(

&context

);

}

...

// On CPU-2 with interrupts disabled...

void NmiHandler(iframe_t* frame) {

exchange.HandleRequest(frame->rbp, *frame);

}

The template parameter |NotifyFn| is functor that accepts one cpu_num_t

argument. It will be called by |RequestContext| with interrupts disabled and

be passed |target_cpu|. When called it should *somehow* notify |target_cpu|

that another CPU has requested its context. The |target_cpu| should then

call |HandleRequest|.

Public Methods

void CpuContextExchange<NotifyFn> (NotifyFn notify_fn)

Defined at line 61 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

void CpuContextExchange<NotifyFn> (const CpuContextExchange<NotifyFn> & )

No copy. No move.

Defined at line 83 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

CpuContextExchange<NotifyFn> & operator= (const CpuContextExchange<NotifyFn> & )

Defined at line 84 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

void CpuContextExchange<NotifyFn> (CpuContextExchange<NotifyFn> && )

Defined at line 85 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

CpuContextExchange<NotifyFn> & operator= (CpuContextExchange<NotifyFn> && )

Defined at line 86 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

zx_status_t RequestContext (cpu_num_t target_cpu, zx_duration_mono_t timeout, CpuContext & context)

Synchronously request |target_cpu| to fill in |context|. Spins until

|target_cpu| handles the request or |timeout| has elapsed.

All requests for a given exchange instance are serialized so if the target

does not respond, the exchange will remain "tied up" indefinitely. When

this happens, subsequent requests will spin for |timeout| before failing

with ZX_ERR_TIMED_OUT.

Must be called with interrupts disabled.

Defined at line 104 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h

void HandleRequest (vaddr_t fp, const iframe_t & frame)

Synchronously reply to a request. This method is a no-op if there is no

active request for this CPU's context.

Safe for use in interrupt context.

Must be called with interrupts disabled.

Defined at line 158 of file ../../zircon/kernel/lib/backtrace/include/lib/backtrace/cpu_context_exchange.h