[Intel-gfx] [RFC] Cross-driver ww transaction lock lists
Thomas Hellström
thomas.hellstrom at linux.intel.com
Tue Apr 13 07:50:15 UTC 2021
Hi!
During the dma_resv conversion of the i915 driver, we've been using ww
transaction lock lists to keep track of ww_mutexes that are locked
during the transaction so that they can be batch unlocked at suitable
locations. Including also the LMEM/VRAM eviction we've ended up with
two static lists per transaction context; one typically unlocked at the
end of transaction and one initialized before and unlocked after each
buffer object validate. This enables us to do sleeping locking at
eviction and keep objects locked on the eviction list until we
eventually succeed allocating memory (modulo minor flaws of course).
It would be beneficial with the i915 TTM conversion to be able to
introduce a similar functionality that would work in ttm but also
cross-driver in, for example move_notify. It would also be beneficial
to be able to put any dma_resv ww mutex on the lists, and not require
it to be embedded in a particular object type.
I started scetching on some utilities for this. For TTM, for example,
the idea would be to pass a list head for the ww transaction lock list
in the ttm_operation_ctx. A function taking a ww_mutex could then
either attach a grabbed lock to the list for batch unlocking, or be
responsible for unlocking when the lock's scope is exited. It's also
possible to create sublists if so desired. I believe the below would be
sufficient to cover the i915 functionality.
Any comments and suggestions appreciated!
8<------------------------------------------------------
#ifndef _TRANSACTION_LOCKLIST_H_
#define _TRANSACTION_LOCKLIST_H_
struct trans_lockitem;
/**
* struct trans_locklist_ops - Ops structure for the ww locklist
functionality.
*
* Typically a const struct trans_locklist_ops is defined for each type
that
* embeds a struct trans_lockitem, or hav a struct trans_lockitem
pointing
* at it using the private pointer. It can be a buffer object,
reservation
* object, a single ww_mutex or even a sublist of trans_lockitems.
*/
struct trans_locklist_ops {
/**
* slow_lock: Slow lock to relax the transaction. Only used by
* a contending lock item.
* @item: The struct trans_lockitem to lock
* @intr: Whether to lock interruptible
*
* Return: -ERESTARTSYS: Hit a signal when relaxing,
* -EAGAIN, relaxing succesful, but the contending lock
* remains unlocked.
*/
int (*slow_lock) (struct trans_lockitem *item, bool intr);
/**
* unlock: Unlock.
* @item: The struct trans_lockitem to unlock.
*/
void (*unlock) (struct trans_lockitem *item);
/**
* unlock: Unlock.
* @item: The struct trans_lockitem to put. This function may
be NULL.
*/
void (*put) (struct trans_lockitem *item);
};
/**
* struct trans_lockitem
* @ops: Pointer to an Ops structure for this lockitem.
* @link: List link for the transaction locklist.
* @private: Private info.
* @relax_unlock: Unlock contending lock after relaxation since it is
* likely not needed after a transaction restart.
*
* A struct trans_lockitem typically represents a single lock, but is
* generic enough to represent a sublist of locks. It can either be
* embedded, or allocated on demand. A kmem_cache might be beneficial.
*/
struct trans_lockitem {
const struct trans_locklist_ops *ops;
struct list_head link;
u32 relax_unlock:1;
void *private;
};
/* unlock example */
static inline void trans_unlock_put_all(struct list_head *list)
{
struct trans_lockitem *lock, *next;
list_for_each_entry_safe(lock, next, typeof(*lock), link) {
lock->ops->unlock(lock);
list_del_init(&lock->link);
if (lock->ops_put)
lock->ops->put(lock);
}
}
/* Backoff example */
static inline int __must_check trans_backoff(struct list_head *list,
bool intr,
struct trans_lockitem
*contending)
{
int ret = 0;
trans_unlock_put_all(list);
if (contending) {
ret = contending->ops->slow_lock(contending, intr);
if (!ret && contending->relax_unlock)
contending->unlock(contending);
if (ret == -EAGAIN)
ret = 0;
contending->ops->put(contending);
}
return ret;
}
#endif _TRANSACTION_LOCKLIST_
More information about the Intel-gfx
mailing list