fix: resolve LIBCUDA_LOG_LEVEL on first use so early messages honour it - #245
fix: resolve LIBCUDA_LOG_LEVEL on first use so early messages honour it#245krim404 wants to merge 1 commit into
Conversation
g_log_level defaults to 2 and both LOG_WARN and LOG_MSG fire at >= 2, but the variable is only read by log_utils_init(), which preInit() reaches after the dlsym hook and after the Initializing message have already logged. Those messages therefore ignore LIBCUDA_LOG_LEVEL entirely, including the value 1 that the device plugin injects into every container. Resolve the level on first use through pthread_once instead of relying on log_utils_init() having run. Behaviour is unchanged when the variable is unset; LOG_ERROR keeps its unconditional path. Signed-off-by: Krim <git@krim.dev>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: krim404 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @krim404! It looks like this is your first PR to Project-HAMi/HAMi-core 🎉 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughLogging macros now use a public ChangesLogging level initialization and macro integration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant LoggingMacro
participant log_level
participant pthread_once
participant log_utils_init
participant Environment
LoggingMacro->>log_level: request threshold level
log_level->>pthread_once: initialize once
pthread_once->>log_utils_init: resolve cached level
log_utils_init->>Environment: read LIBCUDA_LOG_LEVEL
log_level-->>LoggingMacro: return g_log_level
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
I spent most of a day chasing this before reading the source, so I figured I should write it up
properly rather than just work around it.
Every process in our HAMi containers prints these to stderr, no matter what I set
LIBCUDA_LOG_LEVELto:What eventually made it click is that the device plugin already sets
LIBCUDA_LOG_LEVEL=1in thecontainer environment. The container is asking for warn level to be quiet, and it isn't, so
something was off rather than me holding it wrong.
The reason is just ordering.
g_log_levelstarts at 2 inlog_utils.c, and bothLOG_WARNandLOG_MSGfire at>= 2. But the variable is only read bylog_utils_init(), and inlibvgpu.cthat call sits at line 872, while the dlsym hook lives at 74 with its warning at 115 and the
"Initializing" message at 870. Both messages happen while
g_log_levelis still the compile timedefault, which is exactly the threshold. Setting the variable to 0 in the pod environment changes
nothing for the warnings, and the Msg lines are identical for every value from 0 to 5.
One thing that might help reproducing: we only see the
recursive dlsymwarnings in containersthat ask for
graphicsinNVIDIA_DRIVER_CAPABILITIES. Compute only pods on the same node andthe same card have never shown them, presumably because far fewer libraries get resolved on the
way up.
Why I care enough to send a patch rather than pipe it to /dev/null: we run KDE desktops on HAMi
GPUs through Coder, which collects a few workspace metrics by running a small script per metric
and storing whatever comes back. The shell it spawns emits the warning while it is still being
linked, before the script's first line runs, so the warning ends up as the metric value. I tried
to filter it and could not, and the thing that finally convinced me was setting one metric's
entire script to
echo ok. It came back as a HAMi warning. There is no point in the script thatis early enough, so there is nothing a consumer can do about it.
I did look for a way to patch around it on our side first.
/etc/ld.so.preloadand/usr/local/vgpu/libvgpu.soare read only bind mounts, so nothing inside the container canredirect them, and patching the library on the node gets overwritten on the next upgrade.
The change
log_level()resolvesLIBCUDA_LOG_LEVELon first use viapthread_onceinstead of dependingon
log_utils_init()having run, and the four threshold checks in the macros go through it.log_utils_init()keeps working and stays the thingpthread_oncecalls, so the existing callsite in
preInit()is harmless either way.LOG_ERRORis untouched, it has no threshold.Behaviour is unchanged when the variable is unset, and the levels now apply from the very first
message:
In case it comes up in review: calling
getenv()from inside the dlsym hook is fine, it does notroute through
dlsymitself, so this does not feed the recursion the hook exists to catch.If you would rather keep
log_utils_init()as the single entry point and call it from aconstructor instead, that works for me too. I went with the accessor because it does not depend
on constructor ordering, which is the part that broke here in the first place.
Tested against HAMi v2.9.0 on an RTX PRO 6000 Blackwell, driver 610.43.02, Debian 13 on kernel
6.12, k3s v1.35.1 with containerd.
Summary by CodeRabbit