On Mon, Dec 10, 2018 at 14:37:25 +0300, Pavel Dovgalyuk wrote:
> > From: Emilio G. Cota [mailto:[email protected]]
(snip)
> > +struct qemu_plugin_dyn_cb_arr {
> > + struct qemu_plugin_dyn_cb *data;
> > + size_t n;
> > + size_t capacity;
> > +};
> > +
>
> Why not list or something dynamic?
Performance. Registering of dynamic callbacks can happen
very frequently (e.g. several times per instruction
translated), so we avoid malloc/free churn by keeping
an array of callback requests that we reuse across
translated TB's. The hierarchy is:
struct qemu_plugin_tb {
insns[n_insns_in_the_tb] {
dyn_cb_arr[various types];
}
}
Each array has a "capacity" field so that we only ever expand
the arrays. This ensures that the amortized cost of
adding callbacks is negligible.
> Is the indexing required?
No, this is done just for performance.
> Can you add the comments for the data structures and functions?
> It is very hard to seek through the whole patch to get the details about them.
I had some comments but then the code evolved quickly and the
comments were outdated, which led to confusion. So I removed
most of them.
To understand the code I recommend you to go through one
of the examples and then follow the API calls, first through
plugin.c and then to plugin-gen.c where the instrumentation
is injected (based on the contents of the dyn_cb arrays).
Please ask further questions if anything is unclear.
Thanks,
Emilio