Skip to content

Commit 0df6db7

Browse files
edumazetKAGA-KOKO
authored andcommitted
posix-timers: Initialize cache early and move pointer into __timer_data
Move posix_timers_cache initialization to posixtimer_init(). At that point the memory subsystem is already up and running. Also move the cache pointer to the __timer_data variable to avoid potential false sharing, since it never was marked as __ro_after_init. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250402133114.253901-1-edumazet@google.com
1 parent 0af2f6b commit 0df6db7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

kernel/time/posix-timers.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "timekeeping.h"
3131
#include "posix-timers.h"
3232

33-
static struct kmem_cache *posix_timers_cache;
34-
3533
/*
3634
* Timers are managed in a hash table for lockless lookup. The hash key is
3735
* constructed from current::signal and the timer ID and the timer is
@@ -49,10 +47,12 @@ struct timer_hash_bucket {
4947
static struct {
5048
struct timer_hash_bucket *buckets;
5149
unsigned long mask;
52-
} __timer_data __ro_after_init __aligned(2*sizeof(long));
50+
struct kmem_cache *cache;
51+
} __timer_data __ro_after_init __aligned(4*sizeof(long));
5352

54-
#define timer_buckets (__timer_data.buckets)
55-
#define timer_hashmask (__timer_data.mask)
53+
#define timer_buckets (__timer_data.buckets)
54+
#define timer_hashmask (__timer_data.mask)
55+
#define posix_timers_cache (__timer_data.cache)
5656

5757
static const struct k_clock * const posix_clocks[];
5858
static const struct k_clock *clockid_to_kclock(const clockid_t id);
@@ -283,14 +283,6 @@ static int posix_get_hrtimer_res(clockid_t which_clock, struct timespec64 *tp)
283283
return 0;
284284
}
285285

286-
static __init int init_posix_timers(void)
287-
{
288-
posix_timers_cache = kmem_cache_create("posix_timers_cache", sizeof(struct k_itimer),
289-
__alignof__(struct k_itimer), SLAB_ACCOUNT, NULL);
290-
return 0;
291-
}
292-
__initcall(init_posix_timers);
293-
294286
/*
295287
* The siginfo si_overrun field and the return value of timer_getoverrun(2)
296288
* are of type int. Clamp the overrun value to INT_MAX
@@ -1556,6 +1548,11 @@ static int __init posixtimer_init(void)
15561548
unsigned long i, size;
15571549
unsigned int shift;
15581550

1551+
posix_timers_cache = kmem_cache_create("posix_timers_cache",
1552+
sizeof(struct k_itimer),
1553+
__alignof__(struct k_itimer),
1554+
SLAB_ACCOUNT, NULL);
1555+
15591556
if (IS_ENABLED(CONFIG_BASE_SMALL))
15601557
size = 512;
15611558
else

0 commit comments

Comments
 (0)