Hi Honza,

Here's an idea to make it easier to manually annotate
large C code bases for hot/cold functions where
it's too difficult to use profile feedback.

It's fairly common here to call function through
function pointers in manual method tables.

A lot of code is targetted by a few function pointers
(think like backends or drivers) 

Some of these function pointers always point to cold
code (e.g. init/exit code) while others are usually
hot.

Now as an alternative to manually annotate the hot/cold 
functions it would be much simpler to annotate the function
pointers and let the functions that get assigned to 
inherit that.

So for example 

struct ops {
        void (*init)() __attribute__((cold));
        void (*exit)() __attribute__((cold));
        void (*hot_op)() __attribute__((hot));
};

void init_a(void) {} 
void exit_a(void) {}
void hot_op(void) {} 

const struct ops objecta = {
        .init = init_a,
        .exit = exit_a,
        .hot_op = hot_op_a
};

/* lots of similar objects with struct ops method tables */

init_a, exit_a and their callees (if they are not
called by anything else) would automatically become all cold,
and hot_op_a (and unique callees) hot, because they
are assigned to a cold or hot function pointer.

Basically the hot/coldness would be inheritted from
a function pointer assignment too.

Do you think a scheme like this would be possible to implement?

Thanks,
-Andi
-- 
a...@linux.intel.com -- Speaking for myself only.

Reply via email to