Skip to content

Commit 2a4187f

Browse files
zx2c4kuba-moo
authored andcommitted
once: rename _SLOW to _SLEEPABLE
The _SLOW designation wasn't really descriptive of anything. This is meant to be called from process context when it's possible to sleep. So name this more aptly _SLEEPABLE, which better fits its intended use. Fixes: 62c0798 ("once: add DO_ONCE_SLOW() for sleepable contexts") Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20221003181413.1221968-1-Jason@zx2c4.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3318348 commit 2a4187f

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

include/linux/once.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ void __do_once_done(bool *done, struct static_key_true *once_key,
1313
unsigned long *flags, struct module *mod);
1414

1515
/* Variant for process contexts only. */
16-
bool __do_once_slow_start(bool *done);
17-
void __do_once_slow_done(bool *done, struct static_key_true *once_key,
18-
struct module *mod);
16+
bool __do_once_sleepable_start(bool *done);
17+
void __do_once_sleepable_done(bool *done, struct static_key_true *once_key,
18+
struct module *mod);
1919

2020
/* Call a function exactly once. The idea of DO_ONCE() is to perform
2121
* a function call such as initialization of random seeds, etc, only
@@ -61,26 +61,26 @@ void __do_once_slow_done(bool *done, struct static_key_true *once_key,
6161
})
6262

6363
/* Variant of DO_ONCE() for process/sleepable contexts. */
64-
#define DO_ONCE_SLOW(func, ...) \
65-
({ \
66-
bool ___ret = false; \
67-
static bool __section(".data.once") ___done = false; \
68-
static DEFINE_STATIC_KEY_TRUE(___once_key); \
69-
if (static_branch_unlikely(&___once_key)) { \
70-
___ret = __do_once_slow_start(&___done); \
71-
if (unlikely(___ret)) { \
72-
func(__VA_ARGS__); \
73-
__do_once_slow_done(&___done, &___once_key, \
74-
THIS_MODULE); \
75-
} \
76-
} \
77-
___ret; \
64+
#define DO_ONCE_SLEEPABLE(func, ...) \
65+
({ \
66+
bool ___ret = false; \
67+
static bool __section(".data.once") ___done = false; \
68+
static DEFINE_STATIC_KEY_TRUE(___once_key); \
69+
if (static_branch_unlikely(&___once_key)) { \
70+
___ret = __do_once_sleepable_start(&___done); \
71+
if (unlikely(___ret)) { \
72+
func(__VA_ARGS__); \
73+
__do_once_sleepable_done(&___done, &___once_key,\
74+
THIS_MODULE); \
75+
} \
76+
} \
77+
___ret; \
7878
})
7979

8080
#define get_random_once(buf, nbytes) \
8181
DO_ONCE(get_random_bytes, (buf), (nbytes))
8282

83-
#define get_random_slow_once(buf, nbytes) \
84-
DO_ONCE_SLOW(get_random_bytes, (buf), (nbytes))
83+
#define get_random_sleepable_once(buf, nbytes) \
84+
DO_ONCE_SLEEPABLE(get_random_bytes, (buf), (nbytes))
8585

8686
#endif /* _LINUX_ONCE_H */

lib/once.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,30 @@ EXPORT_SYMBOL(__do_once_done);
6969

7070
static DEFINE_MUTEX(once_mutex);
7171

72-
bool __do_once_slow_start(bool *done)
72+
bool __do_once_sleepable_start(bool *done)
7373
__acquires(once_mutex)
7474
{
7575
mutex_lock(&once_mutex);
7676
if (*done) {
7777
mutex_unlock(&once_mutex);
7878
/* Keep sparse happy by restoring an even lock count on
7979
* this mutex. In case we return here, we don't call into
80-
* __do_once_done but return early in the DO_ONCE_SLOW() macro.
80+
* __do_once_done but return early in the DO_ONCE_SLEEPABLE() macro.
8181
*/
8282
__acquire(once_mutex);
8383
return false;
8484
}
8585

8686
return true;
8787
}
88-
EXPORT_SYMBOL(__do_once_slow_start);
88+
EXPORT_SYMBOL(__do_once_sleepable_start);
8989

90-
void __do_once_slow_done(bool *done, struct static_key_true *once_key,
90+
void __do_once_sleepable_done(bool *done, struct static_key_true *once_key,
9191
struct module *mod)
9292
__releases(once_mutex)
9393
{
9494
*done = true;
9595
mutex_unlock(&once_mutex);
9696
once_disable_jump(once_key, mod);
9797
}
98-
EXPORT_SYMBOL(__do_once_slow_done);
98+
EXPORT_SYMBOL(__do_once_sleepable_done);

net/ipv4/inet_hashtables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,8 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
958958
if (likely(remaining > 1))
959959
remaining &= ~1U;
960960

961-
get_random_slow_once(table_perturb,
962-
INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb));
961+
get_random_sleepable_once(table_perturb,
962+
INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb));
963963
index = port_offset & (INET_TABLE_PERTURB_SIZE - 1);
964964

965965
offset = READ_ONCE(table_perturb[index]) + (port_offset >> 32);

0 commit comments

Comments
 (0)