2017-01-05 15:30:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2016 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __I915_UTILS_H
|
|
|
|
#define __I915_UTILS_H
|
|
|
|
|
2017-03-28 08:45:12 +00:00
|
|
|
#undef WARN_ON
|
|
|
|
/* Many gcc seem to no see through this and fall over :( */
|
|
|
|
#if 0
|
|
|
|
#define WARN_ON(x) ({ \
|
|
|
|
bool __i915_warn_cond = (x); \
|
|
|
|
if (__builtin_constant_p(__i915_warn_cond)) \
|
|
|
|
BUILD_BUG_ON(__i915_warn_cond); \
|
|
|
|
WARN(__i915_warn_cond, "WARN_ON(" #x ")"); })
|
|
|
|
#else
|
|
|
|
#define WARN_ON(x) WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef WARN_ON_ONCE
|
|
|
|
#define WARN_ON_ONCE(x) WARN_ONCE((x), "%s", "WARN_ON_ONCE(" __stringify(x) ")")
|
|
|
|
|
|
|
|
#define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
|
|
|
|
(long)(x), __func__)
|
|
|
|
|
2017-01-30 13:47:21 +00:00
|
|
|
#if GCC_VERSION >= 70000
|
|
|
|
#define add_overflows(A, B) \
|
|
|
|
__builtin_add_overflow_p((A), (B), (typeof((A) + (B)))0)
|
|
|
|
#else
|
|
|
|
#define add_overflows(A, B) ({ \
|
|
|
|
typeof(A) a = (A); \
|
|
|
|
typeof(B) b = (B); \
|
|
|
|
a + b < a; \
|
|
|
|
})
|
|
|
|
#endif
|
|
|
|
|
2017-01-05 15:30:22 +00:00
|
|
|
#define range_overflows(start, size, max) ({ \
|
|
|
|
typeof(start) start__ = (start); \
|
|
|
|
typeof(size) size__ = (size); \
|
|
|
|
typeof(max) max__ = (max); \
|
|
|
|
(void)(&start__ == &size__); \
|
|
|
|
(void)(&start__ == &max__); \
|
|
|
|
start__ > max__ || size__ > max__ - start__; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define range_overflows_t(type, start, size, max) \
|
|
|
|
range_overflows((type)(start), (type)(size), (type)(max))
|
|
|
|
|
|
|
|
/* Note we don't consider signbits :| */
|
|
|
|
#define overflows_type(x, T) \
|
|
|
|
(sizeof(x) > sizeof(T) && (x) >> (sizeof(T) * BITS_PER_BYTE))
|
|
|
|
|
2017-05-17 12:09:59 +00:00
|
|
|
#define ptr_mask_bits(ptr, n) ({ \
|
2017-01-05 16:41:48 +00:00
|
|
|
unsigned long __v = (unsigned long)(ptr); \
|
2017-05-17 12:09:59 +00:00
|
|
|
(typeof(ptr))(__v & -BIT(n)); \
|
2017-01-05 16:41:48 +00:00
|
|
|
})
|
|
|
|
|
2017-05-17 12:09:59 +00:00
|
|
|
#define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
|
|
|
|
|
|
|
|
#define ptr_unpack_bits(ptr, bits, n) ({ \
|
2017-01-05 16:41:48 +00:00
|
|
|
unsigned long __v = (unsigned long)(ptr); \
|
2017-05-17 12:09:59 +00:00
|
|
|
*(bits) = __v & (BIT(n) - 1); \
|
|
|
|
(typeof(ptr))(__v & -BIT(n)); \
|
2017-01-05 16:41:48 +00:00
|
|
|
})
|
|
|
|
|
2017-05-17 12:09:59 +00:00
|
|
|
#define ptr_pack_bits(ptr, bits, n) \
|
2017-01-05 16:41:48 +00:00
|
|
|
((typeof(ptr))((unsigned long)(ptr) | (bits)))
|
|
|
|
|
2017-05-17 12:09:59 +00:00
|
|
|
#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
|
|
|
|
#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
|
|
|
|
#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
|
|
|
|
#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
|
|
|
|
|
2017-03-14 13:33:09 +00:00
|
|
|
#define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member)
|
|
|
|
|
2017-01-05 16:41:48 +00:00
|
|
|
#define fetch_and_zero(ptr) ({ \
|
|
|
|
typeof(*ptr) __T = *(ptr); \
|
|
|
|
*(ptr) = (typeof(*ptr))0; \
|
|
|
|
__T; \
|
|
|
|
})
|
|
|
|
|
2017-05-09 09:20:21 +00:00
|
|
|
#define __mask_next_bit(mask) ({ \
|
|
|
|
int __idx = ffs(mask) - 1; \
|
|
|
|
mask &= ~BIT(__idx); \
|
|
|
|
__idx; \
|
|
|
|
})
|
|
|
|
|
drm/i915: Split execlist priority queue into rbtree + linked list
All the requests at the same priority are executed in FIFO order. They
do not need to be stored in the rbtree themselves, as they are a simple
list within a level. If we move the requests at one priority into a list,
we can then reduce the rbtree to the set of priorities. This should keep
the height of the rbtree small, as the number of active priorities can not
exceed the number of active requests and should be typically only a few.
Currently, we have ~2k possible different priority levels, that may
increase to allow even more fine grained selection. Allocating those in
advance seems a waste (and may be impossible), so we opt for allocating
upon first use, and freeing after its requests are depleted. To avoid
the possibility of an allocation failure causing us to lose a request,
we preallocate the default priority (0) and bump any request to that
priority if we fail to allocate it the appropriate plist. Having a
request (that is ready to run, so not leading to corruption) execute
out-of-order is better than leaking the request (and its dependency
tree) entirely.
There should be a benefit to reducing execlists_dequeue() to principally
using a simple list (and reducing the frequency of both rbtree iteration
and balancing on erase) but for typical workloads, request coalescing
should be small enough that we don't notice any change. The main gain is
from improving PI calls to schedule, and the explicit list within a
level should make request unwinding simpler (we just need to insert at
the head of the list rather than the tail and not have to make the
rbtree search more complicated).
v2: Avoid use-after-free when deleting a depleted priolist
v3: Michał found the solution to handling the allocation failure
gracefully. If we disable all priority scheduling following the
allocation failure, those requests will be executed in fifo and we will
ensure that this request and its dependencies are in strict fifo (even
when it doesn't realise it is only a single list). Normal scheduling is
restored once we know the device is idle, until the next failure!
Suggested-by: Michał Wajdeczko <michal.wajdeczko@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170517121007.27224-8-chris@chris-wilson.co.uk
2017-05-17 12:10:03 +00:00
|
|
|
#include <linux/list.h>
|
|
|
|
|
|
|
|
static inline void __list_del_many(struct list_head *head,
|
|
|
|
struct list_head *first)
|
|
|
|
{
|
|
|
|
first->prev = head;
|
|
|
|
WRITE_ONCE(head->next, first);
|
|
|
|
}
|
|
|
|
|
2017-01-05 15:30:22 +00:00
|
|
|
#endif /* !__I915_UTILS_H */
|