--- zzzz-none-000/linux-4.9.276/kernel/locking/semaphore.c 2021-07-20 14:21:16.000000000 +0000 +++ falcon-5530-750/linux-4.9.276/kernel/locking/semaphore.c 2023-04-05 08:19:02.000000000 +0000 @@ -32,6 +32,9 @@ #include #include #include +#if defined(CONFIG_AVM_IPI_YIELD) +#include +#endif /*--- #if defined(CONFIG_AVM_IPI_YIELD) ---*/ static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); @@ -142,6 +145,26 @@ } EXPORT_SYMBOL(down_trylock); +#if defined(CONFIG_AVM_IPI_YIELD) +/*--------------------------------------------------------------------------------*\ + auch aus YIELD-Kontext verwendbar +\*--------------------------------------------------------------------------------*/ +int yield_down_trylock(struct semaphore *sem) +{ + unsigned long flags; + int count; + + yield_raw_spin_lock_irqsave(&sem->lock, flags); + count = sem->count - 1; + if (likely(count >= 0)) + sem->count = count; + yield_raw_spin_unlock_irqrestore(&sem->lock, flags); + + return (count < 0); +} +EXPORT_SYMBOL(yield_down_trylock); +#endif /*--- #if defined(CONFIG_AVM_IPI_YIELD) ---*/ + /** * down_timeout - acquire the semaphore within a specified time * @sem: the semaphore to be acquired @@ -195,6 +218,31 @@ struct task_struct *task; bool up; }; +#if defined(CONFIG_AVM_IPI_YIELD) +/*--------------------------------------------------------------------------------*\ + auch aus YIELD-Kontext verwendbar +\*--------------------------------------------------------------------------------*/ +void yield_up(struct semaphore *sem) +{ + unsigned long flags; + + if (yield_is_linux_context()) { + up(sem); + return; + } + yield_raw_spin_lock_irqsave(&sem->lock, flags); + if (likely(list_empty(&sem->wait_list))) { + sem->count++; + } else { + struct semaphore_waiter *waiter = list_first_entry( + &sem->wait_list, struct semaphore_waiter, list); + list_del(&waiter->list); + waiter->up = true; + yield_wake_up_process(waiter->task); + } + yield_raw_spin_unlock_irqrestore(&sem->lock, flags); +} +#endif /*--- #if defined(CONFIG_AVM_IPI_YIELD) ---*/ /* * Because this function is inlined, the 'state' parameter will be