From: Jens Axboe <axboe@kernel.dk>
To: Thomas Gleixner <tglx@linutronix.de>,
Nam Cao <namcao@linutronix.de>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 05/12] io_uring: Use helper function hrtimer_update_function()
Date: Fri, 7 Feb 2025 10:46:08 -0700 [thread overview]
Message-ID: <ad55978e-4356-494e-8cda-9e6487344768@kernel.dk> (raw)
In-Reply-To: <87h656n3r6.ffs@tglx>
On 2/6/25 2:48 PM, Thomas Gleixner wrote:
> On Thu, Feb 06 2025 at 13:05, Jens Axboe wrote:
>> On 2/6/25 9:18 AM, Thomas Gleixner wrote:
>>> On Wed, Feb 05 2025 at 11:45, Jens Axboe wrote:
>>>> On 2/5/25 3:55 AM, Nam Cao wrote:
>>>>> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
>>>>> index ceacf6230e34..936f8b4106cf 100644
>>>>> --- a/io_uring/io_uring.c
>>>>> +++ b/io_uring/io_uring.c
>>>>> @@ -2421,7 +2421,7 @@ static enum hrtimer_restart io_cqring_min_timer_wakeup(struct hrtimer *timer)
>>>>> goto out_wake;
>>>>> }
>>>>>
>>>>> - iowq->t.function = io_cqring_timer_wakeup;
>>>>> + hrtimer_update_function(&iowq->t, io_cqring_timer_wakeup);
>>>>> hrtimer_set_expires(timer, iowq->timeout);
>>>>> return HRTIMER_RESTART;
>>>>> out_wake:
>>>>
>>>> The timer is known expired here, it's inside the callback. Is this
>>>> really necessary or useful?
>>>
>>> It's not strictly required here, but in the end this allows to make the
>>> .function member private, which prevents stupid code fiddling with it
>>> without proper sanity checks in the debug case.
>>
>> While that makes sense, this is also a potentially hot path for min
>> timeout usage, which with small timeouts for batch/latency reasons
>> can be run tens of thousand times per second. Adding a lock and IRQ
>> dance would be counter productive.
>
> I fundamentally hate the fact that C does not enforce encapsulation in
> the first place. :)
>
>> How about we just add a comment on why this is fine, rather than
>
> Comments are the worst of a solution as you know.
Sure I don't disagree - this is just my way of attempting to be nice and
suggest alternatives, as I don't like this patch.
>> slow down a case that's perfectly fine by wrapping it in something
>> much more expensive than a simple memory write? Or perhaps have
>> a basic helper to set it that doesn't do the unnecessary irq lock
>> guard? That would still allow you to make .function private.
>
> The right solution is to add a hotpath helper, which falls back to the
> more expensive variant with some anyway expensive debug option, or make
> the expensive part of hrtimer_update_function() depend on that debug
> option in the first place and otherwise fall back to a simple store.
>
> The latter is the right thing to do. Let me fix that up in mainline.
Yep exactly, this is the way. Thanks!
--
Jens Axboe
next prev parent reply other threads:[~2025-02-07 17:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 10:55 [PATCH v2 00/12] Consolidate hrtimer initialization - Part 5 Nam Cao
2025-02-05 10:55 ` [PATCH v2 01/12] hrtimers: Delete hrtimer_init() Nam Cao
2025-02-05 10:55 ` [PATCH v2 02/12] hrtimers: Switch to use __htimer_setup() Nam Cao
2025-02-05 10:55 ` [PATCH v2 03/12] hrtimers: Merge __hrtimer_init() into __hrtimer_setup() Nam Cao
2025-02-05 10:55 ` [PATCH v2 04/12] serial: xilinx_uartps: Use helper function hrtimer_update_function() Nam Cao
2025-02-05 10:55 ` [PATCH v2 05/12] io_uring: " Nam Cao
2025-02-05 18:45 ` Jens Axboe
2025-02-06 16:18 ` Thomas Gleixner
2025-02-06 20:05 ` Jens Axboe
2025-02-06 21:48 ` Thomas Gleixner
2025-02-07 17:46 ` Jens Axboe [this message]
2025-02-07 21:16 ` [PATCH] hrtimers: Make hrtimer_update_function() less expensive Thomas Gleixner
2025-02-08 15:18 ` Jens Axboe
2025-02-10 19:52 ` Thomas Gleixner
2025-02-10 19:56 ` Jens Axboe
2025-02-10 20:05 ` [tip: timers/core] " tip-bot2 for Thomas Gleixner
2025-02-05 10:55 ` [PATCH v2 06/12] wifi: rt2x00: Switch to use hrtimer_update_function() Nam Cao
2025-02-05 10:55 ` [PATCH v2 07/12] hrtimers: Make callback function pointer private Nam Cao
2025-02-05 10:55 ` [PATCH v2 08/12] hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns() Nam Cao
2025-02-05 10:55 ` [PATCH v2 09/12] hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper() Nam Cao
2025-02-05 10:55 ` [PATCH v2 10/12] hrtimers: Rename debug_init() to debug_setup() Nam Cao
2025-02-05 10:55 ` [PATCH v2 11/12] hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack() Nam Cao
2025-02-05 10:55 ` [PATCH v2 12/12] tracing/timers: Rename hrtimer_init event to hrtimer_setup Nam Cao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad55978e-4356-494e-8cda-9e6487344768@kernel.dk \
--to=axboe@kernel.dk \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®