Re: [PATCH v8 6/7] rust: Add read_poll_timeout functions
From: FUJITA Tomonori
Date: Thu Jan 16 2025 - 06:32:46 EST
On Thu, 16 Jan 2025 10:45:00 +0100
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>> +void __might_sleep(const char *file, int line)
>> +{
>> + long len = strlen(file);
>> +
>> + __might_sleep_precision(file, len, line);
>> }
>> EXPORT_SYMBOL(__might_sleep);
>
> I think these strlen() calls could be pretty expensive. You run them
> every time might_sleep() runs even if the check does not fail.
Ah, yes.
> How about changing __might_resched_precision() to accept a length of
> -1 for nul-terminated strings, and having it compute the length with
> strlen only *if* we know that we actually need the length?
>
> if (len < 0) len = strlen(file);
> pr_err("BUG: sleeping function called from invalid context at %.*s:%d\n",
> len, file, line);
Works for me.
> Another option might be to compile the lengths at compile-time by
> having the macros use sizeof on __FILE__, but that sounds more tricky
> to get right.
Yeah.
By the way, from what I saw in the discussion about Location::file(),
I got the impression that the feature for a null-terminated string
seems likely to be supported in the near future. Am I correct?
If so, rather than adding a Rust-specific helper function to the C
side, it would be better to solve the problem on the Rust side like
the previous versions with c_str()! and file()! for now?