Commit 44505168 authored by Matthew Brost's avatar Matthew Brost Committed by John Harrison

drm/i915: Drop stealing of bits from i915_sw_fence function pointer

Rather than stealing bits from i915_sw_fence function pointer use
separate fields for function pointer and flags. If using two different
fields, the 4 byte alignment for the i915_sw_fence function pointer can
also be dropped.

v2:
 (CI)
  - Set new function field rather than flags in __i915_sw_fence_init
v3:
 (Tvrtko)
  - Remove BUG_ON(!fence->flags) in reinit as that will now blow up
  - Only define fence->flags if CONFIG_DRM_I915_SW_FENCE_CHECK_DAG is
    defined
v4:
  - Rebase, resend for CI
Signed-off-by: default avatarMatthew Brost <matthew.brost@intel.com>
Acked-by: default avatarJani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarAlan Previn <alan.previn.teres.alexis@intel.com>
Signed-off-by: default avatarJohn Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211116194929.10211-1-matthew.brost@intel.com
parent 2a67b18e
...@@ -9967,7 +9967,7 @@ static void intel_atomic_commit_work(struct work_struct *work) ...@@ -9967,7 +9967,7 @@ static void intel_atomic_commit_work(struct work_struct *work)
intel_atomic_commit_tail(state); intel_atomic_commit_tail(state);
} }
static int __i915_sw_fence_call static int
intel_atomic_commit_ready(struct i915_sw_fence *fence, intel_atomic_commit_ready(struct i915_sw_fence *fence,
enum i915_sw_fence_notify notify) enum i915_sw_fence_notify notify)
{ {
......
...@@ -1001,7 +1001,7 @@ static void free_engines_rcu(struct rcu_head *rcu) ...@@ -1001,7 +1001,7 @@ static void free_engines_rcu(struct rcu_head *rcu)
free_engines(engines); free_engines(engines);
} }
static int __i915_sw_fence_call static int
engines_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) engines_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
struct i915_gem_engines *engines = struct i915_gem_engines *engines =
......
...@@ -364,7 +364,7 @@ static int __intel_context_active(struct i915_active *active) ...@@ -364,7 +364,7 @@ static int __intel_context_active(struct i915_active *active)
return 0; return 0;
} }
static int __i915_sw_fence_call static int
sw_fence_dummy_notify(struct i915_sw_fence *sf, sw_fence_dummy_notify(struct i915_sw_fence *sf,
enum i915_sw_fence_notify state) enum i915_sw_fence_notify state)
{ {
......
...@@ -719,7 +719,7 @@ void i915_request_cancel(struct i915_request *rq, int error) ...@@ -719,7 +719,7 @@ void i915_request_cancel(struct i915_request *rq, int error)
intel_context_cancel_request(rq->context, rq); intel_context_cancel_request(rq->context, rq);
} }
static int __i915_sw_fence_call static int
submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
struct i915_request *request = struct i915_request *request =
...@@ -755,7 +755,7 @@ submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) ...@@ -755,7 +755,7 @@ submit_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
return NOTIFY_DONE; return NOTIFY_DONE;
} }
static int __i915_sw_fence_call static int
semaphore_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) semaphore_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
struct i915_request *rq = container_of(fence, typeof(*rq), semaphore); struct i915_request *rq = container_of(fence, typeof(*rq), semaphore);
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#define I915_SW_FENCE_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr) #define I915_SW_FENCE_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
#endif #endif
#ifdef CONFIG_DRM_I915_SW_FENCE_CHECK_DAG
static DEFINE_SPINLOCK(i915_sw_fence_lock); static DEFINE_SPINLOCK(i915_sw_fence_lock);
#endif
#define WQ_FLAG_BITS \ #define WQ_FLAG_BITS \
BITS_PER_TYPE(typeof_member(struct wait_queue_entry, flags)) BITS_PER_TYPE(typeof_member(struct wait_queue_entry, flags))
...@@ -34,7 +36,7 @@ enum { ...@@ -34,7 +36,7 @@ enum {
static void *i915_sw_fence_debug_hint(void *addr) static void *i915_sw_fence_debug_hint(void *addr)
{ {
return (void *)(((struct i915_sw_fence *)addr)->flags & I915_SW_FENCE_MASK); return (void *)(((struct i915_sw_fence *)addr)->fn);
} }
#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS #ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
...@@ -126,10 +128,7 @@ static inline void debug_fence_assert(struct i915_sw_fence *fence) ...@@ -126,10 +128,7 @@ static inline void debug_fence_assert(struct i915_sw_fence *fence)
static int __i915_sw_fence_notify(struct i915_sw_fence *fence, static int __i915_sw_fence_notify(struct i915_sw_fence *fence,
enum i915_sw_fence_notify state) enum i915_sw_fence_notify state)
{ {
i915_sw_fence_notify_t fn; return fence->fn(fence, state);
fn = (i915_sw_fence_notify_t)(fence->flags & I915_SW_FENCE_MASK);
return fn(fence, state);
} }
#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS #ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
...@@ -242,10 +241,13 @@ void __i915_sw_fence_init(struct i915_sw_fence *fence, ...@@ -242,10 +241,13 @@ void __i915_sw_fence_init(struct i915_sw_fence *fence,
const char *name, const char *name,
struct lock_class_key *key) struct lock_class_key *key)
{ {
BUG_ON(!fn || (unsigned long)fn & ~I915_SW_FENCE_MASK); BUG_ON(!fn);
__init_waitqueue_head(&fence->wait, name, key); __init_waitqueue_head(&fence->wait, name, key);
fence->flags = (unsigned long)fn; fence->fn = fn;
#ifdef CONFIG_DRM_I915_SW_FENCE_CHECK_DAG
fence->flags = 0;
#endif
i915_sw_fence_reinit(fence); i915_sw_fence_reinit(fence);
} }
...@@ -257,7 +259,6 @@ void i915_sw_fence_reinit(struct i915_sw_fence *fence) ...@@ -257,7 +259,6 @@ void i915_sw_fence_reinit(struct i915_sw_fence *fence)
atomic_set(&fence->pending, 1); atomic_set(&fence->pending, 1);
fence->error = 0; fence->error = 0;
I915_SW_FENCE_BUG_ON(!fence->flags);
I915_SW_FENCE_BUG_ON(!list_empty(&fence->wait.head)); I915_SW_FENCE_BUG_ON(!list_empty(&fence->wait.head));
} }
...@@ -279,6 +280,7 @@ static int i915_sw_fence_wake(wait_queue_entry_t *wq, unsigned mode, int flags, ...@@ -279,6 +280,7 @@ static int i915_sw_fence_wake(wait_queue_entry_t *wq, unsigned mode, int flags,
return 0; return 0;
} }
#ifdef CONFIG_DRM_I915_SW_FENCE_CHECK_DAG
static bool __i915_sw_fence_check_if_after(struct i915_sw_fence *fence, static bool __i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
const struct i915_sw_fence * const signaler) const struct i915_sw_fence * const signaler)
{ {
...@@ -322,9 +324,6 @@ static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence, ...@@ -322,9 +324,6 @@ static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
unsigned long flags; unsigned long flags;
bool err; bool err;
if (!IS_ENABLED(CONFIG_DRM_I915_SW_FENCE_CHECK_DAG))
return false;
spin_lock_irqsave(&i915_sw_fence_lock, flags); spin_lock_irqsave(&i915_sw_fence_lock, flags);
err = __i915_sw_fence_check_if_after(fence, signaler); err = __i915_sw_fence_check_if_after(fence, signaler);
__i915_sw_fence_clear_checked_bit(fence); __i915_sw_fence_clear_checked_bit(fence);
...@@ -332,6 +331,13 @@ static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence, ...@@ -332,6 +331,13 @@ static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
return err; return err;
} }
#else
static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
const struct i915_sw_fence * const signaler)
{
return false;
}
#endif
static int __i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence, static int __i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
struct i915_sw_fence *signaler, struct i915_sw_fence *signaler,
......
...@@ -17,26 +17,27 @@ ...@@ -17,26 +17,27 @@
struct completion; struct completion;
struct dma_resv; struct dma_resv;
struct i915_sw_fence;
enum i915_sw_fence_notify {
FENCE_COMPLETE,
FENCE_FREE
};
typedef int (*i915_sw_fence_notify_t)(struct i915_sw_fence *,
enum i915_sw_fence_notify state);
struct i915_sw_fence { struct i915_sw_fence {
wait_queue_head_t wait; wait_queue_head_t wait;
i915_sw_fence_notify_t fn;
#ifdef CONFIG_DRM_I915_SW_FENCE_CHECK_DAG
unsigned long flags; unsigned long flags;
#endif
atomic_t pending; atomic_t pending;
int error; int error;
}; };
#define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */ #define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */
#define I915_SW_FENCE_PRIVATE_BIT 1 /* available for use by owner */
#define I915_SW_FENCE_MASK (~3)
enum i915_sw_fence_notify {
FENCE_COMPLETE,
FENCE_FREE
};
typedef int (*i915_sw_fence_notify_t)(struct i915_sw_fence *,
enum i915_sw_fence_notify state);
#define __i915_sw_fence_call __aligned(4)
void __i915_sw_fence_init(struct i915_sw_fence *fence, void __i915_sw_fence_init(struct i915_sw_fence *fence,
i915_sw_fence_notify_t fn, i915_sw_fence_notify_t fn,
......
...@@ -23,7 +23,7 @@ static void fence_work(struct work_struct *work) ...@@ -23,7 +23,7 @@ static void fence_work(struct work_struct *work)
dma_fence_put(&f->dma); dma_fence_put(&f->dma);
} }
static int __i915_sw_fence_call static int
fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
struct dma_fence_work *f = container_of(fence, typeof(*f), chain); struct dma_fence_work *f = container_of(fence, typeof(*f), chain);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "../i915_selftest.h" #include "../i915_selftest.h"
static int __i915_sw_fence_call static int
fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
switch (state) { switch (state) {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/* Small library of different fence types useful for writing tests */ /* Small library of different fence types useful for writing tests */
static int __i915_sw_fence_call static int
nop_fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) nop_fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
return NOTIFY_DONE; return NOTIFY_DONE;
...@@ -41,12 +41,12 @@ void __onstack_fence_init(struct i915_sw_fence *fence, ...@@ -41,12 +41,12 @@ void __onstack_fence_init(struct i915_sw_fence *fence,
__init_waitqueue_head(&fence->wait, name, key); __init_waitqueue_head(&fence->wait, name, key);
atomic_set(&fence->pending, 1); atomic_set(&fence->pending, 1);
fence->error = 0; fence->error = 0;
fence->flags = (unsigned long)nop_fence_notify; fence->fn = nop_fence_notify;
} }
void onstack_fence_fini(struct i915_sw_fence *fence) void onstack_fence_fini(struct i915_sw_fence *fence)
{ {
if (!fence->flags) if (!fence->fn)
return; return;
i915_sw_fence_commit(fence); i915_sw_fence_commit(fence);
...@@ -89,7 +89,7 @@ struct heap_fence { ...@@ -89,7 +89,7 @@ struct heap_fence {
}; };
}; };
static int __i915_sw_fence_call static int
heap_fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state) heap_fence_notify(struct i915_sw_fence *fence, enum i915_sw_fence_notify state)
{ {
struct heap_fence *h = container_of(fence, typeof(*h), fence); struct heap_fence *h = container_of(fence, typeof(*h), fence);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment