From: Guillaume Tucker <guillaume.tucker@collabora.com>
To: Arkadiusz Hiler <arkadiusz.hiler@intel.com>,
Petri Latvala <petri.latvala@intel.com>,
"Ser, Simon" <simon.ser@intel.com>
Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v3 3/4] i915/gem_create: use atomic_* instead of __sync_*
Date: Tue, 18 Jun 2019 13:27:45 +0100 [thread overview]
Message-ID: <20190618122746.61310-4-guillaume.tucker@collabora.com> (raw)
In-Reply-To: <20190618122746.61310-1-guillaume.tucker@collabora.com>
This fixes builds on some architectures, in particular MIPS which
doesn't have __sync_add_and_fetch_8 and __sync_val_compare_and_swap_8
for 64-bit variable handling.
* replace calls to the older __sync_* functions with the new atomic_*
standard ones
* use the _Atomic type modifier as required with stdatomic.h functions
* add dependency for gem_create on libatomic
Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Reviewed-by: Simon Ser <simon.ser@intel.com>
---
Notes:
v2: use atomic_* and only link libatomic with gem_create
tests/Makefile.am | 2 +-
tests/i915/gem_create.c | 16 ++++++++++++----
tests/meson.build | 9 ++++++++-
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5a428b8ac213..bbd386c9c2db 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -90,7 +90,7 @@ AM_LDFLAGS = -Wl,--as-needed
drm_import_export_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
drm_import_export_LDADD = $(LDADD) -lpthread
gem_create_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
-gem_create_LDADD = $(LDADD) -lpthread
+gem_create_LDADD = $(LDADD) -lpthread -latomic
gem_close_race_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
gem_close_race_LDADD = $(LDADD) -lpthread
gem_ctx_thrash_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
index 43cbf45f289b..9008cd8a21e3 100644
--- a/tests/i915/gem_create.c
+++ b/tests/i915/gem_create.c
@@ -45,6 +45,7 @@
#include <sys/time.h>
#include <getopt.h>
#include <pthread.h>
+#include <stdatomic.h>
#include <drm.h>
@@ -156,7 +157,14 @@ static void invalid_nonaligned_size(int fd)
gem_close(fd, create.handle);
}
-static uint64_t get_npages(uint64_t *global, uint64_t npages)
+static uint64_t atomic_compare_swap_u64(_Atomic(uint64_t) *ptr,
+ uint64_t oldval, uint64_t newval)
+{
+ atomic_compare_exchange_strong(ptr, &oldval, newval);
+ return oldval;
+}
+
+static uint64_t get_npages(_Atomic(uint64_t) *global, uint64_t npages)
{
uint64_t try, old, max;
@@ -165,13 +173,13 @@ static uint64_t get_npages(uint64_t *global, uint64_t npages)
old = max;
try = 1 + npages % (max / 2);
max -= try;
- } while ((max = __sync_val_compare_and_swap(global, old, max)) != old);
+ } while ((max = atomic_compare_swap_u64(global, old, max)) != old);
return try;
}
struct thread_clear {
- uint64_t max;
+ _Atomic(uint64_t) max;
int timeout;
int i915;
};
@@ -202,7 +210,7 @@ static void *thread_clear(void *data)
}
gem_close(i915, create.handle);
- __sync_add_and_fetch(&arg->max, npages);
+ atomic_fetch_add(&arg->max, npages);
}
return NULL;
diff --git a/tests/meson.build b/tests/meson.build
index f168fbbae2a8..ffd432d38193 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -110,7 +110,6 @@ i915_progs = [
'gem_close_race',
'gem_concurrent_blit',
'gem_cpu_reloc',
- 'gem_create',
'gem_cs_prefetch',
'gem_cs_tlb',
'gem_ctx_bad_destroy',
@@ -277,6 +276,14 @@ foreach prog : i915_progs
test_list += prog
endforeach
+test_executables += executable('gem_create',
+ join_paths('i915', 'gem_create.c'),
+ dependencies : test_deps + [ libatomic ],
+ install_dir : libexecdir,
+ install_rpath : libexecdir_rpathdir,
+ install : true)
+test_list += 'gem_create'
+
test_executables += executable('gem_ctx_sseu',
join_paths('i915', 'gem_ctx_sseu.c'),
dependencies : test_deps + [ lib_igt_perf ],
--
2.20.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-06-18 12:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-18 12:27 [igt-dev] [PATCH i-g-t v3 0/4] Use C11 atomics Guillaume Tucker
2019-06-18 12:27 ` [Intel-gfx] [PATCH i-g-t v3 1/4] meson: add libatomic dependency Guillaume Tucker
2019-06-18 13:20 ` [igt-dev] " Ser, Simon
2019-06-18 13:59 ` Guillaume Tucker
2019-06-18 14:37 ` Ser, Simon
2019-06-18 16:03 ` Guillaume Tucker
2019-06-19 6:42 ` Ser, Simon
2019-06-19 7:24 ` Guillaume Tucker
2019-06-18 12:27 ` [igt-dev] [PATCH i-g-t v3 2/4] gitlab-ci: add libatomic to docker images Guillaume Tucker
2019-06-19 6:50 ` Ser, Simon
2019-06-19 8:09 ` Guillaume Tucker
2019-06-18 12:27 ` Guillaume Tucker [this message]
2019-06-18 12:27 ` [Intel-gfx] [PATCH i-g-t v3 4/4] tests/sw_sync: use atomic_* instead of __sync_* Guillaume Tucker
2019-06-18 13:31 ` [igt-dev] ✗ Fi.CI.BAT: failure for Use C11 atomics (rev2) Patchwork
2019-06-19 6:52 ` Ser, Simon
2019-06-19 7:02 ` Saarinen, Jani
2019-06-19 7:32 ` Peres, Martin
2019-06-19 7:46 ` Guillaume Tucker
2019-06-19 8:05 ` [igt-dev] ✓ Fi.CI.BAT: success for Use C11 atomics (rev3) Patchwork
2019-06-19 21:21 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190618122746.61310-4-guillaume.tucker@collabora.com \
--to=guillaume.tucker@collabora.com \
--cc=arkadiusz.hiler@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=petri.latvala@intel.com \
--cc=simon.ser@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox