From 140a67c13aad2595ee6c72e41d14d35a793158b5 Mon Sep 17 00:00:00 2001 From: Antonio Argenziano Date: Tue, 10 Jul 2018 16:45:26 -0700 Subject: lib/gt: Make use of dummyload library to create recursive batch An hanging batch is nothing more than a spinning batch that never gets stopped, so re-use the routines implemented in dummyload.c. v2: Let caller decide spin loop size v3: Only use loose loops for hangs (Chris) v4: No requires v5: Free the spinner v6: Chamelium exists. Signed-off-by: Antonio Argenziano #v3 Signed-off-by: Chris Wilson Reviewed-by: Antonio Argenziano --- lib/i915/gem_ring.c | 1 + lib/igt_aux.h | 105 ------------------------------------------ lib/igt_chamelium.c | 3 +- lib/igt_core.h | 4 ++ lib/igt_dummyload.h | 3 +- lib/igt_gt.c | 72 +++++------------------------ lib/igt_gt.h | 9 ++-- lib/igt_kmod.c | 3 +- lib/igt_kmod.h | 2 +- lib/igt_list.h | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 156 insertions(+), 175 deletions(-) create mode 100644 lib/igt_list.h (limited to 'lib') diff --git a/lib/i915/gem_ring.c b/lib/i915/gem_ring.c index 0708c8a2..fdb9fc1b 100644 --- a/lib/i915/gem_ring.c +++ b/lib/i915/gem_ring.c @@ -25,6 +25,7 @@ #include #include +#include #include "intel_reg.h" #include "drmtest.h" diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 9a962881..639a9077 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -39,12 +38,6 @@ extern drm_intel_bo **trash_bos; extern int num_trash_bos; -/* signal interrupt helpers */ - -#define MSEC_PER_SEC (1000) -#define USEC_PER_SEC (1000*MSEC_PER_SEC) -#define NSEC_PER_SEC (1000*USEC_PER_SEC) - /* signal interrupt helpers */ #define gettid() syscall(__NR_gettid) #define sigev_notify_thread_id _sigev_un._tid @@ -295,104 +288,6 @@ void igt_set_module_param_int(const char *name, int val); int igt_terminate_process(int sig, const char *comm); void igt_lsof(const char *dpath); -/* - * This list data structure is a verbatim copy from wayland-util.h from the - * Wayland project; except that wl_ prefix has been removed. - */ - -struct igt_list { - struct igt_list *prev; - struct igt_list *next; -}; - -#define __IGT_INIT_LIST(name) { &(name), &(name) } -#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name) - -static inline void igt_list_init(struct igt_list *list) -{ - list->prev = list; - list->next = list; -} - -static inline void __igt_list_add(struct igt_list *list, - struct igt_list *prev, - struct igt_list *next) -{ - next->prev = list; - list->next = next; - list->prev = prev; - prev->next = list; -} - -static inline void igt_list_add(struct igt_list *elm, struct igt_list *list) -{ - __igt_list_add(elm, list, list->next); -} - -static inline void igt_list_add_tail(struct igt_list *elm, - struct igt_list *list) -{ - __igt_list_add(elm, list->prev, list); -} - -static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next) -{ - next->prev = prev; - prev->next = next; -} - -static inline void igt_list_del(struct igt_list *elm) -{ - __igt_list_del(elm->prev, elm->next); -} - -static inline void igt_list_move(struct igt_list *elm, struct igt_list *list) -{ - igt_list_del(elm); - igt_list_add(elm, list); -} - -static inline void igt_list_move_tail(struct igt_list *elm, - struct igt_list *list) -{ - igt_list_del(elm); - igt_list_add_tail(elm, list); -} - -static inline bool igt_list_empty(const struct igt_list *list) -{ - return list->next == list; -} - -#define container_of(ptr, sample, member) \ - (typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member)) - -#define igt_list_first_entry(head, pos, member) \ - container_of((head)->next, (pos), member) -#define igt_list_last_entry(head, pos, member) \ - container_of((head)->prev, (pos), member) - -#define igt_list_next_entry(pos, member) \ - container_of((pos)->member.next, (pos), member) -#define igt_list_prev_entry(pos, member) \ - container_of((pos)->member.prev, (pos), member) - -#define igt_list_for_each(pos, head, member) \ - for (pos = igt_list_first_entry(head, pos, member); \ - &pos->member != (head); \ - pos = igt_list_next_entry(pos, member)) - -#define igt_list_for_each_reverse(pos, head, member) \ - for (pos = igt_list_last_entry(head, pos, member); \ - &pos->member != (head); \ - pos = igt_list_prev_entry(pos, member)) - -#define igt_list_for_each_safe(pos, tmp, head, member) \ - for (pos = igt_list_first_entry(head, pos, member), \ - tmp = igt_list_next_entry(pos, member); \ - &pos->member != (head); \ - pos = tmp, tmp = igt_list_next_entry(pos, member)) - #define igt_hweight(x) \ __builtin_choose_expr(sizeof(x) == 8, \ __builtin_popcountll(x), \ diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c index b25855a4..b8418e13 100644 --- a/lib/igt_chamelium.c +++ b/lib/igt_chamelium.c @@ -38,8 +38,9 @@ #include "igt_chamelium.h" #include "igt_core.h" #include "igt_aux.h" -#include "igt_kms.h" #include "igt_frame.h" +#include "igt_list.h" +#include "igt_kms.h" #include "igt_rc.h" /** diff --git a/lib/igt_core.h b/lib/igt_core.h index a73b0649..aaf1b626 100644 --- a/lib/igt_core.h +++ b/lib/igt_core.h @@ -1005,4 +1005,8 @@ void igt_kmsg(const char *format, ...); #define READ_ONCE(x) (*(volatile typeof(x) *)(&(x))) +#define MSEC_PER_SEC (1000) +#define USEC_PER_SEC (1000*MSEC_PER_SEC) +#define NSEC_PER_SEC (1000*USEC_PER_SEC) + #endif /* IGT_CORE_H */ diff --git a/lib/igt_dummyload.h b/lib/igt_dummyload.h index 38bc7682..73bd035b 100644 --- a/lib/igt_dummyload.h +++ b/lib/igt_dummyload.h @@ -28,7 +28,8 @@ #include #include -#include "igt_aux.h" +#include "igt_core.h" +#include "igt_list.h" #include "i915_drm.h" typedef struct igt_spin { diff --git a/lib/igt_gt.c b/lib/igt_gt.c index 89b318ae..a2061924 100644 --- a/lib/igt_gt.c +++ b/lib/igt_gt.c @@ -40,6 +40,7 @@ #include "ioctl_wrappers.h" #include "intel_reg.h" #include "intel_chipset.h" +#include "igt_dummyload.h" /** * SECTION:igt_gt @@ -265,20 +266,11 @@ static bool has_ctx_exec(int fd, unsigned ring, uint32_t ctx) * Returns: * Structure with helper internal state for igt_post_hang_ring(). */ -igt_hang_t igt_hang_ctx(int fd, - uint32_t ctx, - int ring, - unsigned flags, - uint64_t *offset) +igt_hang_t igt_hang_ctx(int fd, uint32_t ctx, int ring, unsigned flags) { - struct drm_i915_gem_relocation_entry reloc; - struct drm_i915_gem_execbuffer2 execbuf; - struct drm_i915_gem_exec_object2 exec; struct drm_i915_gem_context_param param; - uint32_t b[16]; + igt_spin_t *spin; unsigned ban; - unsigned len; - int gen; igt_require_hang_ring(fd, ring); @@ -302,52 +294,12 @@ igt_hang_t igt_hang_ctx(int fd, if ((flags & HANG_ALLOW_BAN) == 0) context_set_ban(fd, ctx, 0); - memset(&reloc, 0, sizeof(reloc)); - memset(&exec, 0, sizeof(exec)); - memset(&execbuf, 0, sizeof(execbuf)); - - exec.handle = gem_create(fd, 4096); - exec.relocation_count = 1; - exec.relocs_ptr = to_user_pointer(&reloc); - - memset(b, 0xc5, sizeof(b)); - - len = 0; - gen = intel_gen(intel_get_drm_devid(fd)); - if (gen >= 8) { - b[len++] = MI_BATCH_BUFFER_START | 1 << 8 | 1; - b[len++] = 0; - b[len++] = 0; - } else if (gen >= 6) { - b[len++] = MI_BATCH_BUFFER_START | 1 << 8; - b[len++] = 0; - } else { - b[len++] = MI_BATCH_BUFFER_START | 2 << 6; - b[len] = 0; - if (gen < 4) { - b[len] |= 1; - reloc.delta = 1; - } - len++; - } - b[len++] = MI_BATCH_BUFFER_END; - b[len] = MI_NOOP; - gem_write(fd, exec.handle, 0, b, sizeof(b)); - - reloc.offset = sizeof(uint32_t); - reloc.target_handle = exec.handle; - reloc.read_domains = I915_GEM_DOMAIN_COMMAND; - - execbuf.buffers_ptr = to_user_pointer(&exec); - execbuf.buffer_count = 1; - execbuf.flags = ring; - i915_execbuffer2_set_context_id(execbuf, ctx); - gem_execbuf(fd, &execbuf); - - if (offset) - *offset = exec.offset; + spin = __igt_spin_batch_new(fd, + .ctx = ctx, + .engine = ring, + .flags = IGT_SPIN_NO_PREEMPTION); - return (igt_hang_t){ exec.handle, ctx, ban, flags }; + return (igt_hang_t){ spin, ctx, ban, flags }; } /** @@ -364,7 +316,7 @@ igt_hang_t igt_hang_ctx(int fd, */ igt_hang_t igt_hang_ring(int fd, int ring) { - return igt_hang_ctx(fd, 0, ring, 0, NULL); + return igt_hang_ctx(fd, 0, ring, 0); } /** @@ -377,11 +329,11 @@ igt_hang_t igt_hang_ring(int fd, int ring) */ void igt_post_hang_ring(int fd, igt_hang_t arg) { - if (arg.handle == 0) + if (!arg.spin) return; - gem_sync(fd, arg.handle); - gem_close(fd, arg.handle); + gem_sync(fd, arg.spin->handle); /* Wait until it hangs */ + igt_spin_batch_free(fd, arg.spin); context_set_ban(fd, arg.ctx, arg.ban); diff --git a/lib/igt_gt.h b/lib/igt_gt.h index d44b7552..54e95da9 100644 --- a/lib/igt_gt.h +++ b/lib/igt_gt.h @@ -25,6 +25,7 @@ #define IGT_GT_H #include "igt_debugfs.h" +#include "igt_dummyload.h" #include "igt_core.h" #include "i915_drm.h" @@ -32,7 +33,7 @@ void igt_require_hang_ring(int fd, int ring); typedef struct igt_hang { - unsigned handle; + igt_spin_t *spin; unsigned ctx; unsigned ban; unsigned flags; @@ -43,11 +44,7 @@ void igt_disallow_hang(int fd, igt_hang_t arg); #define HANG_POISON 0xc5c5c5c5 -igt_hang_t igt_hang_ctx(int fd, - uint32_t ctx, - int ring, - unsigned flags, - uint64_t *offset); +igt_hang_t igt_hang_ctx(int fd, uint32_t ctx, int ring, unsigned flags); #define HANG_ALLOW_BAN 1 #define HANG_ALLOW_CAPTURE 2 diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index f3f34a62..b2f4f884 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -24,9 +24,10 @@ #include #include +#include "igt_aux.h" #include "igt_core.h" -#include "igt_sysfs.h" #include "igt_kmod.h" +#include "igt_sysfs.h" /** * SECTION:igt_kmod diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h index fd307a45..87d36d40 100644 --- a/lib/igt_kmod.h +++ b/lib/igt_kmod.h @@ -26,7 +26,7 @@ #include -#include "igt_aux.h" +#include "igt_list.h" bool igt_kmod_is_loaded(const char *mod_name); void igt_kmod_list_loaded(void); diff --git a/lib/igt_list.h b/lib/igt_list.h new file mode 100644 index 00000000..cadf9dd3 --- /dev/null +++ b/lib/igt_list.h @@ -0,0 +1,129 @@ +/* + * Copyright © 2015 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 IGT_LIST_H +#define IGT_LIST_H + +#include +#include + +/* + * This list data structure is a verbatim copy from wayland-util.h from the + * Wayland project; except that wl_ prefix has been removed. + */ + +struct igt_list { + struct igt_list *prev; + struct igt_list *next; +}; + +#define __IGT_INIT_LIST(name) { &(name), &(name) } +#define IGT_LIST(name) struct igt_list name = __IGT_INIT_LIST(name) + +static inline void igt_list_init(struct igt_list *list) +{ + list->prev = list; + list->next = list; +} + +static inline void __igt_list_add(struct igt_list *list, + struct igt_list *prev, + struct igt_list *next) +{ + next->prev = list; + list->next = next; + list->prev = prev; + prev->next = list; +} + +static inline void igt_list_add(struct igt_list *elm, struct igt_list *list) +{ + __igt_list_add(elm, list, list->next); +} + +static inline void igt_list_add_tail(struct igt_list *elm, + struct igt_list *list) +{ + __igt_list_add(elm, list->prev, list); +} + +static inline void __igt_list_del(struct igt_list *prev, struct igt_list *next) +{ + next->prev = prev; + prev->next = next; +} + +static inline void igt_list_del(struct igt_list *elm) +{ + __igt_list_del(elm->prev, elm->next); +} + +static inline void igt_list_move(struct igt_list *elm, struct igt_list *list) +{ + igt_list_del(elm); + igt_list_add(elm, list); +} + +static inline void igt_list_move_tail(struct igt_list *elm, + struct igt_list *list) +{ + igt_list_del(elm); + igt_list_add_tail(elm, list); +} + +static inline bool igt_list_empty(const struct igt_list *list) +{ + return list->next == list; +} + +#define container_of(ptr, sample, member) \ + (typeof(sample))((char *)(ptr) - offsetof(typeof(*sample), member)) + +#define igt_list_first_entry(head, pos, member) \ + container_of((head)->next, (pos), member) +#define igt_list_last_entry(head, pos, member) \ + container_of((head)->prev, (pos), member) + +#define igt_list_next_entry(pos, member) \ + container_of((pos)->member.next, (pos), member) +#define igt_list_prev_entry(pos, member) \ + container_of((pos)->member.prev, (pos), member) + +#define igt_list_for_each(pos, head, member) \ + for (pos = igt_list_first_entry(head, pos, member); \ + &pos->member != (head); \ + pos = igt_list_next_entry(pos, member)) + +#define igt_list_for_each_reverse(pos, head, member) \ + for (pos = igt_list_last_entry(head, pos, member); \ + &pos->member != (head); \ + pos = igt_list_prev_entry(pos, member)) + +#define igt_list_for_each_safe(pos, tmp, head, member) \ + for (pos = igt_list_first_entry(head, pos, member), \ + tmp = igt_list_next_entry(pos, member); \ + &pos->member != (head); \ + pos = tmp, tmp = igt_list_next_entry(pos, member)) + +#endif /* IGT_LIST_H */ -- cgit v1.2.3