From patchwork Mon Jun 24 16:22:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Tucker X-Patchwork-Id: 11013773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 995F414E5 for ; Mon, 24 Jun 2019 16:23:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AA9528B01 for ; Mon, 24 Jun 2019 16:23:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F0D228B38; Mon, 24 Jun 2019 16:23:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 23BD728B45 for ; Mon, 24 Jun 2019 16:23:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED9AF89CF6; Mon, 24 Jun 2019 16:23:24 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 40FA589CF1; Mon, 24 Jun 2019 16:23:23 +0000 (UTC) Received: from submarine.cbg.collabora.co.uk (unknown [IPv6:2a00:5f00:102:0:6dae:eb08:2e0f:5281]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: gtucker) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 1512B287D10; Mon, 24 Jun 2019 17:23:22 +0100 (BST) From: Guillaume Tucker To: Arkadiusz Hiler , Petri Latvala , "Ser, Simon" Date: Mon, 24 Jun 2019 17:22:35 +0100 Message-Id: <75b02ab7448852c56a86edbf03891af27abc62d4.1561393147.git.guillaume.tucker@collabora.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t v4 3/4] i915/gem_create: use atomic_* instead of __sync_* X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Simon Ser --- 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 #include #include +#include #include @@ -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 ],