<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hello everyone,<div><br></div><div>I am currently working on my bachelor thesis and I have a question regarding PIDs/TGIDs in the sunrpc layer of the kernel.</div><div>I was wondering if I can obtain the PID/TGID of the userland process that originally caused a RPC request to be <font color="#000000"><span style="caret-color: rgb(0, 0, 0);">transmitted, from within the RPC request itself</span></font>.</div><div><br></div><div>Here is what I did:</div><div>With a BPF program I collect the following metrics from a tracepoint inside “xprt_request_transmit()” function defined in /net/sunrpc/xprt.c:</div><div><br></div><div>1. current task name </div><div>2. current PID/TGID as a return value of bpf_get_current_pid_tgid()</div><div>3. The TGID assigned in the tk_owner field of struct rpc_task. (Using: BPF_CORE_READ(rpc_rqst, rq_task, tk_owner))</div><div><br></div><div>From the sources I have learned that TGID from 3. is assigned in “rpc_init_task() function” defined in /net/sunrpc/sched.c:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>task->tk_owner = current->tgid;</div><div><br></div><div><br></div><div>In the output of the BPF program I see records with the following entries for the above metrics:</div><div><br></div><div>1. "kworker/u389:3”</div><div>2. "PID": 455045, "TGID": 455045</div><div>3. "rpc_tk_owner_tgid": 3989219</div><div><br></div><div>Here, evidently, the thread that executes the "<font color="#000000"><span style="caret-color: rgb(0, 0, 0);">xprt_request_transmit()” differs from the one that assigned the </span></font><font color="#000000">rpc_tk_owner_tgid in “rpc_init_task()”. </font></div><div><font color="#000000">The latter was executed by the userland process. </font></div><div><font color="#000000"><br></font></div><div><font color="#000000">But there are also records like this:</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">1. "</font>kworker/u128:4"</div><div>2. "PID": 1457360, "TGID": 1457360</div><div>3. <span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"> </span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">"rpc_tk_owner_tgid": </span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">1457360</span></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br></span></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Here, the kworker did both the jobs.</span></div><div><br></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">Now to my questions:</span></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);"><br></span></div><div><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);">1. </span>What determines which thread executes rpc_init_task()? </div><div>2. How can I, with certainty, obtain the userland process’ PID/TGID from inside rpc_init_task() ?</div><div><br></div><div><br></div><div>Thank you for your answers.</div><div><br></div><div>Best regards,</div><div>Sandro</div><div><br></div></body></html>