Invoke trace event in registration callback function

From: Matthew Clarkson
Date: Mon Nov 18 2019 - 06:29:38 EST


We are looking to introduce a power/gpu_frequency trace event for Mali GPUs. This integrates nicely with Google's Perfetto (https://perfetto.dev/) ftrace reader to provide a graph of the GPU frequency against GPU workloads.

Google would like for the trace event to output the current GPU frequency when the tracepoint is activated. This is so that if there is no frequency change during the trace the current GPU frequency is known and an unchanging frequency graph can be shown.

To do this we tried adding a registration function to the trace event:

DEFINE_EVENT_FN(gpu, gpu_frequency,
TP_PROTO(unsigned int frequency, unsigned int gpu_id),
TP_ARGS(frequency, gpu_id),
trace_gpu_frequency_register, // <-- added
trace_gpu_frequency_unregister
);

Which invokes the trace point when registered:

static void log_all_gpu_frequencies(void) {
// In production would log the actual current GPU frequency
printk("gpu: frequency: %lu\n", 5000);
trace_gpu_frequency(5000, 0);
}

int trace_gpu_frequency_register(void) {
printk("gpu: register\n");
log_all_gpu_frequencies();
return 0;
}

void trace_gpu_frequency_unregister(void) {
printk("gpu: unregister\n");
}

When performing a trace, there is no data received from the trace point even though the dmesg output shows that the registration callback was invoked. Perfetto also does not receive the event either.

$ sudo trace-cmd record -e power:gpu_frequency
/sys/kernel/tracing/events/power/gpu_frequency
Hit Ctrl^C to stop recording
$ dmesg
[Nov18 10:02] gpu: register
[ +0.002699] gpu: frequency: 5000
[ +7.783861] gpu: unregister

Is it acceptable to invoke a trace point in the registration callback? Is the trace point not full initialized at that point?
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.