[Intel-gfx] [PATCH i-g-t] gitlab-ci: add tests for MIPS

2019-06-27 Thread Guillaume Tucker
Use the libatomic1:mips package only in the Debian Stretch Docker
image for MIPS and add Gitlab CI step to run tests on MIPS.

Signed-off-by: Guillaume Tucker 
---
 .gitlab-ci.yml | 14 ++
 Dockerfile.debian-mips |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 37184b98f5da..665fbb79c523 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -173,6 +173,20 @@ test:ninja-test-armhf:
   - build
 when: on_failure
 
+test:ninja-test-mips:
+  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
+  dependencies:
+- build:tests-debian-meson-mips
+  stage: test
+  script:
+- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
+- env > build/envdump.txt
+- ninja -C build test
+  artifacts:
+paths:
+  - build
+when: on_failure
+
 test:test-list-diff:
   dependencies:
 - build:tests-debian-autotools
diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
index ebe08db644ea..ee29f5f4ccda 100644
--- a/Dockerfile.debian-mips
+++ b/Dockerfile.debian-mips
@@ -5,7 +5,6 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
-   libatomic1 \
x11proto-dri2-dev \
python-docutils \
valgrind \
@@ -15,6 +14,7 @@ RUN dpkg --add-architecture mips
 RUN apt-get update
 RUN apt-get install -y \
gcc-mips-linux-gnu \
+   libatomic1:mips \
libpciaccess-dev:mips \
libkmod-dev:mips \
libprocps-dev:mips \
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH i-g-t v3 1/1] gitlab-ci: add build and tests for MIPS

2019-06-27 Thread Guillaume Tucker
On 27/06/2019 08:02, Ser, Simon wrote:
> On Tue, 2019-06-25 at 14:08 +0100, Guillaume Tucker wrote:
>> On 18/06/2019 13:42, Guillaume Tucker wrote:
>>> Add Docker image and Gitlab CI steps to run builds and tests for
>>> the
>>> MIPS architecture using Debian Stretch with backports.
>>>
>>> Signed-off-by: Guillaume Tucker 
>>> ---
>>>
>>> Notes:
>>> v2: use stretch-backports and require libatomic1
>>> v3: add mips ci tests and require Debian libatomic1 for mips
>>
>> The series to use portable atomics functions was merged today, so
>> I think this one should now be good to go as well.  It applies
>> cleanly on top of the current master branch and the Gitlab CI
>> pipeline passed:
>>
>>   
>> https://gitlab.freedesktop.org/gtucker/igt-gpu-tools/pipelines/44704
>>
>> Please let me know if you want me to resubmit it to get another
>> Patchwork CI run or if anything else needs to be done.
> 
> LGTM!
> 
> Reviewed-by: Simon Ser 
> 
> And pushed:
> 
> To gitlab.freedesktop.org:drm/igt-gpu-tools.git
>15ad66453441..439a9f5d615f  master -> master

Thanks!

Err, however it looks like you pushed the v2 which had only
builds rather than this v3 which does builds and tests:

  439a9f5d615f gitlab-ci: add build for MIPS

I've made another patch with the difference between v2 and v3 and
pushed it to my branch:

  
https://gitlab.freedesktop.org/gtucker/igt-gpu-tools/commit/9693e28871f27efb7340ad29d54de4be7b5461a9

I'll wait for the Gitlab CI pipeline to complete and then I guess
I should send that to the mailing list.

Guillaume

>>>  .gitlab-ci.yml | 42
>>> ++
>>>  Dockerfile.debian-mips | 39
>>> +++
>>>  meson-cross-mips.txt   | 12 
>>>  3 files changed, 93 insertions(+)
>>>  create mode 100644 Dockerfile.debian-mips
>>>  create mode 100644 meson-cross-mips.txt
>>>
>>> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
>>> index 771143a9ea95..bd9619e7e28b 100644
>>> --- a/.gitlab-ci.yml
>>> +++ b/.gitlab-ci.yml
>>> @@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
>>>  paths:
>>>- build
>>>  
>>> +build:tests-debian-meson-mips:
>>> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
>>> +  stage: build
>>> +  script:
>>> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
>>> +- meson --cross-file meson-cross-mips.txt build
>>> +- ninja -C build
>>> +  artifacts:
>>> +paths:
>>> +  - build
>>> +
>>>  build:tests-debian-autotools:
>>>image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
>>>stage: build
>>> @@ -145,6 +156,20 @@ test:ninja-test-armhf:
>>>- build
>>>  when: on_failure
>>>  
>>> +test:ninja-test-mips:
>>> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
>>> +  dependencies:
>>> +- build:tests-debian-meson-mips
>>> +  stage: test
>>> +  script:
>>> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
>>> +- env > build/envdump.txt
>>> +- ninja -C build test
>>> +  artifacts:
>>> +paths:
>>> +  - build
>>> +when: on_failure
>>> +
>>>  test:test-list-diff:
>>>dependencies:
>>>  - build:tests-debian-autotools
>>> @@ -221,6 +246,23 @@ containers:igt-debian-arm64:
>>>  - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-
>>> arm64 -f Dockerfile.debian-arm64 .
>>>  - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
>>>  
>>> +containers:igt-debian-mips:
>>> +  stage: containers
>>> +  image: docker:stable
>>> +  only:
>>> +changes:
>>> +  - Dockerfile.debian-mips
>>> +  - .gitlab-ci.yml
>>> +  services:
>>> +- docker:dind
>>> +  variables:
>>> +DOCKER_HOST: tcp://docker:2375
>>> +DOCKER_DRIVER: overlay2
>>> +  script:
>>> +- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN
>>> $CI_REGISTRY
>>> +- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-
>>> mips -f Dockerfile.debian-mips .
>>> +- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
>>> +
>>>  containers:igt-fedora:
>>>stage: containers
>>>image: do

Re: [Intel-gfx] [PATCH i-g-t v3 1/1] gitlab-ci: add build and tests for MIPS

2019-06-25 Thread Guillaume Tucker
On 18/06/2019 13:42, Guillaume Tucker wrote:
> Add Docker image and Gitlab CI steps to run builds and tests for the
> MIPS architecture using Debian Stretch with backports.
> 
> Signed-off-by: Guillaume Tucker 
> ---
> 
> Notes:
> v2: use stretch-backports and require libatomic1
> v3: add mips ci tests and require Debian libatomic1 for mips

The series to use portable atomics functions was merged today, so
I think this one should now be good to go as well.  It applies
cleanly on top of the current master branch and the Gitlab CI
pipeline passed:

  https://gitlab.freedesktop.org/gtucker/igt-gpu-tools/pipelines/44704

Please let me know if you want me to resubmit it to get another
Patchwork CI run or if anything else needs to be done.

Guillaume

>  .gitlab-ci.yml | 42 ++
>  Dockerfile.debian-mips | 39 +++
>  meson-cross-mips.txt   | 12 
>  3 files changed, 93 insertions(+)
>  create mode 100644 Dockerfile.debian-mips
>  create mode 100644 meson-cross-mips.txt
> 
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index 771143a9ea95..bd9619e7e28b 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
>  paths:
>- build
>  
> +build:tests-debian-meson-mips:
> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
> +  stage: build
> +  script:
> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
> +- meson --cross-file meson-cross-mips.txt build
> +- ninja -C build
> +  artifacts:
> +paths:
> +  - build
> +
>  build:tests-debian-autotools:
>image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
>stage: build
> @@ -145,6 +156,20 @@ test:ninja-test-armhf:
>- build
>  when: on_failure
>  
> +test:ninja-test-mips:
> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
> +  dependencies:
> +- build:tests-debian-meson-mips
> +  stage: test
> +  script:
> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
> +- env > build/envdump.txt
> +- ninja -C build test
> +  artifacts:
> +paths:
> +  - build
> +when: on_failure
> +
>  test:test-list-diff:
>dependencies:
>  - build:tests-debian-autotools
> @@ -221,6 +246,23 @@ containers:igt-debian-arm64:
>  - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
> Dockerfile.debian-arm64 .
>  - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
>  
> +containers:igt-debian-mips:
> +  stage: containers
> +  image: docker:stable
> +  only:
> +changes:
> +  - Dockerfile.debian-mips
> +  - .gitlab-ci.yml
> +  services:
> +- docker:dind
> +  variables:
> +DOCKER_HOST: tcp://docker:2375
> +DOCKER_DRIVER: overlay2
> +  script:
> +- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
> +- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips -f 
> Dockerfile.debian-mips .
> +- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
> +
>  containers:igt-fedora:
>stage: containers
>image: docker:stable
> diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
> new file mode 100644
> index ..ee29f5f4ccda
> --- /dev/null
> +++ b/Dockerfile.debian-mips
> @@ -0,0 +1,39 @@
> +FROM debian:stretch-backports
> +
> +RUN apt-get update
> +RUN apt-get install -y \
> + flex \
> + bison \
> + pkg-config \
> + x11proto-dri2-dev \
> + python-docutils \
> + valgrind \
> + peg
> +
> +RUN dpkg --add-architecture mips
> +RUN apt-get update
> +RUN apt-get install -y \
> + gcc-mips-linux-gnu \
> + libatomic1:mips \
> + libpciaccess-dev:mips \
> + libkmod-dev:mips \
> + libprocps-dev:mips \
> + libunwind-dev:mips \
> + libdw-dev:mips \
> + zlib1g-dev:mips \
> + liblzma-dev:mips \
> + libcairo-dev:mips \
> + libpixman-1-dev:mips \
> + libudev-dev:mips \
> + libgsl-dev:mips \
> + libasound2-dev:mips \
> + libjson-c-dev:mips \
> + libcurl4-openssl-dev:mips \
> + libxrandr-dev:mips \
> + libxv-dev:mips
> +
> +RUN apt-get install -t stretch-backports -y \
> + 

Re: [Intel-gfx] [PATCH i-g-t v4 0/4] Use C11 atomics

2019-06-25 Thread Guillaume Tucker
On 25/06/2019 11:54, Ser, Simon wrote:
> On Mon, 2019-06-24 at 17:22 +0100, Guillaume Tucker wrote:
>> This series replaces calls to the __sync_* functions with the more
>> recent atomic_* ones defined in stdatomic.h in gem_create and
>> sw_sync.  It also adds dependency on libatomic when required, that is
>> to say when the CPU architecture doesn't provide native support for
>> some atomic operations.  This makes the tests more portable, in
>> particular for 32-bit MIPS which doesn't support 64-bit atomics.
>>
> Thanks for this series! Pushed:
> 
> To gitlab.freedesktop.org:drm/igt-gpu-tools.git
>a6f5cc854efb..5eafa33dbdb1  master -> master

Awesome!

The patch I sent separately to enable MIPS in Gitlab CI should
now be ready to be pushed as well, I'll follow up on the other
thread.

Guillaume

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v4 2/4] gitlab-ci: add libatomic to docker images

2019-06-24 Thread Guillaume Tucker
Add libatomic to the Fedora docker image so it can link binaries that
use __atomic_* functions.  Also explicitly add libatomic1 to Debian
docker images as it is needed in particular on non-x86 architectures
for run-time linkage.

Signed-off-by: Guillaume Tucker 
---

Notes:
v2: add libatomic1 in Debian docker images
v3: add libatomic1 for non-x86 arches in Debian docker images
v4: rebase to add libatomic1 in Dockerfile.debian-minimal

 Dockerfile.debian-arm64   | 1 +
 Dockerfile.debian-armhf   | 1 +
 Dockerfile.debian-minimal | 1 +
 Dockerfile.fedora | 2 +-
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Dockerfile.debian-arm64 b/Dockerfile.debian-arm64
index 7b3a3c7ca803..c9fb28c804b8 100644
--- a/Dockerfile.debian-arm64
+++ b/Dockerfile.debian-arm64
@@ -14,6 +14,7 @@ RUN dpkg --add-architecture arm64
 RUN apt-get update
 RUN apt-get install -y \
gcc-aarch64-linux-gnu \
+   libatomic1:arm64 \
libpciaccess-dev:arm64 \
libkmod-dev:arm64 \
libprocps-dev:arm64 \
diff --git a/Dockerfile.debian-armhf b/Dockerfile.debian-armhf
index c67a1e2acf6a..3a133d849d68 100644
--- a/Dockerfile.debian-armhf
+++ b/Dockerfile.debian-armhf
@@ -14,6 +14,7 @@ RUN dpkg --add-architecture armhf
 RUN apt-get update
 RUN apt-get install -y \
gcc-arm-linux-gnueabihf \
+   libatomic1:armhf \
libpciaccess-dev:armhf \
libkmod-dev:armhf \
libprocps-dev:armhf \
diff --git a/Dockerfile.debian-minimal b/Dockerfile.debian-minimal
index bbe70bed2fb4..63844694dafa 100644
--- a/Dockerfile.debian-minimal
+++ b/Dockerfile.debian-minimal
@@ -6,6 +6,7 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
+   libatomic1 \
libpciaccess-dev \
libkmod-dev \
libprocps-dev \
diff --git a/Dockerfile.fedora b/Dockerfile.fedora
index 6686e587613d..c84b412b0723 100644
--- a/Dockerfile.fedora
+++ b/Dockerfile.fedora
@@ -1,7 +1,7 @@
 FROM fedora:30
 
 RUN dnf install -y \
-   gcc flex bison meson ninja-build xdotool \
+   gcc flex bison libatomic meson ninja-build xdotool \
'pkgconfig(libdrm)' \
'pkgconfig(pciaccess)' \
'pkgconfig(libkmod)' \
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v4 1/4] meson: add libatomic dependency

2019-06-24 Thread Guillaume Tucker
Add conditional dependency on GCC's libatomic in order to be able to
use the __atomic_* functions instead of the older __sync_* ones.  The
libatomic library is only needed when there aren't any native support
on the current architecture, so a linker test is used for this
purpose.  This makes atomic operations available on a wider number of
architectures including MIPS.

Signed-off-by: Guillaume Tucker 
Reviewed-by: Simon Ser 
---

Notes:
v2: add linker test for libatomic
v3: use null_dep
v4: fix sentence in commit message

 meson.build | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/meson.build b/meson.build
index b1028ee6aaaf..f0cb2543ca64 100644
--- a/meson.build
+++ b/meson.build
@@ -180,6 +180,20 @@ realtime = cc.find_library('rt')
 dlsym = cc.find_library('dl')
 zlib = cc.find_library('z')
 
+if cc.links('''
+#include 
+int main(void) {
+  uint32_t x32 = 0;
+  uint64_t x64 = 0;
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  return 0;
+}''', name : 'built-in atomics')
+   libatomic = null_dep
+else
+   libatomic = cc.find_library('atomic')
+endif
+
 if cc.has_header('linux/kd.h')
config.set('HAVE_LINUX_KD_H', 1)
 endif
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v4 4/4] tests/sw_sync: use atomic_* instead of __sync_*

2019-06-24 Thread Guillaume Tucker
Replace calls to the older __sync_* functions with the new atomic_*
standard ones to be consistent with other tests and improve
portability across CPU architectures.  Add dependency of sw_sync on
libatomic.

Signed-off-by: Guillaume Tucker 
Reviewed-by: Simon Ser 
---

Notes:
v2: use atomic_* and only link libatomic with sw_sync

 tests/Makefile.am |  1 +
 tests/meson.build |  8 +++-
 tests/sw_sync.c   | 12 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index bbd386c9c2db..7d71df8c7a2e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -122,6 +122,7 @@ prime_self_import_LDADD = $(LDADD) -lpthread
 gem_userptr_blits_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_userptr_blits_LDADD = $(LDADD) -lpthread
 perf_pmu_LDADD = $(LDADD) $(top_builddir)/lib/libigt_perf.la
+sw_sync_LDADD = $(LDADD) -latomic
 
 kms_flip_LDADD = $(LDADD) -lpthread
 
diff --git a/tests/meson.build b/tests/meson.build
index ffd432d38193..34a74025a537 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -76,7 +76,6 @@ test_progs = [
'prime_self_import',
'prime_udl',
'prime_vgem',
-   'sw_sync',
'syncobj_basic',
'syncobj_wait',
'template',
@@ -329,6 +328,13 @@ executable('testdisplay', ['testdisplay.c', 
'testdisplay_hotplug.c'],
   install : true)
 test_list += 'testdisplay'
 
+test_executables += executable('sw_sync', 'sw_sync.c',
+  dependencies : test_deps + [ libatomic ],
+  install_dir : libexecdir,
+  install_rpath : libexecdir_rpathdir,
+  install : true)
+test_list += 'sw_sync'
+
 subdir('amdgpu')
 
 gen_testlist = find_program('generate_testlist.sh')
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 950b8b614759..62d1d17cab45 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,7 +44,7 @@ IGT_TEST_DESCRIPTION("Test SW Sync Framework");
 typedef struct {
int timeline;
uint32_t thread_id;
-   uint32_t *counter;
+   _Atomic(uint32_t) *counter;
sem_t *sem;
 } data_t;
 
@@ -489,7 +490,7 @@ static void test_sync_multi_consumer(void)
pthread_t thread_arr[MULTI_CONSUMER_THREADS];
sem_t sem;
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -517,7 +518,7 @@ static void test_sync_multi_consumer(void)
{
sem_wait();
 
-   __sync_fetch_and_add(, 1);
+   atomic_fetch_add(, 1);
sw_sync_timeline_inc(timeline, 1);
}
 
@@ -554,7 +555,7 @@ static void * test_sync_multi_consumer_producer_thread(void 
*arg)
if (sync_fence_wait(fence, 1000) < 0)
return (void *) 1;
 
-   if (__sync_fetch_and_add(data->counter, 1) != next_point)
+   if (atomic_fetch_add(data->counter, 1) != next_point)
return (void *) 1;
 
/* Kick off the next thread. */
@@ -570,7 +571,7 @@ static void test_sync_multi_consumer_producer(void)
data_t data_arr[MULTI_CONSUMER_PRODUCER_THREADS];
pthread_t thread_arr[MULTI_CONSUMER_PRODUCER_THREADS];
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -900,4 +901,3 @@ igt_main
igt_subtest("sync_random_merge")
test_sync_random_merge();
 }
-
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v4 3/4] i915/gem_create: use atomic_* instead of __sync_*

2019-06-24 Thread Guillaume Tucker
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, , 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(>max, npages);
+   atomic_fetch_add(>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

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v4 0/4] Use C11 atomics

2019-06-24 Thread Guillaume Tucker
This series replaces calls to the __sync_* functions with the more
recent atomic_* ones defined in stdatomic.h in gem_create and
sw_sync.  It also adds dependency on libatomic when required, that is
to say when the CPU architecture doesn't provide native support for
some atomic operations.  This makes the tests more portable, in
particular for 32-bit MIPS which doesn't support 64-bit atomics.

v2:
 - add linker test to only add dependency on libatomic when needed
 - only add libatomic dependency to gem_create and sw_sync
 - use stdatomic.h and _Atomic type modifier
 - explicitly require libatomic in all Docker images

v3:
 - use sub-arch libatomic1 in Debian docker images
 - use null_dep in meson.build

v4:
 - rebase with changes in Dockerfile.debian-minimal

Guillaume Tucker (4):
  meson: add libatomic dependency
  gitlab-ci: add libatomic to docker images
  i915/gem_create: use atomic_* instead of __sync_*
  tests/sw_sync: use atomic_* instead of __sync_*

 Dockerfile.debian-arm64   |  1 +
 Dockerfile.debian-armhf   |  1 +
 Dockerfile.debian-minimal |  1 +
 Dockerfile.fedora |  2 +-
 meson.build   | 14 ++
 tests/Makefile.am |  3 ++-
 tests/i915/gem_create.c   | 16 
 tests/meson.build | 17 +++--
 tests/sw_sync.c   | 12 ++--
 9 files changed, 53 insertions(+), 14 deletions(-)

--
2.20.1
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH i-g-t v3 2/4] gitlab-ci: add libatomic to docker images

2019-06-19 Thread Guillaume Tucker
On 19/06/2019 07:50, Ser, Simon wrote:
> On Tue, 2019-06-18 at 13:27 +0100, Guillaume Tucker wrote:
>> Add libatomic to the Fedora docker image so it can link binaries that
>> use __atomic_* functions.  Also explicitly add libatomic1 to Debian
>> docker images as it is needed in particular on non-x86 architectures
>> for run-time linkage.
> 
> Per "[PATCH i-g-t v3 1/4] meson: add libatomic dependency", do we need
> libatomic for all of these images?

I suppose it's safer to include it, so if the linker test in
meson.build does happen to add the dependency it will actually
work.  Also as per an earlier comment:

  [PATCH i-g-t 2/4] gitlab-ci: add libatomic to Fedora docker image

  On 06/06/2019 08:26, Ser, Simon wrote:
  >> I wonder how does the libatomic gets installed implicitly in Debian.
  > It's a dependency of GCC. Probably a good idea to add it anyway?

It's true that we may optimise this a bit by checking for every
arch whether the test is expected to always pass or not and drop
the libatomic1 sub-arch package for those that link fine without
it.  I suspect only the mips version really needs it, the CI jobs
can help us confirm that.  Does that seem worth doing?

Guillaume

>> Signed-off-by: Guillaume Tucker 
>> ---
>>
>> Notes:
>> v2: add libatomic1 in Debian docker images
>> v3: add libatomic1 for non-x86 arches in Debian docker images
>>
>>  Dockerfile.debian   | 1 +
>>  Dockerfile.debian-arm64 | 1 +
>>  Dockerfile.debian-armhf | 1 +
>>  Dockerfile.fedora   | 2 +-
>>  4 files changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/Dockerfile.debian b/Dockerfile.debian
>> index b9c3be3945e0..d23591850c4e 100644
>> --- a/Dockerfile.debian
>> +++ b/Dockerfile.debian
>> @@ -6,6 +6,7 @@ RUN apt-get install -y \
>>  flex \
>>  bison \
>>  pkg-config \
>> +libatomic1 \
>>  libpciaccess-dev \
>>  libkmod-dev \
>>  libprocps-dev \
>> diff --git a/Dockerfile.debian-arm64 b/Dockerfile.debian-arm64
>> index 7b3a3c7ca803..c9fb28c804b8 100644
>> --- a/Dockerfile.debian-arm64
>> +++ b/Dockerfile.debian-arm64
>> @@ -14,6 +14,7 @@ RUN dpkg --add-architecture arm64
>>  RUN apt-get update
>>  RUN apt-get install -y \
>>  gcc-aarch64-linux-gnu \
>> +libatomic1:arm64 \
>>  libpciaccess-dev:arm64 \
>>  libkmod-dev:arm64 \
>>  libprocps-dev:arm64 \
>> diff --git a/Dockerfile.debian-armhf b/Dockerfile.debian-armhf
>> index c67a1e2acf6a..3a133d849d68 100644
>> --- a/Dockerfile.debian-armhf
>> +++ b/Dockerfile.debian-armhf
>> @@ -14,6 +14,7 @@ RUN dpkg --add-architecture armhf
>>  RUN apt-get update
>>  RUN apt-get install -y \
>>  gcc-arm-linux-gnueabihf \
>> +libatomic1:armhf \
>>  libpciaccess-dev:armhf \
>>  libkmod-dev:armhf \
>>  libprocps-dev:armhf \
>> diff --git a/Dockerfile.fedora b/Dockerfile.fedora
>> index 6686e587613d..c84b412b0723 100644
>> --- a/Dockerfile.fedora
>> +++ b/Dockerfile.fedora
>> @@ -1,7 +1,7 @@
>>  FROM fedora:30
>>  
>>  RUN dnf install -y \
>> -gcc flex bison meson ninja-build xdotool \
>> +gcc flex bison libatomic meson ninja-build xdotool \
>>  'pkgconfig(libdrm)' \
>>  'pkgconfig(pciaccess)' \
>>  'pkgconfig(libkmod)' \

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH i-g-t v3 1/4] meson: add libatomic dependency

2019-06-19 Thread Guillaume Tucker
On 19/06/2019 07:42, Ser, Simon wrote:
> On Tue, 2019-06-18 at 17:03 +0100, Guillaume Tucker wrote:
>> On 18/06/2019 15:37, Ser, Simon wrote:
>>> On Tue, 2019-06-18 at 14:59 +0100, Guillaume Tucker wrote:
>>>> On 18/06/2019 14:20, Ser, Simon wrote:
>>>>> On Tue, 2019-06-18 at 13:27 +0100, Guillaume Tucker wrote:
>>>>>> Add conditional dependency on libatomic in order to be able to use the
>>>>>> __atomic_* functions instead of the older __sync_* ones.  The
>>>>>> libatomic library is only needed when there aren't any native support
>>>>>> on the current architecture, so a linker test is used for this
>>>>>> purpose.  This enables atomic operations to be on a wider number of
>>>>>> architectures including MIPS.
>>>>>>
>>>>>> Signed-off-by: Guillaume Tucker 
>>>>>> ---
>>>>>>
>>>>>> Notes:
>>>>>> v2: add linker test for libatomic
>>>>>> v3: use null_dep
>>>>>>
>>>>>>  meson.build | 14 ++
>>>>>>  1 file changed, 14 insertions(+)
>>>>>>
>>>>>> diff --git a/meson.build b/meson.build
>>>>>> index 6268c58d3634..118ad667ffb5 100644
>>>>>> --- a/meson.build
>>>>>> +++ b/meson.build
>>>>>> @@ -180,6 +180,20 @@ realtime = cc.find_library('rt')
>>>>>>  dlsym = cc.find_library('dl')
>>>>>>  zlib = cc.find_library('z')
>>>>>>  
>>>>>> +if cc.links('''
>>>>>> +#include 
>>>>>> +int main(void) {
>>>>>> +  uint32_t x32 = 0;
>>>>>> +  uint64_t x64 = 0;
>>>>>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>>>>>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>>>>>
>>>>> See my reply for v2. I've looked into this a little bit more and it
>>>>> looks like __atomic_* functions are a GCC implementation detail. OIn
>>>>> other words, the C11 standard [1] defines only atomic_* functions, and
>>>>> GCC implements them with __atomic_* builtins when the platform supports
>>>>> it, but other compilers might not expose those builtins and still
>>>>> support atomic_* functions without them. This also seems to be what [2]
>>>>> explains:
>>>>>
>>>>>> The first set of library functions are named __atomic_*. This set has
>>>>>> been “standardized” by GCC, and is described below. (See also GCC’s
>>>>>> documentation)
>>>>>
>>>>> (Notice the quotes around “standardized”, meaning they are a GCC
>>>>> extension)
>>>>
>>>> Quite, and while the stdatomic.h API is part of the C11 standard,
>>>> libatomic is part of GCC.  So this test is to determine whether
>>>> linking against GCC's libatomic.so is needed for its __atomic_*
>>>> fallback implementation.
>>>>
>>>> It raises the question of what to do with other compilers, but
>>>> igt has other build errors with clang on mips at the moment.
>>>> With a quick search, it looks like its __atomic_* functions are
>>>> part of libclang.so for clang.
>>>
>>> I don't see anything in `readelf -s /usr/lib/libclang.so.8`.
>>
>> Yes, well I did this:
>>
>> $ for f in $(find . -name "*.so"); do strings $f | grep __atomic_load && 
>> echo $f; done
>> __atomic_load
>> __atomic_load_1
>> __atomic_load_2
>> __atomic_load_4
>> __atomic_load_8
>> ./gcc/mips-linux-gnu/8/libatomic.so
>> __atomic_load
>> __atomic_load_1
>> __atomic_load_2
>> __atomic_load_4
>> __atomic_load_8
>> __atomic_load_16
>> ./mips-linux-gnu/libLLVM-7.so
>>
>> although it's true that they don't appear as proper symbols with
>> readelf.  It would take a bit more investigation in the LLVM
>> source code to get to the bottom of that, but I don't think it's
>> necessary to solve the problem at hand.
> 
> Are you sure these are not undefined symbols? (That is, symbols used in
> the library because it's linked to libatomic)

I'm not sure but I would be surprised if LLVM was linked against
GCC's libatomic library.

>>>> Maybe this test should only be used when the compiler name is
>>>> gcc?  In practice it does work with both gcc and clang though, as
>>>> they b

Re: [Intel-gfx] [PATCH i-g-t v3 1/4] meson: add libatomic dependency

2019-06-18 Thread Guillaume Tucker
On 18/06/2019 15:37, Ser, Simon wrote:
> On Tue, 2019-06-18 at 14:59 +0100, Guillaume Tucker wrote:
>> On 18/06/2019 14:20, Ser, Simon wrote:
>>> On Tue, 2019-06-18 at 13:27 +0100, Guillaume Tucker wrote:
>>>> Add conditional dependency on libatomic in order to be able to use the
>>>> __atomic_* functions instead of the older __sync_* ones.  The
>>>> libatomic library is only needed when there aren't any native support
>>>> on the current architecture, so a linker test is used for this
>>>> purpose.  This enables atomic operations to be on a wider number of
>>>> architectures including MIPS.
>>>>
>>>> Signed-off-by: Guillaume Tucker 
>>>> ---
>>>>
>>>> Notes:
>>>> v2: add linker test for libatomic
>>>> v3: use null_dep
>>>>
>>>>  meson.build | 14 ++
>>>>  1 file changed, 14 insertions(+)
>>>>
>>>> diff --git a/meson.build b/meson.build
>>>> index 6268c58d3634..118ad667ffb5 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -180,6 +180,20 @@ realtime = cc.find_library('rt')
>>>>  dlsym = cc.find_library('dl')
>>>>  zlib = cc.find_library('z')
>>>>  
>>>> +if cc.links('''
>>>> +#include 
>>>> +int main(void) {
>>>> +  uint32_t x32 = 0;
>>>> +  uint64_t x64 = 0;
>>>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>>>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>>>
>>> See my reply for v2. I've looked into this a little bit more and it
>>> looks like __atomic_* functions are a GCC implementation detail. OIn
>>> other words, the C11 standard [1] defines only atomic_* functions, and
>>> GCC implements them with __atomic_* builtins when the platform supports
>>> it, but other compilers might not expose those builtins and still
>>> support atomic_* functions without them. This also seems to be what [2]
>>> explains:
>>>
>>>> The first set of library functions are named __atomic_*. This set has
>>>> been “standardized” by GCC, and is described below. (See also GCC’s
>>>> documentation)
>>>
>>> (Notice the quotes around “standardized”, meaning they are a GCC
>>> extension)
>>
>> Quite, and while the stdatomic.h API is part of the C11 standard,
>> libatomic is part of GCC.  So this test is to determine whether
>> linking against GCC's libatomic.so is needed for its __atomic_*
>> fallback implementation.
>>
>> It raises the question of what to do with other compilers, but
>> igt has other build errors with clang on mips at the moment.
>> With a quick search, it looks like its __atomic_* functions are
>> part of libclang.so for clang.
> 
> I don't see anything in `readelf -s /usr/lib/libclang.so.8`.

Yes, well I did this:

$ for f in $(find . -name "*.so"); do strings $f | grep __atomic_load && echo 
$f; done
__atomic_load
__atomic_load_1
__atomic_load_2
__atomic_load_4
__atomic_load_8
./gcc/mips-linux-gnu/8/libatomic.so
__atomic_load
__atomic_load_1
__atomic_load_2
__atomic_load_4
__atomic_load_8
__atomic_load_16
./mips-linux-gnu/libLLVM-7.so

although it's true that they don't appear as proper symbols with
readelf.  It would take a bit more investigation in the LLVM
source code to get to the bottom of that, but I don't think it's
necessary to solve the problem at hand.

>> Maybe this test should only be used when the compiler name is
>> gcc?  In practice it does work with both gcc and clang though, as
>> they both use the same naming convention for atomic built-ins.
> 
> Hmm. I'm still not quite sure I understand why checking with __atomic_*
> is preferred.
> 
> - If the compiler has __atomic_* builtins: this won't link with
>   libatomic
> - If the compiler doesn't have __atomic_* builtins: this will link with
>   libatomic even if stdatomic.h works without it
> 
> What we're really interested in is stdatomic.h support, not __atomic_*.
> So I still think checking for atomic_* is better than __atomic_*. Am I
> missing something?

I think the issue is that there is no absolute relationship
between stdatomic.h and the __atomic_* functions.  So the test is
currently designed from libatomic's point of view, and it might
add libatomic dependency even if stdatomic.h doesn't use the
__atomic_* functions.  Then conversely, using the C11 atomic_*
instead in the test means that we would add dependency on
libatomic if it fails to link without being completely sure that
it is the missing library.

If you take the current test on its 

Re: [Intel-gfx] [PATCH i-g-t v3 1/4] meson: add libatomic dependency

2019-06-18 Thread Guillaume Tucker
On 18/06/2019 14:20, Ser, Simon wrote:
> On Tue, 2019-06-18 at 13:27 +0100, Guillaume Tucker wrote:
>> Add conditional dependency on libatomic in order to be able to use the
>> __atomic_* functions instead of the older __sync_* ones.  The
>> libatomic library is only needed when there aren't any native support
>> on the current architecture, so a linker test is used for this
>> purpose.  This enables atomic operations to be on a wider number of
>> architectures including MIPS.
>>
>> Signed-off-by: Guillaume Tucker 
>> ---
>>
>> Notes:
>> v2: add linker test for libatomic
>> v3: use null_dep
>>
>>  meson.build | 14 ++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/meson.build b/meson.build
>> index 6268c58d3634..118ad667ffb5 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -180,6 +180,20 @@ realtime = cc.find_library('rt')
>>  dlsym = cc.find_library('dl')
>>  zlib = cc.find_library('z')
>>  
>> +if cc.links('''
>> +#include 
>> +int main(void) {
>> +  uint32_t x32 = 0;
>> +  uint64_t x64 = 0;
>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
> 
> See my reply for v2. I've looked into this a little bit more and it
> looks like __atomic_* functions are a GCC implementation detail. OIn
> other words, the C11 standard [1] defines only atomic_* functions, and
> GCC implements them with __atomic_* builtins when the platform supports
> it, but other compilers might not expose those builtins and still
> support atomic_* functions without them. This also seems to be what [2]
> explains:
> 
>> The first set of library functions are named __atomic_*. This set has
>> been “standardized” by GCC, and is described below. (See also GCC’s
>> documentation)
> 
> (Notice the quotes around “standardized”, meaning they are a GCC
> extension)

Quite, and while the stdatomic.h API is part of the C11 standard,
libatomic is part of GCC.  So this test is to determine whether
linking against GCC's libatomic.so is needed for its __atomic_*
fallback implementation.

It raises the question of what to do with other compilers, but
igt has other build errors with clang on mips at the moment.
With a quick search, it looks like its __atomic_* functions are
part of libclang.so for clang.

Maybe this test should only be used when the compiler name is
gcc?  In practice it does work with both gcc and clang though, as
they both use the same naming convention for atomic built-ins.

Guillaume

> [1]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf
> [2]: https://llvm.org/docs/Atomics.html
> 
>> +  return 0;
>> +}''', name : 'built-in atomics')
>> +libatomic = null_dep
>> +else
>> +libatomic = cc.find_library('atomic')
>> +endif
>> +
>>  if cc.has_header('linux/kd.h')
>>  config.set('HAVE_LINUX_KD_H', 1)
>>  endif

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 1/1] gitlab-ci: add build and tests for MIPS

2019-06-18 Thread Guillaume Tucker
Add Docker image and Gitlab CI steps to run builds and tests for the
MIPS architecture using Debian Stretch with backports.

Signed-off-by: Guillaume Tucker 
---

Notes:
v2: use stretch-backports and require libatomic1
v3: add mips ci tests and require Debian libatomic1 for mips

 .gitlab-ci.yml | 42 ++
 Dockerfile.debian-mips | 39 +++
 meson-cross-mips.txt   | 12 
 3 files changed, 93 insertions(+)
 create mode 100644 Dockerfile.debian-mips
 create mode 100644 meson-cross-mips.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 771143a9ea95..bd9619e7e28b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
 paths:
   - build
 
+build:tests-debian-meson-mips:
+  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
+  stage: build
+  script:
+- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
+- meson --cross-file meson-cross-mips.txt build
+- ninja -C build
+  artifacts:
+paths:
+  - build
+
 build:tests-debian-autotools:
   image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
   stage: build
@@ -145,6 +156,20 @@ test:ninja-test-armhf:
   - build
 when: on_failure
 
+test:ninja-test-mips:
+  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
+  dependencies:
+- build:tests-debian-meson-mips
+  stage: test
+  script:
+- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
+- env > build/envdump.txt
+- ninja -C build test
+  artifacts:
+paths:
+  - build
+when: on_failure
+
 test:test-list-diff:
   dependencies:
 - build:tests-debian-autotools
@@ -221,6 +246,23 @@ containers:igt-debian-arm64:
 - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
Dockerfile.debian-arm64 .
 - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
 
+containers:igt-debian-mips:
+  stage: containers
+  image: docker:stable
+  only:
+changes:
+  - Dockerfile.debian-mips
+  - .gitlab-ci.yml
+  services:
+- docker:dind
+  variables:
+DOCKER_HOST: tcp://docker:2375
+DOCKER_DRIVER: overlay2
+  script:
+- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
+- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips -f 
Dockerfile.debian-mips .
+- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
+
 containers:igt-fedora:
   stage: containers
   image: docker:stable
diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
new file mode 100644
index ..ee29f5f4ccda
--- /dev/null
+++ b/Dockerfile.debian-mips
@@ -0,0 +1,39 @@
+FROM debian:stretch-backports
+
+RUN apt-get update
+RUN apt-get install -y \
+   flex \
+   bison \
+   pkg-config \
+   x11proto-dri2-dev \
+   python-docutils \
+   valgrind \
+   peg
+
+RUN dpkg --add-architecture mips
+RUN apt-get update
+RUN apt-get install -y \
+   gcc-mips-linux-gnu \
+   libatomic1:mips \
+   libpciaccess-dev:mips \
+   libkmod-dev:mips \
+   libprocps-dev:mips \
+   libunwind-dev:mips \
+   libdw-dev:mips \
+   zlib1g-dev:mips \
+   liblzma-dev:mips \
+   libcairo-dev:mips \
+   libpixman-1-dev:mips \
+   libudev-dev:mips \
+   libgsl-dev:mips \
+   libasound2-dev:mips \
+   libjson-c-dev:mips \
+   libcurl4-openssl-dev:mips \
+   libxrandr-dev:mips \
+   libxv-dev:mips
+
+RUN apt-get install -t stretch-backports -y \
+   meson \
+   libdrm-dev:mips \
+   qemu-user \
+   qemu-user-static
diff --git a/meson-cross-mips.txt b/meson-cross-mips.txt
new file mode 100644
index ..6350d677e0bc
--- /dev/null
+++ b/meson-cross-mips.txt
@@ -0,0 +1,12 @@
+[binaries]
+c = '/usr/bin/mips-linux-gnu-gcc'
+ar = '/usr/bin/mips-linux-gnu-gcc-ar'
+strip = '/usr/bin/mips-linux-gnu-strip'
+pkgconfig = 'pkg-config'
+exe_wrapper = 'qemu-mips'
+
+[host_machine]
+system = 'linux'
+cpu_family = 'mips'
+cpu = 'mips'
+endian = 'big'
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 0/4] Use C11 atomics

2019-06-18 Thread Guillaume Tucker
This series replaces calls to the __sync_* functions with the more
recent atomic_* ones defined in stdatomic.h in gem_create and
sw_sync.  It also adds dependency on libatomic when required, that is
to say when the CPU architecture doesn't provide native support for
some atomic operations.  This makes the tests more portable, in
particular for 32-bit MIPS which doesn't support 64-bit atomics.

v2:
 - add linker test to only add dependency on libatomic when needed
 - only add libatomic dependency to gem_create and sw_sync
 - use stdatomic.h and _Atomic type modifier
 - explicitly require libatomic in all Docker images

v3:
 - use sub-arch libatomic1 in Debian docker images
 - use null_dep in meson.build

Guillaume Tucker (4):
  meson: add libatomic dependency
  gitlab-ci: add libatomic to docker images
  i915/gem_create: use atomic_* instead of __sync_*
  tests/sw_sync: use atomic_* instead of __sync_*

 Dockerfile.debian   |  1 +
 Dockerfile.debian-arm64 |  1 +
 Dockerfile.debian-armhf |  1 +
 Dockerfile.fedora   |  2 +-
 meson.build | 14 ++
 tests/Makefile.am   |  3 ++-
 tests/i915/gem_create.c | 16 
 tests/meson.build   | 17 +++--
 tests/sw_sync.c | 12 ++--
 9 files changed, 53 insertions(+), 14 deletions(-)

--
2.20.1
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 2/4] gitlab-ci: add libatomic to docker images

2019-06-18 Thread Guillaume Tucker
Add libatomic to the Fedora docker image so it can link binaries that
use __atomic_* functions.  Also explicitly add libatomic1 to Debian
docker images as it is needed in particular on non-x86 architectures
for run-time linkage.

Signed-off-by: Guillaume Tucker 
---

Notes:
v2: add libatomic1 in Debian docker images
v3: add libatomic1 for non-x86 arches in Debian docker images

 Dockerfile.debian   | 1 +
 Dockerfile.debian-arm64 | 1 +
 Dockerfile.debian-armhf | 1 +
 Dockerfile.fedora   | 2 +-
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Dockerfile.debian b/Dockerfile.debian
index b9c3be3945e0..d23591850c4e 100644
--- a/Dockerfile.debian
+++ b/Dockerfile.debian
@@ -6,6 +6,7 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
+   libatomic1 \
libpciaccess-dev \
libkmod-dev \
libprocps-dev \
diff --git a/Dockerfile.debian-arm64 b/Dockerfile.debian-arm64
index 7b3a3c7ca803..c9fb28c804b8 100644
--- a/Dockerfile.debian-arm64
+++ b/Dockerfile.debian-arm64
@@ -14,6 +14,7 @@ RUN dpkg --add-architecture arm64
 RUN apt-get update
 RUN apt-get install -y \
gcc-aarch64-linux-gnu \
+   libatomic1:arm64 \
libpciaccess-dev:arm64 \
libkmod-dev:arm64 \
libprocps-dev:arm64 \
diff --git a/Dockerfile.debian-armhf b/Dockerfile.debian-armhf
index c67a1e2acf6a..3a133d849d68 100644
--- a/Dockerfile.debian-armhf
+++ b/Dockerfile.debian-armhf
@@ -14,6 +14,7 @@ RUN dpkg --add-architecture armhf
 RUN apt-get update
 RUN apt-get install -y \
gcc-arm-linux-gnueabihf \
+   libatomic1:armhf \
libpciaccess-dev:armhf \
libkmod-dev:armhf \
libprocps-dev:armhf \
diff --git a/Dockerfile.fedora b/Dockerfile.fedora
index 6686e587613d..c84b412b0723 100644
--- a/Dockerfile.fedora
+++ b/Dockerfile.fedora
@@ -1,7 +1,7 @@
 FROM fedora:30
 
 RUN dnf install -y \
-   gcc flex bison meson ninja-build xdotool \
+   gcc flex bison libatomic meson ninja-build xdotool \
'pkgconfig(libdrm)' \
'pkgconfig(pciaccess)' \
'pkgconfig(libkmod)' \
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 1/4] meson: add libatomic dependency

2019-06-18 Thread Guillaume Tucker
Add conditional dependency on libatomic in order to be able to use the
__atomic_* functions instead of the older __sync_* ones.  The
libatomic library is only needed when there aren't any native support
on the current architecture, so a linker test is used for this
purpose.  This enables atomic operations to be on a wider number of
architectures including MIPS.

Signed-off-by: Guillaume Tucker 
---

Notes:
v2: add linker test for libatomic
v3: use null_dep

 meson.build | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/meson.build b/meson.build
index 6268c58d3634..118ad667ffb5 100644
--- a/meson.build
+++ b/meson.build
@@ -180,6 +180,20 @@ realtime = cc.find_library('rt')
 dlsym = cc.find_library('dl')
 zlib = cc.find_library('z')
 
+if cc.links('''
+#include 
+int main(void) {
+  uint32_t x32 = 0;
+  uint64_t x64 = 0;
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  return 0;
+}''', name : 'built-in atomics')
+   libatomic = null_dep
+else
+   libatomic = cc.find_library('atomic')
+endif
+
 if cc.has_header('linux/kd.h')
config.set('HAVE_LINUX_KD_H', 1)
 endif
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 3/4] i915/gem_create: use atomic_* instead of __sync_*

2019-06-18 Thread Guillaume Tucker
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, , 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(>max, npages);
+   atomic_fetch_add(>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

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v3 4/4] tests/sw_sync: use atomic_* instead of __sync_*

2019-06-18 Thread Guillaume Tucker
Replace calls to the older __sync_* functions with the new atomic_*
standard ones to be consistent with other tests and improve
portability across CPU architectures.  Add dependency of sw_sync on
libatomic.

Signed-off-by: Guillaume Tucker 
Reviewed-by: Simon Ser 
---

Notes:
v2: use atomic_* and only link libatomic with sw_sync

 tests/Makefile.am |  1 +
 tests/meson.build |  8 +++-
 tests/sw_sync.c   | 12 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index bbd386c9c2db..7d71df8c7a2e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -122,6 +122,7 @@ prime_self_import_LDADD = $(LDADD) -lpthread
 gem_userptr_blits_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_userptr_blits_LDADD = $(LDADD) -lpthread
 perf_pmu_LDADD = $(LDADD) $(top_builddir)/lib/libigt_perf.la
+sw_sync_LDADD = $(LDADD) -latomic
 
 kms_flip_LDADD = $(LDADD) -lpthread
 
diff --git a/tests/meson.build b/tests/meson.build
index ffd432d38193..34a74025a537 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -76,7 +76,6 @@ test_progs = [
'prime_self_import',
'prime_udl',
'prime_vgem',
-   'sw_sync',
'syncobj_basic',
'syncobj_wait',
'template',
@@ -329,6 +328,13 @@ executable('testdisplay', ['testdisplay.c', 
'testdisplay_hotplug.c'],
   install : true)
 test_list += 'testdisplay'
 
+test_executables += executable('sw_sync', 'sw_sync.c',
+  dependencies : test_deps + [ libatomic ],
+  install_dir : libexecdir,
+  install_rpath : libexecdir_rpathdir,
+  install : true)
+test_list += 'sw_sync'
+
 subdir('amdgpu')
 
 gen_testlist = find_program('generate_testlist.sh')
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 950b8b614759..62d1d17cab45 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,7 +44,7 @@ IGT_TEST_DESCRIPTION("Test SW Sync Framework");
 typedef struct {
int timeline;
uint32_t thread_id;
-   uint32_t *counter;
+   _Atomic(uint32_t) *counter;
sem_t *sem;
 } data_t;
 
@@ -489,7 +490,7 @@ static void test_sync_multi_consumer(void)
pthread_t thread_arr[MULTI_CONSUMER_THREADS];
sem_t sem;
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -517,7 +518,7 @@ static void test_sync_multi_consumer(void)
{
sem_wait();
 
-   __sync_fetch_and_add(, 1);
+   atomic_fetch_add(, 1);
sw_sync_timeline_inc(timeline, 1);
}
 
@@ -554,7 +555,7 @@ static void * test_sync_multi_consumer_producer_thread(void 
*arg)
if (sync_fence_wait(fence, 1000) < 0)
return (void *) 1;
 
-   if (__sync_fetch_and_add(data->counter, 1) != next_point)
+   if (atomic_fetch_add(data->counter, 1) != next_point)
return (void *) 1;
 
/* Kick off the next thread. */
@@ -570,7 +571,7 @@ static void test_sync_multi_consumer_producer(void)
data_t data_arr[MULTI_CONSUMER_PRODUCER_THREADS];
pthread_t thread_arr[MULTI_CONSUMER_PRODUCER_THREADS];
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -900,4 +901,3 @@ igt_main
igt_subtest("sync_random_merge")
test_sync_random_merge();
 }
-
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH i-g-t v2] gitlab-ci: add build for MIPS

2019-06-18 Thread Guillaume Tucker
On 14/06/2019 11:33, Arkadiusz Hiler wrote:
> On Thu, Jun 13, 2019 at 03:01:06PM +0100, Guillaume Tucker wrote:
>> Add Docker image and Gitlab CI steps to run builds for the MIPS
>> architecture using Debian Stretch with backports.
>>
>> Signed-off-by: Guillaume Tucker 
>> ---
>>  .gitlab-ci.yml | 28 
>>  Dockerfile.debian-mips | 39 +++
>>  meson-cross-mips.txt   | 12 
>>  3 files changed, 79 insertions(+)
>>  create mode 100644 Dockerfile.debian-mips
>>  create mode 100644 meson-cross-mips.txt
>>
>> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
>> index 771143a9ea95..e390f8f472d5 100644
>> --- a/.gitlab-ci.yml
>> +++ b/.gitlab-ci.yml
>> @@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
>>  paths:
>>- build
>>  
>> +build:tests-debian-meson-mips:
>> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
>> +  stage: build
>> +  script:
>> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
>> +- meson --cross-file meson-cross-mips.txt build
>> +- ninja -C build
>> +  artifacts:
>> +paths:
>> +  - build
>> +
>>  build:tests-debian-autotools:
>>image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
>>stage: build
>> @@ -221,6 +232,23 @@ containers:igt-debian-arm64:
>>  - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
>> Dockerfile.debian-arm64 .
>>  - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
> 
> Any particular reason for not having ninja-test step for MIPS?

Sorry I overlooked that bit, I'm adding it in a v3.  That made me
realise that the libatomic1:mips package was required for
run-time linking on multi-arch file systems.

> Other than that (and Petri's concern, since I don't speak Debian),
> looks good.

Thanks, I also replied on the other thread about adding
libatomic1 for sub-architectures.

Guillaume
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t v2 2/4] gitlab-ci: add libatomic to docker images

2019-06-18 Thread Guillaume Tucker
On 14/06/2019 13:53, Ser, Simon wrote:
> On Fri, 2019-06-14 at 15:43 +0300, Petri Latvala wrote:
>> On Fri, Jun 14, 2019 at 02:24:53PM +0300, Ser, Simon wrote:
>>> On Fri, 2019-06-14 at 13:00 +0300, Petri Latvala wrote:
>>>> On Thu, Jun 13, 2019 at 02:53:20PM +0100, Guillaume Tucker wrote:
>>>>> Add libatomic to the Fedora docker image so it can link binaries that
>>>>> use __atomic_* functions.  Also explicitly add libatomic1 to Debian
>>>>> docker images even though it's already installed as a dependency.
>>>>>
>>>>> Signed-off-by: Guillaume Tucker 
>>>>> ---
>>>>>  Dockerfile.debian   | 1 +
>>>>>  Dockerfile.debian-arm64 | 1 +
>>>>>  Dockerfile.debian-armhf | 1 +
>>>>>  Dockerfile.fedora   | 2 +-
>>>>>  4 files changed, 4 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/Dockerfile.debian b/Dockerfile.debian
>>>>> index b9c3be3945e0..d23591850c4e 100644
>>>>> --- a/Dockerfile.debian
>>>>> +++ b/Dockerfile.debian
>>>>> @@ -6,6 +6,7 @@ RUN apt-get install -y \
>>>>>   flex \
>>>>>   bison \
>>>>>   pkg-config \
>>>>> + libatomic1 \
>>>>>   libpciaccess-dev \
>>>>>   libkmod-dev \
>>>>>   libprocps-dev \
>>>>> diff --git a/Dockerfile.debian-arm64 b/Dockerfile.debian-arm64
>>>>> index 7b3a3c7ca803..003bb22b3215 100644
>>>>> --- a/Dockerfile.debian-arm64
>>>>> +++ b/Dockerfile.debian-arm64
>>>>> @@ -5,6 +5,7 @@ RUN apt-get install -y \
>>>>>   flex \
>>>>>   bison \
>>>>>   pkg-config \
>>>>> + libatomic1 \
>>>>>   x11proto-dri2-dev \
>>>>>   python-docutils \
>>>>>   valgrind \
>>>>> diff --git a/Dockerfile.debian-armhf b/Dockerfile.debian-armhf
>>>>> index c67a1e2acf6a..3139927c193a 100644
>>>>> --- a/Dockerfile.debian-armhf
>>>>> +++ b/Dockerfile.debian-armhf
>>>>> @@ -5,6 +5,7 @@ RUN apt-get install -y \
>>>>>   flex \
>>>>>   bison \
>>>>>   pkg-config \
>>>>> + libatomic1 \
>>>>
>>>> libatomic1 is the runtime lib, for linking you need the package that
>>>> contains libatomic.so. That is *quick search*
>>>> libgcc-$version-dev. There doesn't seem to be a generic metapackage
>>>> for "the latest libgcc-dev", other than... 'gcc'.
>>>>
>>>> Since Debian is acting a bit speshul here I'd just drop the explicit
>>>> libatomic installation.
>>>
>>> Hmm, I see the .so in libatomic1…
>>>
>>> https://packages.debian.org/jessie/amd64/libatomic1/filelist
>>
>> Where? I only see the .so.1 and .so.1.1.0
> 
> Bleh, indeed
So, I've dropped the libatomic1 as it's indeed not required
*except* that it is for non-x86 architectures at run-time with
multi-arch file systems.  I found that when adding ci tests for
mips, as of course it then needs it when running gem_create.  I'm
sending a v3 with this.

Thanks,
Guillaume
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t v2 1/4] meson: add libatomic dependency

2019-06-18 Thread Guillaume Tucker
On 14/06/2019 09:07, Ser, Simon wrote:
> On Thu, 2019-06-13 at 14:53 +0100, Guillaume Tucker wrote:
>> Add conditional dependency on libatomic in order to be able to use the
>> __atomic_* functions instead of the older __sync_* ones.  The
>> libatomic library is only needed when there aren't any native support
>> on the current architecture, so a linker test is used for this
>> purpose.  This enables atomic operations to be on a wider number of
>> architectures including MIPS.
>>
>> Signed-off-by: Guillaume Tucker 
>> ---
>>  meson.build | 13 +
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/meson.build b/meson.build
>> index 6268c58d3634..da25a28f3268 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -179,6 +179,19 @@ math = cc.find_library('m')
>>  realtime = cc.find_library('rt')
>>  dlsym = cc.find_library('dl')
>>  zlib = cc.find_library('z')
>> +if cc.links('''
>> +#include 
>> +int main(void) {
>> +  uint32_t x32 = 0;
>> +  uint64_t x64 = 0;
>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
>> +  __atomic_load_n(, __ATOMIC_SEQ_CST);
> 
> Minor: maybe we could've used stdatomic.h's atomic_* functions (without
> the "__" prefix) for consistency with the actual IGT code?

I actually thought it was more correct to use the __atomic_*
functions directly from the libatomic library as this is a linker
test.  If for any reason stdatomic.h changes between versions or
compilers and uses something else than libatomic, then this test
would become invalid.

>> +  return 0;
>> +}''', name : 'built-in atomics')
>> +libatomic = []
> 
> We could use null_dep instead, to make it consistent with the other
> branch.

Ack, will fix that in v3.

>> +else
>> +libatomic = cc.find_library('atomic')
>> +endif
>>  
>>  if cc.has_header('linux/kd.h')
>>  config.set('HAVE_LINUX_KD_H', 1)

Thanks,
Guillaume
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2] gitlab-ci: add build for MIPS

2019-06-13 Thread Guillaume Tucker
This is to add MIPS builds to Gitlab CI.

v2:
 - use stretch-backports rather than Buster
 - explicitly require libatomic

Guillaume Tucker (1):
  gitlab-ci: add build for MIPS

 .gitlab-ci.yml | 28 
 Dockerfile.debian-mips | 39 +++
 meson-cross-mips.txt   | 12 
 3 files changed, 79 insertions(+)
 create mode 100644 Dockerfile.debian-mips
 create mode 100644 meson-cross-mips.txt

--
2.20.1
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2] gitlab-ci: add build for MIPS

2019-06-13 Thread Guillaume Tucker
Add Docker image and Gitlab CI steps to run builds for the MIPS
architecture using Debian Stretch with backports.

Signed-off-by: Guillaume Tucker 
---
 .gitlab-ci.yml | 28 
 Dockerfile.debian-mips | 39 +++
 meson-cross-mips.txt   | 12 
 3 files changed, 79 insertions(+)
 create mode 100644 Dockerfile.debian-mips
 create mode 100644 meson-cross-mips.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 771143a9ea95..e390f8f472d5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
 paths:
   - build
 
+build:tests-debian-meson-mips:
+  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
+  stage: build
+  script:
+- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
+- meson --cross-file meson-cross-mips.txt build
+- ninja -C build
+  artifacts:
+paths:
+  - build
+
 build:tests-debian-autotools:
   image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
   stage: build
@@ -221,6 +232,23 @@ containers:igt-debian-arm64:
 - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
Dockerfile.debian-arm64 .
 - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
 
+containers:igt-debian-mips:
+  stage: containers
+  image: docker:stable
+  only:
+changes:
+  - Dockerfile.debian-mips
+  - .gitlab-ci.yml
+  services:
+- docker:dind
+  variables:
+DOCKER_HOST: tcp://docker:2375
+DOCKER_DRIVER: overlay2
+  script:
+- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
+- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips -f 
Dockerfile.debian-mips .
+- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
+
 containers:igt-fedora:
   stage: containers
   image: docker:stable
diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
new file mode 100644
index ..ebe08db644ea
--- /dev/null
+++ b/Dockerfile.debian-mips
@@ -0,0 +1,39 @@
+FROM debian:stretch-backports
+
+RUN apt-get update
+RUN apt-get install -y \
+   flex \
+   bison \
+   pkg-config \
+   libatomic1 \
+   x11proto-dri2-dev \
+   python-docutils \
+   valgrind \
+   peg
+
+RUN dpkg --add-architecture mips
+RUN apt-get update
+RUN apt-get install -y \
+   gcc-mips-linux-gnu \
+   libpciaccess-dev:mips \
+   libkmod-dev:mips \
+   libprocps-dev:mips \
+   libunwind-dev:mips \
+   libdw-dev:mips \
+   zlib1g-dev:mips \
+   liblzma-dev:mips \
+   libcairo-dev:mips \
+   libpixman-1-dev:mips \
+   libudev-dev:mips \
+   libgsl-dev:mips \
+   libasound2-dev:mips \
+   libjson-c-dev:mips \
+   libcurl4-openssl-dev:mips \
+   libxrandr-dev:mips \
+   libxv-dev:mips
+
+RUN apt-get install -t stretch-backports -y \
+   meson \
+   libdrm-dev:mips \
+   qemu-user \
+   qemu-user-static
diff --git a/meson-cross-mips.txt b/meson-cross-mips.txt
new file mode 100644
index ..6350d677e0bc
--- /dev/null
+++ b/meson-cross-mips.txt
@@ -0,0 +1,12 @@
+[binaries]
+c = '/usr/bin/mips-linux-gnu-gcc'
+ar = '/usr/bin/mips-linux-gnu-gcc-ar'
+strip = '/usr/bin/mips-linux-gnu-strip'
+pkgconfig = 'pkg-config'
+exe_wrapper = 'qemu-mips'
+
+[host_machine]
+system = 'linux'
+cpu_family = 'mips'
+cpu = 'mips'
+endian = 'big'
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2 2/4] gitlab-ci: add libatomic to docker images

2019-06-13 Thread Guillaume Tucker
Add libatomic to the Fedora docker image so it can link binaries that
use __atomic_* functions.  Also explicitly add libatomic1 to Debian
docker images even though it's already installed as a dependency.

Signed-off-by: Guillaume Tucker 
---
 Dockerfile.debian   | 1 +
 Dockerfile.debian-arm64 | 1 +
 Dockerfile.debian-armhf | 1 +
 Dockerfile.fedora   | 2 +-
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Dockerfile.debian b/Dockerfile.debian
index b9c3be3945e0..d23591850c4e 100644
--- a/Dockerfile.debian
+++ b/Dockerfile.debian
@@ -6,6 +6,7 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
+   libatomic1 \
libpciaccess-dev \
libkmod-dev \
libprocps-dev \
diff --git a/Dockerfile.debian-arm64 b/Dockerfile.debian-arm64
index 7b3a3c7ca803..003bb22b3215 100644
--- a/Dockerfile.debian-arm64
+++ b/Dockerfile.debian-arm64
@@ -5,6 +5,7 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
+   libatomic1 \
x11proto-dri2-dev \
python-docutils \
valgrind \
diff --git a/Dockerfile.debian-armhf b/Dockerfile.debian-armhf
index c67a1e2acf6a..3139927c193a 100644
--- a/Dockerfile.debian-armhf
+++ b/Dockerfile.debian-armhf
@@ -5,6 +5,7 @@ RUN apt-get install -y \
flex \
bison \
pkg-config \
+   libatomic1 \
x11proto-dri2-dev \
python-docutils \
valgrind \
diff --git a/Dockerfile.fedora b/Dockerfile.fedora
index 6686e587613d..c84b412b0723 100644
--- a/Dockerfile.fedora
+++ b/Dockerfile.fedora
@@ -1,7 +1,7 @@
 FROM fedora:30
 
 RUN dnf install -y \
-   gcc flex bison meson ninja-build xdotool \
+   gcc flex bison libatomic meson ninja-build xdotool \
'pkgconfig(libdrm)' \
'pkgconfig(pciaccess)' \
'pkgconfig(libkmod)' \
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2 4/4] tests/sw_sync: use atomic_* instead of __sync_*

2019-06-13 Thread Guillaume Tucker
Replace calls to the older __sync_* functions with the new atomic_*
standard ones to be consistent with other tests and improve
portability across CPU architectures.  Add dependency of sw_sync on
libatomic.

Signed-off-by: Guillaume Tucker 
---
 tests/Makefile.am |  1 +
 tests/meson.build |  8 +++-
 tests/sw_sync.c   | 12 ++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index bbd386c9c2db..7d71df8c7a2e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -122,6 +122,7 @@ prime_self_import_LDADD = $(LDADD) -lpthread
 gem_userptr_blits_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_userptr_blits_LDADD = $(LDADD) -lpthread
 perf_pmu_LDADD = $(LDADD) $(top_builddir)/lib/libigt_perf.la
+sw_sync_LDADD = $(LDADD) -latomic
 
 kms_flip_LDADD = $(LDADD) -lpthread
 
diff --git a/tests/meson.build b/tests/meson.build
index ffd432d38193..34a74025a537 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -76,7 +76,6 @@ test_progs = [
'prime_self_import',
'prime_udl',
'prime_vgem',
-   'sw_sync',
'syncobj_basic',
'syncobj_wait',
'template',
@@ -329,6 +328,13 @@ executable('testdisplay', ['testdisplay.c', 
'testdisplay_hotplug.c'],
   install : true)
 test_list += 'testdisplay'
 
+test_executables += executable('sw_sync', 'sw_sync.c',
+  dependencies : test_deps + [ libatomic ],
+  install_dir : libexecdir,
+  install_rpath : libexecdir_rpathdir,
+  install : true)
+test_list += 'sw_sync'
+
 subdir('amdgpu')
 
 gen_testlist = find_program('generate_testlist.sh')
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 950b8b614759..62d1d17cab45 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,7 +44,7 @@ IGT_TEST_DESCRIPTION("Test SW Sync Framework");
 typedef struct {
int timeline;
uint32_t thread_id;
-   uint32_t *counter;
+   _Atomic(uint32_t) *counter;
sem_t *sem;
 } data_t;
 
@@ -489,7 +490,7 @@ static void test_sync_multi_consumer(void)
pthread_t thread_arr[MULTI_CONSUMER_THREADS];
sem_t sem;
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -517,7 +518,7 @@ static void test_sync_multi_consumer(void)
{
sem_wait();
 
-   __sync_fetch_and_add(, 1);
+   atomic_fetch_add(, 1);
sw_sync_timeline_inc(timeline, 1);
}
 
@@ -554,7 +555,7 @@ static void * test_sync_multi_consumer_producer_thread(void 
*arg)
if (sync_fence_wait(fence, 1000) < 0)
return (void *) 1;
 
-   if (__sync_fetch_and_add(data->counter, 1) != next_point)
+   if (atomic_fetch_add(data->counter, 1) != next_point)
return (void *) 1;
 
/* Kick off the next thread. */
@@ -570,7 +571,7 @@ static void test_sync_multi_consumer_producer(void)
data_t data_arr[MULTI_CONSUMER_PRODUCER_THREADS];
pthread_t thread_arr[MULTI_CONSUMER_PRODUCER_THREADS];
int timeline;
-   uint32_t counter = 0;
+   _Atomic(uint32_t) counter = 0;
uintptr_t thread_ret = 0;
data_t data;
int i, ret;
@@ -900,4 +901,3 @@ igt_main
igt_subtest("sync_random_merge")
test_sync_random_merge();
 }
-
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2 3/4] i915/gem_create: use atomic_* instead of __sync_*

2019-06-13 Thread Guillaume Tucker
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 
---
 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, , 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(>max, npages);
+   atomic_fetch_add(>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

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2 1/4] meson: add libatomic dependency

2019-06-13 Thread Guillaume Tucker
Add conditional dependency on libatomic in order to be able to use the
__atomic_* functions instead of the older __sync_* ones.  The
libatomic library is only needed when there aren't any native support
on the current architecture, so a linker test is used for this
purpose.  This enables atomic operations to be on a wider number of
architectures including MIPS.

Signed-off-by: Guillaume Tucker 
---
 meson.build | 13 +
 1 file changed, 13 insertions(+)

diff --git a/meson.build b/meson.build
index 6268c58d3634..da25a28f3268 100644
--- a/meson.build
+++ b/meson.build
@@ -179,6 +179,19 @@ math = cc.find_library('m')
 realtime = cc.find_library('rt')
 dlsym = cc.find_library('dl')
 zlib = cc.find_library('z')
+if cc.links('''
+#include 
+int main(void) {
+  uint32_t x32 = 0;
+  uint64_t x64 = 0;
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  __atomic_load_n(, __ATOMIC_SEQ_CST);
+  return 0;
+}''', name : 'built-in atomics')
+   libatomic = []
+else
+   libatomic = cc.find_library('atomic')
+endif
 
 if cc.has_header('linux/kd.h')
config.set('HAVE_LINUX_KD_H', 1)
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t v2 0/4] Use C11 atomics

2019-06-13 Thread Guillaume Tucker
This series replaces calls to the __sync_* functions with the more
recent atomic_* ones defined in stdatomic.h in gem_create and
sw_sync.  It also adds dependency on libatomic when required, that is
to say when the CPU architecture doesn't provide native support for
some atomic operations.  This makes the tests more portable, in
particular for 32-bit MIPS which doesn't support 64-bit atomics.

v2:
 - add linker test to only add dependency on libatomic when needed
 - only add libatomic dependency to gem_create and sw_sync
 - use stdatomic.h and _Atomic type modifier
 - explicitly require libatomic in all Docker images

Guillaume Tucker (4):
  meson: add libatomic dependency
  gitlab-ci: add libatomic to docker images
  i915/gem_create: use atomic_* instead of __sync_*
  tests/sw_sync: use atomic_* instead of __sync_*

 Dockerfile.debian   |  1 +
 Dockerfile.debian-arm64 |  1 +
 Dockerfile.debian-armhf |  1 +
 Dockerfile.fedora   |  2 +-
 meson.build | 13 +
 tests/Makefile.am   |  3 ++-
 tests/i915/gem_create.c | 16 
 tests/meson.build   | 17 +++--
 tests/sw_sync.c | 12 ++--
 9 files changed, 52 insertions(+), 14 deletions(-)

--
2.20.1
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [PATCH i-g-t] gitlab-ci: add build for MIPS

2019-06-13 Thread Guillaume Tucker
On 06/06/2019 14:16, Arkadiusz Hiler wrote:
> On Wed, Jun 05, 2019 at 09:18:09PM +0100, Guillaume Tucker wrote:
>> Add Docker image and Gitlab CI steps to run builds for the MIPS
>> architecture using Debian Buster.
>>
>> Signed-off-by: Guillaume Tucker 
>> ---
>>  .gitlab-ci.yml | 28 
>>  Dockerfile.debian-mips | 38 ++
>>  meson-cross-mips.txt   | 12 
>>  3 files changed, 78 insertions(+)
>>  create mode 100644 Dockerfile.debian-mips
>>  create mode 100644 meson-cross-mips.txt
>>
>> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
>> index 771143a9ea95..e390f8f472d5 100644
>> --- a/.gitlab-ci.yml
>> +++ b/.gitlab-ci.yml
>> @@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
>>  paths:
>>- build
>>  
>> +build:tests-debian-meson-mips:
>> +  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
>> +  stage: build
>> +  script:
>> +- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
>> +- meson --cross-file meson-cross-mips.txt build
>> +- ninja -C build
>> +  artifacts:
>> +paths:
>> +  - build
>> +
>>  build:tests-debian-autotools:
>>image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
>>stage: build
>> @@ -221,6 +232,23 @@ containers:igt-debian-arm64:
>>  - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
>> Dockerfile.debian-arm64 .
>>  - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
>>  
>> +containers:igt-debian-mips:
>> +  stage: containers
>> +  image: docker:stable
>> +  only:
>> +changes:
>> +  - Dockerfile.debian-mips
>> +  - .gitlab-ci.yml
>> +  services:
>> +- docker:dind
>> +  variables:
>> +DOCKER_HOST: tcp://docker:2375
>> +DOCKER_DRIVER: overlay2
>> +  script:
>> +- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
>> +- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips -f 
>> Dockerfile.debian-mips .
>> +- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
>> +
>>  containers:igt-fedora:
>>stage: containers
>>image: docker:stable
>> diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
>> new file mode 100644
>> index ..2612b7b148e3
>> --- /dev/null
>> +++ b/Dockerfile.debian-mips
>> @@ -0,0 +1,38 @@
>> +FROM debian:buster
> 
> Any particular reason you went here for buster instead of
> stretch-backports like with other images? I am not very fluent in
> Debian.

Well, not really.  I was rather seeing the other side of this,
i.e. why use stretch-backports when we can just use buster?  It's
now frozen so it's good enough to use and should in principle be
officially released next month.

But that's just a detail, I've reworked the patch with
stretch-backports and it works just the same.  It's probably
better to keep all the Debian Docker images on the same distro,
so stick to Stretch now and upgrade them to Buster later.  I'll
send a v2 with stretch-backports (and libatomic added).

Guillaume

> Other than that looks good to land after the atomic compatibility fixes.
> 
>> +
>> +RUN apt-get update
>> +RUN apt-get install -y \
>> +flex \
>> +bison \
>> +pkg-config \
>> +x11proto-dri2-dev \
>> +python-docutils \
>> +valgrind \
>> +peg
>> +
>> +RUN dpkg --add-architecture mips
>> +RUN apt-get update
>> +RUN apt-get install -y \
>> +gcc-mips-linux-gnu \
>> +libpciaccess-dev:mips \
>> +libkmod-dev:mips \
>> +libprocps-dev:mips \
>> +libunwind-dev:mips \
>> +libdw-dev:mips \
>> +zlib1g-dev:mips \
>> +liblzma-dev:mips \
>> +libcairo-dev:mips \
>> +libpixman-1-dev:mips \
>> +libudev-dev:mips \
>> +libgsl-dev:mips \
>> +libasound2-dev:mips \
>> +libjson-c-dev:mips \
>> +libcurl4-openssl-dev:mips \
>> +libxrandr-dev:mips \
>> +libxv-dev:mips
>> +
>> +RUN apt-get install -y \
>> +meson 

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 1/4] tests: add libatomic dependency

2019-06-13 Thread Guillaume Tucker
On 06/06/2019 08:18, Ser, Simon wrote:
> On Mon, 2019-06-03 at 12:54 +0100, Guillaume Tucker wrote:
>> Add dependency to libatomic in order to be able to use the __atomic_*
>> functions instead of the older __sync_* ones.  This is to enable
>> atomic operations on a wider number of architectures including MIPS.
> 
> Thanks for your patch! I have a few questions because I don't know well
> how libatomic works.

Thanks for the review!

> Do we want to always link against libatomic? For instance LLVM tries to
> compile a program with atomic before falling back to libatomic:
> https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/CheckAtomic.cmake
> 
> Should this dependency be mandatory?

I've had a look around, the short answer is we should make this
dependency optional.  I'm sending a v2 of this series which
addresses this issue.

From what I understand, linking against libatomic is actually
only needed when some atomic operations aren't supported natively
by a CPU architecture.  For example, this is the case with 64-bit
atomics on 32-bit MIPS.  If the CPU can't do an atomic operation
and there's no libatomic available, then it won't build.  So I've
made a test in meson.build to check whether linking against
libatomic is required or not, to drop the dependency when it
isn't.  I've verified that the test passes on x86 (i.e. no
dependency) and fails on 32-bit MIPS (i.e. with dependency).

Guillaume


>> Signed-off-by: Guillaume Tucker 
>> ---
>>  meson.build   | 1 +
>>  tests/meson.build | 2 +-
>>  2 files changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/meson.build b/meson.build
>> index 6268c58d3634..4e5bb323fa49 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -179,6 +179,7 @@ math = cc.find_library('m')
>>  realtime = cc.find_library('rt')
>>  dlsym = cc.find_library('dl')
>>  zlib = cc.find_library('z')
>> +libatomic = cc.find_library('atomic')
>>  
>>  if cc.has_header('linux/kd.h')
>>  config.set('HAVE_LINUX_KD_H', 1)
>> diff --git a/tests/meson.build b/tests/meson.build
>> index 806766e51667..6877ccd59235 100644
>> --- a/tests/meson.build
>> +++ b/tests/meson.build
>> @@ -233,7 +233,7 @@ i915_progs = [
>>  'i915_suspend',
>>  ]
>>  
>> -test_deps = [ igt_deps ]
>> +test_deps = [ igt_deps, libatomic ]
>>  
>>  if libdrm_nouveau.found()
>>  test_progs += [

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 2/4] gitlab-ci: add libatomic to Fedora docker image

2019-06-13 Thread Guillaume Tucker
On 06/06/2019 08:26, Ser, Simon wrote:
> On Thu, 2019-06-06 at 10:21 +0300, Arkadiusz Hiler wrote:
>> On Mon, Jun 03, 2019 at 12:54:48PM +0100, Guillaume Tucker wrote:
>>> Add libatomic to the Fedora docker image so it can link binaries that
>>> use __atomic_* functions.
>>>
>>> Signed-off-by: Guillaume Tucker 
>>> ---
>>>  Dockerfile.fedora | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/Dockerfile.fedora b/Dockerfile.fedora
>>> index 6686e587613d..c84b412b0723 100644
>>> --- a/Dockerfile.fedora
>>> +++ b/Dockerfile.fedora
>>> @@ -1,7 +1,7 @@
>>>  FROM fedora:30
>>>  
>>>  RUN dnf install -y \
>>> -   gcc flex bison meson ninja-build xdotool \
>>> +   gcc flex bison libatomic meson ninja-build xdotool \
>>> 'pkgconfig(libdrm)' \
>>> 'pkgconfig(pciaccess)' \
>>> 'pkgconfig(libkmod)' \
>>
>> Reviewed-by: Arkadiusz Hiler 
>>
>> I wonder how does the libatomic gets installed implicitly in Debian.
> 
> It's a dependency of GCC. Probably a good idea to add it anyway?
Fair enough, I'm adding it in the v2.

Guillaume
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 3/4] i915/gem_create: use __atomic_* instead of __sync_*

2019-06-13 Thread Guillaume Tucker
On 06/06/2019 08:20, Ser, Simon wrote:
> On Mon, 2019-06-03 at 12:54 +0100, Guillaume Tucker wrote:
>> Replace calls to the older __sync_* functions with the new __atomic_*
>> standard ones.  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.
> 
> Can't we use the C11 atomics from stdatomic.h instead?
> 
> For instance:
> https://en.cppreference.com/w/c/atomic/atomic_compare_exchange

Yes, thanks for pointing this out.  The stdatomic.h macros also
use the __atomic_* functions so the libatomic dependency remains
the same, but it's a bit better than using the __atomic_*
functions directly.  In particular, stdatomic.h enforces the use
of the _Atomic type modifier which seems very important esp for
pointers to atomic variables.  That's also being fixed in the v2.

Guillaume

>> Signed-off-by: Guillaume Tucker 
>> ---
>>  tests/Makefile.am   |  2 +-
>>  tests/i915/gem_create.c | 12 ++--
>>  2 files changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/Makefile.am b/tests/Makefile.am
>> index 5097debf629c..18a0f1f20592 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..a4aeb94b3f93 100644
>> --- a/tests/i915/gem_create.c
>> +++ b/tests/i915/gem_create.c
>> @@ -156,6 +156,14 @@ static void invalid_nonaligned_size(int fd)
>>  gem_close(fd, create.handle);
>>  }
>>  
>> +static uint64_t atomic_compare_swap_u64(uint64_t *ptr, uint64_t oldval,
>> +uint64_t newval)
>> +{
>> +__atomic_compare_exchange_n(ptr, , newval, 0,
>> +__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
>> +return oldval;
>> +}
>> +
>>  static uint64_t get_npages(uint64_t *global, uint64_t npages)
>>  {
>>  uint64_t try, old, max;
>> @@ -165,7 +173,7 @@ 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;
>>  }
>> @@ -202,7 +210,7 @@ static void *thread_clear(void *data)
>>  }
>>  gem_close(i915, create.handle);
>>  
>> -__sync_add_and_fetch(>max, npages);
>> +__atomic_add_fetch(>max, npages, __ATOMIC_SEQ_CST);
>>  }
>>  
>>  return NULL;

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t] i915/gem_create: Do not build create-clear for MIPS

2019-06-05 Thread Guillaume Tucker
On 03/04/2019 08:25, Guillaume Tucker wrote:
> On 02/04/2019 09:35, Petri Latvala wrote:
>> On Mon, Apr 01, 2019 at 04:39:24PM +0200, Guillaume Tucker wrote:
>>> The MIPS architecture doesn't provide the hardware atomics that are
>>> required for the "create-clear" sub-test such as
>>> __sync_add_and_fetch().  As a simple and pragmatic solution, disable
>>> this sub-test when building for MIPS.  A better approach would be to
>>> add a fallback implementation for these operations.
>>>
>>> Fixes: 6727e17c00b2 ("i915/gem_create: Verify that all new objects are 
>>> clear")
>>> Signed-off-by: Guillaume Tucker 
>>> ---
>>>  tests/i915/gem_create.c | 4 
>>>  1 file changed, 4 insertions(+)
>>>
>>> diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
>>> index 2a861ca8a7ec..8a48496e6c19 100644
>>> --- a/tests/i915/gem_create.c
>>> +++ b/tests/i915/gem_create.c
>>> @@ -142,6 +142,7 @@ static void invalid_nonaligned_size(int fd)
>>> gem_close(fd, handle);
>>>  }
>>>  
>>> +#if !defined(__mips__) /* MIPS doesn't provide the required hardware 
>>> atomics */
>>>  static uint64_t get_npages(uint64_t *global, uint64_t npages)
>>>  {
>>> uint64_t try, old, max;
>>> @@ -208,6 +209,7 @@ static void always_clear(int i915, int timeout)
>>> for (int i = 0; i < ncpus; i++)
>>> pthread_join(thread[i], NULL);
>>>  }
>>> +#endif /* !defined(__mips__) */
>>>  
>>>  igt_main
>>>  {
>>> @@ -231,6 +233,8 @@ igt_main
>>> igt_subtest("create-invalid-nonaligned")
>>> invalid_nonaligned_size(fd);
>>>  
>>> +#if !defined(__mips__)
>>> igt_subtest("create-clear")
>>> always_clear(fd, 30);
>>> +#endif
>>>  }
>>
>>
>> It's a bit ugly. I wonder how much work a fallback mechanism would be?
> 
> Sorry I should have sent this as RFC.
> 
>> The test is i915 specific and using those on non-x86 architectures
>> sounds silly. We could limit building tests/i915/* only if
>> host_machine.cpu_family() is x86 or x86_64. But that requires
>> revisiting this issue if ever the day comes when i915 can be used on
>> other architectures *cough*.
> 
> Right, I thought it might not be worth implementing fallback
> functions if there is no MIPS hardware on which this test can be
> run.  Still it would be a shame to leave i-g-t failing to build
> on MIPS.
> 
>> Apropos, compile-testing on MIPS in gitlab-CI?
> 
> This issue was actually hit while building the KernelCI root file
> system with i-g-t tests.  We're starting to add some MIPS
> platforms, so running the generic DRM/KMS tests on them might
> start to make sense at some point (cc khilman).
> 
> And yes I guess it seems worth considering adding MIPS to
> Gitlab-CI as it only appears to be covering x86, armhf and
> arm64 (although I did fix an armhf build issue a few weeks ago).
> 
>> A compile-tested-only fallback mechanism suggestion, and a bad spot
>> for placing the fallback functions:
> 
> Thanks, I agree that does look like a sustainable way forward.
> We don't quite have a MIPS platform to test that yet in KernelCI,
> so hopefully QEMU can be used to test a fallback implementation.
> 
> I guess adding placeholder functions as in your example with
> igt_assert_f() statements would just add some technical debt with
> little added benefit, so I'll work on a v2 with something that
> works.  Meanwhile we'll just skip i-g-t KernelCI builds on MIPS.
> 
>> diff --git a/meson.build b/meson.build
>> index 557400a5..0552e858 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -246,6 +246,9 @@ endif
>>  have = cc.has_function('memfd_create', prefix : '''#include 
>> ''', args : '-D_GNU_SOURCE')
>>  config.set10('HAVE_MEMFD_CREATE', have)
>>  
>> +have_atomics = cc.compiles('void f() { int x, y; __sync_add_and_fetch(, 
>> y); }')
>> +config.set10('HAVE_BUILTIN_ATOMICS', have_atomics)
>> +
>>  add_project_arguments('-D_GNU_SOURCE', language : 'c')
>>  add_project_arguments('-include', 'config.h', language : 'c')
>>  
>> diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
>> index 2a861ca8..615bb475 100644
>> --- a/tests/i915/gem_create.c
>> +++ b/tests/i915/gem_create.c
>> @@ -62,6 +62,18 @@ IGT_TEST_DESCRIPTION("This is a test for the extended & 
>> old gem_create ioctl,"
>>   &

[Intel-gfx] [PATCH i-g-t] gitlab-ci: add build for MIPS

2019-06-05 Thread Guillaume Tucker
Add Docker image and Gitlab CI steps to run builds for the MIPS
architecture using Debian Buster.

Signed-off-by: Guillaume Tucker 
---
 .gitlab-ci.yml | 28 
 Dockerfile.debian-mips | 38 ++
 meson-cross-mips.txt   | 12 
 3 files changed, 78 insertions(+)
 create mode 100644 Dockerfile.debian-mips
 create mode 100644 meson-cross-mips.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 771143a9ea95..e390f8f472d5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -90,6 +90,17 @@ build:tests-debian-meson-arm64:
 paths:
   - build
 
+build:tests-debian-meson-mips:
+  image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips:latest
+  stage: build
+  script:
+- export PKG_CONFIG_PATH=/usr/lib/mips-linux-gnu/pkgconfig/
+- meson --cross-file meson-cross-mips.txt build
+- ninja -C build
+  artifacts:
+paths:
+  - build
+
 build:tests-debian-autotools:
   image: $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian:latest
   stage: build
@@ -221,6 +232,23 @@ containers:igt-debian-arm64:
 - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64 -f 
Dockerfile.debian-arm64 .
 - docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-arm64
 
+containers:igt-debian-mips:
+  stage: containers
+  image: docker:stable
+  only:
+changes:
+  - Dockerfile.debian-mips
+  - .gitlab-ci.yml
+  services:
+- docker:dind
+  variables:
+DOCKER_HOST: tcp://docker:2375
+DOCKER_DRIVER: overlay2
+  script:
+- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
+- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips -f 
Dockerfile.debian-mips .
+- docker push $CI_REGISTRY/$CI_PROJECT_PATH/igt-debian-mips
+
 containers:igt-fedora:
   stage: containers
   image: docker:stable
diff --git a/Dockerfile.debian-mips b/Dockerfile.debian-mips
new file mode 100644
index ..2612b7b148e3
--- /dev/null
+++ b/Dockerfile.debian-mips
@@ -0,0 +1,38 @@
+FROM debian:buster
+
+RUN apt-get update
+RUN apt-get install -y \
+   flex \
+   bison \
+   pkg-config \
+   x11proto-dri2-dev \
+   python-docutils \
+   valgrind \
+   peg
+
+RUN dpkg --add-architecture mips
+RUN apt-get update
+RUN apt-get install -y \
+   gcc-mips-linux-gnu \
+   libpciaccess-dev:mips \
+   libkmod-dev:mips \
+   libprocps-dev:mips \
+   libunwind-dev:mips \
+   libdw-dev:mips \
+   zlib1g-dev:mips \
+   liblzma-dev:mips \
+   libcairo-dev:mips \
+   libpixman-1-dev:mips \
+   libudev-dev:mips \
+   libgsl-dev:mips \
+   libasound2-dev:mips \
+   libjson-c-dev:mips \
+   libcurl4-openssl-dev:mips \
+   libxrandr-dev:mips \
+   libxv-dev:mips
+
+RUN apt-get install -y \
+   meson \
+   libdrm-dev:mips \
+   qemu-user \
+   qemu-user-static
diff --git a/meson-cross-mips.txt b/meson-cross-mips.txt
new file mode 100644
index ..6350d677e0bc
--- /dev/null
+++ b/meson-cross-mips.txt
@@ -0,0 +1,12 @@
+[binaries]
+c = '/usr/bin/mips-linux-gnu-gcc'
+ar = '/usr/bin/mips-linux-gnu-gcc-ar'
+strip = '/usr/bin/mips-linux-gnu-strip'
+pkgconfig = 'pkg-config'
+exe_wrapper = 'qemu-mips'
+
+[host_machine]
+system = 'linux'
+cpu_family = 'mips'
+cpu = 'mips'
+endian = 'big'
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t 3/4] i915/gem_create: use __atomic_* instead of __sync_*

2019-06-03 Thread Guillaume Tucker
Replace calls to the older __sync_* functions with the new __atomic_*
standard ones.  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.

Signed-off-by: Guillaume Tucker 
---
 tests/Makefile.am   |  2 +-
 tests/i915/gem_create.c | 12 ++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5097debf629c..18a0f1f20592 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..a4aeb94b3f93 100644
--- a/tests/i915/gem_create.c
+++ b/tests/i915/gem_create.c
@@ -156,6 +156,14 @@ static void invalid_nonaligned_size(int fd)
gem_close(fd, create.handle);
 }
 
+static uint64_t atomic_compare_swap_u64(uint64_t *ptr, uint64_t oldval,
+   uint64_t newval)
+{
+   __atomic_compare_exchange_n(ptr, , newval, 0,
+   __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
+   return oldval;
+}
+
 static uint64_t get_npages(uint64_t *global, uint64_t npages)
 {
uint64_t try, old, max;
@@ -165,7 +173,7 @@ 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;
 }
@@ -202,7 +210,7 @@ static void *thread_clear(void *data)
}
gem_close(i915, create.handle);
 
-   __sync_add_and_fetch(>max, npages);
+   __atomic_add_fetch(>max, npages, __ATOMIC_SEQ_CST);
}
 
return NULL;
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t 4/4] tests/sw_sync: use __atomic_* instead of __sync_*

2019-06-03 Thread Guillaume Tucker
Replace calls to the older __sync_* functions with the new __atomic_*
standard ones to be consistent with other tests and improve
portability across CPU architectures.

Signed-off-by: Guillaume Tucker 
---
 tests/Makefile.am | 1 +
 tests/sw_sync.c   | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 18a0f1f20592..71514d4d2e5a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -121,6 +121,7 @@ prime_self_import_LDADD = $(LDADD) -lpthread
 gem_userptr_blits_CFLAGS = $(AM_CFLAGS) $(THREAD_CFLAGS)
 gem_userptr_blits_LDADD = $(LDADD) -lpthread
 perf_pmu_LDADD = $(LDADD) $(top_builddir)/lib/libigt_perf.la
+sw_sync_LDADD = $(LDADD) -latomic
 
 kms_flip_LDADD = $(LDADD) -lpthread
 
diff --git a/tests/sw_sync.c b/tests/sw_sync.c
index 950b8b614759..2ee1e1c60b32 100644
--- a/tests/sw_sync.c
+++ b/tests/sw_sync.c
@@ -517,7 +517,7 @@ static void test_sync_multi_consumer(void)
{
sem_wait();
 
-   __sync_fetch_and_add(, 1);
+   __atomic_fetch_add(, 1, __ATOMIC_SEQ_CST);
sw_sync_timeline_inc(timeline, 1);
}
 
@@ -554,7 +554,8 @@ static void * test_sync_multi_consumer_producer_thread(void 
*arg)
if (sync_fence_wait(fence, 1000) < 0)
return (void *) 1;
 
-   if (__sync_fetch_and_add(data->counter, 1) != next_point)
+   if (__atomic_fetch_add(data->counter, 1, __ATOMIC_SEQ_CST) !=
+   next_point)
return (void *) 1;
 
/* Kick off the next thread. */
@@ -900,4 +901,3 @@ igt_main
igt_subtest("sync_random_merge")
test_sync_random_merge();
 }
-
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t 2/4] gitlab-ci: add libatomic to Fedora docker image

2019-06-03 Thread Guillaume Tucker
Add libatomic to the Fedora docker image so it can link binaries that
use __atomic_* functions.

Signed-off-by: Guillaume Tucker 
---
 Dockerfile.fedora | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Dockerfile.fedora b/Dockerfile.fedora
index 6686e587613d..c84b412b0723 100644
--- a/Dockerfile.fedora
+++ b/Dockerfile.fedora
@@ -1,7 +1,7 @@
 FROM fedora:30
 
 RUN dnf install -y \
-   gcc flex bison meson ninja-build xdotool \
+   gcc flex bison libatomic meson ninja-build xdotool \
'pkgconfig(libdrm)' \
'pkgconfig(pciaccess)' \
'pkgconfig(libkmod)' \
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t 1/4] tests: add libatomic dependency

2019-06-03 Thread Guillaume Tucker
Add dependency to libatomic in order to be able to use the __atomic_*
functions instead of the older __sync_* ones.  This is to enable
atomic operations on a wider number of architectures including MIPS.

Signed-off-by: Guillaume Tucker 
---
 meson.build   | 1 +
 tests/meson.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 6268c58d3634..4e5bb323fa49 100644
--- a/meson.build
+++ b/meson.build
@@ -179,6 +179,7 @@ math = cc.find_library('m')
 realtime = cc.find_library('rt')
 dlsym = cc.find_library('dl')
 zlib = cc.find_library('z')
+libatomic = cc.find_library('atomic')
 
 if cc.has_header('linux/kd.h')
config.set('HAVE_LINUX_KD_H', 1)
diff --git a/tests/meson.build b/tests/meson.build
index 806766e51667..6877ccd59235 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -233,7 +233,7 @@ i915_progs = [
'i915_suspend',
 ]
 
-test_deps = [ igt_deps ]
+test_deps = [ igt_deps, libatomic ]
 
 if libdrm_nouveau.found()
test_progs += [
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t] i915/gem_create: Do not build create-clear for MIPS

2019-04-03 Thread Guillaume Tucker
On 02/04/2019 09:35, Petri Latvala wrote:
> On Mon, Apr 01, 2019 at 04:39:24PM +0200, Guillaume Tucker wrote:
>> The MIPS architecture doesn't provide the hardware atomics that are
>> required for the "create-clear" sub-test such as
>> __sync_add_and_fetch().  As a simple and pragmatic solution, disable
>> this sub-test when building for MIPS.  A better approach would be to
>> add a fallback implementation for these operations.
>>
>> Fixes: 6727e17c00b2 ("i915/gem_create: Verify that all new objects are 
>> clear")
>> Signed-off-by: Guillaume Tucker 
>> ---
>>  tests/i915/gem_create.c | 4 
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
>> index 2a861ca8a7ec..8a48496e6c19 100644
>> --- a/tests/i915/gem_create.c
>> +++ b/tests/i915/gem_create.c
>> @@ -142,6 +142,7 @@ static void invalid_nonaligned_size(int fd)
>>  gem_close(fd, handle);
>>  }
>>  
>> +#if !defined(__mips__) /* MIPS doesn't provide the required hardware 
>> atomics */
>>  static uint64_t get_npages(uint64_t *global, uint64_t npages)
>>  {
>>  uint64_t try, old, max;
>> @@ -208,6 +209,7 @@ static void always_clear(int i915, int timeout)
>>  for (int i = 0; i < ncpus; i++)
>>  pthread_join(thread[i], NULL);
>>  }
>> +#endif /* !defined(__mips__) */
>>  
>>  igt_main
>>  {
>> @@ -231,6 +233,8 @@ igt_main
>>  igt_subtest("create-invalid-nonaligned")
>>  invalid_nonaligned_size(fd);
>>  
>> +#if !defined(__mips__)
>>  igt_subtest("create-clear")
>>  always_clear(fd, 30);
>> +#endif
>>  }
> 
> 
> It's a bit ugly. I wonder how much work a fallback mechanism would be?

Sorry I should have sent this as RFC.

> The test is i915 specific and using those on non-x86 architectures
> sounds silly. We could limit building tests/i915/* only if
> host_machine.cpu_family() is x86 or x86_64. But that requires
> revisiting this issue if ever the day comes when i915 can be used on
> other architectures *cough*.

Right, I thought it might not be worth implementing fallback
functions if there is no MIPS hardware on which this test can be
run.  Still it would be a shame to leave i-g-t failing to build
on MIPS.

> Apropos, compile-testing on MIPS in gitlab-CI?

This issue was actually hit while building the KernelCI root file
system with i-g-t tests.  We're starting to add some MIPS
platforms, so running the generic DRM/KMS tests on them might
start to make sense at some point (cc khilman).

And yes I guess it seems worth considering adding MIPS to
Gitlab-CI as it only appears to be covering x86, armhf and
arm64 (although I did fix an armhf build issue a few weeks ago).

> A compile-tested-only fallback mechanism suggestion, and a bad spot
> for placing the fallback functions:

Thanks, I agree that does look like a sustainable way forward.
We don't quite have a MIPS platform to test that yet in KernelCI,
so hopefully QEMU can be used to test a fallback implementation.

I guess adding placeholder functions as in your example with
igt_assert_f() statements would just add some technical debt with
little added benefit, so I'll work on a v2 with something that
works.  Meanwhile we'll just skip i-g-t KernelCI builds on MIPS.

> diff --git a/meson.build b/meson.build
> index 557400a5..0552e858 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -246,6 +246,9 @@ endif
>  have = cc.has_function('memfd_create', prefix : '''#include ''', 
> args : '-D_GNU_SOURCE')
>  config.set10('HAVE_MEMFD_CREATE', have)
>  
> +have_atomics = cc.compiles('void f() { int x, y; __sync_add_and_fetch(, 
> y); }')
> +config.set10('HAVE_BUILTIN_ATOMICS', have_atomics)
> +
>  add_project_arguments('-D_GNU_SOURCE', language : 'c')
>  add_project_arguments('-include', 'config.h', language : 'c')
>  
> diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
> index 2a861ca8..615bb475 100644
> --- a/tests/i915/gem_create.c
> +++ b/tests/i915/gem_create.c
> @@ -62,6 +62,18 @@ IGT_TEST_DESCRIPTION("This is a test for the extended & 
> old gem_create ioctl,"
>" that includes allocation of object from stolen memory"
>" and shmem.");
>  
> +#if !HAVE_BUILTIN_ATOMICS
> +int __sync_add_and_fetch(void *ptr, uint64_t val)
> +{
> +  igt_assert_f(false, "Don't have builtin atomics\n");
> +}
> +
> +int __sync_val_compare_and_swap(void *ptr, uint64_t old, uint64_t new)
> +{
> +  igt_assert_f(false, "Don't have builtin atomics\n");
> +}
> +#endif
> +
>  #define CLEAR(s) memset(, 0, sizeof(s))
>  #define PAGE_SIZE 4096

Thanks,
Guillaume
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t] i915/gem_create: Do not build create-clear for MIPS

2019-04-01 Thread Guillaume Tucker
The MIPS architecture doesn't provide the hardware atomics that are
required for the "create-clear" sub-test such as
__sync_add_and_fetch().  As a simple and pragmatic solution, disable
this sub-test when building for MIPS.  A better approach would be to
add a fallback implementation for these operations.

Fixes: 6727e17c00b2 ("i915/gem_create: Verify that all new objects are clear")
Signed-off-by: Guillaume Tucker 
---
 tests/i915/gem_create.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c
index 2a861ca8a7ec..8a48496e6c19 100644
--- a/tests/i915/gem_create.c
+++ b/tests/i915/gem_create.c
@@ -142,6 +142,7 @@ static void invalid_nonaligned_size(int fd)
gem_close(fd, handle);
 }
 
+#if !defined(__mips__) /* MIPS doesn't provide the required hardware atomics */
 static uint64_t get_npages(uint64_t *global, uint64_t npages)
 {
uint64_t try, old, max;
@@ -208,6 +209,7 @@ static void always_clear(int i915, int timeout)
for (int i = 0; i < ncpus; i++)
pthread_join(thread[i], NULL);
 }
+#endif /* !defined(__mips__) */
 
 igt_main
 {
@@ -231,6 +233,8 @@ igt_main
igt_subtest("create-invalid-nonaligned")
invalid_nonaligned_size(fd);
 
+#if !defined(__mips__)
igt_subtest("create-clear")
always_clear(fd, 30);
+#endif
 }
-- 
2.20.1

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Intel-gfx] [PATCH i-g-t] i915/gem_ctx_sseu: Fix 32-bit build

2019-02-13 Thread Guillaume Tucker
This fixes a compiler warning treated as an error when building for
32-bit architectures since their pointer size does not match the size
of drm_i915_gem_context_param.value which is 64 bits:

  CC   i915/gem_ctx_sseu.o
  i915/gem_ctx_sseu.c: In function ‘test_ggtt_args’:
  i915/gem_ctx_sseu.c:384:9: error: cast to pointer from integer of different 
size [-Werror=int-to-pointer-cast]
munmap((void *)arg.value, 4096);

It was found while building for arm with gcc 6.3.0 and I suspect the
same problem would arise for i386 or other 32-bit architectures.  The
uintptr_t type is by definition an unsigned integer of the same length
as a pointer on a given architecture, so this should fix the problem
for all architectures up to 64 bits.

Signed-off-by: Guillaume Tucker 
---
 tests/i915/gem_ctx_sseu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/i915/gem_ctx_sseu.c b/tests/i915/gem_ctx_sseu.c
index 16609bee61c8..3afa5c152939 100644
--- a/tests/i915/gem_ctx_sseu.c
+++ b/tests/i915/gem_ctx_sseu.c
@@ -381,7 +381,7 @@ test_ggtt_args(int fd)
igt_assert_eq(__gem_context_get_param(fd, ), 0);
igt_assert_eq(__gem_context_set_param(fd, ), 0);
 
-   munmap((void *)arg.value, 4096);
+   munmap((void *)(uintptr_t)arg.value, 4096);
gem_close(fd, bo);
gem_context_destroy(fd, arg.ctx_id);
 }
-- 
2.11.0

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx