mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-12-22 12:17:45 +01:00
mutex_init() invokes __mutex_init() providing the name of the lock and
a pointer to a the lock class. With LOCKDEP enabled this information is
useful but without LOCKDEP it not used at all. Passing the pointer
information of the lock class might be considered negligible but the
name of the lock is passed as well and the string is stored. This
information is wasting storage.
Split __mutex_init() into a _genereic() variant doing the initialisation
of the lock and a _lockdep() version which does _genereic() plus the
lockdep bits. Restrict the lockdep version to lockdep enabled builds
allowing the compiler to remove the unused parameter.
This results in the following size reduction:
text data bss dec filename
| 30237599 8161430 1176624 39575653 vmlinux.defconfig
| 30233269 8149142 1176560 39558971 vmlinux.defconfig.patched
-4.2KiB -12KiB
| 32455099 8471098 12934684 53860881 vmlinux.defconfig.lockdep
| 32455100 8471098 12934684 53860882 vmlinux.defconfig.patched.lockdep
| 27152407 7191822 2068040 36412269 vmlinux.defconfig.preempt_rt
| 27145937 7183630 2067976 36397543 vmlinux.defconfig.patched.preempt_rt
-6.3KiB -8KiB
| 29382020 7505742 13784608 50672370 vmlinux.defconfig.preempt_rt.lockdep
| 29376229 7505742 13784544 50666515 vmlinux.defconfig.patched.preempt_rt.lockdep
-5.6KiB
[peterz: folded fix from boqun]
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Waiman Long <longman@redhat.com>
Link: https://lkml.kernel.org/r/20251125145425.68319-1-boqun.feng@gmail.com
Link: https://patch.msgid.link/20251105142350.Tfeevs2N@linutronix.de
73 lines
2.5 KiB
C
73 lines
2.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Mutexes: blocking mutual exclusion locks
|
|
*
|
|
* started by Ingo Molnar:
|
|
*
|
|
* Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
|
|
*/
|
|
#ifndef CONFIG_PREEMPT_RT
|
|
/*
|
|
* This is the control structure for tasks blocked on mutex, which resides
|
|
* on the blocked task's kernel stack:
|
|
*/
|
|
struct mutex_waiter {
|
|
struct list_head list;
|
|
struct task_struct *task;
|
|
struct ww_acquire_ctx *ww_ctx;
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
void *magic;
|
|
#endif
|
|
};
|
|
|
|
/*
|
|
* @owner: contains: 'struct task_struct *' to the current lock owner,
|
|
* NULL means not owned. Since task_struct pointers are aligned at
|
|
* at least L1_CACHE_BYTES, we have low bits to store extra state.
|
|
*
|
|
* Bit0 indicates a non-empty waiter list; unlock must issue a wakeup.
|
|
* Bit1 indicates unlock needs to hand the lock to the top-waiter
|
|
* Bit2 indicates handoff has been done and we're waiting for pickup.
|
|
*/
|
|
#define MUTEX_FLAG_WAITERS 0x01
|
|
#define MUTEX_FLAG_HANDOFF 0x02
|
|
#define MUTEX_FLAG_PICKUP 0x04
|
|
|
|
#define MUTEX_FLAGS 0x07
|
|
|
|
/*
|
|
* Internal helper function; C doesn't allow us to hide it :/
|
|
*
|
|
* DO NOT USE (outside of mutex & scheduler code).
|
|
*/
|
|
static inline struct task_struct *__mutex_owner(struct mutex *lock)
|
|
{
|
|
if (!lock)
|
|
return NULL;
|
|
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
|
|
}
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
extern void debug_mutex_lock_common(struct mutex *lock,
|
|
struct mutex_waiter *waiter);
|
|
extern void debug_mutex_wake_waiter(struct mutex *lock,
|
|
struct mutex_waiter *waiter);
|
|
extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
|
|
extern void debug_mutex_add_waiter(struct mutex *lock,
|
|
struct mutex_waiter *waiter,
|
|
struct task_struct *task);
|
|
extern void debug_mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
|
|
struct task_struct *task);
|
|
extern void debug_mutex_unlock(struct mutex *lock);
|
|
extern void debug_mutex_init(struct mutex *lock);
|
|
#else /* CONFIG_DEBUG_MUTEXES */
|
|
# define debug_mutex_lock_common(lock, waiter) do { } while (0)
|
|
# define debug_mutex_wake_waiter(lock, waiter) do { } while (0)
|
|
# define debug_mutex_free_waiter(waiter) do { } while (0)
|
|
# define debug_mutex_add_waiter(lock, waiter, ti) do { } while (0)
|
|
# define debug_mutex_remove_waiter(lock, waiter, ti) do { } while (0)
|
|
# define debug_mutex_unlock(lock) do { } while (0)
|
|
# define debug_mutex_init(lock) do { } while (0)
|
|
#endif /* !CONFIG_DEBUG_MUTEXES */
|
|
#endif /* CONFIG_PREEMPT_RT */
|