Re: [patch V2 10/17] posix-timers: Make signal_struct::next_posix_timer_id an atomic_t
From: Cyrill Gorcunov
Date: Tue Mar 04 2025 - 17:16:33 EST
On Tue, Mar 04, 2025 at 09:30:04PM +0100, Thomas Gleixner wrote:
> On Tue, Mar 04 2025 at 20:56, Cyrill Gorcunov wrote:
> > On Mon, Mar 03, 2025 at 10:24:28PM +0100, Thomas Gleixner wrote:
> >>
> >> Welcome. Some quick validation with CRIU would be appreciated.
> >
> > Just tested in criu: works without problem, both modes -- with new
> > prctl and without it. Note that I only have ran separate posix-timers
> > test case, probably virtuozzo team might do more deep tesing.
>
> Thank you very much!
Thanks for handling this) Also looking into this series I wonder why can't
we instead of mangling ::it_signal zero bit just use ::it_id with negative
value as a sign of not yet fully initialized timer? This would allow to not
read-modify action while traversing bucket hash chain. I mean we could do
static bool posix_timer_add_at(struct k_itimer *timer, struct signal_struct *sig, unsigned int id)
{
struct timer_hash_bucket *bucket = hash_bucket(sig, id);
scoped_guard (spinlock, &bucket->lock) {
if (!posix_timer_hashed(bucket, sig, id)) {
---> timer->it_id = -(timer_t)id;
timer->it_signal = (struct signal_struct *)((unsigned long)sig | 1UL);
hlist_add_head_rcu(&timer->t_hash, &bucket->head);
return true;
}
}
return false;
}
Then hash traverse won't find the timer until the do_timer_create will do
scoped_guard (spinlock_irq, ¤t->sighand->siglock) {
WRITE_ONCE(new_timer->it_id, abs(new_timer->it_id));
hlist_add_head_rcu(&new_timer->list, ¤t->signal->posix_timers);
}
Or I miss something obvious? (Of course when deleting timer we will have to pass
abs it_id for hash traversing).
It looks that in case of many many timers present in the system traversing hash
in read-modify way might be heavy (though I didn't measure of course).
Cyrill