userland process PID/TGID in the RPC layer
sandro
s-sandro at gmx.de
Fri Dec 20 10:25:28 EST 2024
Hello everyone,
I am currently working on my bachelor thesis and I have a question regarding PIDs/TGIDs in the sunrpc layer of the kernel.
I was wondering if I can obtain the PID/TGID of the userland process that originally caused a RPC request to be transmitted, from within the RPC request itself.
Here is what I did:
With a BPF program I collect the following metrics from a tracepoint inside “xprt_request_transmit()” function defined in /net/sunrpc/xprt.c:
1. current task name
2. current PID/TGID as a return value of bpf_get_current_pid_tgid()
3. The TGID assigned in the tk_owner field of struct rpc_task. (Using: BPF_CORE_READ(rpc_rqst, rq_task, tk_owner))
From the sources I have learned that TGID from 3. is assigned in “rpc_init_task() function” defined in /net/sunrpc/sched.c:
task->tk_owner = current->tgid;
In the output of the BPF program I see records with the following entries for the above metrics:
1. "kworker/u389:3”
2. "PID": 455045, "TGID": 455045
3. "rpc_tk_owner_tgid": 3989219
Here, evidently, the thread that executes the "xprt_request_transmit()” differs from the one that assigned the rpc_tk_owner_tgid in “rpc_init_task()”.
The latter was executed by the userland process.
But there are also records like this:
1. "kworker/u128:4"
2. "PID": 1457360, "TGID": 1457360
3. "rpc_tk_owner_tgid": 1457360
Here, the kworker did both the jobs.
Now to my questions:
1. What determines which thread executes rpc_init_task()?
2. How can I, with certainty, obtain the userland process’ PID/TGID from inside rpc_init_task() ?
Thank you for your answers.
Best regards,
Sandro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20241220/02155550/attachment.html>
More information about the Kernelnewbies
mailing list