Re: [PATCH v2 1/7] selftest: sync: basic tests for sw_sync framework

2016-11-01 Thread Gustavo Padovan
Hi Emilio,

2016-10-19 Emilio López :

> These tests are based on the libsync test suite from Android.
> This commit lays the ground for future tests, as well as includes
> tests for a variety of basic allocation commands.
> 
> Signed-off-by: Emilio López 
> ---
>  tools/testing/selftests/Makefile  |   1 +
>  tools/testing/selftests/sync/.gitignore   |   1 +
>  tools/testing/selftests/sync/Makefile |  18 +++
>  tools/testing/selftests/sync/sw_sync.h|  46 +++
>  tools/testing/selftests/sync/sync.c   | 221 
> ++
>  tools/testing/selftests/sync/sync.h   |  40 ++
>  tools/testing/selftests/sync/sync_alloc.c |  74 ++
>  tools/testing/selftests/sync/sync_test.c  |  71 ++
>  tools/testing/selftests/sync/synctest.h   |  47 +++
>  9 files changed, 519 insertions(+)
>  create mode 100644 tools/testing/selftests/sync/.gitignore
>  create mode 100644 tools/testing/selftests/sync/Makefile
>  create mode 100644 tools/testing/selftests/sync/sw_sync.h
>  create mode 100644 tools/testing/selftests/sync/sync.c
>  create mode 100644 tools/testing/selftests/sync/sync.h
>  create mode 100644 tools/testing/selftests/sync/sync_alloc.c
>  create mode 100644 tools/testing/selftests/sync/sync_test.c
>  create mode 100644 tools/testing/selftests/sync/synctest.h
> 
> diff --git a/tools/testing/selftests/Makefile 
> b/tools/testing/selftests/Makefile
> index f770dba..69cf1a6 100644
> --- a/tools/testing/selftests/Makefile
> +++ b/tools/testing/selftests/Makefile
> @@ -23,6 +23,7 @@ TARGETS += seccomp
>  TARGETS += sigaltstack
>  TARGETS += size
>  TARGETS += static_keys
> +TARGETS += sync
>  TARGETS += sysctl
>  ifneq (1, $(quicktest))
>  TARGETS += timers
> diff --git a/tools/testing/selftests/sync/.gitignore 
> b/tools/testing/selftests/sync/.gitignore
> new file mode 100644
> index 000..f5091e7
> --- /dev/null
> +++ b/tools/testing/selftests/sync/.gitignore
> @@ -0,0 +1 @@
> +sync_test
> diff --git a/tools/testing/selftests/sync/Makefile 
> b/tools/testing/selftests/sync/Makefile
> new file mode 100644
> index 000..620a59a
> --- /dev/null
> +++ b/tools/testing/selftests/sync/Makefile
> @@ -0,0 +1,18 @@
> +CFLAGS += -O2 -g -std=gnu89 -pthread -Wall -Wextra
> +CFLAGS += -I../../../../usr/include/
> +LDFLAGS += -pthread
> +
> +TEST_PROGS = sync_test
> +
> +all: $(TEST_PROGS)
> +
> +include ../lib.mk
> +
> +OBJS = sync_test.o sync.o
> +
> +TESTS += sync_alloc.o
> +
> +sync_test: $(OBJS) $(TESTS)
> +
> +clean:
> + $(RM) sync_test $(OBJS) $(TESTS)
> diff --git a/tools/testing/selftests/sync/sw_sync.h 
> b/tools/testing/selftests/sync/sw_sync.h
> new file mode 100644
> index 000..e2cfc6ba
> --- /dev/null
> +++ b/tools/testing/selftests/sync/sw_sync.h
> @@ -0,0 +1,46 @@
> +/*
> + *  sw_sync abstraction
> + *
> + *  Copyright 2015-2016 Collabora Ltd.
> + *
> + *  Based on the implementation from the Android Open Source Project,
> + *
> + *  Copyright 2013 Google, Inc
> + *
> + *  Permission is hereby granted, free of charge, to any person obtaining a
> + *  copy of this software and associated documentation files (the 
> "Software"),
> + *  to deal in the Software without restriction, including without limitation
> + *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + *  and/or sell copies of the Software, and to permit persons to whom the
> + *  Software is furnished to do so, subject to the following conditions:
> + *
> + *  The above copyright notice and this permission notice shall be included 
> in
> + *  all copies or substantial portions of the Software.
> + *
> + *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
> OR
> + *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + *  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + *  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + *  OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef SELFTESTS_SW_SYNC_H
> +#define SELFTESTS_SW_SYNC_H
> +
> +/*
> + * sw_sync is mainly intended for testing and should not be compiled into
> + * production kernels
> + */
> +
> +int sw_sync_timeline_create(void);
> +int sw_sync_timeline_is_valid(int fd);
> +int sw_sync_timeline_inc(int fd, unsigned int count);
> +void sw_sync_timeline_destroy(int fd);
> +
> +int sw_sync_fence_create(int fd, const char *name, unsigned int value);
> +int sw_sync_fence_is_valid(int fd);
> +void sw_sync_fence_destroy(int fd);
> +
> +#endif
> diff --git a/tools/testing/selftests/sync/sync.c 
> b/tools/testing/selftests/sync/sync.c
> new file mode 100644
> index 000..f3d599f
> --- /dev/null
> +++ b/tools/testing/selftests/sync/sync.c
> @@ -0,0 +1,221 @@
> +/*
> + *  sync / sw_sync abstraction
> + *  Copyright 2015-2016 Collabora Ltd.
> + *
> + *  Base

[PATCH] staging/android: add Doc for SW_SYNC ioctl interface

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

This interface is hidden from kernel headers and it is intended for use
only for testing. So testers would have to add the ioctl information
internally. This is to prevent misuse of this feature.

v2: take in Eric suggestions for the Documentation

v3: really take in Eric suggestions

Signed-off-by: Gustavo Padovan 
Reviewed-by: Eric Engestrom 
---
 drivers/staging/android/sw_sync.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 039e1f4..62e8e6d 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,6 +25,36 @@
 #define CREATE_TRACE_POINTS
 #include "sync_trace.h"
 
+/*
+ * SW SYNC validation framework
+ *
+ * A sync object driver that uses a 32bit counter to coordinate
+ * synchronization.  Useful when there is no hardware primitive backing
+ * the synchronization.
+ *
+ * To start the framework just open:
+ *
+ * /sync/sw_sync
+ *
+ * That will create a sync timeline, all fences created under this timeline
+ * file descriptor will belong to the this timeline.
+ *
+ * The 'sw_sync' file can be opened many times as to create different
+ * timelines.
+ *
+ * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct
+ * sw_sync_ioctl_create_fence as parameter.
+ *
+ * To increment the timeline counter, SW_SYNC_IOC_INC ioctl should be used
+ * with the increment as u32. This will update the last signaled value
+ * from the timeline and signal any fence that has a seqno smaller or equal
+ * to it.
+ *
+ * struct sw_sync_ioctl_create_fence
+ * @value: the seqno to initialise the fence with
+ * @name:  the name of the new sync point
+ * @fence: return the fd of the new sync_file with the created fence
+ */
 struct sw_sync_create_fence_data {
__u32   value;
charname[32];
@@ -35,6 +65,7 @@ struct sw_sync_create_fence_data {
 
 #define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
struct sw_sync_create_fence_data)
+
 #define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
 
 static const struct fence_ops timeline_fence_ops;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v3 4/5] staging/android: add Doc for SW_SYNC ioctl interface

2016-08-11 Thread Gustavo Padovan
2016-08-11 Eric Engestrom :

> On Thu, Aug 11, 2016 at 12:26:43PM -0300, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > This interface is hidden from kernel headers and it is intended for use
> > only for testing. So testers would have to add the ioctl information
> > internally. This is to prevent misuse of this feature.
> > 
> > v2: take in Eric suggestions for the Documentation
> > 
> > Signed-off-by: Gustavo Padovan 
> > Reviewed-by: Eric Engestrom 
> > ---
> >  drivers/staging/android/sw_sync.c | 31 +++
> >  1 file changed, 31 insertions(+)
> > 
> > diff --git a/drivers/staging/android/sw_sync.c 
> > b/drivers/staging/android/sw_sync.c
> > index 039e1f4..498ab55 100644
> > --- a/drivers/staging/android/sw_sync.c
> > +++ b/drivers/staging/android/sw_sync.c
> > @@ -25,6 +25,36 @@
> >  #define CREATE_TRACE_POINTS
> >  #include "sync_trace.h"
> >  
> > +/*
> > + * SW SYNC validation framework
> > + *
> > + * A sync object driver that uses a 32bit counter to coordinate
> > + * synchronization.  Useful when there is no hardware primitive backing
> > + * the synchronization.
> > + *
> > + * To start the framework just open:
> > + *
> > + * /sync/sw_sync
> > + *
> > + * That will create a sync timeline, all fences created under this timeline
> > + * file descriptor will belong to the this timeline.
> > + *
> > + * The 'sw_sync' file can be opened many times as to create different
> > + * timelines.
> > + *
> > + * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct
> > + * sw_sync_ioctl_create_fence as parameter.
> > + *
> > + * To increment the timeline counter, SW_SYNC_IOC_INC ioctl should be used
> > + * with the increment as u32. This will update the last signaled value
> > + * from the timeline and signal any fence that has seqno smaller of equal
> > + * it.
> 
> You didn't fix all of it: "that has a seqno smaller or equal to it."
> Missing "a" (just noticed), s/of/or/, and missing "to"  :)

Oh. Right. I didn't pay attention to all your fixes in that phrase.
Thanks. I'll send an updated patch.

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 3/5] staging/android: prepare sw_sync files for de-staging

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

remove file paths in the comments and add short description about each
file.

v2: remove file paths instead of just change them.

v3: improve header description as sugggested by Eric

Signed-off-by: Gustavo Padovan 
Reviewed-by: Eric Engestrom 
---
 drivers/staging/android/sw_sync.c| 2 +-
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_debug.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 92c1f8b..039e1f4 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -1,5 +1,5 @@
 /*
- * drivers/dma-buf/sw_sync.c
+ * Sync File validation framework
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 4c5a855..fab9520 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -1,5 +1,5 @@
 /*
- * drivers/base/sync.c
+ * Sync File validation framework and debug information
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index fab6639..d269aa6 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -1,5 +1,5 @@
 /*
- * include/linux/sync.h
+ * Sync File validation framework and debug infomation
  *
  * Copyright (C) 2012 Google, Inc.
  *
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 2/5] staging/android: move trace/sync.h to sync_trace.h

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

The common behaviour for trace headers is to have them in the same folder
they are used, instead of creating a special trace/ directory.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Eric Engestrom 
---
 drivers/staging/android/sw_sync.c  | 2 +-
 drivers/staging/android/{trace/sync.h => sync_trace.h} | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/staging/android/{trace/sync.h => sync_trace.h} (84%)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index bda1f6a..92c1f8b 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -23,7 +23,7 @@
 #include "sync_debug.h"
 
 #define CREATE_TRACE_POINTS
-#include "trace/sync.h"
+#include "sync_trace.h"
 
 struct sw_sync_create_fence_data {
__u32   value;
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/android/sync_trace.h
similarity index 84%
rename from drivers/staging/android/trace/sync.h
rename to drivers/staging/android/sync_trace.h
index 6b5ce96..ea485f7 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/sync_trace.h
@@ -1,11 +1,11 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
-#define TRACE_SYSTEM sync
+#define TRACE_INCLUDE_PATH ../../drivers/staging/android
+#define TRACE_SYSTEM sync_trace
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_SYNC_H
 
-#include "../sync_debug.h"
+#include "sync_debug.h"
 #include 
 
 TRACE_EVENT(sync_timeline,
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 4/5] staging/android: add Doc for SW_SYNC ioctl interface

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

This interface is hidden from kernel headers and it is intended for use
only for testing. So testers would have to add the ioctl information
internally. This is to prevent misuse of this feature.

v2: take in Eric suggestions for the Documentation

Signed-off-by: Gustavo Padovan 
Reviewed-by: Eric Engestrom 
---
 drivers/staging/android/sw_sync.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 039e1f4..498ab55 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,6 +25,36 @@
 #define CREATE_TRACE_POINTS
 #include "sync_trace.h"
 
+/*
+ * SW SYNC validation framework
+ *
+ * A sync object driver that uses a 32bit counter to coordinate
+ * synchronization.  Useful when there is no hardware primitive backing
+ * the synchronization.
+ *
+ * To start the framework just open:
+ *
+ * /sync/sw_sync
+ *
+ * That will create a sync timeline, all fences created under this timeline
+ * file descriptor will belong to the this timeline.
+ *
+ * The 'sw_sync' file can be opened many times as to create different
+ * timelines.
+ *
+ * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct
+ * sw_sync_ioctl_create_fence as parameter.
+ *
+ * To increment the timeline counter, SW_SYNC_IOC_INC ioctl should be used
+ * with the increment as u32. This will update the last signaled value
+ * from the timeline and signal any fence that has seqno smaller of equal
+ * it.
+ *
+ * struct sw_sync_ioctl_create_fence
+ * @value: the seqno to initialise the fence with
+ * @name:  the name of the new sync point
+ * @fence: return the fd of the new sync_file with the created fence
+ */
 struct sw_sync_create_fence_data {
__u32   value;
charname[32];
@@ -35,6 +65,7 @@ struct sw_sync_create_fence_data {
 
 #define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
struct sw_sync_create_fence_data)
+
 #define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
 
 static const struct fence_ops timeline_fence_ops;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 5/5] dma-buf/sw_sync: de-stage SW_SYNC

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC allows to run tests on the sync_file framework via debugfs on

/sync/sw_sync

Opening and closing the file triggers creation and release of a sync
timeline. To create fences on this timeline the SW_SYNC_IOC_CREATE_FENCE
ioctl should be used. To increment the timeline value use SW_SYNC_IOC_INC.

Also it exports Sync information on

/sync/info

Signed-off-by: Gustavo Padovan 
Reviewed-by: Eric Engestrom 
---
 drivers/dma-buf/Kconfig   | 13 +
 drivers/dma-buf/Makefile  |  1 +
 drivers/{staging/android => dma-buf}/sw_sync.c|  0
 drivers/{staging/android => dma-buf}/sync_debug.c |  0
 drivers/{staging/android => dma-buf}/sync_debug.h |  0
 drivers/{staging/android => dma-buf}/sync_trace.h |  2 +-
 drivers/staging/android/Kconfig   | 13 -
 drivers/staging/android/Makefile  |  1 -
 8 files changed, 15 insertions(+), 15 deletions(-)
 rename drivers/{staging/android => dma-buf}/sw_sync.c (100%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (100%)
 rename drivers/{staging/android => dma-buf}/sync_debug.h (100%)
 rename drivers/{staging/android => dma-buf}/sync_trace.h (92%)

diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index 25bcfa0..2585821 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -17,4 +17,17 @@ config SYNC_FILE
  Files fds, to the DRM driver for example. More details at
  Documentation/sync_file.txt.
 
+config SW_SYNC
+   bool "Sync File Validation Framework"
+   default n
+   depends on SYNC_FILE
+   depends on DEBUG_FS
+   ---help---
+ A sync object driver that uses a 32bit counter to coordinate
+ synchronization.  Useful when there is no hardware primitive backing
+ the synchronization.
+
+ WARNING: improper use of this can result in deadlocking kernel
+ drivers from userspace. Intended for test and debug only.
+
 endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index f353db2..210a10b 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,2 +1,3 @@
 obj-y := dma-buf.o fence.o reservation.o seqno-fence.o fence-array.o
 obj-$(CONFIG_SYNC_FILE)+= sync_file.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/dma-buf/sw_sync.c
similarity index 100%
rename from drivers/staging/android/sw_sync.c
rename to drivers/dma-buf/sw_sync.c
diff --git a/drivers/staging/android/sync_debug.c b/drivers/dma-buf/sync_debug.c
similarity index 100%
rename from drivers/staging/android/sync_debug.c
rename to drivers/dma-buf/sync_debug.c
diff --git a/drivers/staging/android/sync_debug.h b/drivers/dma-buf/sync_debug.h
similarity index 100%
rename from drivers/staging/android/sync_debug.h
rename to drivers/dma-buf/sync_debug.h
diff --git a/drivers/staging/android/sync_trace.h b/drivers/dma-buf/sync_trace.h
similarity index 92%
rename from drivers/staging/android/sync_trace.h
rename to drivers/dma-buf/sync_trace.h
index ea485f7..d13d59f 100644
--- a/drivers/staging/android/sync_trace.h
+++ b/drivers/dma-buf/sync_trace.h
@@ -1,5 +1,5 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android
+#define TRACE_INCLUDE_PATH ../../drivers/dma-buf
 #define TRACE_SYSTEM sync_trace
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 06e41d2..6c00d6f 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -24,19 +24,6 @@ config ANDROID_LOW_MEMORY_KILLER
  scripts (/init.rc), and it defines priority values with minimum free 
memory size
  for each priority.
 
-config SW_SYNC
-   bool "Software synchronization framework"
-   default n
-   depends on SYNC_FILE
-   depends on DEBUG_FS
-   ---help---
- A sync object driver that uses a 32bit counter to coordinate
- synchronization.  Useful when there is no hardware primitive backing
- the synchronization.
-
- WARNING: improper use of this can result in deadlocking kernel
- drivers from userspace. Intended for test and debug only.
-
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 7ca61b7..7ed1be7 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,4 +4,3 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproje

[PATCH v3 0/5] de-stage SW_SYNC validation frawework

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi Greg,

This is the last step in the Sync Framwork de-stage task. It de-stage
the SW_SYNC validation framework and the sync_debug info debugfs file.

The first 2 patches are clean up and improvements and the rest is preparation
to de-stage and then finally the actual de-stage.

v2:
 - add documentation about the SW_SYNC ioctl API (comments from Pavel Machek)
 - remove for now patch to add sync_pt name to debugfs

v3:
 - doc improvements (comments from Eric Engestrom)
 - remove patch that removes documentation (comments from Pavel Machek)

Gustavo Padovan (5):
  staging/android: do not let userspace trigger WARN_ON
  staging/android: move trace/sync.h to sync_trace.h
  staging/android: prepare sw_sync files for de-staging
  staging/android: add Doc for SW_SYNC ioctl interface
  dma-buf/sw_sync: de-stage SW_SYNC

 drivers/dma-buf/Kconfig| 13 
 drivers/dma-buf/Makefile   |  1 +
 drivers/{staging/android => dma-buf}/sw_sync.c | 37 --
 drivers/{staging/android => dma-buf}/sync_debug.c  |  2 +-
 drivers/{staging/android => dma-buf}/sync_debug.h  |  2 +-
 .../android/trace/sync.h => dma-buf/sync_trace.h}  |  6 ++--
 drivers/staging/android/Kconfig| 13 
 drivers/staging/android/Makefile   |  1 -
 8 files changed, 53 insertions(+), 22 deletions(-)
 rename drivers/{staging/android => dma-buf}/sw_sync.c (87%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (99%)
 rename drivers/{staging/android => dma-buf}/sync_debug.h (97%)
 rename drivers/{staging/android/trace/sync.h => dma-buf/sync_trace.h} (84%)

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 1/5] staging/android: do not let userspace trigger WARN_ON

2016-08-11 Thread Gustavo Padovan
From: Gustavo Padovan 

Closing the timeline without waiting all fences to signal is not
a critical failure, it is just bad usage from userspace so avoid
calling WARN_ON in this case.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 115c917..bda1f6a 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -176,7 +176,7 @@ static void timeline_fence_release(struct fence *fence)
 
spin_lock_irqsave(fence->lock, flags);
list_del(&pt->child_list);
-   if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+   if (!list_empty(&pt->active_list))
list_del(&pt->active_list);
spin_unlock_irqrestore(fence->lock, flags);
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 0/6] de-stage SW_SYNC validation frawework

2016-08-11 Thread Gustavo Padovan
Hi Eric,

2016-08-11 Eric Engestrom :

> On Mon, Aug 08, 2016 at 06:24:16PM -0300, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > Hi Greg,
> > 
> > This is the last step in the Sync Framwork de-stage task. It de-stage
> > the SW_SYNC validation framework and the sync_debug info debugfs file.
> > 
> > The first 2 patches are clean up and improvements and the rest is 
> > preparation
> > to de-stage and then finally the actual de-stage.
> > 
> > v2: 
> >  - add documentation about the SW_SYNC ioctl API (comments from Pavel 
> > Machek)
> >  - remove for now patch to add sync_pt name to debugfs
> > 
> > Please review,
> > 
> > Gustavo
> > 
> > ---
> > Gustavo Padovan (6):
> >   staging/android: remove doc from sw_sync
> >   staging/android: do not let userspace trigger WARN_ON
> >   staging/android: move trace/sync.h to sync_trace.h
> >   staging/android: prepare sw_sync files for de-staging
> >   staging/android: add Doc for SW_SYNC ioctl interface
> >   dma-buf/sw_sync: de-stage SW_SYNC
> > 
> >  drivers/dma-buf/Kconfig  |  13 ++
> >  drivers/dma-buf/Makefile |   1 +
> >  drivers/dma-buf/sw_sync.c| 349 
> > +++
> >  drivers/dma-buf/sync_debug.c | 230 +++
> >  drivers/dma-buf/sync_debug.h |  69 +++
> >  drivers/dma-buf/sync_trace.h |  32 
> >  drivers/staging/android/Kconfig  |  13 --
> >  drivers/staging/android/Makefile |   1 -
> >  drivers/staging/android/sw_sync.c| 344 
> > --
> >  drivers/staging/android/sync_debug.c | 230 ---
> >  drivers/staging/android/sync_debug.h |  84 -
> >  drivers/staging/android/trace/sync.h |  32 
> >  12 files changed, 694 insertions(+), 704 deletions(-)
> 
> >  create mode 100644 drivers/dma-buf/sw_sync.c
> >  create mode 100644 drivers/dma-buf/sync_debug.c
> >  create mode 100644 drivers/dma-buf/sync_debug.h
> >  create mode 100644 drivers/dma-buf/sync_trace.h
> >  delete mode 100644 drivers/staging/android/sw_sync.c
> >  delete mode 100644 drivers/staging/android/sync_debug.c
> >  delete mode 100644 drivers/staging/android/sync_debug.h
> >  delete mode 100644 drivers/staging/android/trace/sync.h
> 
> When you send your next revision, could you use `git format-patch -M`?
> A good 95% of the lines in these patches aren't actually modified, just
> moved around, which makes it much harder to spot the actual changes :)

Sure, I was doing this for previous revisions, but forgot to do it for
this one.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH v2 1/6] staging/android: remove doc from sw_sync

2016-08-11 Thread Gustavo Padovan
Hi Pavel,

2016-08-09 Pavel Machek :

> On Mon 2016-08-08 18:24:17, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > SW_SYNC should never be used by other pieces of the kernel apart from
> > sync_debug as it is only a Sync File Validation Framework, so hide any
> > info to avoid confuse this with a standard kernel internal API.
> 
> > Signed-off-by: Gustavo Padovan 
> 
> NAK.
> 
> It is unclear for what the code does, removing the docs is not going to help.
> 
> If it should not be used, document that it should not be used.. but not remove
> the docs.

Okay, I'll skip this patch.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/7] staging/android: display sync_pt name on debugfs

2016-08-09 Thread Gustavo Padovan
2016-08-09 Maarten Lankhorst :

> Op 08-08-16 om 21:59 schreef Gustavo Padovan:
> > 2016-08-08 Maarten Lankhorst :
> >
> >> Op 20-06-16 om 17:53 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan 
> >>>
> >>> When creating a sync_pt the name received wasn't used anywhere.
> >>> Now we add it to the sync info debug output to make it easier to indetify
> >>> the userspace name of that sync pt.
> >>>
> >>> Signed-off-by: Gustavo Padovan 
> >>> ---
> >>>  drivers/staging/android/sw_sync.c| 16 
> >>>  drivers/staging/android/sync_debug.c |  5 +++--
> >>>  drivers/staging/android/sync_debug.h |  9 +
> >>>  3 files changed, 16 insertions(+), 14 deletions(-)
> >>>
> >>> diff --git a/drivers/staging/android/sw_sync.c 
> >>> b/drivers/staging/android/sw_sync.c
> >>> index b4ae092..ea27512 100644
> >>> --- a/drivers/staging/android/sw_sync.c
> >>> +++ b/drivers/staging/android/sw_sync.c
> >>> @@ -37,15 +37,6 @@ struct sw_sync_create_fence_data {
> >>>   struct sw_sync_create_fence_data)
> >>>  #define SW_SYNC_IOC_INC  _IOW(SW_SYNC_IOC_MAGIC, 1, 
> >>> __u32)
> >>>  
> >>> -static const struct fence_ops timeline_fence_ops;
> >>> -
> >>> -static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
> >>> -{
> >>> - if (fence->ops != &timeline_fence_ops)
> >>> - return NULL;
> >>> - return container_of(fence, struct sync_pt, base);
> >>> -}
> >>> -
> >>>  struct sync_timeline *sync_timeline_create(const char *name)
> >>>  {
> >>>   struct sync_timeline *obj;
> >>> @@ -108,7 +99,7 @@ static void sync_timeline_signal(struct sync_timeline 
> >>> *obj, unsigned int inc)
> >>>  }
> >>>  
> >>>  static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int 
> >>> size,
> >>> -  unsigned int value)
> >>> +  unsigned int value, char *name)
> >>>  {
> >>>   unsigned long flags;
> >>>   struct sync_pt *pt;
> >>> @@ -120,6 +111,7 @@ static struct sync_pt *sync_pt_create(struct 
> >>> sync_timeline *obj, int size,
> >>>   if (!pt)
> >>>   return NULL;
> >>>  
> >>> + strlcpy(pt->name, name, sizeof(pt->name));
> >>>   spin_lock_irqsave(&obj->child_list_lock, flags);
> >>>   sync_timeline_get(obj);
> >>>   fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
> >>> @@ -191,7 +183,7 @@ static void timeline_fence_timeline_value_str(struct 
> >>> fence *fence,
> >>>   snprintf(str, size, "%d", parent->value);
> >>>  }
> >>>  
> >>> -static const struct fence_ops timeline_fence_ops = {
> >>> +const struct fence_ops timeline_fence_ops = {
> >>>   .get_driver_name = timeline_fence_get_driver_name,
> >>>   .get_timeline_name = timeline_fence_get_timeline_name,
> >>>   .enable_signaling = timeline_fence_enable_signaling,
> >>> @@ -252,7 +244,7 @@ static long sw_sync_ioctl_create_fence(struct 
> >>> sync_timeline *obj,
> >>>   goto err;
> >>>   }
> >>>  
> >>> - pt = sync_pt_create(obj, sizeof(*pt), data.value);
> >>> + pt = sync_pt_create(obj, sizeof(*pt), data.value, data.name);
> >>>   if (!pt) {
> >>>   err = -ENOMEM;
> >>>   goto err;
> >>> diff --git a/drivers/staging/android/sync_debug.c 
> >>> b/drivers/staging/android/sync_debug.c
> >>> index 4c5a855..b732ea3 100644
> >>> --- a/drivers/staging/android/sync_debug.c
> >>> +++ b/drivers/staging/android/sync_debug.c
> >>> @@ -75,13 +75,14 @@ static void sync_print_fence(struct seq_file *s, 
> >>> struct fence *fence, bool show)
> >>>  {
> >>>   int status = 1;
> >>>   struct sync_timeline *parent = fence_parent(fence);
> >>> + struct sync_pt *pt = fence_to_sync_pt(fence);
> >>>  
> >>>   if (fence_is_signaled_locked(fence))
> >>>   status = fence->status;
> >>>  
> >>> - seq_printf(s, "  %s%sfence %s",
> >>> + seq_printf(s, "  %s%sfence %s %s",
> >>>  show ? parent->name : "",
> >>> -show ? "_" : "",
> >>> +show ? "_" : "", pt->name,
> >>>  sync_status_str(status));
> >>>  
> >> NAK,
> >> A fence in sync_print_fence can be of any type. If you want to print the 
> >> name, use the fence_value_str callback.
> > Indeed. But fence_value_str doesn't return the sync_pt name, but the
> > seqno of that fence. I'll keep this change out for the de-staging and
> > then try to come with something that works better.
> >
> > Gustavo
> 
> This will probably cause a kernel panic if you keep it like it is and you 
> look at
> debugfs for non sync_pt fences, it should definitely be fixed before 
> destaging.
> Ignoring sync_pt name would be better than crashing.

No, I meant ignoring sync_pt name for now. I've already sent v2 without
it.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 5/6] staging/android: add Doc for SW_SYNC ioctl interface

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

This interface is hidden from kernel headers and it is intended for use
only for testing. So testers would have to add the ioctl information
internally. This is to prevent misuse of this feature.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 43491b6..2ac5608 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,6 +25,36 @@
 #define CREATE_TRACE_POINTS
 #include "sync_trace.h"
 
+/*
+ * SW SYNC validation framework
+ *
+ * A sync object driver that uses a 32bit counter to coordinate
+ * synchronization.  Useful when there is no hardware primitive backing
+ * the synchronization.
+ *
+ * To start the framework just open:
+ *
+ * /sync/sw_sync
+ *
+ * That will create a sync timeline, all fences created under this timeline
+ * file descriptor will belong to the this timeline.
+ *
+ * The 'sw_sync' file can be opened many times as to create different
+ * timelines.
+ *
+ * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct
+ * sw_sync_ioctl_create_fence as parameter.
+ *
+ * To increment the timeline counter SW_SYNC_IOC_INC ioctl should be used
+ * with the increment as u32. This will update the last signaled value
+ * from the timeline and signal any fence that has seqno, smaller of equal
+ * it.
+ *
+ * struct sw_sync_ioctl_create_fence
+ * @value: the seqno to initiate the fence with
+ * @name:  the name of the new sync point
+ * @fence: return the fd of the new sync_file with the created fence
+ */
 struct sw_sync_create_fence_data {
__u32   value;
charname[32];
@@ -35,6 +65,7 @@ struct sw_sync_create_fence_data {
 
 #define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
struct sw_sync_create_fence_data)
+
 #define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
 
 static const struct fence_ops timeline_fence_ops;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 6/6] dma-buf/sw_sync: de-stage SW_SYNC

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC allows to run tests on the sync_file framework via debugfs on

/sync/sw_sync

Opening and closing the file triggers creation and release of a sync
timeline. To create fences on this timeline the SW_SYNC_IOC_CREATE_FENCE
ioctl should be used. To increment the timeline value use SW_SYNC_IOC_INC.

Also it exports Sync information on

/sync/info

Signed-off-by: Gustavo Padovan 
---
 drivers/dma-buf/Kconfig  |  13 ++
 drivers/dma-buf/Makefile |   1 +
 drivers/dma-buf/sw_sync.c| 349 +++
 drivers/dma-buf/sync_debug.c | 230 +++
 drivers/dma-buf/sync_debug.h |  69 +++
 drivers/dma-buf/sync_trace.h |  32 
 drivers/staging/android/Kconfig  |  13 --
 drivers/staging/android/Makefile |   1 -
 drivers/staging/android/sw_sync.c| 349 ---
 drivers/staging/android/sync_debug.c | 230 ---
 drivers/staging/android/sync_debug.h |  69 ---
 drivers/staging/android/sync_trace.h |  32 
 12 files changed, 694 insertions(+), 694 deletions(-)
 create mode 100644 drivers/dma-buf/sw_sync.c
 create mode 100644 drivers/dma-buf/sync_debug.c
 create mode 100644 drivers/dma-buf/sync_debug.h
 create mode 100644 drivers/dma-buf/sync_trace.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/sync_debug.h
 delete mode 100644 drivers/staging/android/sync_trace.h

diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index 25bcfa0..2585821 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -17,4 +17,17 @@ config SYNC_FILE
  Files fds, to the DRM driver for example. More details at
  Documentation/sync_file.txt.
 
+config SW_SYNC
+   bool "Sync File Validation Framework"
+   default n
+   depends on SYNC_FILE
+   depends on DEBUG_FS
+   ---help---
+ A sync object driver that uses a 32bit counter to coordinate
+ synchronization.  Useful when there is no hardware primitive backing
+ the synchronization.
+
+ WARNING: improper use of this can result in deadlocking kernel
+ drivers from userspace. Intended for test and debug only.
+
 endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index f353db2..210a10b 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,2 +1,3 @@
 obj-y := dma-buf.o fence.o reservation.o seqno-fence.o fence-array.o
 obj-$(CONFIG_SYNC_FILE)+= sync_file.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
new file mode 100644
index 000..2ac5608
--- /dev/null
+++ b/drivers/dma-buf/sw_sync.c
@@ -0,0 +1,349 @@
+/*
+ * Sync File validation framework
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sync_debug.h"
+
+#define CREATE_TRACE_POINTS
+#include "sync_trace.h"
+
+/*
+ * SW SYNC validation framework
+ *
+ * A sync object driver that uses a 32bit counter to coordinate
+ * synchronization.  Useful when there is no hardware primitive backing
+ * the synchronization.
+ *
+ * To start the framework just open:
+ *
+ * /sync/sw_sync
+ *
+ * That will create a sync timeline, all fences created under this timeline
+ * file descriptor will belong to the this timeline.
+ *
+ * The 'sw_sync' file can be opened many times as to create different
+ * timelines.
+ *
+ * Fences can be created with SW_SYNC_IOC_CREATE_FENCE ioctl with struct
+ * sw_sync_ioctl_create_fence as parameter.
+ *
+ * To increment the timeline counter SW_SYNC_IOC_INC ioctl should be used
+ * with the increment as u32. This will update the last signaled value
+ * from the timeline and signal any fence that has seqno, smaller of equal
+ * it.
+ *
+ * struct sw_sync_ioctl_create_fence
+ * @value: the seqno to initiate the fence with
+ * @name:  the name of the new sync point
+ * @fence: return the fd of the new sync_file with the created fence
+ */
+struct sw_sync_create_fence_data {
+   __u32   value;
+   charname[32];
+   __s32   fence; /* fd of new fence */
+};
+
+#define SW_SYNC_IOC_MAGIC  'W'
+
+#define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+   struct sw_

[PATCH v2 4/6] staging/android: prepare sw_sync files for de-staging

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

remove file paths in the comments and add short description about each
file.

v2: remove file paths instead of just change them.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 2 +-
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_debug.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 745597b..43491b6 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -1,5 +1,5 @@
 /*
- * drivers/dma-buf/sw_sync.c
+ * Sync File validation framework
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 4c5a855..fab9520 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -1,5 +1,5 @@
 /*
- * drivers/base/sync.c
+ * Sync File validation framework and debug information
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index 5b82cf8..ee3c27b 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -1,5 +1,5 @@
 /*
- * include/linux/sync.h
+ * Sync File validation framework
  *
  * Copyright (C) 2012 Google, Inc.
  *
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/6] staging/android: move trace/sync.h to sync_trace.h

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

The common behaviour for trace headers is to have them in the same folder
they are used, instead of creating a special trace/ directory.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c|  2 +-
 drivers/staging/android/sync_trace.h | 32 
 drivers/staging/android/trace/sync.h | 32 
 3 files changed, 33 insertions(+), 33 deletions(-)
 create mode 100644 drivers/staging/android/sync_trace.h
 delete mode 100644 drivers/staging/android/trace/sync.h

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index ad0bb1a..745597b 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -23,7 +23,7 @@
 #include "sync_debug.h"
 
 #define CREATE_TRACE_POINTS
-#include "trace/sync.h"
+#include "sync_trace.h"
 
 struct sw_sync_create_fence_data {
__u32   value;
diff --git a/drivers/staging/android/sync_trace.h 
b/drivers/staging/android/sync_trace.h
new file mode 100644
index 000..ea485f7
--- /dev/null
+++ b/drivers/staging/android/sync_trace.h
@@ -0,0 +1,32 @@
+#undef TRACE_SYSTEM
+#define TRACE_INCLUDE_PATH ../../drivers/staging/android
+#define TRACE_SYSTEM sync_trace
+
+#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SYNC_H
+
+#include "sync_debug.h"
+#include 
+
+TRACE_EVENT(sync_timeline,
+   TP_PROTO(struct sync_timeline *timeline),
+
+   TP_ARGS(timeline),
+
+   TP_STRUCT__entry(
+   __string(name, timeline->name)
+   __field(u32, value)
+   ),
+
+   TP_fast_assign(
+   __assign_str(name, timeline->name);
+   __entry->value = timeline->value;
+   ),
+
+   TP_printk("name=%s value=%d", __get_str(name), __entry->value)
+);
+
+#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */
+
+/* This part must be outside protection */
+#include 
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/android/trace/sync.h
deleted file mode 100644
index 6b5ce96..000
--- a/drivers/staging/android/trace/sync.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
-#define TRACE_SYSTEM sync
-
-#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
-#define _TRACE_SYNC_H
-
-#include "../sync_debug.h"
-#include 
-
-TRACE_EVENT(sync_timeline,
-   TP_PROTO(struct sync_timeline *timeline),
-
-   TP_ARGS(timeline),
-
-   TP_STRUCT__entry(
-   __string(name, timeline->name)
-   __field(u32, value)
-   ),
-
-   TP_fast_assign(
-   __assign_str(name, timeline->name);
-   __entry->value = timeline->value;
-   ),
-
-   TP_printk("name=%s value=%d", __get_str(name), __entry->value)
-);
-
-#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */
-
-/* This part must be outside protection */
-#include 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/6] staging/android: remove doc from sw_sync

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC should never be used by other pieces of the kernel apart from
sync_debug as it is only a Sync File Validation Framework, so hide any
info to avoid confuse this with a standard kernel internal API.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 26 --
 drivers/staging/android/sync_debug.h | 15 ---
 2 files changed, 41 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 115c917..b4ae092 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -46,13 +46,6 @@ static inline struct sync_pt *fence_to_sync_pt(struct fence 
*fence)
return container_of(fence, struct sync_pt, base);
 }
 
-/**
- * sync_timeline_create() - creates a sync object
- * @name:  sync_timeline name
- *
- * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
- * case of error.
- */
 struct sync_timeline *sync_timeline_create(const char *name)
 {
struct sync_timeline *obj;
@@ -94,14 +87,6 @@ static void sync_timeline_put(struct sync_timeline *obj)
kref_put(&obj->kref, sync_timeline_free);
 }
 
-/**
- * sync_timeline_signal() - signal a status change on a sync_timeline
- * @obj:   sync_timeline to signal
- * @inc:   num to increment on timeline->value
- *
- * A sync implementation should call this any time one of it's fences
- * has signaled or has an error condition.
- */
 static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
@@ -122,17 +107,6 @@ static void sync_timeline_signal(struct sync_timeline 
*obj, unsigned int inc)
spin_unlock_irqrestore(&obj->child_list_lock, flags);
 }
 
-/**
- * sync_pt_create() - creates a sync pt
- * @parent:fence's parent sync_timeline
- * @size:  size to allocate for this pt
- * @inc:   value of the fence
- *
- * Creates a new sync_pt as a child of @parent.  @size bytes will be
- * allocated allowing for implementation specific data to be kept after
- * the generic sync_timeline struct. Returns the sync_pt object or
- * NULL in case of error.
- */
 static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
 unsigned int value)
 {
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index fab6639..5b82cf8 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -20,15 +20,6 @@
 #include 
 #include 
 
-/**
- * struct sync_timeline - sync object
- * @kref:  reference count on fence.
- * @name:  name of the sync_timeline. Useful for debugging
- * @child_list_head:   list of children sync_pts for this sync_timeline
- * @child_list_lock:   lock protecting @child_list_head and fence.status
- * @active_list_head:  list of active (unsignaled/errored) sync_pts
- * @sync_timeline_list:membership in global sync_timeline_list
- */
 struct sync_timeline {
struct kref kref;
charname[32];
@@ -51,12 +42,6 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
child_list_lock);
 }
 
-/**
- * struct sync_pt - sync_pt object
- * @base: base fence object
- * @child_list: sync timeline child's list
- * @active_list: sync timeline active child's list
- */
 struct sync_pt {
struct fence base;
struct list_head child_list;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/6] de-stage SW_SYNC validation frawework

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi Greg,

This is the last step in the Sync Framwork de-stage task. It de-stage
the SW_SYNC validation framework and the sync_debug info debugfs file.

The first 2 patches are clean up and improvements and the rest is preparation
to de-stage and then finally the actual de-stage.

v2: 
 - add documentation about the SW_SYNC ioctl API (comments from Pavel Machek)
 - remove for now patch to add sync_pt name to debugfs

Please review,

Gustavo

---
Gustavo Padovan (6):
  staging/android: remove doc from sw_sync
  staging/android: do not let userspace trigger WARN_ON
  staging/android: move trace/sync.h to sync_trace.h
  staging/android: prepare sw_sync files for de-staging
  staging/android: add Doc for SW_SYNC ioctl interface
  dma-buf/sw_sync: de-stage SW_SYNC

 drivers/dma-buf/Kconfig  |  13 ++
 drivers/dma-buf/Makefile |   1 +
 drivers/dma-buf/sw_sync.c| 349 +++
 drivers/dma-buf/sync_debug.c | 230 +++
 drivers/dma-buf/sync_debug.h |  69 +++
 drivers/dma-buf/sync_trace.h |  32 
 drivers/staging/android/Kconfig  |  13 --
 drivers/staging/android/Makefile |   1 -
 drivers/staging/android/sw_sync.c| 344 --
 drivers/staging/android/sync_debug.c | 230 ---
 drivers/staging/android/sync_debug.h |  84 -
 drivers/staging/android/trace/sync.h |  32 
 12 files changed, 694 insertions(+), 704 deletions(-)
 create mode 100644 drivers/dma-buf/sw_sync.c
 create mode 100644 drivers/dma-buf/sync_debug.c
 create mode 100644 drivers/dma-buf/sync_debug.h
 create mode 100644 drivers/dma-buf/sync_trace.h
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sync_debug.c
 delete mode 100644 drivers/staging/android/sync_debug.h
 delete mode 100644 drivers/staging/android/trace/sync.h

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/6] staging/android: do not let userspace trigger WARN_ON

2016-08-08 Thread Gustavo Padovan
From: Gustavo Padovan 

Closing the timeline without waiting all fences to signal is not
a critical failure, it is just bad usage from userspace so avoid
calling WARN_ON in this case.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index b4ae092..ad0bb1a 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -150,7 +150,7 @@ static void timeline_fence_release(struct fence *fence)
 
spin_lock_irqsave(fence->lock, flags);
list_del(&pt->child_list);
-   if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+   if (!list_empty(&pt->active_list))
list_del(&pt->active_list);
spin_unlock_irqrestore(fence->lock, flags);
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 2/7] staging/android: display sync_pt name on debugfs

2016-08-08 Thread Gustavo Padovan
2016-08-08 Maarten Lankhorst :

> Op 20-06-16 om 17:53 schreef Gustavo Padovan:
> > From: Gustavo Padovan 
> >
> > When creating a sync_pt the name received wasn't used anywhere.
> > Now we add it to the sync info debug output to make it easier to indetify
> > the userspace name of that sync pt.
> >
> > Signed-off-by: Gustavo Padovan 
> > ---
> >  drivers/staging/android/sw_sync.c| 16 
> >  drivers/staging/android/sync_debug.c |  5 +++--
> >  drivers/staging/android/sync_debug.h |  9 +
> >  3 files changed, 16 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/staging/android/sw_sync.c 
> > b/drivers/staging/android/sw_sync.c
> > index b4ae092..ea27512 100644
> > --- a/drivers/staging/android/sw_sync.c
> > +++ b/drivers/staging/android/sw_sync.c
> > @@ -37,15 +37,6 @@ struct sw_sync_create_fence_data {
> > struct sw_sync_create_fence_data)
> >  #define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
> > __u32)
> >  
> > -static const struct fence_ops timeline_fence_ops;
> > -
> > -static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
> > -{
> > -   if (fence->ops != &timeline_fence_ops)
> > -   return NULL;
> > -   return container_of(fence, struct sync_pt, base);
> > -}
> > -
> >  struct sync_timeline *sync_timeline_create(const char *name)
> >  {
> > struct sync_timeline *obj;
> > @@ -108,7 +99,7 @@ static void sync_timeline_signal(struct sync_timeline 
> > *obj, unsigned int inc)
> >  }
> >  
> >  static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
> > -unsigned int value)
> > +unsigned int value, char *name)
> >  {
> > unsigned long flags;
> > struct sync_pt *pt;
> > @@ -120,6 +111,7 @@ static struct sync_pt *sync_pt_create(struct 
> > sync_timeline *obj, int size,
> > if (!pt)
> > return NULL;
> >  
> > +   strlcpy(pt->name, name, sizeof(pt->name));
> > spin_lock_irqsave(&obj->child_list_lock, flags);
> > sync_timeline_get(obj);
> > fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
> > @@ -191,7 +183,7 @@ static void timeline_fence_timeline_value_str(struct 
> > fence *fence,
> > snprintf(str, size, "%d", parent->value);
> >  }
> >  
> > -static const struct fence_ops timeline_fence_ops = {
> > +const struct fence_ops timeline_fence_ops = {
> > .get_driver_name = timeline_fence_get_driver_name,
> > .get_timeline_name = timeline_fence_get_timeline_name,
> > .enable_signaling = timeline_fence_enable_signaling,
> > @@ -252,7 +244,7 @@ static long sw_sync_ioctl_create_fence(struct 
> > sync_timeline *obj,
> > goto err;
> > }
> >  
> > -   pt = sync_pt_create(obj, sizeof(*pt), data.value);
> > +   pt = sync_pt_create(obj, sizeof(*pt), data.value, data.name);
> > if (!pt) {
> > err = -ENOMEM;
> > goto err;
> > diff --git a/drivers/staging/android/sync_debug.c 
> > b/drivers/staging/android/sync_debug.c
> > index 4c5a855..b732ea3 100644
> > --- a/drivers/staging/android/sync_debug.c
> > +++ b/drivers/staging/android/sync_debug.c
> > @@ -75,13 +75,14 @@ static void sync_print_fence(struct seq_file *s, struct 
> > fence *fence, bool show)
> >  {
> > int status = 1;
> > struct sync_timeline *parent = fence_parent(fence);
> > +   struct sync_pt *pt = fence_to_sync_pt(fence);
> >  
> > if (fence_is_signaled_locked(fence))
> > status = fence->status;
> >  
> > -   seq_printf(s, "  %s%sfence %s",
> > +   seq_printf(s, "  %s%sfence %s %s",
> >show ? parent->name : "",
> > -  show ? "_" : "",
> > +  show ? "_" : "", pt->name,
> >sync_status_str(status));
> >  
> NAK,
> A fence in sync_print_fence can be of any type. If you want to print the 
> name, use the fence_value_str callback.

Indeed. But fence_value_str doesn't return the sync_pt name, but the
seqno of that fence. I'll keep this change out for the de-staging and
then try to come with something that works better.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/7] de-stage SW_SYNC validation frawework

2016-08-08 Thread Gustavo Padovan
2016-07-24 Pavel Machek :

> On Mon 2016-08-08 16:08:12, Gustavo Padovan wrote:
> > 2016-08-07 Pavel Machek :
> > 
> > > On Sun 2016-07-24 15:21:11, Greg Kroah-Hartman wrote:
> > > > On Mon, Jul 18, 2016 at 04:12:45PM -0300, Gustavo Padovan wrote:
> > > > > Hi,
> > > > > 
> > > > > Do you think there is time to get this in for 4.8?
> > > > 
> > > > No, it was too late on my end, due to travel and vacation, sorry.  I'll
> > > > queue it up for 4.9-rc1.
> > > 
> > > Could we get some documentation what this does? Is it visilble to
> > > userspace?
> > 
> > This interface is only intended for testing and validation, there are
> > ioctls on the debugfs file that can be accessed by userspace but there
> > isn't any exported kernel header with this info. The tester should know
> > and add a internal header to be able to access it. We want to prevent
> > people from misusing this feature by not advertising it nor providing
> > documentation.
> 
> You are playing dangerous game here. debugfs is not normally considered 
> stable,
> but otoh... ioctls on debugfs?
> 
> Anyway, please provide some documentation. Kernel hackers need to know what 
> this does.

Okay, where do you think is the best place? Would documentation inside
the .c file suffice for you?
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/7] de-stage SW_SYNC validation frawework

2016-08-08 Thread Gustavo Padovan
2016-08-07 Pavel Machek :

> On Sun 2016-07-24 15:21:11, Greg Kroah-Hartman wrote:
> > On Mon, Jul 18, 2016 at 04:12:45PM -0300, Gustavo Padovan wrote:
> > > Hi,
> > > 
> > > Do you think there is time to get this in for 4.8?
> > 
> > No, it was too late on my end, due to travel and vacation, sorry.  I'll
> > queue it up for 4.9-rc1.
> 
> Could we get some documentation what this does? Is it visilble to
> userspace?

This interface is only intended for testing and validation, there are
ioctls on the debugfs file that can be accessed by userspace but there
isn't any exported kernel header with this info. The tester should know
and add a internal header to be able to access it. We want to prevent
people from misusing this feature by not advertising it nor providing
documentation.

There will be, though, kselftest for this interface, that I send out
once SW_SYNC is de-staged.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/7] de-stage SW_SYNC validation frawework

2016-07-18 Thread Gustavo Padovan
Hi,

Do you think there is time to get this in for 4.8?

Thanks.

2016-06-20 Gustavo Padovan :

> From: Gustavo Padovan 
> 
> Hi Greg,
> 
> This is the last step in the Sync Framwork de-stage task. It de-stage
> the SW_SYNC validation framework and the sync_debug info debugfs file.
> 
> The first 3 patches are clean up and improvements and the rest is preparation
> to de-stage and then finally the actual de-stage.
> 
> Please review,
> 
> Gustavo
> 
> ---
> Gustavo Padovan (7):
>   staging/android: move trace/sync.h to sync_trace.h
>   staging/android: remove doc from sw_sync
>   staging/android: display sync_pt name on debugfs
>   staging/android: do not let userspace trigger WARN_ON
>   staging/android: prepare sw_sync files for de-staging
>   dma-buf/sw_sync: de-stage SW_SYNC
>   staging/android: remove sync framework TODO
> 
>  drivers/dma-buf/Kconfig| 14 +++
>  drivers/dma-buf/Makefile   |  1 +
>  drivers/{staging/android => dma-buf}/sw_sync.c | 46 
> +++---
>  drivers/{staging/android => dma-buf}/sync_debug.c  |  7 ++--
>  drivers/{staging/android => dma-buf}/sync_debug.h  | 26 +---
>  .../android/trace/sync.h => dma-buf/sync_trace.h}  |  6 +--
>  drivers/staging/android/Kconfig| 13 --
>  drivers/staging/android/Makefile   |  1 -
>  drivers/staging/android/TODO   |  8 
>  9 files changed, 38 insertions(+), 84 deletions(-)
>  rename drivers/{staging/android => dma-buf}/sw_sync.c (84%)
>  rename drivers/{staging/android => dma-buf}/sync_debug.c (97%)
>  rename drivers/{staging/android => dma-buf}/sync_debug.h (72%)
>  rename drivers/{staging/android/trace/sync.h => dma-buf/sync_trace.h} (84%)
> 
> -- 
> 2.5.5
> 

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/7] de-stage SW_SYNC validation frawework

2016-07-07 Thread Gustavo Padovan
Hi Greg,

Any comment on this?

Thanks,

Gustavo

2016-06-20 Gustavo Padovan :

> From: Gustavo Padovan 
> 
> Hi Greg,
> 
> This is the last step in the Sync Framwork de-stage task. It de-stage
> the SW_SYNC validation framework and the sync_debug info debugfs file.
> 
> The first 3 patches are clean up and improvements and the rest is preparation
> to de-stage and then finally the actual de-stage.
> 
> Please review,
> 
> Gustavo
> 
> ---
> Gustavo Padovan (7):
>   staging/android: move trace/sync.h to sync_trace.h
>   staging/android: remove doc from sw_sync
>   staging/android: display sync_pt name on debugfs
>   staging/android: do not let userspace trigger WARN_ON
>   staging/android: prepare sw_sync files for de-staging
>   dma-buf/sw_sync: de-stage SW_SYNC
>   staging/android: remove sync framework TODO
> 
>  drivers/dma-buf/Kconfig| 14 +++
>  drivers/dma-buf/Makefile   |  1 +
>  drivers/{staging/android => dma-buf}/sw_sync.c | 46 
> +++---
>  drivers/{staging/android => dma-buf}/sync_debug.c  |  7 ++--
>  drivers/{staging/android => dma-buf}/sync_debug.h  | 26 +---
>  .../android/trace/sync.h => dma-buf/sync_trace.h}  |  6 +--
>  drivers/staging/android/Kconfig| 13 --
>  drivers/staging/android/Makefile   |  1 -
>  drivers/staging/android/TODO   |  8 
>  9 files changed, 38 insertions(+), 84 deletions(-)
>  rename drivers/{staging/android => dma-buf}/sw_sync.c (84%)
>  rename drivers/{staging/android => dma-buf}/sync_debug.c (97%)
>  rename drivers/{staging/android => dma-buf}/sync_debug.h (72%)
>  rename drivers/{staging/android/trace/sync.h => dma-buf/sync_trace.h} (84%)
> 
> -- 
> 2.5.5
> 

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 7/7] staging/android: remove sync framework TODO

2016-06-23 Thread Gustavo Padovan
2016-06-23 Emil Velikov :

> Hi Gustavo,
> 
> On 20 June 2016 at 16:53, Gustavo Padovan  wrote:
> > - - port libsync tests to kselftest
> 
> I believe the tests haven't landed yet right, so this should stay right ?

Yes, you are right. That part is still missing in upstream.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] staging/android: prepare sw_sync files for de-staging

2016-06-22 Thread Gustavo Padovan
From: Gustavo Padovan 

remove file paths in the comments and add short description about each
file.

v2: remove file paths instead of just change them.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 2 +-
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_debug.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 25196f5..a355e9b 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -1,5 +1,5 @@
 /*
- * drivers/dma-buf/sw_sync.c
+ * Sync File validation framework
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index b732ea3..03bcc6f 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -1,5 +1,5 @@
 /*
- * drivers/base/sync.c
+ * Sync File validation framework and debug information
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index c14587c..63cfcff 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -1,5 +1,5 @@
 /*
- * include/linux/sync.h
+ * Sync File validation framework
  *
  * Copyright (C) 2012 Google, Inc.
  *
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 5/7] staging/android: prepare sw_sync files for de-staging

2016-06-20 Thread Gustavo Padovan
2016-06-20 Joe Perches :

> On Mon, 2016-06-20 at 12:53 -0300, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > Fix paths in the comments.
> 
> Why is it useful to have the path or filename embedded
> in the file at
> all?

I just kept it as is. Thinking about this now I don't see
this as useful, I'll send v2 removing it.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 7/7] staging/android: remove sync framework TODO

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

Sync Framework was de-staged to drivers/dma-buf/, so remove it entries
in the TODO file.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/TODO | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO
index 64d8c87..8f3ac37 100644
--- a/drivers/staging/android/TODO
+++ b/drivers/staging/android/TODO
@@ -25,13 +25,5 @@ ion/
exposes existing cma regions and doesn't reserve unecessarily memory when
booting a system which doesn't use ion.
 
-sync framework:
- - remove CONFIG_SW_SYNC_USER, it is used only for testing/debugging and
- should not be upstreamed.
- - port CONFIG_SW_SYNC_USER tests interfaces to use debugfs somehow
- - port libsync tests to kselftest
- - clean up and ABI check for security issues
- - move it to drivers/base/dma-buf
-
 Please send patches to Greg Kroah-Hartman  and Cc:
 Arve Hjønnevåg  and Riley Andrews 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/7] staging/android: prepare sw_sync files for de-staging

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

Fix paths in the comments.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_debug.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index b732ea3..5f0d41e 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -1,5 +1,5 @@
 /*
- * drivers/base/sync.c
+ * drivers/dma-buf/sync_debug.c
  *
  * Copyright (C) 2012 Google, Inc.
  *
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index c14587c..e359047 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -1,5 +1,5 @@
 /*
- * include/linux/sync.h
+ * drivers/dma-buf/sync_debug.h
  *
  * Copyright (C) 2012 Google, Inc.
  *
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/7] de-stage SW_SYNC validation frawework

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi Greg,

This is the last step in the Sync Framwork de-stage task. It de-stage
the SW_SYNC validation framework and the sync_debug info debugfs file.

The first 3 patches are clean up and improvements and the rest is preparation
to de-stage and then finally the actual de-stage.

Please review,

Gustavo

---
Gustavo Padovan (7):
  staging/android: move trace/sync.h to sync_trace.h
  staging/android: remove doc from sw_sync
  staging/android: display sync_pt name on debugfs
  staging/android: do not let userspace trigger WARN_ON
  staging/android: prepare sw_sync files for de-staging
  dma-buf/sw_sync: de-stage SW_SYNC
  staging/android: remove sync framework TODO

 drivers/dma-buf/Kconfig| 14 +++
 drivers/dma-buf/Makefile   |  1 +
 drivers/{staging/android => dma-buf}/sw_sync.c | 46 +++---
 drivers/{staging/android => dma-buf}/sync_debug.c  |  7 ++--
 drivers/{staging/android => dma-buf}/sync_debug.h  | 26 +---
 .../android/trace/sync.h => dma-buf/sync_trace.h}  |  6 +--
 drivers/staging/android/Kconfig| 13 --
 drivers/staging/android/Makefile   |  1 -
 drivers/staging/android/TODO   |  8 
 9 files changed, 38 insertions(+), 84 deletions(-)
 rename drivers/{staging/android => dma-buf}/sw_sync.c (84%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (97%)
 rename drivers/{staging/android => dma-buf}/sync_debug.h (72%)
 rename drivers/{staging/android/trace/sync.h => dma-buf/sync_trace.h} (84%)

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/7] dma-buf/sw_sync: de-stage SW_SYNC

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC allows to run tests on the sync_file framework via debugfs on

/sync/sw_sync

Opening and closing the file triggers creation and release of a sync
timeline. To create fences on this timeline the SW_SYNC_IOC_CREATE_FENCE
ioctl should be used. To increment the timeline value use SW_SYNC_IOC_INC.

Also it exports Sync information on

/sync/info

Signed-off-by: Gustavo Padovan 
---
 drivers/dma-buf/Kconfig   | 14 ++
 drivers/dma-buf/Makefile  |  1 +
 drivers/{staging/android => dma-buf}/sw_sync.c|  0
 drivers/{staging/android => dma-buf}/sync_debug.c |  0
 drivers/{staging/android => dma-buf}/sync_debug.h |  0
 drivers/{staging/android => dma-buf}/sync_trace.h |  2 +-
 drivers/staging/android/Kconfig   | 13 -
 drivers/staging/android/Makefile  |  1 -
 8 files changed, 16 insertions(+), 15 deletions(-)
 rename drivers/{staging/android => dma-buf}/sw_sync.c (100%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (100%)
 rename drivers/{staging/android => dma-buf}/sync_debug.h (100%)
 rename drivers/{staging/android => dma-buf}/sync_trace.h (92%)

diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index 9824bc4..7227022 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -8,4 +8,18 @@ config SYNC_FILE
---help---
  This option enables the fence framework synchronization to export
  sync_files to userspace that can represent one or more fences.
+
+config SW_SYNC
+   bool "Sync File Validation Framework"
+   default n
+   depends on SYNC_FILE
+   depends on DEBUG_FS
+   ---help---
+ A sync object driver that uses a 32bit counter to coordinate
+ synchronization.  Useful when there is no hardware primitive backing
+ the synchronization.
+
+ WARNING: improper use of this can result in deadlocking kernel
+ drivers from userspace. Intended for test and debug only.
+
 endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 4a424ec..d2d02fc 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,2 +1,3 @@
 obj-y := dma-buf.o fence.o reservation.o seqno-fence.o
 obj-$(CONFIG_SYNC_FILE)+= sync_file.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/dma-buf/sw_sync.c
similarity index 100%
rename from drivers/staging/android/sw_sync.c
rename to drivers/dma-buf/sw_sync.c
diff --git a/drivers/staging/android/sync_debug.c b/drivers/dma-buf/sync_debug.c
similarity index 100%
rename from drivers/staging/android/sync_debug.c
rename to drivers/dma-buf/sync_debug.c
diff --git a/drivers/staging/android/sync_debug.h b/drivers/dma-buf/sync_debug.h
similarity index 100%
rename from drivers/staging/android/sync_debug.h
rename to drivers/dma-buf/sync_debug.h
diff --git a/drivers/staging/android/sync_trace.h b/drivers/dma-buf/sync_trace.h
similarity index 92%
rename from drivers/staging/android/sync_trace.h
rename to drivers/dma-buf/sync_trace.h
index ea485f7..d13d59f 100644
--- a/drivers/staging/android/sync_trace.h
+++ b/drivers/dma-buf/sync_trace.h
@@ -1,5 +1,5 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android
+#define TRACE_INCLUDE_PATH ../../drivers/dma-buf
 #define TRACE_SYSTEM sync_trace
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 06e41d2..6c00d6f 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -24,19 +24,6 @@ config ANDROID_LOW_MEMORY_KILLER
  scripts (/init.rc), and it defines priority values with minimum free 
memory size
  for each priority.
 
-config SW_SYNC
-   bool "Software synchronization framework"
-   default n
-   depends on SYNC_FILE
-   depends on DEBUG_FS
-   ---help---
- A sync object driver that uses a 32bit counter to coordinate
- synchronization.  Useful when there is no hardware primitive backing
- the synchronization.
-
- WARNING: improper use of this can result in deadlocking kernel
- drivers from userspace. Intended for test and debug only.
-
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 7ca61b7..7ed1be7 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,4 +4,3 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
-- 
2.5.5

__

[PATCH 1/7] staging/android: remove doc from sw_sync

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC should never be used by other pieces of the kernel apart from
sync_debug as it is only a Sync File Validation Framework, so hide any
info to avoid confuse this with a standard kernel internal API.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 26 --
 drivers/staging/android/sync_debug.h | 15 ---
 2 files changed, 41 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 115c917..b4ae092 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -46,13 +46,6 @@ static inline struct sync_pt *fence_to_sync_pt(struct fence 
*fence)
return container_of(fence, struct sync_pt, base);
 }
 
-/**
- * sync_timeline_create() - creates a sync object
- * @name:  sync_timeline name
- *
- * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
- * case of error.
- */
 struct sync_timeline *sync_timeline_create(const char *name)
 {
struct sync_timeline *obj;
@@ -94,14 +87,6 @@ static void sync_timeline_put(struct sync_timeline *obj)
kref_put(&obj->kref, sync_timeline_free);
 }
 
-/**
- * sync_timeline_signal() - signal a status change on a sync_timeline
- * @obj:   sync_timeline to signal
- * @inc:   num to increment on timeline->value
- *
- * A sync implementation should call this any time one of it's fences
- * has signaled or has an error condition.
- */
 static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
@@ -122,17 +107,6 @@ static void sync_timeline_signal(struct sync_timeline 
*obj, unsigned int inc)
spin_unlock_irqrestore(&obj->child_list_lock, flags);
 }
 
-/**
- * sync_pt_create() - creates a sync pt
- * @parent:fence's parent sync_timeline
- * @size:  size to allocate for this pt
- * @inc:   value of the fence
- *
- * Creates a new sync_pt as a child of @parent.  @size bytes will be
- * allocated allowing for implementation specific data to be kept after
- * the generic sync_timeline struct. Returns the sync_pt object or
- * NULL in case of error.
- */
 static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
 unsigned int value)
 {
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index 425ebc5..c44f447 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -20,15 +20,6 @@
 #include 
 #include 
 
-/**
- * struct sync_timeline - sync object
- * @kref:  reference count on fence.
- * @name:  name of the sync_timeline. Useful for debugging
- * @child_list_head:   list of children sync_pts for this sync_timeline
- * @child_list_lock:   lock protecting @child_list_head and fence.status
- * @active_list_head:  list of active (unsignaled/errored) sync_pts
- * @sync_timeline_list:membership in global sync_timeline_list
- */
 struct sync_timeline {
struct kref kref;
charname[32];
@@ -50,12 +41,6 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
child_list_lock);
 }
 
-/**
- * struct sync_pt - sync_pt object
- * @base: base fence object
- * @child_list: sync timeline child's list
- * @active_list: sync timeline active child's list
- */
 struct sync_pt {
struct fence base;
struct list_head child_list;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/7] staging/android: move trace/sync.h to sync_trace.h

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

The common behaviour for trace headers is to have them in the same folder
they are used, instead of creating a special trace/ directory.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c  | 2 +-
 drivers/staging/android/{trace/sync.h => sync_trace.h} | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/staging/android/{trace/sync.h => sync_trace.h} (84%)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 66837ca..25196f5 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -23,7 +23,7 @@
 #include "sync_debug.h"
 
 #define CREATE_TRACE_POINTS
-#include "trace/sync.h"
+#include "sync_trace.h"
 
 struct sw_sync_create_fence_data {
__u32   value;
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/android/sync_trace.h
similarity index 84%
rename from drivers/staging/android/trace/sync.h
rename to drivers/staging/android/sync_trace.h
index 6b5ce96..ea485f7 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/sync_trace.h
@@ -1,11 +1,11 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
-#define TRACE_SYSTEM sync
+#define TRACE_INCLUDE_PATH ../../drivers/staging/android
+#define TRACE_SYSTEM sync_trace
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_SYNC_H
 
-#include "../sync_debug.h"
+#include "sync_debug.h"
 #include 
 
 TRACE_EVENT(sync_timeline,
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/7] staging/android: do not let userspace trigger WARN_ON

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

Closing the timeline without waiting all fences to signal is not
a critical failure, it is just bad usage from userspace so avoid
calling WARN_ON in this case.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index ea27512..66837ca 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -142,7 +142,7 @@ static void timeline_fence_release(struct fence *fence)
 
spin_lock_irqsave(fence->lock, flags);
list_del(&pt->child_list);
-   if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+   if (!list_empty(&pt->active_list))
list_del(&pt->active_list);
spin_unlock_irqrestore(fence->lock, flags);
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/7] staging/android: display sync_pt name on debugfs

2016-06-20 Thread Gustavo Padovan
From: Gustavo Padovan 

When creating a sync_pt the name received wasn't used anywhere.
Now we add it to the sync info debug output to make it easier to indetify
the userspace name of that sync pt.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 16 
 drivers/staging/android/sync_debug.c |  5 +++--
 drivers/staging/android/sync_debug.h |  9 +
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index b4ae092..ea27512 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -37,15 +37,6 @@ struct sw_sync_create_fence_data {
struct sw_sync_create_fence_data)
 #define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
 
-static const struct fence_ops timeline_fence_ops;
-
-static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
-{
-   if (fence->ops != &timeline_fence_ops)
-   return NULL;
-   return container_of(fence, struct sync_pt, base);
-}
-
 struct sync_timeline *sync_timeline_create(const char *name)
 {
struct sync_timeline *obj;
@@ -108,7 +99,7 @@ static void sync_timeline_signal(struct sync_timeline *obj, 
unsigned int inc)
 }
 
 static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
-unsigned int value)
+unsigned int value, char *name)
 {
unsigned long flags;
struct sync_pt *pt;
@@ -120,6 +111,7 @@ static struct sync_pt *sync_pt_create(struct sync_timeline 
*obj, int size,
if (!pt)
return NULL;
 
+   strlcpy(pt->name, name, sizeof(pt->name));
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
@@ -191,7 +183,7 @@ static void timeline_fence_timeline_value_str(struct fence 
*fence,
snprintf(str, size, "%d", parent->value);
 }
 
-static const struct fence_ops timeline_fence_ops = {
+const struct fence_ops timeline_fence_ops = {
.get_driver_name = timeline_fence_get_driver_name,
.get_timeline_name = timeline_fence_get_timeline_name,
.enable_signaling = timeline_fence_enable_signaling,
@@ -252,7 +244,7 @@ static long sw_sync_ioctl_create_fence(struct sync_timeline 
*obj,
goto err;
}
 
-   pt = sync_pt_create(obj, sizeof(*pt), data.value);
+   pt = sync_pt_create(obj, sizeof(*pt), data.value, data.name);
if (!pt) {
err = -ENOMEM;
goto err;
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 4c5a855..b732ea3 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -75,13 +75,14 @@ static void sync_print_fence(struct seq_file *s, struct 
fence *fence, bool show)
 {
int status = 1;
struct sync_timeline *parent = fence_parent(fence);
+   struct sync_pt *pt = fence_to_sync_pt(fence);
 
if (fence_is_signaled_locked(fence))
status = fence->status;
 
-   seq_printf(s, "  %s%sfence %s",
+   seq_printf(s, "  %s%sfence %s %s",
   show ? parent->name : "",
-  show ? "_" : "",
+  show ? "_" : "", pt->name,
   sync_status_str(status));
 
if (status <= 0) {
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index c44f447..c14587c 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -43,10 +43,19 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
 
 struct sync_pt {
struct fence base;
+   char name[32];
struct list_head child_list;
struct list_head active_list;
 };
 
+extern const struct fence_ops timeline_fence_ops;
+static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
+{
+   if (fence->ops != &timeline_fence_ops)
+   return NULL;
+   return container_of(fence, struct sync_pt, base);
+}
+
 #ifdef CONFIG_SW_SYNC
 
 extern const struct file_operations sw_sync_debugfs_fops;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/18] staging/android: clean up SW_SYNC

2016-06-08 Thread Gustavo Padovan
Hi Greg,

Any comment on this?

Gustavo

2016-05-31 Gustavo Padovan :

> From: Gustavo Padovan 
> 
> Hi,
> 
> The following patches do a clean up on the sw_sync inteface. It starts by
> removing struct sync_timeline_ops, which was creating unecessary wrappers
> in the code and the start to organize the sync_timeline and sw_sync code
> better.
> 
> sw_sync interface was moved to sw_sync.c along with sync_timeline - which
> is now internal to sw_sync.
> 
> The next step after this work is the actual de-stage of SW_SYNC and
> the upstreaming of selftests for sw_sync and sync_file.
> 
> Please review!
> 
>   Gustavo
> 
> ---
> 
> Gustavo Padovan (18):
>   staging/android: store last signaled value on sync timeline
>   staging/android: remove .{fence,timeline}_value_str() from timeline_ops
>   staging/android: remove struct sync_timeline_ops
>   staging/android: remove sw_sync_timeline and sw_sync_pt
>   staging/android: remove sw_sync.[ch] files
>   staging/android: rename android_fence to timeline_fence
>   staging/android: remove unnecessary check for fence
>   staging/android: remove size arg of sync_timeline_create()
>   staging/android: bring struct sync_pt back
>   staging/android: move sw_sync related code to sw_sync.c
>   staging/android: clean up #includes in the sync framework
>   staging/android: make sync_timeline internal to sw_sync
>   staging/android: make sw_ioctl info internal to sw_sync.c
>   staging/android: remove 'destroyed' member from struct sync_timeline
>   staging/android: remove sync_timeline_destroy()
>   staging/android: remove drv_name from sync_timeline
>   staging/android: rename sync.h to sync_debug.h
>   staging/android: add DEBUG_FS dependence on Kconfig
> 
>  drivers/staging/android/Kconfig|  17 +-
>  drivers/staging/android/Makefile   |   3 +-
>  drivers/staging/android/sw_sync.c  | 341 
> -
>  drivers/staging/android/sw_sync.h  |  59 --
>  drivers/staging/android/sync.c | 221 -
>  drivers/staging/android/sync.h | 154 ---
>  drivers/staging/android/sync_debug.c   | 154 +--
>  drivers/staging/android/sync_debug.h   |  83 
>  drivers/staging/android/trace/sync.h   |  14 +-
>  drivers/staging/android/uapi/sw_sync.h |  32 
>  include/linux/fence.h  |   2 -
>  11 files changed, 399 insertions(+), 681 deletions(-)
>  delete mode 100644 drivers/staging/android/sw_sync.h
>  delete mode 100644 drivers/staging/android/sync.c
>  delete mode 100644 drivers/staging/android/sync.h
>  create mode 100644 drivers/staging/android/sync_debug.h
>  delete mode 100644 drivers/staging/android/uapi/sw_sync.h
> 
> -- 
> 2.5.5
> 
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 18/18] staging/android: add DEBUG_FS dependence on Kconfig

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

SW_SYNC only works with DEBUG_FS so state it in the Kconfig file.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Kconfig  | 1 +
 drivers/staging/android/sync_debug.c | 4 
 drivers/staging/android/sync_debug.h | 4 +---
 3 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index f52c682..06e41d2 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -28,6 +28,7 @@ config SW_SYNC
bool "Software synchronization framework"
default n
depends on SYNC_FILE
+   depends on DEBUG_FS
---help---
  A sync object driver that uses a 32bit counter to coordinate
  synchronization.  Useful when there is no hardware primitive backing
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index b760226..9032969 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -17,8 +17,6 @@
 #include 
 #include "sync_debug.h"
 
-#ifdef CONFIG_DEBUG_FS
-
 static struct dentry *dbgfs;
 
 static LIST_HEAD(sync_timeline_list_head);
@@ -225,5 +223,3 @@ void sync_dump(void)
}
}
 }
-
-#endif
diff --git a/drivers/staging/android/sync_debug.h 
b/drivers/staging/android/sync_debug.h
index 48e2d1c..425ebc5 100644
--- a/drivers/staging/android/sync_debug.h
+++ b/drivers/staging/android/sync_debug.h
@@ -41,9 +41,7 @@ struct sync_timeline {
 
struct list_headactive_list_head;
 
-#ifdef CONFIG_DEBUG_FS
struct list_headsync_timeline_list;
-#endif
 };
 
 static inline struct sync_timeline *fence_parent(struct fence *fence)
@@ -64,7 +62,7 @@ struct sync_pt {
struct list_head active_list;
 };
 
-#ifdef CONFIG_DEBUG_FS
+#ifdef CONFIG_SW_SYNC
 
 extern const struct file_operations sw_sync_debugfs_fops;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 17/18] staging/android: rename sync.h to sync_debug.h

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

This header file only contains information for debugging and SW_SYNC, so
rename it to sync_debug.h instead of having a more generic name.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 2 +-
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/{sync.h => sync_debug.h} | 0
 drivers/staging/android/trace/sync.h | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename drivers/staging/android/{sync.h => sync_debug.h} (100%)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index ae56ece..115c917 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 
-#include "sync.h"
+#include "sync_debug.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index b2697a1..b760226 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -15,7 +15,7 @@
  */
 
 #include 
-#include "sync.h"
+#include "sync_debug.h"
 
 #ifdef CONFIG_DEBUG_FS
 
diff --git a/drivers/staging/android/sync.h 
b/drivers/staging/android/sync_debug.h
similarity index 100%
rename from drivers/staging/android/sync.h
rename to drivers/staging/android/sync_debug.h
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/android/trace/sync.h
index d7f6457f..6b5ce96 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -5,7 +5,7 @@
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_SYNC_H
 
-#include "../sync.h"
+#include "../sync_debug.h"
 #include 
 
 TRACE_EVENT(sync_timeline,
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 16/18] staging/android: remove drv_name from sync_timeline

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

As it is internal to sw_sync now this value will always be "sw_sync".

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 11 +++
 drivers/staging/android/sync.h   |  2 --
 drivers/staging/android/sync_debug.c |  2 +-
 3 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index cf4de27..ae56ece 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -48,14 +48,12 @@ static inline struct sync_pt *fence_to_sync_pt(struct fence 
*fence)
 
 /**
  * sync_timeline_create() - creates a sync object
- * @drv_name:  sync_timeline driver name
  * @name:  sync_timeline name
  *
  * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
  * case of error.
  */
-struct sync_timeline *sync_timeline_create(const char *drv_name,
-  const char *name)
+struct sync_timeline *sync_timeline_create(const char *name)
 {
struct sync_timeline *obj;
 
@@ -66,7 +64,6 @@ struct sync_timeline *sync_timeline_create(const char 
*drv_name,
kref_init(&obj->kref);
obj->context = fence_context_alloc(1);
strlcpy(obj->name, name, sizeof(obj->name));
-   strlcpy(obj->drv_name, drv_name, sizeof(obj->drv_name));
 
INIT_LIST_HEAD(&obj->child_list_head);
INIT_LIST_HEAD(&obj->active_list_head);
@@ -161,9 +158,7 @@ static struct sync_pt *sync_pt_create(struct sync_timeline 
*obj, int size,
 
 static const char *timeline_fence_get_driver_name(struct fence *fence)
 {
-   struct sync_timeline *parent = fence_parent(fence);
-
-   return parent->drv_name;
+   return "sw_sync";
 }
 
 static const char *timeline_fence_get_timeline_name(struct fence *fence)
@@ -247,7 +242,7 @@ static int sw_sync_debugfs_open(struct inode *inode, struct 
file *file)
 
get_task_comm(task_comm, current);
 
-   obj = sync_timeline_create("sw_sync", task_comm);
+   obj = sync_timeline_create(task_comm);
if (!obj)
return -ENOMEM;
 
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 3c551f5..48e2d1c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -23,7 +23,6 @@
 /**
  * struct sync_timeline - sync object
  * @kref:  reference count on fence.
- * @drv_name:  drv_name of the driver using the sync_timeline
  * @name:  name of the sync_timeline. Useful for debugging
  * @child_list_head:   list of children sync_pts for this sync_timeline
  * @child_list_lock:   lock protecting @child_list_head and fence.status
@@ -32,7 +31,6 @@
  */
 struct sync_timeline {
struct kref kref;
-   chardrv_name[32];
charname[32];
 
/* protected by child_list_lock */
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 77386d2..b2697a1 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -120,7 +120,7 @@ static void sync_print_obj(struct seq_file *s, struct 
sync_timeline *obj)
struct list_head *pos;
unsigned long flags;
 
-   seq_printf(s, "%s %s: %d\n", obj->name, obj->drv_name, obj->value);
+   seq_printf(s, "%s: %d\n", obj->name, obj->value);
 
spin_lock_irqsave(&obj->child_list_lock, flags);
list_for_each(pos, &obj->child_list_head) {
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 15/18] staging/android: remove sync_timeline_destroy()

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

This function was just used by the file release function, so we just fold
its content there and remove sync_timeline_destroy().

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 19 +++
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 1f956b9..cf4de27 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -98,21 +98,6 @@ static void sync_timeline_put(struct sync_timeline *obj)
 }
 
 /**
- * sync_timeline_destroy() - destroys a sync object
- * @obj:   sync_timeline to destroy
- *
- * A sync implementation should call this when the @obj is going away
- * (i.e. module unload.)  @obj won't actually be freed until all its children
- * fences are freed.
- */
-static void sync_timeline_destroy(struct sync_timeline *obj)
-{
-   smp_wmb();
-
-   sync_timeline_put(obj);
-}
-
-/**
  * sync_timeline_signal() - signal a status change on a sync_timeline
  * @obj:   sync_timeline to signal
  * @inc:   num to increment on timeline->value
@@ -275,7 +260,9 @@ static int sw_sync_debugfs_release(struct inode *inode, 
struct file *file)
 {
struct sync_timeline *obj = file->private_data;
 
-   sync_timeline_destroy(obj);
+   smp_wmb();
+
+   sync_timeline_put(obj);
return 0;
 }
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 14/18] staging/android: remove 'destroyed' member from struct sync_timeline

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

'destroyed' was set but not used ny anyone.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 5 -
 drivers/staging/android/sync.h| 5 +
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 72262ba..1f956b9 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -107,11 +107,6 @@ static void sync_timeline_put(struct sync_timeline *obj)
  */
 static void sync_timeline_destroy(struct sync_timeline *obj)
 {
-   obj->destroyed = true;
-   /*
-* Ensure timeline is marked as destroyed before
-* changing timeline's fences status.
-*/
smp_wmb();
 
sync_timeline_put(obj);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 3a50851..3c551f5 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -25,10 +25,8 @@
  * @kref:  reference count on fence.
  * @drv_name:  drv_name of the driver using the sync_timeline
  * @name:  name of the sync_timeline. Useful for debugging
- * @destroyed: set when sync_timeline is destroyed
  * @child_list_head:   list of children sync_pts for this sync_timeline
- * @child_list_lock:   lock protecting @child_list_head, destroyed, and
- * fence.status
+ * @child_list_lock:   lock protecting @child_list_head and fence.status
  * @active_list_head:  list of active (unsignaled/errored) sync_pts
  * @sync_timeline_list:membership in global sync_timeline_list
  */
@@ -38,7 +36,6 @@ struct sync_timeline {
charname[32];
 
/* protected by child_list_lock */
-   booldestroyed;
int context, value;
 
struct list_headchild_list_head;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/18] staging/android: make sync_timeline internal to sw_sync

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

The only use sync_timeline will have in upstream kernel is for debugging
through the SW_SYNC interface. So make it internal to SW_SYNC to avoid
people use it in the future.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Kconfig  |  16 +--
 drivers/staging/android/Makefile |   3 +-
 drivers/staging/android/sw_sync.c| 220 +++
 drivers/staging/android/sync.c   | 199 ---
 drivers/staging/android/sync.h   |  58 -
 drivers/staging/android/sync_debug.c |   2 -
 6 files changed, 225 insertions(+), 273 deletions(-)
 delete mode 100644 drivers/staging/android/sync.c

diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 6480f60..f52c682 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -24,26 +24,18 @@ config ANDROID_LOW_MEMORY_KILLER
  scripts (/init.rc), and it defines priority values with minimum free 
memory size
  for each priority.
 
-config SYNC
-   bool "Synchronization framework"
-   default n
-   select ANON_INODES
-   select DMA_SHARED_BUFFER
-   ---help---
- This option enables the framework for synchronization between multiple
- drivers.  Sync implementations can take advantage of hardware
- synchronization built into devices like GPUs.
-
 config SW_SYNC
-   bool "Software synchronization objects"
+   bool "Software synchronization framework"
default n
-   depends on SYNC
depends on SYNC_FILE
---help---
  A sync object driver that uses a 32bit counter to coordinate
  synchronization.  Useful when there is no hardware primitive backing
  the synchronization.
 
+ WARNING: improper use of this can result in deadlocking kernel
+ drivers from userspace. Intended for test and debug only.
+
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..7ca61b7 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,4 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 90e3ee5..c149ac90 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -17,11 +17,231 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "uapi/sw_sync.h"
 #include "sync.h"
 
+#define CREATE_TRACE_POINTS
+#include "trace/sync.h"
+
+static const struct fence_ops timeline_fence_ops;
+
+static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
+{
+   if (fence->ops != &timeline_fence_ops)
+   return NULL;
+   return container_of(fence, struct sync_pt, base);
+}
+
+/**
+ * sync_timeline_create() - creates a sync object
+ * @drv_name:  sync_timeline driver name
+ * @name:  sync_timeline name
+ *
+ * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
+ * case of error.
+ */
+struct sync_timeline *sync_timeline_create(const char *drv_name,
+  const char *name)
+{
+   struct sync_timeline *obj;
+
+   obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+   if (!obj)
+   return NULL;
+
+   kref_init(&obj->kref);
+   obj->context = fence_context_alloc(1);
+   strlcpy(obj->name, name, sizeof(obj->name));
+   strlcpy(obj->drv_name, drv_name, sizeof(obj->drv_name));
+
+   INIT_LIST_HEAD(&obj->child_list_head);
+   INIT_LIST_HEAD(&obj->active_list_head);
+   spin_lock_init(&obj->child_list_lock);
+
+   sync_timeline_debug_add(obj);
+
+   return obj;
+}
+
+static void sync_timeline_free(struct kref *kref)
+{
+   struct sync_timeline *obj =
+   container_of(kref, struct sync_timeline, kref);
+
+   sync_timeline_debug_remove(obj);
+
+   kfree(obj);
+}
+
+static void sync_timeline_get(struct sync_timeline *obj)
+{
+   kref_get(&obj->kref);
+}
+
+static void sync_timeline_put(struct sync_timeline *obj)
+{
+   kref_put(&obj->kref, sync_timeline_free);
+}
+
+/**
+ * sync_timeline_destroy() - destroys a sync object
+ * @obj:   sync_timeline to destroy
+ *
+ * A sync implementation should call this when the @obj is going away
+ * (i.e. module unload.)  @obj won't actually be freed until all its children
+ * fences are freed.
+ */
+static void sync

[PATCH 13/18] staging/android: make sw_ioctl info internal to sw_sync.c

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

We don't want to export this from the kernel. This is interface is only
for testing and debug. So testers shall copy the ioctl info in their own
projects.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c  | 13 -
 drivers/staging/android/uapi/sw_sync.h | 32 
 2 files changed, 12 insertions(+), 33 deletions(-)
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index c149ac90..72262ba 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -20,12 +20,23 @@
 #include 
 #include 
 
-#include "uapi/sw_sync.h"
 #include "sync.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
+struct sw_sync_create_fence_data {
+   __u32   value;
+   charname[32];
+   __s32   fence; /* fd of new fence */
+};
+
+#define SW_SYNC_IOC_MAGIC  'W'
+
+#define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+   struct sw_sync_create_fence_data)
+#define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
+
 static const struct fence_ops timeline_fence_ops;
 
 static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
diff --git a/drivers/staging/android/uapi/sw_sync.h 
b/drivers/staging/android/uapi/sw_sync.h
deleted file mode 100644
index 9b5d486..000
--- a/drivers/staging/android/uapi/sw_sync.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _UAPI_LINUX_SW_SYNC_H
-#define _UAPI_LINUX_SW_SYNC_H
-
-#include 
-
-struct sw_sync_create_fence_data {
-   __u32   value;
-   charname[32];
-   __s32   fence; /* fd of new fence */
-};
-
-#define SW_SYNC_IOC_MAGIC  'W'
-
-#define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
-   struct sw_sync_create_fence_data)
-#define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
-
-#endif /* _UAPI_LINUX_SW_SYNC_H */
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/18] staging/android: clean up #includes in the sync framework

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Most of the includes there are not necessary anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   |  6 --
 drivers/staging/android/sync.h   |  3 ---
 drivers/staging/android/sync_debug.c | 16 
 3 files changed, 25 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index aab80ec..bb12d86 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -14,14 +14,8 @@
  *
  */
 
-#include 
 #include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
 
 #include "sync.h"
 
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 02ecf44..54c515b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -13,9 +13,6 @@
 #ifndef _LINUX_SYNC_H
 #define _LINUX_SYNC_H
 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 2733cc3..864ad01 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -15,22 +15,6 @@
  */
 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "uapi/sw_sync.h"
 #include "sync.h"
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/18] staging/android: remove size arg of sync_timeline_create()

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

After we removed sw_sync_timeline this arg has not been really used by
anyone, all its users pass the size of struct sync_timeline there.

So simplify this function but not requiring the size anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   | 7 ++-
 drivers/staging/android/sync.h   | 7 ++-
 drivers/staging/android/sync_debug.c | 2 +-
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 442d808..c83a599 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -30,15 +30,12 @@
 
 static const struct fence_ops timeline_fence_ops;
 
-struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name)
 {
struct sync_timeline *obj;
 
-   if (size < sizeof(struct sync_timeline))
-   return NULL;
-
-   obj = kzalloc(size, GFP_KERNEL);
+   obj = kzalloc(sizeof(*obj), GFP_KERNEL);
if (!obj)
return NULL;
 
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index f003e97..f2fbf98 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -66,16 +66,13 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
 
 /**
  * sync_timeline_create() - creates a sync object
- * @size:  size to allocate for this obj
  * @drv_name:  sync_timeline driver name
  * @name:  sync_timeline name
  *
- * Creates a new sync_timeline. @size bytes will be allocated allowing
- * for implementation specific data to be kept after the generic
- * sync_timeline struct. Returns the sync_timeline object or NULL in
+ * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
  * case of error.
  */
-struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name);
 
 /**
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 6282046..cb0f888 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -218,7 +218,7 @@ static int sw_sync_debugfs_open(struct inode *inode, struct 
file *file)
 
get_task_comm(task_comm, current);
 
-   obj = sync_timeline_create(sizeof(*obj), "sw_sync", task_comm);
+   obj = sync_timeline_create("sw_sync", task_comm);
if (!obj)
return -ENOMEM;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/18] staging/android: move sw_sync related code to sw_sync.c

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Split sync_debug and sw_sync in two different files.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Makefile |   1 +
 drivers/staging/android/sw_sync.c| 136 +++
 drivers/staging/android/sync.h   |   2 +
 drivers/staging/android/sync_debug.c | 115 -
 4 files changed, 139 insertions(+), 115 deletions(-)
 create mode 100644 drivers/staging/android/sw_sync.c

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index bf45967..980d6dc 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,3 +5,4 @@ obj-y   += ion/
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
 obj-$(CONFIG_SYNC) += sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
new file mode 100644
index 000..90e3ee5
--- /dev/null
+++ b/drivers/staging/android/sw_sync.c
@@ -0,0 +1,136 @@
+/*
+ * drivers/dma-buf/sw_sync.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "uapi/sw_sync.h"
+#include "sync.h"
+
+/*
+ * *WARNING*
+ *
+ * improper use of this can result in deadlocking kernel drivers from 
userspace.
+ */
+
+/* opening sw_sync create a new sync obj */
+static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
+{
+   struct sync_timeline *obj;
+   char task_comm[TASK_COMM_LEN];
+
+   get_task_comm(task_comm, current);
+
+   obj = sync_timeline_create("sw_sync", task_comm);
+   if (!obj)
+   return -ENOMEM;
+
+   file->private_data = obj;
+
+   return 0;
+}
+
+static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
+{
+   struct sync_timeline *obj = file->private_data;
+
+   sync_timeline_destroy(obj);
+   return 0;
+}
+
+static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
+  unsigned long arg)
+{
+   int fd = get_unused_fd_flags(O_CLOEXEC);
+   int err;
+   struct sync_pt *pt;
+   struct sync_file *sync_file;
+   struct sw_sync_create_fence_data data;
+
+   if (fd < 0)
+   return fd;
+
+   if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+   err = -EFAULT;
+   goto err;
+   }
+
+   pt = sync_pt_create(obj, sizeof(*pt), data.value);
+   if (!pt) {
+   err = -ENOMEM;
+   goto err;
+   }
+
+   sync_file = sync_file_create(&pt->base);
+   if (!sync_file) {
+   fence_put(&pt->base);
+   err = -ENOMEM;
+   goto err;
+   }
+
+   data.fence = fd;
+   if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
+   fput(sync_file->file);
+   err = -EFAULT;
+   goto err;
+   }
+
+   fd_install(fd, sync_file->file);
+
+   return 0;
+
+err:
+   put_unused_fd(fd);
+   return err;
+}
+
+static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
+{
+   u32 value;
+
+   if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
+   return -EFAULT;
+
+   sync_timeline_signal(obj, value);
+
+   return 0;
+}
+
+static long sw_sync_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+   struct sync_timeline *obj = file->private_data;
+
+   switch (cmd) {
+   case SW_SYNC_IOC_CREATE_FENCE:
+   return sw_sync_ioctl_create_fence(obj, arg);
+
+   case SW_SYNC_IOC_INC:
+   return sw_sync_ioctl_inc(obj, arg);
+
+   default:
+   return -ENOTTY;
+   }
+}
+
+const struct file_operations sw_sync_debugfs_fops = {
+   .open   = sw_sync_debugfs_open,
+   .release= sw_sync_debugfs_release,
+   .unlocked_ioctl = sw_sync_ioctl,
+   .compat_ioctl   = sw_sync_ioctl,
+};
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 14b61cb..02ecf44 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -132,6 +132,8 @@ struct sync_pt *sync_pt_create(struct sync_timeline 
*parent, int size,
 
 #ifdef CONFIG_DEB

[PATCH 09/18] staging/android: bring struct sync_pt back

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Move the list_head members from sync_pt to struct fence was a mistake,
they will not be used by struct fence as planned before, so here we create
sync_pt again to bring the list heads back.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   | 40 ++--
 drivers/staging/android/sync.h   | 29 ++
 drivers/staging/android/sync_debug.c | 16 +++
 include/linux/fence.h|  2 --
 4 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c83a599..aab80ec 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -28,8 +28,6 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops timeline_fence_ops;
-
 struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name)
 {
@@ -90,7 +88,7 @@ EXPORT_SYMBOL(sync_timeline_destroy);
 void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
-   struct fence *fence, *next;
+   struct sync_pt *pt, *next;
 
trace_sync_timeline(obj);
 
@@ -98,37 +96,37 @@ void sync_timeline_signal(struct sync_timeline *obj, 
unsigned int inc)
 
obj->value += inc;
 
-   list_for_each_entry_safe(fence, next, &obj->active_list_head,
+   list_for_each_entry_safe(pt, next, &obj->active_list_head,
 active_list) {
-   if (fence_is_signaled_locked(fence))
-   list_del_init(&fence->active_list);
+   if (fence_is_signaled_locked(&pt->base))
+   list_del_init(&pt->active_list);
}
 
spin_unlock_irqrestore(&obj->child_list_lock, flags);
 }
 EXPORT_SYMBOL(sync_timeline_signal);
 
-struct fence *sync_pt_create(struct sync_timeline *obj, int size,
+struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
 unsigned int value)
 {
unsigned long flags;
-   struct fence *fence;
+   struct sync_pt *pt;
 
-   if (size < sizeof(*fence))
+   if (size < sizeof(*pt))
return NULL;
 
-   fence = kzalloc(size, GFP_KERNEL);
-   if (!fence)
+   pt = kzalloc(size, GFP_KERNEL);
+   if (!pt)
return NULL;
 
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
-   fence_init(fence, &timeline_fence_ops, &obj->child_list_lock,
+   fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
   obj->context, value);
-   list_add_tail(&fence->child_list, &obj->child_list_head);
-   INIT_LIST_HEAD(&fence->active_list);
+   list_add_tail(&pt->child_list, &obj->child_list_head);
+   INIT_LIST_HEAD(&pt->active_list);
spin_unlock_irqrestore(&obj->child_list_lock, flags);
-   return fence;
+   return pt;
 }
 EXPORT_SYMBOL(sync_pt_create);
 
@@ -148,13 +146,14 @@ static const char 
*timeline_fence_get_timeline_name(struct fence *fence)
 
 static void timeline_fence_release(struct fence *fence)
 {
+   struct sync_pt *pt = fence_to_sync_pt(fence);
struct sync_timeline *parent = fence_parent(fence);
unsigned long flags;
 
spin_lock_irqsave(fence->lock, flags);
-   list_del(&fence->child_list);
-   if (WARN_ON_ONCE(!list_empty(&fence->active_list)))
-   list_del(&fence->active_list);
+   list_del(&pt->child_list);
+   if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+   list_del(&pt->active_list);
spin_unlock_irqrestore(fence->lock, flags);
 
sync_timeline_put(parent);
@@ -170,12 +169,13 @@ static bool timeline_fence_signaled(struct fence *fence)
 
 static bool timeline_fence_enable_signaling(struct fence *fence)
 {
+   struct sync_pt *pt = fence_to_sync_pt(fence);
struct sync_timeline *parent = fence_parent(fence);
 
if (timeline_fence_signaled(fence))
return false;
 
-   list_add_tail(&fence->active_list, &parent->active_list_head);
+   list_add_tail(&pt->active_list, &parent->active_list_head);
return true;
 }
 
@@ -193,7 +193,7 @@ static void timeline_fence_timeline_value_str(struct fence 
*fence,
snprintf(str, size, "%d", parent->value);
 }
 
-static const struct fence_ops timeline_fence_ops = {
+const struct fence_ops timeline_fence_ops = {
.get_driver_name = timeline_fence_get_driver_name,
.get_timeline_name = timeline_fence_get_timeline_name,
.enable_signaling = timeline_fence_enable_signaling,
diff --git a/drivers/staging/an

[PATCH 07/18] staging/android: remove unnecessary check for fence

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

When we call sync_print_fence() fence is always valid.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync_debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index dc85d5f..6282046 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -109,7 +109,7 @@ static void sync_print_fence(struct seq_file *s, struct 
fence *fence, bool show)
seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
}
 
-   if ((!fence || fence->ops->timeline_value_str) &&
+   if (fence->ops->timeline_value_str &&
fence->ops->fence_value_str) {
char value[64];
bool success;
@@ -117,10 +117,9 @@ static void sync_print_fence(struct seq_file *s, struct 
fence *fence, bool show)
fence->ops->fence_value_str(fence, value, sizeof(value));
success = strlen(value);
 
-   if (success)
+   if (success) {
seq_printf(s, ": %s", value);
 
-   if (success && fence) {
fence->ops->timeline_value_str(fence, value,
   sizeof(value));
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/18] staging/android: remove struct sync_timeline_ops

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Move drv_name, the last field of sync_timeline_ops, to sync_timeline
and remove sync_timeline_ops.

struct sync_timeline_ops was just an extra abstraction on top of
fence_ops, and in the last few commits we removed all it ops in favor
of cleaner fence_ops.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c|  9 ++---
 drivers/staging/android/sync.c   |  8 
 drivers/staging/android/sync.h   | 28 +---
 drivers/staging/android/sync_debug.c |  3 +--
 4 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 4200b12..c5e92c6 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,16 +38,11 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static struct sync_timeline_ops sw_sync_timeline_ops = {
-   .driver_name = "sw_sync",
-};
-
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 {
struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-   sync_timeline_create(&sw_sync_timeline_ops,
-sizeof(struct sw_sync_timeline),
-name);
+   sync_timeline_create(sizeof(struct sw_sync_timeline),
+"sw_sync", name);
 
return obj;
 }
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c75d1e6..b3efcaa 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -30,8 +30,8 @@
 
 static const struct fence_ops android_fence_ops;
 
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
-  int size, const char *name)
+struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+  const char *name)
 {
struct sync_timeline *obj;
 
@@ -43,9 +43,9 @@ struct sync_timeline *sync_timeline_create(const struct 
sync_timeline_ops *ops,
return NULL;
 
kref_init(&obj->kref);
-   obj->ops = ops;
obj->context = fence_context_alloc(1);
strlcpy(obj->name, name, sizeof(obj->name));
+   strlcpy(obj->drv_name, drv_name, sizeof(obj->drv_name));
 
INIT_LIST_HEAD(&obj->child_list_head);
INIT_LIST_HEAD(&obj->active_list_head);
@@ -139,7 +139,7 @@ static const char *android_fence_get_driver_name(struct 
fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   return parent->ops->driver_name;
+   return parent->drv_name;
 }
 
 static const char *android_fence_get_timeline_name(struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 29f8c19..f003e97 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -23,20 +23,10 @@
 #include 
 #include 
 
-struct sync_timeline;
-
-/**
- * struct sync_timeline_ops - sync object implementation ops
- * @driver_name:   name of the implementation
- */
-struct sync_timeline_ops {
-   const char *driver_name;
-};
-
 /**
  * struct sync_timeline - sync object
  * @kref:  reference count on fence.
- * @ops:   ops that define the implementation of the sync_timeline
+ * @drv_name:  drv_name of the driver using the sync_timeline
  * @name:  name of the sync_timeline. Useful for debugging
  * @destroyed: set when sync_timeline is destroyed
  * @child_list_head:   list of children sync_pts for this sync_timeline
@@ -47,7 +37,7 @@ struct sync_timeline_ops {
  */
 struct sync_timeline {
struct kref kref;
-   const struct sync_timeline_ops  *ops;
+   chardrv_name[32];
charname[32];
 
/* protected by child_list_lock */
@@ -76,17 +66,17 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
 
 /**
  * sync_timeline_create() - creates a sync object
- * @ops:   specifies the implementation ops for the object
  * @size:  size to allocate for this obj
+ * @drv_name:  sync_timeline driver name
  * @name:  sync_timeline name
  *
- * Creates a new sync_timeline which will use the implementation specified by
- * @ops.  @size bytes will be allocated allowing for implementation specific
- * data to be kept after the generic sync_timeline struct. Returns the
- * sync_timeline object or NULL in case of error.
+ * Creates a new sync_timeline. @size bytes will be allocated allowing
+ * for implementation specific data to be kept after the generic
+ * sync_timeline struct. Returns the sync_timeline object or NULL in
+ * case of error.
  */
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_o

[PATCH 05/18] staging/android: remove sw_sync.[ch] files

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

We can glue the sw_sync file operations directly on the sync framework
without the need to pass through sw_sync wrappers.

It only builds sw_sync debugfs file support if CONFIG_SW_SYNC is enabled.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Makefile |  1 -
 drivers/staging/android/sw_sync.c| 45 --
 drivers/staging/android/sw_sync.h| 47 
 drivers/staging/android/sync_debug.c | 17 ++---
 4 files changed, 13 insertions(+), 97 deletions(-)
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..bf45967 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,4 +5,3 @@ obj-y   += ion/
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
 obj-$(CONFIG_SYNC) += sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
deleted file mode 100644
index 461dbd9..000
--- a/drivers/staging/android/sw_sync.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * drivers/base/sw_sync.c
- *
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "sw_sync.h"
-
-struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value)
-{
-   return sync_pt_create(obj, sizeof(struct fence), value);
-}
-EXPORT_SYMBOL(sw_sync_pt_create);
-
-struct sync_timeline *sw_sync_timeline_create(const char *name)
-{
-   return sync_timeline_create(sizeof(struct sync_timeline),
-   "sw_sync", name);
-}
-EXPORT_SYMBOL(sw_sync_timeline_create);
-
-void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
-{
-   sync_timeline_signal(obj, inc);
-}
-EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h 
b/drivers/staging/android/sw_sync.h
deleted file mode 100644
index 9f26c62..000
--- a/drivers/staging/android/sw_sync.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * include/linux/sw_sync.h
- *
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _LINUX_SW_SYNC_H
-#define _LINUX_SW_SYNC_H
-
-#include 
-#include 
-#include "sync.h"
-#include "uapi/sw_sync.h"
-
-#if IS_ENABLED(CONFIG_SW_SYNC)
-struct sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc);
-
-struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value);
-#else
-static inline struct sync_timeline *sw_sync_timeline_create(const char *name)
-{
-   return NULL;
-}
-
-static inline void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
-{
-}
-
-static inline struct fence *sw_sync_pt_create(struct sync_timeline *obj,
- u32 value)
-{
-   return NULL;
-}
-#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
-
-#endif /* _LINUX_SW_SYNC_H */
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index e207a4d..dc85d5f 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -27,7 +27,11 @@
 #include 
 #include 
 #include 
-#include "sw_sync.h"
+#include 
+#include 
+
+#include "uapi/sw_sync.h"
+#include "sync.h"
 
 #ifdef CONFIG_DEBUG_FS
 
@@ -200,6 +204,7 @@ static const struct file_operations sync_info_debugfs_fops 
= {
.release= single_release,
 };
 
+#if IS_ENABLED(CONFIG_SW_SYNC)
 /*
  * *WARNING*
  *
@@ -214,7 +219,7 @@ static int sw_sync_debugfs_open(struct inode *inode, struct 
file *file)
 
get_task_comm(task_comm, current);
 
-   obj = sw_sync_timeline_create(task_comm);
+   obj = sync

[PATCH 06/18] staging/android: rename android_fence to timeline_fence

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

We are moving out of staging/android so rename it to a name that is not
related to android anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index b3efcaa..442d808 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -28,7 +28,7 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops android_fence_ops;
+static const struct fence_ops timeline_fence_ops;
 
 struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
   const char *name)
@@ -126,7 +126,7 @@ struct fence *sync_pt_create(struct sync_timeline *obj, int 
size,
 
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
-   fence_init(fence, &android_fence_ops, &obj->child_list_lock,
+   fence_init(fence, &timeline_fence_ops, &obj->child_list_lock,
   obj->context, value);
list_add_tail(&fence->child_list, &obj->child_list_head);
INIT_LIST_HEAD(&fence->active_list);
@@ -135,21 +135,21 @@ struct fence *sync_pt_create(struct sync_timeline *obj, 
int size,
 }
 EXPORT_SYMBOL(sync_pt_create);
 
-static const char *android_fence_get_driver_name(struct fence *fence)
+static const char *timeline_fence_get_driver_name(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return parent->drv_name;
 }
 
-static const char *android_fence_get_timeline_name(struct fence *fence)
+static const char *timeline_fence_get_timeline_name(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return parent->name;
 }
 
-static void android_fence_release(struct fence *fence)
+static void timeline_fence_release(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
unsigned long flags;
@@ -164,31 +164,31 @@ static void android_fence_release(struct fence *fence)
fence_free(fence);
 }
 
-static bool android_fence_signaled(struct fence *fence)
+static bool timeline_fence_signaled(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return (fence->seqno > parent->value) ? false : true;
 }
 
-static bool android_fence_enable_signaling(struct fence *fence)
+static bool timeline_fence_enable_signaling(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   if (android_fence_signaled(fence))
+   if (timeline_fence_signaled(fence))
return false;
 
list_add_tail(&fence->active_list, &parent->active_list_head);
return true;
 }
 
-static void android_fence_value_str(struct fence *fence,
+static void timeline_fence_value_str(struct fence *fence,
char *str, int size)
 {
snprintf(str, size, "%d", fence->seqno);
 }
 
-static void android_fence_timeline_value_str(struct fence *fence,
+static void timeline_fence_timeline_value_str(struct fence *fence,
 char *str, int size)
 {
struct sync_timeline *parent = fence_parent(fence);
@@ -196,13 +196,13 @@ static void android_fence_timeline_value_str(struct fence 
*fence,
snprintf(str, size, "%d", parent->value);
 }
 
-static const struct fence_ops android_fence_ops = {
-   .get_driver_name = android_fence_get_driver_name,
-   .get_timeline_name = android_fence_get_timeline_name,
-   .enable_signaling = android_fence_enable_signaling,
-   .signaled = android_fence_signaled,
+static const struct fence_ops timeline_fence_ops = {
+   .get_driver_name = timeline_fence_get_driver_name,
+   .get_timeline_name = timeline_fence_get_timeline_name,
+   .enable_signaling = timeline_fence_enable_signaling,
+   .signaled = timeline_fence_signaled,
.wait = fence_default_wait,
-   .release = android_fence_release,
-   .fence_value_str = android_fence_value_str,
-   .timeline_value_str = android_fence_timeline_value_str,
+   .release = timeline_fence_release,
+   .fence_value_str = timeline_fence_value_str,
+   .timeline_value_str = timeline_fence_timeline_value_str,
 };
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 04/18] staging/android: remove sw_sync_timeline and sw_sync_pt

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

As we moved value storage to sync_timeline and fence those two structs
became useless and can be removed now.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 24 +++-
 drivers/staging/android/sw_sync.h| 24 ++--
 drivers/staging/android/sync_debug.c | 12 ++--
 3 files changed, 19 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index c5e92c6..461dbd9 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,31 +25,21 @@
 
 #include "sw_sync.h"
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
+struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value)
 {
-   struct sw_sync_pt *pt;
-
-   pt = (struct sw_sync_pt *)
-   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt), value);
-
-   pt->value = value;
-
-   return (struct fence *)pt;
+   return sync_pt_create(obj, sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+struct sync_timeline *sw_sync_timeline_create(const char *name)
 {
-   struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-   sync_timeline_create(sizeof(struct sw_sync_timeline),
-"sw_sync", name);
-
-   return obj;
+   return sync_timeline_create(sizeof(struct sync_timeline),
+   "sw_sync", name);
 }
 EXPORT_SYMBOL(sw_sync_timeline_create);
 
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
 {
-   sync_timeline_signal(&obj->obj, inc);
+   sync_timeline_signal(obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h 
b/drivers/staging/android/sw_sync.h
index e18667b..9f26c62 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -22,34 +22,22 @@
 #include "sync.h"
 #include "uapi/sw_sync.h"
 
-struct sw_sync_timeline {
-   struct  sync_timeline   obj;
-
-   u32 value;
-};
-
-struct sw_sync_pt {
-   struct fencept;
-
-   u32 value;
-};
-
 #if IS_ENABLED(CONFIG_SW_SYNC)
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
+struct sync_timeline *sw_sync_timeline_create(const char *name);
+void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc);
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
+struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value);
 #else
-static inline struct sw_sync_timeline *sw_sync_timeline_create(const char 
*name)
+static inline struct sync_timeline *sw_sync_timeline_create(const char *name)
 {
return NULL;
 }
 
-static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+static inline void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
 {
 }
 
-static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj,
+static inline struct fence *sw_sync_pt_create(struct sync_timeline *obj,
  u32 value)
 {
return NULL;
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index e5634f2..e207a4d 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -209,7 +209,7 @@ static const struct file_operations sync_info_debugfs_fops 
= {
 /* opening sw_sync create a new sync obj */
 static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
 {
-   struct sw_sync_timeline *obj;
+   struct sync_timeline *obj;
char task_comm[TASK_COMM_LEN];
 
get_task_comm(task_comm, current);
@@ -225,13 +225,13 @@ static int sw_sync_debugfs_open(struct inode *inode, 
struct file *file)
 
 static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
 {
-   struct sw_sync_timeline *obj = file->private_data;
+   struct sync_timeline *obj = file->private_data;
 
-   sync_timeline_destroy(&obj->obj);
+   sync_timeline_destroy(obj);
return 0;
 }
 
-static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
+static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
   unsigned long arg)
 {
int fd = get_unused_fd_flags(O_CLOEXEC);
@@ -277,7 +277,7 @@ err:
return err;
 }
 
-static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
+static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
 {
u32 value;
 
@@ -292,7 +292,7 @@ static long sw_sync_ioctl_inc(struct sw_sync

[PATCH 02/18] staging/android: remove .{fence, timeline}_value_str() from timeline_ops

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Now that the value of fence and the timeline are not stored by sw_sync
anymore we can remove this extra abstraction to retrieve this data.

This patch changes both fence_ops (.fence_value_str and
.timeline_value_str) to return the str directly.

It also clean up struct sync_timeline_ops by removing both ops from there.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 17 -
 drivers/staging/android/sync.c   | 16 ++--
 drivers/staging/android/sync.h   |  9 -
 drivers/staging/android/sync_debug.c | 12 ++--
 drivers/staging/android/trace/sync.h | 12 +++-
 5 files changed, 7 insertions(+), 59 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 428e22c..4200b12 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,25 +38,8 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
-  char *str, int size)
-{
-   struct sw_sync_timeline *timeline =
-   (struct sw_sync_timeline *)sync_timeline;
-   snprintf(str, size, "%d", timeline->value);
-}
-
-static void sw_sync_fence_value_str(struct fence *fence, char *str, int size)
-{
-   struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-   snprintf(str, size, "%d", pt->value);
-}
-
 static struct sync_timeline_ops sw_sync_timeline_ops = {
.driver_name = "sw_sync",
-   .timeline_value_str = sw_sync_timeline_value_str,
-   .fence_value_str = sw_sync_fence_value_str,
 };
 
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 8dd2181..c75d1e6 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -185,14 +185,7 @@ static bool android_fence_enable_signaling(struct fence 
*fence)
 static void android_fence_value_str(struct fence *fence,
char *str, int size)
 {
-   struct sync_timeline *parent = fence_parent(fence);
-
-   if (!parent->ops->fence_value_str) {
-   if (size)
-   *str = 0;
-   return;
-   }
-   parent->ops->fence_value_str(fence, str, size);
+   snprintf(str, size, "%d", fence->seqno);
 }
 
 static void android_fence_timeline_value_str(struct fence *fence,
@@ -200,12 +193,7 @@ static void android_fence_timeline_value_str(struct fence 
*fence,
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   if (!parent->ops->timeline_value_str) {
-   if (size)
-   *str = 0;
-   return;
-   }
-   parent->ops->timeline_value_str(parent, str, size);
+   snprintf(str, size, "%d", parent->value);
 }
 
 static const struct fence_ops android_fence_ops = {
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 627525c..29f8c19 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -28,18 +28,9 @@ struct sync_timeline;
 /**
  * struct sync_timeline_ops - sync object implementation ops
  * @driver_name:   name of the implementation
- * @timeline_value_str: fill str with the value of the sync_timeline's counter
- * @fence_value_str:   fill str with the value of the fence
  */
 struct sync_timeline_ops {
const char *driver_name;
-
-   /* optional */
-   void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
-  int size);
-
-   /* optional */
-   void (*fence_value_str)(struct fence *fence, char *str, int size);
 };
 
 /**
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 5f57499..c532457 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,16 +133,8 @@ static void sync_print_obj(struct seq_file *s, struct 
sync_timeline *obj)
struct list_head *pos;
unsigned long flags;
 
-   seq_printf(s, "%s %s", obj->name, obj->ops->driver_name);
-
-   if (obj->ops->timeline_value_str) {
-   char value[64];
-
-   obj->ops->timeline_value_str(obj, value, sizeof(value));
-   seq_printf(s, ": %s", value);
-   }
-
-   seq_puts(s, "\n");
+   seq_printf(s, "%s %s: %d\n", obj->name, obj->ops->driver_name,
+  obj->value);
 
spin_lock_irqsave(&obj->child_list_lock, flags);
list_for_each(pos, &obj->child_list_head) {
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/andro

[PATCH 00/18] staging/android: clean up SW_SYNC

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi,

The following patches do a clean up on the sw_sync inteface. It starts by
removing struct sync_timeline_ops, which was creating unecessary wrappers
in the code and the start to organize the sync_timeline and sw_sync code
better.

sw_sync interface was moved to sw_sync.c along with sync_timeline - which
is now internal to sw_sync.

The next step after this work is the actual de-stage of SW_SYNC and
the upstreaming of selftests for sw_sync and sync_file.

Please review!

Gustavo

---

Gustavo Padovan (18):
  staging/android: store last signaled value on sync timeline
  staging/android: remove .{fence,timeline}_value_str() from timeline_ops
  staging/android: remove struct sync_timeline_ops
  staging/android: remove sw_sync_timeline and sw_sync_pt
  staging/android: remove sw_sync.[ch] files
  staging/android: rename android_fence to timeline_fence
  staging/android: remove unnecessary check for fence
  staging/android: remove size arg of sync_timeline_create()
  staging/android: bring struct sync_pt back
  staging/android: move sw_sync related code to sw_sync.c
  staging/android: clean up #includes in the sync framework
  staging/android: make sync_timeline internal to sw_sync
  staging/android: make sw_ioctl info internal to sw_sync.c
  staging/android: remove 'destroyed' member from struct sync_timeline
  staging/android: remove sync_timeline_destroy()
  staging/android: remove drv_name from sync_timeline
  staging/android: rename sync.h to sync_debug.h
  staging/android: add DEBUG_FS dependence on Kconfig

 drivers/staging/android/Kconfig|  17 +-
 drivers/staging/android/Makefile   |   3 +-
 drivers/staging/android/sw_sync.c  | 341 -
 drivers/staging/android/sw_sync.h  |  59 --
 drivers/staging/android/sync.c | 221 -
 drivers/staging/android/sync.h | 154 ---
 drivers/staging/android/sync_debug.c   | 154 +--
 drivers/staging/android/sync_debug.h   |  83 
 drivers/staging/android/trace/sync.h   |  14 +-
 drivers/staging/android/uapi/sw_sync.h |  32 
 include/linux/fence.h  |   2 -
 11 files changed, 399 insertions(+), 681 deletions(-)
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/sync.h
 create mode 100644 drivers/staging/android/sync_debug.h
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 01/18] staging/android: store last signaled value on sync timeline

2016-05-31 Thread Gustavo Padovan
From: Gustavo Padovan 

Now fence timeline is aware of the last signaled fence, as it
receives the increment to the current value in sync_timeline_signal().

That allow us to remove .has_signaled() from timeline_ops as we can
directly compare using timeline->value and fence->seqno in sync.c

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 16 ++--
 drivers/staging/android/sync.c| 15 +++
 drivers/staging/android/sync.h| 14 +-
 3 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index af39ff5..428e22c 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -30,7 +30,7 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, 
u32 value)
struct sw_sync_pt *pt;
 
pt = (struct sw_sync_pt *)
-   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt));
+   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt), value);
 
pt->value = value;
 
@@ -38,15 +38,6 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static int sw_sync_fence_has_signaled(struct fence *fence)
-{
-   struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-   struct sw_sync_timeline *obj =
-   (struct sw_sync_timeline *)fence_parent(fence);
-
-   return (pt->value > obj->value) ? 0 : 1;
-}
-
 static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
   char *str, int size)
 {
@@ -64,7 +55,6 @@ static void sw_sync_fence_value_str(struct fence *fence, char 
*str, int size)
 
 static struct sync_timeline_ops sw_sync_timeline_ops = {
.driver_name = "sw_sync",
-   .has_signaled = sw_sync_fence_has_signaled,
.timeline_value_str = sw_sync_timeline_value_str,
.fence_value_str = sw_sync_fence_value_str,
 };
@@ -82,8 +72,6 @@ EXPORT_SYMBOL(sw_sync_timeline_create);
 
 void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
 {
-   obj->value += inc;
-
-   sync_timeline_signal(&obj->obj);
+   sync_timeline_signal(&obj->obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 1d14c83..8dd2181 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -90,7 +90,7 @@ void sync_timeline_destroy(struct sync_timeline *obj)
 }
 EXPORT_SYMBOL(sync_timeline_destroy);
 
-void sync_timeline_signal(struct sync_timeline *obj)
+void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
struct fence *fence, *next;
@@ -99,6 +99,8 @@ void sync_timeline_signal(struct sync_timeline *obj)
 
spin_lock_irqsave(&obj->child_list_lock, flags);
 
+   obj->value += inc;
+
list_for_each_entry_safe(fence, next, &obj->active_list_head,
 active_list) {
if (fence_is_signaled_locked(fence))
@@ -109,7 +111,8 @@ void sync_timeline_signal(struct sync_timeline *obj)
 }
 EXPORT_SYMBOL(sync_timeline_signal);
 
-struct fence *sync_pt_create(struct sync_timeline *obj, int size)
+struct fence *sync_pt_create(struct sync_timeline *obj, int size,
+unsigned int value)
 {
unsigned long flags;
struct fence *fence;
@@ -124,7 +127,7 @@ struct fence *sync_pt_create(struct sync_timeline *obj, int 
size)
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
fence_init(fence, &android_fence_ops, &obj->child_list_lock,
-  obj->context, ++obj->value);
+  obj->context, value);
list_add_tail(&fence->child_list, &obj->child_list_head);
INIT_LIST_HEAD(&fence->active_list);
spin_unlock_irqrestore(&obj->child_list_lock, flags);
@@ -164,12 +167,8 @@ static void android_fence_release(struct fence *fence)
 static bool android_fence_signaled(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
-   int ret;
 
-   ret = parent->ops->has_signaled(fence);
-   if (ret < 0)
-   fence->status = ret;
-   return ret;
+   return (fence->seqno > parent->value) ? false : true;
 }
 
 static bool android_fence_enable_signaling(struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index b56885c..627525c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -28,19 +28,12 @@ struct sync_timeline;
 /**
  * struct sync_timeline_ops - sync object implementation ops
  * @driver_name:   name of the implementation
- * @has_signaled:  returns:
- *  

[PATCH v2] MAINTAINERS: add entry for the Sync File Framework

2016-05-13 Thread Gustavo Padovan
From: Gustavo Padovan 

Add Gustavo as maintainer for the Sync File Framework. Sumit is
co-maintainer as he maintains drivers/dma-buf/. It also uses Sumit's
tree as base.

Signed-off-by: Gustavo Padovan 
Acked-by: Sumit Semwal 
Acked-by: Maarten Lankhorst 
---
 MAINTAINERS | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8c10b4c..71c4e7f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3677,6 +3677,17 @@ F:   include/linux/*fence.h
 F: Documentation/dma-buf-sharing.txt
 T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
 
+SYNC FILE FRAMEWORK
+M: Sumit Semwal 
+R: Gustavo Padovan 
+S: Maintained
+L: linux-me...@vger.kernel.org
+L: dri-de...@lists.freedesktop.org
+F: drivers/dma-buf/sync_file.c
+F: include/linux/sync_file.h
+F: Documentation/sync_file.txt
+T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
+
 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
 M: Vinod Koul 
 L: dmaeng...@vger.kernel.org
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] MAINTAINERS: add entry for the Sync File Framework

2016-05-11 Thread Gustavo Padovan
From: Gustavo Padovan 

Add Gustavo as maintainer for the Sync File Framework. Sumit is
co-maintainer as he maintains drivers/dma-buf/. It also uses Sumit's
tree as base.

Cc: Sumit Semwal 
Signed-off-by: Gustavo Padovan 
---
 MAINTAINERS | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8c10b4c..0abc9c3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3677,6 +3677,16 @@ F:   include/linux/*fence.h
 F: Documentation/dma-buf-sharing.txt
 T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
 
+SYNC FILE FRAMEWORK
+M: Gustavo Padovan 
+S: Maintained
+L: linux-me...@vger.kernel.org
+L: dri-de...@lists.freedesktop.org
+F: drivers/dma-buf/sync_file.c
+F: include/linux/sync_file.h
+F: Documentation/sync_file.txt
+T: git git://git.linaro.org/people/sumitsemwal/linux-dma-buf.git
+
 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
 M: Vinod Koul 
 L: dmaeng...@vger.kernel.org
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 06/12] staging/android: prepare sync_file for de-staging

2016-05-02 Thread Gustavo Padovan
Hi Pavel,

2016-05-02 Pavel Machek :

> Hi!
> 
> 
> > -}
> > -EXPORT_SYMBOL(sync_file_merge);
> > -
> >  static const char *android_fence_get_driver_name(struct fence *fence)
> >  {
> > struct sync_timeline *parent = fence_parent(fence);
> 
> if this is meant to be used outside android, should it select some
> better prefix than android_fence_?

Sure, This patchset doesn't touch this code, but my latest patchset
changes them to timeline_*.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 01/12] staging/android: remove redundant comments on sync_merge_data

2016-05-02 Thread Gustavo Padovan
2016-05-02 Pavel Machek :

> On Wed 2016-04-27 13:27:08, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > struct sync_merge_data already have documentation on top of the
> > struct definition. No need to duplicate it.
> > 
> > Signed-off-by: Gustavo Padovan 
> > Reviewed-by: Maarten Lankhorst 
> 
> > @@ -33,8 +33,8 @@ struct sync_merge_data {
> >  /**
> >   * struct sync_fence_info - detailed fence information
> >   * @obj_name:  name of parent sync_timeline
> > - * @driver_name:   name of driver implementing the parent
> > - * @status:status of the fence 0:active 1:signaled <0:error
> > +* @driver_name:name of driver implementing the parent
> > +* @status: status of the fence 0:active 1:signaled <0:error
> 
> The whitespace (or mail client configuration?) looks wrong here.

this has been fixed in v2 already and Greg pulled everything into
staging next already.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/13] staging/android: remove size arg of sync_timeline_create()

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

After we removed sw_sync_timeline this arg has not been really used by
anyone, all its users pass the size of struct sync_timeline there.

So simplify this function but not requiring the size anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   | 7 ++-
 drivers/staging/android/sync.h   | 7 ++-
 drivers/staging/android/sync_debug.c | 2 +-
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 442d808..c83a599 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -30,15 +30,12 @@
 
 static const struct fence_ops timeline_fence_ops;
 
-struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name)
 {
struct sync_timeline *obj;
 
-   if (size < sizeof(struct sync_timeline))
-   return NULL;
-
-   obj = kzalloc(size, GFP_KERNEL);
+   obj = kzalloc(sizeof(*obj), GFP_KERNEL);
if (!obj)
return NULL;
 
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index f003e97..f2fbf98 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -66,16 +66,13 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
 
 /**
  * sync_timeline_create() - creates a sync object
- * @size:  size to allocate for this obj
  * @drv_name:  sync_timeline driver name
  * @name:  sync_timeline name
  *
- * Creates a new sync_timeline. @size bytes will be allocated allowing
- * for implementation specific data to be kept after the generic
- * sync_timeline struct. Returns the sync_timeline object or NULL in
+ * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
  * case of error.
  */
-struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name);
 
 /**
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 6282046..cb0f888 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -218,7 +218,7 @@ static int sw_sync_debugfs_open(struct inode *inode, struct 
file *file)
 
get_task_comm(task_comm, current);
 
-   obj = sync_timeline_create(sizeof(*obj), "sw_sync", task_comm);
+   obj = sync_timeline_create("sw_sync", task_comm);
if (!obj)
return -ENOMEM;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/13] staging/android: move sw_sync related code to sw_sync.c

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Split sync_debug and sw_sync in two different files.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Makefile |   1 +
 drivers/staging/android/sw_sync.c| 136 +++
 drivers/staging/android/sync.h   |   2 +
 drivers/staging/android/sync_debug.c | 115 -
 4 files changed, 139 insertions(+), 115 deletions(-)
 create mode 100644 drivers/staging/android/sw_sync.c

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index bf45967..980d6dc 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,3 +5,4 @@ obj-y   += ion/
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
 obj-$(CONFIG_SYNC) += sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
new file mode 100644
index 000..90e3ee5
--- /dev/null
+++ b/drivers/staging/android/sw_sync.c
@@ -0,0 +1,136 @@
+/*
+ * drivers/dma-buf/sw_sync.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "uapi/sw_sync.h"
+#include "sync.h"
+
+/*
+ * *WARNING*
+ *
+ * improper use of this can result in deadlocking kernel drivers from 
userspace.
+ */
+
+/* opening sw_sync create a new sync obj */
+static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
+{
+   struct sync_timeline *obj;
+   char task_comm[TASK_COMM_LEN];
+
+   get_task_comm(task_comm, current);
+
+   obj = sync_timeline_create("sw_sync", task_comm);
+   if (!obj)
+   return -ENOMEM;
+
+   file->private_data = obj;
+
+   return 0;
+}
+
+static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
+{
+   struct sync_timeline *obj = file->private_data;
+
+   sync_timeline_destroy(obj);
+   return 0;
+}
+
+static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
+  unsigned long arg)
+{
+   int fd = get_unused_fd_flags(O_CLOEXEC);
+   int err;
+   struct sync_pt *pt;
+   struct sync_file *sync_file;
+   struct sw_sync_create_fence_data data;
+
+   if (fd < 0)
+   return fd;
+
+   if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
+   err = -EFAULT;
+   goto err;
+   }
+
+   pt = sync_pt_create(obj, sizeof(*pt), data.value);
+   if (!pt) {
+   err = -ENOMEM;
+   goto err;
+   }
+
+   sync_file = sync_file_create(&pt->base);
+   if (!sync_file) {
+   fence_put(&pt->base);
+   err = -ENOMEM;
+   goto err;
+   }
+
+   data.fence = fd;
+   if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
+   fput(sync_file->file);
+   err = -EFAULT;
+   goto err;
+   }
+
+   fd_install(fd, sync_file->file);
+
+   return 0;
+
+err:
+   put_unused_fd(fd);
+   return err;
+}
+
+static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
+{
+   u32 value;
+
+   if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
+   return -EFAULT;
+
+   sync_timeline_signal(obj, value);
+
+   return 0;
+}
+
+static long sw_sync_ioctl(struct file *file, unsigned int cmd,
+ unsigned long arg)
+{
+   struct sync_timeline *obj = file->private_data;
+
+   switch (cmd) {
+   case SW_SYNC_IOC_CREATE_FENCE:
+   return sw_sync_ioctl_create_fence(obj, arg);
+
+   case SW_SYNC_IOC_INC:
+   return sw_sync_ioctl_inc(obj, arg);
+
+   default:
+   return -ENOTTY;
+   }
+}
+
+const struct file_operations sw_sync_debugfs_fops = {
+   .open   = sw_sync_debugfs_open,
+   .release= sw_sync_debugfs_release,
+   .unlocked_ioctl = sw_sync_ioctl,
+   .compat_ioctl   = sw_sync_ioctl,
+};
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 14b61cb..02ecf44 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -132,6 +132,8 @@ struct sync_pt *sync_pt_create(struct sync_timeline 
*parent, int size,
 
 #ifdef CONFIG_DEB

[PATCH 04/13] staging/android: remove sw_sync_timeline and sw_sync_pt

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

As we moved value storage to sync_timeline and fence those two structs
became useless and can be removed now.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 24 +++-
 drivers/staging/android/sw_sync.h| 24 ++--
 drivers/staging/android/sync_debug.c | 12 ++--
 3 files changed, 19 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index c5e92c6..461dbd9 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,31 +25,21 @@
 
 #include "sw_sync.h"
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
+struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value)
 {
-   struct sw_sync_pt *pt;
-
-   pt = (struct sw_sync_pt *)
-   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt), value);
-
-   pt->value = value;
-
-   return (struct fence *)pt;
+   return sync_pt_create(obj, sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+struct sync_timeline *sw_sync_timeline_create(const char *name)
 {
-   struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-   sync_timeline_create(sizeof(struct sw_sync_timeline),
-"sw_sync", name);
-
-   return obj;
+   return sync_timeline_create(sizeof(struct sync_timeline),
+   "sw_sync", name);
 }
 EXPORT_SYMBOL(sw_sync_timeline_create);
 
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
 {
-   sync_timeline_signal(&obj->obj, inc);
+   sync_timeline_signal(obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h 
b/drivers/staging/android/sw_sync.h
index e18667b..9f26c62 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -22,34 +22,22 @@
 #include "sync.h"
 #include "uapi/sw_sync.h"
 
-struct sw_sync_timeline {
-   struct  sync_timeline   obj;
-
-   u32 value;
-};
-
-struct sw_sync_pt {
-   struct fencept;
-
-   u32 value;
-};
-
 #if IS_ENABLED(CONFIG_SW_SYNC)
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
+struct sync_timeline *sw_sync_timeline_create(const char *name);
+void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc);
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
+struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value);
 #else
-static inline struct sw_sync_timeline *sw_sync_timeline_create(const char 
*name)
+static inline struct sync_timeline *sw_sync_timeline_create(const char *name)
 {
return NULL;
 }
 
-static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+static inline void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
 {
 }
 
-static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj,
+static inline struct fence *sw_sync_pt_create(struct sync_timeline *obj,
  u32 value)
 {
return NULL;
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index e5634f2..e207a4d 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -209,7 +209,7 @@ static const struct file_operations sync_info_debugfs_fops 
= {
 /* opening sw_sync create a new sync obj */
 static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
 {
-   struct sw_sync_timeline *obj;
+   struct sync_timeline *obj;
char task_comm[TASK_COMM_LEN];
 
get_task_comm(task_comm, current);
@@ -225,13 +225,13 @@ static int sw_sync_debugfs_open(struct inode *inode, 
struct file *file)
 
 static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
 {
-   struct sw_sync_timeline *obj = file->private_data;
+   struct sync_timeline *obj = file->private_data;
 
-   sync_timeline_destroy(&obj->obj);
+   sync_timeline_destroy(obj);
return 0;
 }
 
-static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
+static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
   unsigned long arg)
 {
int fd = get_unused_fd_flags(O_CLOEXEC);
@@ -277,7 +277,7 @@ err:
return err;
 }
 
-static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
+static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
 {
u32 value;
 
@@ -292,7 +292,7 @@ static long sw_sync_ioctl_inc(struct sw_sync

[PATCH 02/13] staging/android: remove .{fence, timeline}_value_str() from timeline_ops

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Now that the value of fence and the timeline are not stored by sw_sync
anymore we can remove this extra abstraction to retrieve this data.

This patch changes both fence_ops (.fence_value_str and
.timeline_value_str) to return the str directly.

It also clean up struct sync_timeline_ops by removing both ops from there.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c| 17 -
 drivers/staging/android/sync.c   | 16 ++--
 drivers/staging/android/sync.h   |  9 -
 drivers/staging/android/sync_debug.c | 12 ++--
 drivers/staging/android/trace/sync.h | 12 +++-
 5 files changed, 7 insertions(+), 59 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 428e22c..4200b12 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,25 +38,8 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
-  char *str, int size)
-{
-   struct sw_sync_timeline *timeline =
-   (struct sw_sync_timeline *)sync_timeline;
-   snprintf(str, size, "%d", timeline->value);
-}
-
-static void sw_sync_fence_value_str(struct fence *fence, char *str, int size)
-{
-   struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-   snprintf(str, size, "%d", pt->value);
-}
-
 static struct sync_timeline_ops sw_sync_timeline_ops = {
.driver_name = "sw_sync",
-   .timeline_value_str = sw_sync_timeline_value_str,
-   .fence_value_str = sw_sync_fence_value_str,
 };
 
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 8dd2181..c75d1e6 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -185,14 +185,7 @@ static bool android_fence_enable_signaling(struct fence 
*fence)
 static void android_fence_value_str(struct fence *fence,
char *str, int size)
 {
-   struct sync_timeline *parent = fence_parent(fence);
-
-   if (!parent->ops->fence_value_str) {
-   if (size)
-   *str = 0;
-   return;
-   }
-   parent->ops->fence_value_str(fence, str, size);
+   snprintf(str, size, "%d", fence->seqno);
 }
 
 static void android_fence_timeline_value_str(struct fence *fence,
@@ -200,12 +193,7 @@ static void android_fence_timeline_value_str(struct fence 
*fence,
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   if (!parent->ops->timeline_value_str) {
-   if (size)
-   *str = 0;
-   return;
-   }
-   parent->ops->timeline_value_str(parent, str, size);
+   snprintf(str, size, "%d", parent->value);
 }
 
 static const struct fence_ops android_fence_ops = {
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 627525c..29f8c19 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -28,18 +28,9 @@ struct sync_timeline;
 /**
  * struct sync_timeline_ops - sync object implementation ops
  * @driver_name:   name of the implementation
- * @timeline_value_str: fill str with the value of the sync_timeline's counter
- * @fence_value_str:   fill str with the value of the fence
  */
 struct sync_timeline_ops {
const char *driver_name;
-
-   /* optional */
-   void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
-  int size);
-
-   /* optional */
-   void (*fence_value_str)(struct fence *fence, char *str, int size);
 };
 
 /**
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 5f57499..c532457 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,16 +133,8 @@ static void sync_print_obj(struct seq_file *s, struct 
sync_timeline *obj)
struct list_head *pos;
unsigned long flags;
 
-   seq_printf(s, "%s %s", obj->name, obj->ops->driver_name);
-
-   if (obj->ops->timeline_value_str) {
-   char value[64];
-
-   obj->ops->timeline_value_str(obj, value, sizeof(value));
-   seq_printf(s, ": %s", value);
-   }
-
-   seq_puts(s, "\n");
+   seq_printf(s, "%s %s: %d\n", obj->name, obj->ops->driver_name,
+  obj->value);
 
spin_lock_irqsave(&obj->child_list_lock, flags);
list_for_each(pos, &obj->child_list_head) {
diff --git a/drivers/staging/android/trace/sync.h 
b/drivers/staging/andro

[PATCH 05/13] staging/android: remove sw_sync.[ch] files

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

We can glue the sw_sync file operations directly on the sync framework
without the need to pass through sw_sync wrappers.

It only builds sw_sync debugfs file support if CONFIG_SW_SYNC is enabled.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Makefile |  1 -
 drivers/staging/android/sw_sync.c| 45 --
 drivers/staging/android/sw_sync.h| 47 
 drivers/staging/android/sync_debug.c | 17 ++---
 4 files changed, 13 insertions(+), 97 deletions(-)
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sw_sync.h

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..bf45967 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,4 +5,3 @@ obj-y   += ion/
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
 obj-$(CONFIG_SYNC) += sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
deleted file mode 100644
index 461dbd9..000
--- a/drivers/staging/android/sw_sync.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * drivers/base/sw_sync.c
- *
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "sw_sync.h"
-
-struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value)
-{
-   return sync_pt_create(obj, sizeof(struct fence), value);
-}
-EXPORT_SYMBOL(sw_sync_pt_create);
-
-struct sync_timeline *sw_sync_timeline_create(const char *name)
-{
-   return sync_timeline_create(sizeof(struct sync_timeline),
-   "sw_sync", name);
-}
-EXPORT_SYMBOL(sw_sync_timeline_create);
-
-void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
-{
-   sync_timeline_signal(obj, inc);
-}
-EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h 
b/drivers/staging/android/sw_sync.h
deleted file mode 100644
index 9f26c62..000
--- a/drivers/staging/android/sw_sync.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * include/linux/sw_sync.h
- *
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _LINUX_SW_SYNC_H
-#define _LINUX_SW_SYNC_H
-
-#include 
-#include 
-#include "sync.h"
-#include "uapi/sw_sync.h"
-
-#if IS_ENABLED(CONFIG_SW_SYNC)
-struct sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc);
-
-struct fence *sw_sync_pt_create(struct sync_timeline *obj, u32 value);
-#else
-static inline struct sync_timeline *sw_sync_timeline_create(const char *name)
-{
-   return NULL;
-}
-
-static inline void sw_sync_timeline_inc(struct sync_timeline *obj, u32 inc)
-{
-}
-
-static inline struct fence *sw_sync_pt_create(struct sync_timeline *obj,
- u32 value)
-{
-   return NULL;
-}
-#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
-
-#endif /* _LINUX_SW_SYNC_H */
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index e207a4d..dc85d5f 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -27,7 +27,11 @@
 #include 
 #include 
 #include 
-#include "sw_sync.h"
+#include 
+#include 
+
+#include "uapi/sw_sync.h"
+#include "sync.h"
 
 #ifdef CONFIG_DEBUG_FS
 
@@ -200,6 +204,7 @@ static const struct file_operations sync_info_debugfs_fops 
= {
.release= single_release,
 };
 
+#if IS_ENABLED(CONFIG_SW_SYNC)
 /*
  * *WARNING*
  *
@@ -214,7 +219,7 @@ static int sw_sync_debugfs_open(struct inode *inode, struct 
file *file)
 
get_task_comm(task_comm, current);
 
-   obj = sw_sync_timeline_create(task_comm);
+   obj = sync

[PATCH 01/13] staging/android: store last signaled value on sync timeline

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Now fence timeline is aware of the last signaled fence, as it
receives the increment to the current value in sync_timeline_signal().

That allow us to remove .has_signaled() from timeline_ops as we can
directly compare using timeline->value and fence->seqno in sync.c

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c | 16 ++--
 drivers/staging/android/sync.c| 15 +++
 drivers/staging/android/sync.h| 14 +-
 3 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index af39ff5..428e22c 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -30,7 +30,7 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, 
u32 value)
struct sw_sync_pt *pt;
 
pt = (struct sw_sync_pt *)
-   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt));
+   sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt), value);
 
pt->value = value;
 
@@ -38,15 +38,6 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static int sw_sync_fence_has_signaled(struct fence *fence)
-{
-   struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-   struct sw_sync_timeline *obj =
-   (struct sw_sync_timeline *)fence_parent(fence);
-
-   return (pt->value > obj->value) ? 0 : 1;
-}
-
 static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
   char *str, int size)
 {
@@ -64,7 +55,6 @@ static void sw_sync_fence_value_str(struct fence *fence, char 
*str, int size)
 
 static struct sync_timeline_ops sw_sync_timeline_ops = {
.driver_name = "sw_sync",
-   .has_signaled = sw_sync_fence_has_signaled,
.timeline_value_str = sw_sync_timeline_value_str,
.fence_value_str = sw_sync_fence_value_str,
 };
@@ -82,8 +72,6 @@ EXPORT_SYMBOL(sw_sync_timeline_create);
 
 void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
 {
-   obj->value += inc;
-
-   sync_timeline_signal(&obj->obj);
+   sync_timeline_signal(&obj->obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 1d14c83..8dd2181 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -90,7 +90,7 @@ void sync_timeline_destroy(struct sync_timeline *obj)
 }
 EXPORT_SYMBOL(sync_timeline_destroy);
 
-void sync_timeline_signal(struct sync_timeline *obj)
+void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
struct fence *fence, *next;
@@ -99,6 +99,8 @@ void sync_timeline_signal(struct sync_timeline *obj)
 
spin_lock_irqsave(&obj->child_list_lock, flags);
 
+   obj->value += inc;
+
list_for_each_entry_safe(fence, next, &obj->active_list_head,
 active_list) {
if (fence_is_signaled_locked(fence))
@@ -109,7 +111,8 @@ void sync_timeline_signal(struct sync_timeline *obj)
 }
 EXPORT_SYMBOL(sync_timeline_signal);
 
-struct fence *sync_pt_create(struct sync_timeline *obj, int size)
+struct fence *sync_pt_create(struct sync_timeline *obj, int size,
+unsigned int value)
 {
unsigned long flags;
struct fence *fence;
@@ -124,7 +127,7 @@ struct fence *sync_pt_create(struct sync_timeline *obj, int 
size)
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
fence_init(fence, &android_fence_ops, &obj->child_list_lock,
-  obj->context, ++obj->value);
+  obj->context, value);
list_add_tail(&fence->child_list, &obj->child_list_head);
INIT_LIST_HEAD(&fence->active_list);
spin_unlock_irqrestore(&obj->child_list_lock, flags);
@@ -164,12 +167,8 @@ static void android_fence_release(struct fence *fence)
 static bool android_fence_signaled(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
-   int ret;
 
-   ret = parent->ops->has_signaled(fence);
-   if (ret < 0)
-   fence->status = ret;
-   return ret;
+   return (fence->seqno > parent->value) ? false : true;
 }
 
 static bool android_fence_enable_signaling(struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index b56885c..627525c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -28,19 +28,12 @@ struct sync_timeline;
 /**
  * struct sync_timeline_ops - sync object implementation ops
  * @driver_name:   name of the implementation
- * @has_signaled:  returns:
- *  

[PATCH 06/13] staging/android: rename android_fence to timeline_fence

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

We are moving out of staging/android so rename it to a name that is not
related to android anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index b3efcaa..442d808 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -28,7 +28,7 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops android_fence_ops;
+static const struct fence_ops timeline_fence_ops;
 
 struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
   const char *name)
@@ -126,7 +126,7 @@ struct fence *sync_pt_create(struct sync_timeline *obj, int 
size,
 
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
-   fence_init(fence, &android_fence_ops, &obj->child_list_lock,
+   fence_init(fence, &timeline_fence_ops, &obj->child_list_lock,
   obj->context, value);
list_add_tail(&fence->child_list, &obj->child_list_head);
INIT_LIST_HEAD(&fence->active_list);
@@ -135,21 +135,21 @@ struct fence *sync_pt_create(struct sync_timeline *obj, 
int size,
 }
 EXPORT_SYMBOL(sync_pt_create);
 
-static const char *android_fence_get_driver_name(struct fence *fence)
+static const char *timeline_fence_get_driver_name(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return parent->drv_name;
 }
 
-static const char *android_fence_get_timeline_name(struct fence *fence)
+static const char *timeline_fence_get_timeline_name(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return parent->name;
 }
 
-static void android_fence_release(struct fence *fence)
+static void timeline_fence_release(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
unsigned long flags;
@@ -164,31 +164,31 @@ static void android_fence_release(struct fence *fence)
fence_free(fence);
 }
 
-static bool android_fence_signaled(struct fence *fence)
+static bool timeline_fence_signaled(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
return (fence->seqno > parent->value) ? false : true;
 }
 
-static bool android_fence_enable_signaling(struct fence *fence)
+static bool timeline_fence_enable_signaling(struct fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   if (android_fence_signaled(fence))
+   if (timeline_fence_signaled(fence))
return false;
 
list_add_tail(&fence->active_list, &parent->active_list_head);
return true;
 }
 
-static void android_fence_value_str(struct fence *fence,
+static void timeline_fence_value_str(struct fence *fence,
char *str, int size)
 {
snprintf(str, size, "%d", fence->seqno);
 }
 
-static void android_fence_timeline_value_str(struct fence *fence,
+static void timeline_fence_timeline_value_str(struct fence *fence,
 char *str, int size)
 {
struct sync_timeline *parent = fence_parent(fence);
@@ -196,13 +196,13 @@ static void android_fence_timeline_value_str(struct fence 
*fence,
snprintf(str, size, "%d", parent->value);
 }
 
-static const struct fence_ops android_fence_ops = {
-   .get_driver_name = android_fence_get_driver_name,
-   .get_timeline_name = android_fence_get_timeline_name,
-   .enable_signaling = android_fence_enable_signaling,
-   .signaled = android_fence_signaled,
+static const struct fence_ops timeline_fence_ops = {
+   .get_driver_name = timeline_fence_get_driver_name,
+   .get_timeline_name = timeline_fence_get_timeline_name,
+   .enable_signaling = timeline_fence_enable_signaling,
+   .signaled = timeline_fence_signaled,
.wait = fence_default_wait,
-   .release = android_fence_release,
-   .fence_value_str = android_fence_value_str,
-   .timeline_value_str = android_fence_timeline_value_str,
+   .release = timeline_fence_release,
+   .fence_value_str = timeline_fence_value_str,
+   .timeline_value_str = timeline_fence_timeline_value_str,
 };
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/13] staging/android: make sync_timeline internal to sw_sync

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

The only use sync_timeline will have in upstream kernel is for debugging
through the SW_SYNC interface. So make it internal to SW_SYNC to avoid
people use it in the future.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Kconfig   |  16 +--
 drivers/staging/android/Makefile  |   3 +-
 drivers/staging/android/sw_sync.c | 211 ++
 drivers/staging/android/sync.c| 199 ---
 drivers/staging/android/sync.h|  49 -
 5 files changed, 216 insertions(+), 262 deletions(-)
 delete mode 100644 drivers/staging/android/sync.c

diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 6480f60..f52c682 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -24,26 +24,18 @@ config ANDROID_LOW_MEMORY_KILLER
  scripts (/init.rc), and it defines priority values with minimum free 
memory size
  for each priority.
 
-config SYNC
-   bool "Synchronization framework"
-   default n
-   select ANON_INODES
-   select DMA_SHARED_BUFFER
-   ---help---
- This option enables the framework for synchronization between multiple
- drivers.  Sync implementations can take advantage of hardware
- synchronization built into devices like GPUs.
-
 config SW_SYNC
-   bool "Software synchronization objects"
+   bool "Software synchronization framework"
default n
-   depends on SYNC
depends on SYNC_FILE
---help---
  A sync object driver that uses a 32bit counter to coordinate
  synchronization.  Useful when there is no hardware primitive backing
  the synchronization.
 
+ WARNING: improper use of this can result in deadlocking kernel
+ drivers from userspace. Intended for test and debug only.
+
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..7ca61b7 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,4 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)  += sw_sync.o
+obj-$(CONFIG_SW_SYNC)  += sw_sync.o sync_debug.o
diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 90e3ee5..4922233 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -17,11 +17,222 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "uapi/sw_sync.h"
 #include "sync.h"
 
+#define CREATE_TRACE_POINTS
+#include "trace/sync.h"
+
+/**
+ * sync_timeline_create() - creates a sync object
+ * @drv_name:  sync_timeline driver name
+ * @name:  sync_timeline name
+ *
+ * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
+ * case of error.
+ */
+struct sync_timeline *sync_timeline_create(const char *drv_name,
+  const char *name)
+{
+   struct sync_timeline *obj;
+
+   obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+   if (!obj)
+   return NULL;
+
+   kref_init(&obj->kref);
+   obj->context = fence_context_alloc(1);
+   strlcpy(obj->name, name, sizeof(obj->name));
+   strlcpy(obj->drv_name, drv_name, sizeof(obj->drv_name));
+
+   INIT_LIST_HEAD(&obj->child_list_head);
+   INIT_LIST_HEAD(&obj->active_list_head);
+   spin_lock_init(&obj->child_list_lock);
+
+   sync_timeline_debug_add(obj);
+
+   return obj;
+}
+
+static void sync_timeline_free(struct kref *kref)
+{
+   struct sync_timeline *obj =
+   container_of(kref, struct sync_timeline, kref);
+
+   sync_timeline_debug_remove(obj);
+
+   kfree(obj);
+}
+
+static void sync_timeline_get(struct sync_timeline *obj)
+{
+   kref_get(&obj->kref);
+}
+
+static void sync_timeline_put(struct sync_timeline *obj)
+{
+   kref_put(&obj->kref, sync_timeline_free);
+}
+
+/**
+ * sync_timeline_destroy() - destroys a sync object
+ * @obj:   sync_timeline to destroy
+ *
+ * A sync implementation should call this when the @obj is going away
+ * (i.e. module unload.)  @obj won't actually be freed until all its children
+ * fences are freed.
+ */
+static void sync_timeline_destroy(struct sync_timeline *obj)
+{
+   obj->destroyed = true;
+   /*
+* Ensure timeline is marked as destroyed before
+* changing timeline's fences status.
+*/
+   smp_wmb();
+
+   sync_timeline_put(obj);
+}
+
+/**
+ * sync_timeline_signal() - signal a status change 

[PATCH 11/13] staging/android: clean up #includes in the sync framework

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Most of the includes there are not necessary anymore.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   |  6 --
 drivers/staging/android/sync.h   |  3 ---
 drivers/staging/android/sync_debug.c | 16 
 3 files changed, 25 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index aab80ec..bb12d86 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -14,14 +14,8 @@
  *
  */
 
-#include 
 #include 
-#include 
-#include 
-#include 
 #include 
-#include 
-#include 
 
 #include "sync.h"
 
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 02ecf44..54c515b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -13,9 +13,6 @@
 #ifndef _LINUX_SYNC_H
 #define _LINUX_SYNC_H
 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 2733cc3..864ad01 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -15,22 +15,6 @@
  */
 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "uapi/sw_sync.h"
 #include "sync.h"
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/13] staging/android: remove unnecessary check for fence

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

When we call sync_print_fence() fence is always valid.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync_debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index dc85d5f..6282046 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -109,7 +109,7 @@ static void sync_print_fence(struct seq_file *s, struct 
fence *fence, bool show)
seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
}
 
-   if ((!fence || fence->ops->timeline_value_str) &&
+   if (fence->ops->timeline_value_str &&
fence->ops->fence_value_str) {
char value[64];
bool success;
@@ -117,10 +117,9 @@ static void sync_print_fence(struct seq_file *s, struct 
fence *fence, bool show)
fence->ops->fence_value_str(fence, value, sizeof(value));
success = strlen(value);
 
-   if (success)
+   if (success) {
seq_printf(s, ": %s", value);
 
-   if (success && fence) {
fence->ops->timeline_value_str(fence, value,
   sizeof(value));
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/13] staging/android: make sw_ioctl info internal to sw_sync.c

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

We don't want to export this from the kernel. This is interface is only
for testing and debug. So testers shall copy the ioctl info in their own
projects.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c  | 13 -
 drivers/staging/android/uapi/sw_sync.h | 32 
 2 files changed, 12 insertions(+), 33 deletions(-)
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 4922233..7a7acc1 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -20,12 +20,23 @@
 #include 
 #include 
 
-#include "uapi/sw_sync.h"
 #include "sync.h"
 
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
+struct sw_sync_create_fence_data {
+   __u32   value;
+   charname[32];
+   __s32   fence; /* fd of new fence */
+};
+
+#define SW_SYNC_IOC_MAGIC  'W'
+
+#define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
+   struct sw_sync_create_fence_data)
+#define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
+
 /**
  * sync_timeline_create() - creates a sync object
  * @drv_name:  sync_timeline driver name
diff --git a/drivers/staging/android/uapi/sw_sync.h 
b/drivers/staging/android/uapi/sw_sync.h
deleted file mode 100644
index 9b5d486..000
--- a/drivers/staging/android/uapi/sw_sync.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2012 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#ifndef _UAPI_LINUX_SW_SYNC_H
-#define _UAPI_LINUX_SW_SYNC_H
-
-#include 
-
-struct sw_sync_create_fence_data {
-   __u32   value;
-   charname[32];
-   __s32   fence; /* fd of new fence */
-};
-
-#define SW_SYNC_IOC_MAGIC  'W'
-
-#define SW_SYNC_IOC_CREATE_FENCE   _IOWR(SW_SYNC_IOC_MAGIC, 0,\
-   struct sw_sync_create_fence_data)
-#define SW_SYNC_IOC_INC_IOW(SW_SYNC_IOC_MAGIC, 1, 
__u32)
-
-#endif /* _UAPI_LINUX_SW_SYNC_H */
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/13] staging/android: bring struct sync_pt back

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Move the list_head members from sync_pt to struct fence was a mistake,
they will not be used by struct fence as planned before, so here we create
sync_pt again to bring the list heads back.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   | 40 ++--
 drivers/staging/android/sync.h   | 29 ++
 drivers/staging/android/sync_debug.c | 16 +++
 include/linux/fence.h|  2 --
 4 files changed, 53 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c83a599..aab80ec 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -28,8 +28,6 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops timeline_fence_ops;
-
 struct sync_timeline *sync_timeline_create(const char *drv_name,
   const char *name)
 {
@@ -90,7 +88,7 @@ EXPORT_SYMBOL(sync_timeline_destroy);
 void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
 {
unsigned long flags;
-   struct fence *fence, *next;
+   struct sync_pt *pt, *next;
 
trace_sync_timeline(obj);
 
@@ -98,37 +96,37 @@ void sync_timeline_signal(struct sync_timeline *obj, 
unsigned int inc)
 
obj->value += inc;
 
-   list_for_each_entry_safe(fence, next, &obj->active_list_head,
+   list_for_each_entry_safe(pt, next, &obj->active_list_head,
 active_list) {
-   if (fence_is_signaled_locked(fence))
-   list_del_init(&fence->active_list);
+   if (fence_is_signaled_locked(&pt->base))
+   list_del_init(&pt->active_list);
}
 
spin_unlock_irqrestore(&obj->child_list_lock, flags);
 }
 EXPORT_SYMBOL(sync_timeline_signal);
 
-struct fence *sync_pt_create(struct sync_timeline *obj, int size,
+struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
 unsigned int value)
 {
unsigned long flags;
-   struct fence *fence;
+   struct sync_pt *pt;
 
-   if (size < sizeof(*fence))
+   if (size < sizeof(*pt))
return NULL;
 
-   fence = kzalloc(size, GFP_KERNEL);
-   if (!fence)
+   pt = kzalloc(size, GFP_KERNEL);
+   if (!pt)
return NULL;
 
spin_lock_irqsave(&obj->child_list_lock, flags);
sync_timeline_get(obj);
-   fence_init(fence, &timeline_fence_ops, &obj->child_list_lock,
+   fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
   obj->context, value);
-   list_add_tail(&fence->child_list, &obj->child_list_head);
-   INIT_LIST_HEAD(&fence->active_list);
+   list_add_tail(&pt->child_list, &obj->child_list_head);
+   INIT_LIST_HEAD(&pt->active_list);
spin_unlock_irqrestore(&obj->child_list_lock, flags);
-   return fence;
+   return pt;
 }
 EXPORT_SYMBOL(sync_pt_create);
 
@@ -148,13 +146,14 @@ static const char 
*timeline_fence_get_timeline_name(struct fence *fence)
 
 static void timeline_fence_release(struct fence *fence)
 {
+   struct sync_pt *pt = fence_to_sync_pt(fence);
struct sync_timeline *parent = fence_parent(fence);
unsigned long flags;
 
spin_lock_irqsave(fence->lock, flags);
-   list_del(&fence->child_list);
-   if (WARN_ON_ONCE(!list_empty(&fence->active_list)))
-   list_del(&fence->active_list);
+   list_del(&pt->child_list);
+   if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+   list_del(&pt->active_list);
spin_unlock_irqrestore(fence->lock, flags);
 
sync_timeline_put(parent);
@@ -170,12 +169,13 @@ static bool timeline_fence_signaled(struct fence *fence)
 
 static bool timeline_fence_enable_signaling(struct fence *fence)
 {
+   struct sync_pt *pt = fence_to_sync_pt(fence);
struct sync_timeline *parent = fence_parent(fence);
 
if (timeline_fence_signaled(fence))
return false;
 
-   list_add_tail(&fence->active_list, &parent->active_list_head);
+   list_add_tail(&pt->active_list, &parent->active_list_head);
return true;
 }
 
@@ -193,7 +193,7 @@ static void timeline_fence_timeline_value_str(struct fence 
*fence,
snprintf(str, size, "%d", parent->value);
 }
 
-static const struct fence_ops timeline_fence_ops = {
+const struct fence_ops timeline_fence_ops = {
.get_driver_name = timeline_fence_get_driver_name,
.get_timeline_name = timeline_fence_get_timeline_name,
.enable_signaling = timeline_fence_enable_signaling,
diff --git a/drivers/staging/an

[PATCH 00/13] staging/android: clean up SW_SYNC

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi,

The following patches do a clean up on the sw_sync inteface. It starts by
removing struct sync_timeline_ops, which was creating unecessary wrappers
in the code and the start to organize the sync_timeline and sw_sync code
better.

sw_sync interface was moved to sw_sync.c along with sync_timeline - which
is now internal to sw_sync.

The next step after this work is the actual de-stage of SW_SYNC and
the upstreaming of selftests for sw_sync and sync_file.

Please review!

Gustavo

---
Gustavo Padovan (13):
  staging/android: store last signaled value on sync timeline
  staging/android: remove .{fence,timeline}_value_str() from
timeline_ops
  staging/android: remove struct sync_timeline_ops
  staging/android: remove sw_sync_timeline and sw_sync_pt
  staging/android: remove sw_sync.[ch] files
  staging/android: rename android_fence to timeline_fence
  staging/android: remove unnecessary check for fence
  staging/android: remove size arg of sync_timeline_create()
  staging/android: bring struct sync_pt back
  staging/android: move sw_sync related code to sw_sync.c
  staging/android: clean up #includes in the sync framework
  staging/android: make sync_timeline internal to sw_sync
  staging/android: make sw_ioctl info internal to sw_sync.c

 drivers/staging/android/Kconfig|  16 +-
 drivers/staging/android/Makefile   |   3 +-
 drivers/staging/android/sw_sync.c  | 355 +
 drivers/staging/android/sw_sync.h  |  59 --
 drivers/staging/android/sync.c | 221 
 drivers/staging/android/sync.h |  95 ++---
 drivers/staging/android/sync_debug.c   | 152 +-
 drivers/staging/android/trace/sync.h   |  12 +-
 drivers/staging/android/uapi/sw_sync.h |  32 ---
 include/linux/fence.h  |   2 -
 10 files changed, 350 insertions(+), 597 deletions(-)
 delete mode 100644 drivers/staging/android/sw_sync.h
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/uapi/sw_sync.h

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 03/13] staging/android: remove struct sync_timeline_ops

2016-05-02 Thread Gustavo Padovan
From: Gustavo Padovan 

Move drv_name, the last field of sync_timeline_ops, to sync_timeline
and remove sync_timeline_ops.

struct sync_timeline_ops was just an extra abstraction on top of
fence_ops, and in the last few commits we removed all it ops in favor
of cleaner fence_ops.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sw_sync.c|  9 ++---
 drivers/staging/android/sync.c   |  8 
 drivers/staging/android/sync.h   | 28 +---
 drivers/staging/android/sync_debug.c |  3 +--
 4 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c 
b/drivers/staging/android/sw_sync.c
index 4200b12..c5e92c6 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,16 +38,11 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline 
*obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static struct sync_timeline_ops sw_sync_timeline_ops = {
-   .driver_name = "sw_sync",
-};
-
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 {
struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-   sync_timeline_create(&sw_sync_timeline_ops,
-sizeof(struct sw_sync_timeline),
-name);
+   sync_timeline_create(sizeof(struct sw_sync_timeline),
+"sw_sync", name);
 
return obj;
 }
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c75d1e6..b3efcaa 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -30,8 +30,8 @@
 
 static const struct fence_ops android_fence_ops;
 
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
-  int size, const char *name)
+struct sync_timeline *sync_timeline_create(int size, const char *drv_name,
+  const char *name)
 {
struct sync_timeline *obj;
 
@@ -43,9 +43,9 @@ struct sync_timeline *sync_timeline_create(const struct 
sync_timeline_ops *ops,
return NULL;
 
kref_init(&obj->kref);
-   obj->ops = ops;
obj->context = fence_context_alloc(1);
strlcpy(obj->name, name, sizeof(obj->name));
+   strlcpy(obj->drv_name, drv_name, sizeof(obj->drv_name));
 
INIT_LIST_HEAD(&obj->child_list_head);
INIT_LIST_HEAD(&obj->active_list_head);
@@ -139,7 +139,7 @@ static const char *android_fence_get_driver_name(struct 
fence *fence)
 {
struct sync_timeline *parent = fence_parent(fence);
 
-   return parent->ops->driver_name;
+   return parent->drv_name;
 }
 
 static const char *android_fence_get_timeline_name(struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 29f8c19..f003e97 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -23,20 +23,10 @@
 #include 
 #include 
 
-struct sync_timeline;
-
-/**
- * struct sync_timeline_ops - sync object implementation ops
- * @driver_name:   name of the implementation
- */
-struct sync_timeline_ops {
-   const char *driver_name;
-};
-
 /**
  * struct sync_timeline - sync object
  * @kref:  reference count on fence.
- * @ops:   ops that define the implementation of the sync_timeline
+ * @drv_name:  drv_name of the driver using the sync_timeline
  * @name:  name of the sync_timeline. Useful for debugging
  * @destroyed: set when sync_timeline is destroyed
  * @child_list_head:   list of children sync_pts for this sync_timeline
@@ -47,7 +37,7 @@ struct sync_timeline_ops {
  */
 struct sync_timeline {
struct kref kref;
-   const struct sync_timeline_ops  *ops;
+   chardrv_name[32];
charname[32];
 
/* protected by child_list_lock */
@@ -76,17 +66,17 @@ static inline struct sync_timeline *fence_parent(struct 
fence *fence)
 
 /**
  * sync_timeline_create() - creates a sync object
- * @ops:   specifies the implementation ops for the object
  * @size:  size to allocate for this obj
+ * @drv_name:  sync_timeline driver name
  * @name:  sync_timeline name
  *
- * Creates a new sync_timeline which will use the implementation specified by
- * @ops.  @size bytes will be allocated allowing for implementation specific
- * data to be kept after the generic sync_timeline struct. Returns the
- * sync_timeline object or NULL in case of error.
+ * Creates a new sync_timeline. @size bytes will be allocated allowing
+ * for implementation specific data to be kept after the generic
+ * sync_timeline struct. Returns the sync_timeline object or NULL in
+ * case of error.
  */
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_o

Re: [RFC v2 8/8] drm/fence: add out-fences support

2016-04-28 Thread Gustavo Padovan
2016-04-26 Daniel Vetter :

> On Mon, Apr 25, 2016 at 07:33:28PM -0300, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > Support DRM out-fences creating a sync_file with a fence for each crtc
> > update with the DRM_MODE_ATOMIC_OUT_FENCE flag.
> > 
> > We then send an struct drm_out_fences array with the out-fences fds back in
> > the drm_atomic_ioctl() as an out arg in the out_fences_ptr field.
> > 
> > struct drm_out_fences {
> > __u32   crtc_id;
> > __u32   fd;
> > };
> > 
> > v2: Comment by Rob Clark:
> > - Squash commit that adds DRM_MODE_ATOMIC_OUT_FENCE flag here.
> > 
> > Comment by Daniel Vetter:
> > - Add clean up code for out_fences
> > 
> > Signed-off-by: Gustavo Padovan 
> > ---
> >  drivers/gpu/drm/drm_atomic.c | 163 
> > +--
> >  include/drm/drm_crtc.h   |  10 +++
> >  include/uapi/drm/drm_mode.h  |  11 ++-
> >  3 files changed, 179 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index 5f9d434..06c6007 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -1566,6 +1566,133 @@ void drm_atomic_clean_old_fb(struct drm_device *dev,
> >  }
> >  EXPORT_SYMBOL(drm_atomic_clean_old_fb);
> >  
> > +static struct drm_out_fence_state *get_out_fence(struct drm_device *dev,
> > +struct drm_atomic_state *state,
> > +uint32_t __user 
> > *out_fences_ptr,
> > +uint64_t count_out_fences,
> > +uint64_t user_data)
> > +{
> > +   struct drm_crtc *crtc;
> > +   struct drm_crtc_state *crtc_state;
> > +   struct drm_out_fences *out_fences;
> > +   struct drm_out_fence_state *fence_state;
> > +   int num_fences = 0;
> > +   int i, ret;
> > +
> > +   if (count_out_fences > dev->mode_config.num_crtc)
> > +   return ERR_PTR(-EINVAL);
> > +
> > +   out_fences = kcalloc(count_out_fences, sizeof(*out_fences),
> > +GFP_KERNEL);
> > +   if (!out_fences)
> > +   return ERR_PTR(-ENOMEM);
> 
> A bit tricky, but the above kcalloc is the only thing that catches integer
> overflows in count_out_fences. Needs a comment imo since this could be a
> security exploit if we accidentally screw it up.

The check above makes sure that count_out_fences is not bigger than
num_crtc. Don't that fix this?

> 
> Also needs a testcase imo.
> 
> > +
> > +   fence_state = kcalloc(count_out_fences, sizeof(*fence_state),
> > +GFP_KERNEL);
> > +   if (!fence_state) {
> > +   kfree(out_fences);
> > +   return ERR_PTR(-ENOMEM);
> > +   }
> > +
> > +   for (i = 0 ; i < count_out_fences ; i++)
> > +   fence_state[i].fd = -1;
> > +
> > +   for_each_crtc_in_state(state, crtc, crtc_state, i) {
> > +   struct drm_pending_vblank_event *e;
> > +   struct fence *fence;
> > +   char name[32];
> > +
> > +   fence = kzalloc(sizeof(*fence), GFP_KERNEL);
> > +   if (!fence) {
> > +   ret = -ENOMEM;
> > +   goto out;
> > +   }
> > +
> > +   fence_init(fence, &drm_crtc_fence_ops, &crtc->fence_lock,
> > +  crtc->fence_context, crtc->fence_seqno);
> > +
> > +   snprintf(name, sizeof(name), "crtc-%d_%lu",
> > +drm_crtc_index(crtc), crtc->fence_seqno++);
> 
> Hm ... fence_init_with_name? I'm kinda confused why we only name fences
> that are exported though, and why not all of them. Debugging fence
> deadlocks is real hard, so giving them all names might be a good idea.
> 
> Anyway, seems like more room for a bit more sync_file/struct fence
> merging.

We just removed name from sync_file_create() so snprintf() is not even
necessary here anymore.

> 
> > +
> > +   fence_state[i].fd = get_unused_fd_flags(O_CLOEXEC);
> > +   if (fence_state[i].fd < 0) {
> > +   fence_put(fence);
> > +   ret = fence_state[i].fd;
> > +   goto out;
> > +   }
> > +
> > +   fence_state[i].sync_file = sync_file_create(name, fence);
> > +

Re: [RFC v2 1/8] dma-buf/fence: add fence_collection fences

2016-04-28 Thread Gustavo Padovan
2016-04-26 Chris Wilson :

> On Mon, Apr 25, 2016 at 07:33:21PM -0300, Gustavo Padovan wrote:
> > +static const char *fence_collection_get_timeline_name(struct fence *fence)
> > +{
> > +   return "no context";
> 
> "unbound" to distinguish from fence contexts within a timeline?
> 
> > +static bool fence_collection_enable_signaling(struct fence *fence)
> > +{
> > +   struct fence_collection *collection = to_fence_collection(fence);
> > +   int i;
> > +
> > +   for (i = 0 ; i < collection->num_fences ; i++) {
> > +   if (fence_add_callback(collection->fences[i].fence,
> > +  &collection->fences[i].cb,
> > +  collection_check_cb_func)) {
> > +   atomic_dec(&collection->num_pending_fences);
> > +   return false;
> 
> Don't stop, we need to enable all the others!
> 
> > +   }
> > +   }
> > +
> > +   return !!atomic_read(&collection->num_pending_fences);
> 
> Redundant !!
> 
> > +}
> > +
> > +static bool fence_collection_signaled(struct fence *fence)
> > +{
> > +   struct fence_collection *collection = to_fence_collection(fence);
> > +
> > +   return (atomic_read(&collection->num_pending_fences) == 0);
> 
> Redundant ()
> 
> > +static signed long fence_collection_wait(struct fence *fence, bool intr,
> > +signed long timeout)
> > +{
> 
> What advantage does this have over fence_default_wait? You enable
> signaling on all, then wait sequentially. The code looks redundant and
> could just use fence_default_wait instead.

None actually, I'll just replace it with fence_default_wait().

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 09/13] staging/android: style fix: alignment to match the open parenthesis

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Fix checks reported by checkpatch.pl.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync_file.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index d9da3a4..eabf90d 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -242,7 +242,7 @@ static unsigned int sync_file_poll(struct file *file, 
poll_table *wait)
 }
 
 static long sync_file_ioctl_merge(struct sync_file *sync_file,
-  unsigned long arg)
+ unsigned long arg)
 {
int fd = get_unused_fd_flags(O_CLOEXEC);
int err;
@@ -297,7 +297,7 @@ err_put_fd:
 }
 
 static void sync_fill_fence_info(struct fence *fence,
-   struct sync_fence_info *info)
+struct sync_fence_info *info)
 {
strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
sizeof(info->obj_name));
@@ -311,7 +311,7 @@ static void sync_fill_fence_info(struct fence *fence,
 }
 
 static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
-   unsigned long arg)
+  unsigned long arg)
 {
struct sync_file_info info;
struct sync_fence_info *fence_info = NULL;
@@ -370,7 +370,7 @@ out:
 }
 
 static long sync_file_ioctl(struct file *file, unsigned int cmd,
-unsigned long arg)
+   unsigned long arg)
 {
struct sync_file *sync_file = file->private_data;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 08/13] staging/android: improve documentation for sync_file

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

num_fences was missing a colon mark and sync_file_create() now have
better description.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync_file.c | 5 +++--
 drivers/staging/android/sync_file.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index 2c724ec..d9da3a4 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -65,11 +65,12 @@ static void fence_check_cb_func(struct fence *f, struct 
fence_cb *cb)
 }
 
 /**
- * sync_fence_create() - creates a sync fence
+ * sync_file_create() - creates a sync file
  * @fence: fence to add to the sync_fence
  *
  * Creates a sync_file containg @fence. Once this is called, the sync_file
- * takes ownership of @fence.
+ * takes ownership of @fence. The sync_file can be released with
+ * fput(sync_file->file). Returns the sync_file or NULL in case of error.
  */
 struct sync_file *sync_file_create(struct fence *fence)
 {
diff --git a/drivers/staging/android/sync_file.h 
b/drivers/staging/android/sync_file.h
index 8a1b546..c6ffe8b 100644
--- a/drivers/staging/android/sync_file.h
+++ b/drivers/staging/android/sync_file.h
@@ -32,7 +32,7 @@ struct sync_file_cb {
  * @kref:  reference count on fence.
  * @name:  name of sync_file.  Useful for debugging
  * @sync_file_list:membership in global file list
- * @num_fences number of sync_pts in the fence
+ * @num_fences:number of sync_pts in the fence
  * @wq:wait queue for fence signaling
  * @status:0: signaled, >0:active, <0: error
  * @cbs:   sync_pts callback information
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 12/13] Documentation: include sync_file into DocBook

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Add entry in device-drivers.tmpl for sync_file documentation.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 Documentation/DocBook/device-drivers.tmpl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/DocBook/device-drivers.tmpl 
b/Documentation/DocBook/device-drivers.tmpl
index 184f3c7..509a187 100644
--- a/Documentation/DocBook/device-drivers.tmpl
+++ b/Documentation/DocBook/device-drivers.tmpl
@@ -136,6 +136,8 @@ X!Edrivers/base/interface.c
 !Iinclude/linux/seqno-fence.h
 !Edrivers/dma-buf/reservation.c
 !Iinclude/linux/reservation.h
+!Edrivers/dma-buf/sync_file.c
+!Iinclude/linux/sync_file.h
 !Edrivers/base/dma-coherent.c
 !Edrivers/base/dma-mapping.c
  
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 10/13] dma-buf/sync_file: de-stage sync_file headers

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Move sync_file headers file to include/ dir.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.h   | 4 ++--
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_file.c  | 4 ++--
 {drivers/staging/android => include/linux}/sync_file.h   | 0
 {drivers/staging/android/uapi => include/uapi/linux}/sync_file.h | 0
 5 files changed, 5 insertions(+), 5 deletions(-)
 rename {drivers/staging/android => include/linux}/sync_file.h (100%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sync_file.h (100%)

diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index df44abb..b56885c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -20,8 +20,8 @@
 #include 
 #include 
 
-#include "sync_file.h"
-#include "uapi/sync_file.h"
+#include 
+#include 
 
 struct sync_timeline;
 
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 8b55218..5f57499 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -26,7 +26,7 @@
 #include 
 #include 
 #include 
-#include "sync_file.h"
+#include 
 #include "sw_sync.h"
 
 #ifdef CONFIG_DEBUG_FS
diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index eabf90d..f08cf2d 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -23,8 +23,8 @@
 #include 
 #include 
 #include 
-#include "sync_file.h"
-#include "uapi/sync_file.h"
+#include 
+#include 
 
 static const struct file_operations sync_file_fops;
 
diff --git a/drivers/staging/android/sync_file.h b/include/linux/sync_file.h
similarity index 100%
rename from drivers/staging/android/sync_file.h
rename to include/linux/sync_file.h
diff --git a/drivers/staging/android/uapi/sync_file.h 
b/include/uapi/linux/sync_file.h
similarity index 100%
rename from drivers/staging/android/uapi/sync_file.h
rename to include/uapi/linux/sync_file.h
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 13/13] Documentation: add Sync File doc

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Add sync_file documentation on dma-buf-sync_file.txt
Reviewed-by: Daniel Vetter 
---
 Documentation/sync_file.txt | 69 +
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/sync_file.txt

diff --git a/Documentation/sync_file.txt b/Documentation/sync_file.txt
new file mode 100644
index 000..eaf8297
--- /dev/null
+++ b/Documentation/sync_file.txt
@@ -0,0 +1,69 @@
+ Sync File API Guide
+ ~~~
+
+   Gustavo Padovan
+ 
+
+This document serves as a guide for device drivers writers on what the
+sync_file API is, and how drivers can support it. Sync file is the carrier of
+the fences(struct fence) that needs to synchronized between drivers or across
+process boundaries.
+
+The sync_file API is meant to be used to send and receive fence information
+to/from userspace. It enables userspace to do explicit fencing, where instead
+of attaching a fence to the buffer a producer driver (such as a GPU or V4L
+driver) sends the fence related to the buffer to userspace via a sync_file.
+
+The sync_file then can be sent to the consumer (DRM driver for example), that
+will not use the buffer for anything before the fence(s) signals, i.e., the
+driver that issued the fence is not using/processing the buffer anymore, so it
+signals that the buffer is ready to use. And vice-versa for the consumer ->
+producer part of the cycle.
+
+Sync files allows userspace awareness on buffer sharing synchronization between
+drivers.
+
+Sync file was originally added in the Android kernel but current Linux Desktop
+can benefit a lot from it.
+
+in-fences and out-fences
+
+
+Sync files can go either to or from userspace. When a sync_file is sent from
+the driver to userspace we call the fences it contains 'out-fences'. They are
+related to a buffer that the driver is processing or is going to process, so
+the driver an create out-fence to be able to notify, through fence_signal(),
+when it has finished using (or processing) that buffer. Out-fences are fences
+that the driver creates.
+
+On the other hand if the driver receives fence(s) through a sync_file from
+userspace we call these fence(s) 'in-fences'. Receiveing in-fences means that
+we need to wait for the fence(s) to signal before using any buffer related to
+the in-fences.
+
+Creating Sync Files
+---
+
+When a driver needs to send an out-fence userspace it creates a sync_file.
+
+Interface:
+   struct sync_file *sync_file_create(struct fence *fence);
+
+The caller pass the out-fence and gets back the sync_file. That is just the
+first step, next it needs to install an fd on sync_file->file. So it gets an
+fd:
+
+   fd = get_unused_fd_flags(O_CLOEXEC);
+
+and installs it on sync_file->file:
+
+   fd_install(fd, sync_file->file);
+
+The sync_file fd now can be sent to userspace.
+
+If the creation process fail, or the sync_file needs to be released by any
+other reason fput(sync_file->file) should be used.
+
+References:
+[1] struct sync_file in include/linux/sync_file.h
+[2] All interfaces mentioned above defined in include/linux/sync_file.h
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 11/13] dma-buf/sync_file: de-stage sync_file

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

sync_file is useful to connect one or more fences to the file. The file is
used by userspace to track fences between drivers that share DMA bufs.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/Kconfig  |  2 ++
 drivers/dma-buf/Kconfig  | 11 +++
 drivers/dma-buf/Makefile |  1 +
 drivers/{staging/android => dma-buf}/sync_file.c |  0
 drivers/staging/android/Kconfig  |  1 +
 drivers/staging/android/Makefile |  2 +-
 6 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma-buf/Kconfig
 rename drivers/{staging/android => dma-buf}/sync_file.c (100%)

diff --git a/drivers/Kconfig b/drivers/Kconfig
index d2ac339..430f761 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -114,6 +114,8 @@ source "drivers/rtc/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/dma-buf/Kconfig"
+
 source "drivers/dca/Kconfig"
 
 source "drivers/auxdisplay/Kconfig"
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
new file mode 100644
index 000..9824bc4
--- /dev/null
+++ b/drivers/dma-buf/Kconfig
@@ -0,0 +1,11 @@
+menu "DMABUF options"
+
+config SYNC_FILE
+   bool "sync_file support for fences"
+   default n
+   select ANON_INODES
+   select DMA_SHARED_BUFFER
+   ---help---
+ This option enables the fence framework synchronization to export
+ sync_files to userspace that can represent one or more fences.
+endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 57a675f..4a424ec 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1,2 @@
 obj-y := dma-buf.o fence.o reservation.o seqno-fence.o
+obj-$(CONFIG_SYNC_FILE)+= sync_file.o
diff --git a/drivers/staging/android/sync_file.c b/drivers/dma-buf/sync_file.c
similarity index 100%
rename from drivers/staging/android/sync_file.c
rename to drivers/dma-buf/sync_file.c
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 4244821..7a3a77e 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -38,6 +38,7 @@ config SW_SYNC
bool "Software synchronization objects"
default n
depends on SYNC
+   depends on SYNC_FILE
---help---
  A sync object driver that uses a 32bit counter to coordinate
  synchronization.  Useful when there is no hardware primitive backing
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index ebc2df1..980d6dc 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,5 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync_file.o sync.o sync_debug.o
+obj-$(CONFIG_SYNC) += sync.o sync_debug.o
 obj-$(CONFIG_SW_SYNC)  += sw_sync.o
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 07/13] staging/android: prepare sync_file for de-staging

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Move its functions and structs to their own file. Also moves function's
docs to the .c file.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/Makefile   |   2 +-
 drivers/staging/android/sync.c | 374 ---
 drivers/staging/android/sync.h |  38 +-
 drivers/staging/android/sync_debug.c   |   1 +
 drivers/staging/android/sync_file.c| 394 +
 drivers/staging/android/sync_file.h|  57 +++
 .../staging/android/uapi/{sync.h => sync_file.h}   |   0
 7 files changed, 455 insertions(+), 411 deletions(-)
 create mode 100644 drivers/staging/android/sync_file.c
 create mode 100644 drivers/staging/android/sync_file.h
 rename drivers/staging/android/uapi/{sync.h => sync_file.h} (100%)

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..ebc2df1 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,5 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync.o sync_debug.o
+obj-$(CONFIG_SYNC) += sync_file.o sync.o sync_debug.o
 obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 5470ae9..1d14c83 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -16,10 +16,7 @@
 
 #include 
 #include 
-#include 
-#include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -32,7 +29,6 @@
 #include "trace/sync.h"
 
 static const struct fence_ops android_fence_ops;
-static const struct file_operations sync_file_fops;
 
 struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
   int size, const char *name)
@@ -136,182 +132,6 @@ struct fence *sync_pt_create(struct sync_timeline *obj, 
int size)
 }
 EXPORT_SYMBOL(sync_pt_create);
 
-static struct sync_file *sync_file_alloc(int size)
-{
-   struct sync_file *sync_file;
-
-   sync_file = kzalloc(size, GFP_KERNEL);
-   if (!sync_file)
-   return NULL;
-
-   sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops,
-sync_file, 0);
-   if (IS_ERR(sync_file->file))
-   goto err;
-
-   kref_init(&sync_file->kref);
-
-   init_waitqueue_head(&sync_file->wq);
-
-   return sync_file;
-
-err:
-   kfree(sync_file);
-   return NULL;
-}
-
-static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
-{
-   struct sync_file_cb *check;
-   struct sync_file *sync_file;
-
-   check = container_of(cb, struct sync_file_cb, cb);
-   sync_file = check->sync_file;
-
-   if (atomic_dec_and_test(&sync_file->status))
-   wake_up_all(&sync_file->wq);
-}
-
-/**
- * sync_fence_create() - creates a sync fence
- * @fence: fence to add to the sync_fence
- *
- * Creates a sync_file containg @fence. Once this is called, the sync_file
- * takes ownership of @fence.
- */
-struct sync_file *sync_file_create(struct fence *fence)
-{
-   struct sync_file *sync_file;
-
-   sync_file = sync_file_alloc(offsetof(struct sync_file, cbs[1]));
-   if (!sync_file)
-   return NULL;
-
-   sync_file->num_fences = 1;
-   atomic_set(&sync_file->status, 1);
-   snprintf(sync_file->name, sizeof(sync_file->name), "%s-%s%d-%d",
-fence->ops->get_driver_name(fence),
-fence->ops->get_timeline_name(fence), fence->context,
-fence->seqno);
-
-   sync_file->cbs[0].fence = fence;
-   sync_file->cbs[0].sync_file = sync_file;
-   if (fence_add_callback(fence, &sync_file->cbs[0].cb,
-  fence_check_cb_func))
-   atomic_dec(&sync_file->status);
-
-   sync_file_debug_add(sync_file);
-
-   return sync_file;
-}
-EXPORT_SYMBOL(sync_file_create);
-
-/**
- * sync_file_fdget() - get a sync_file from an fd
- * @fd:fd referencing a fence
- *
- * Ensures @fd references a valid sync_file, increments the refcount of the
- * backing file. Returns the sync_file or NULL in case of error.
- */
-static struct sync_file *sync_file_fdget(int fd)
-{
-   struct file *file = fget(fd);
-
-   if (!file)
-   return NULL;
-
-   if (file->f_op != &sync_file_fops)
-   goto err;
-
-   return file->private_data;
-
-err:
-   fput(file);
-   return NULL;
-}
-
-static void sync_file_add_pt(struct sync_file *sync_file, int *i,
-  

[PATCH v2 05/13] staging/android: make sync_file_fdget() static

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

There is no plan in the near future to use this function outside of this
file so keep it as static.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.c | 3 +--
 drivers/staging/android/sync.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index e9bf251..7e0fa20 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -212,7 +212,7 @@ EXPORT_SYMBOL(sync_file_create);
  * Ensures @fd references a valid sync_file, increments the refcount of the
  * backing file. Returns the sync_file or NULL in case of error.
  */
-struct sync_file *sync_file_fdget(int fd)
+static struct sync_file *sync_file_fdget(int fd)
 {
struct file *file = fget(fd);
 
@@ -228,7 +228,6 @@ err:
fput(file);
return NULL;
 }
-EXPORT_SYMBOL(sync_file_fdget);
 
 static void sync_file_add_pt(struct sync_file *sync_file, int *i,
 struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index ffc6df6..1f164df 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -168,7 +168,6 @@ void sync_timeline_signal(struct sync_timeline *obj);
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
 struct sync_file *sync_file_create(const char *name, struct fence *fence);
-struct sync_file *sync_file_fdget(int fd);
 
 #ifdef CONFIG_DEBUG_FS
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 02/13] staging/android: drop sync_file_install() and sync_file_put()

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

These two functions are just wrappers for one line functions, they
call fd_install() and fput() respectively, so just get rid of them
and use fd_install() and fput() directly for more simplicity.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.c   | 20 
 drivers/staging/android/sync.h   | 19 ---
 drivers/staging/android/sync_debug.c |  4 ++--
 3 files changed, 6 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index f9c6094..b965e2a 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -216,18 +216,6 @@ err:
 }
 EXPORT_SYMBOL(sync_file_fdget);
 
-void sync_file_put(struct sync_file *sync_file)
-{
-   fput(sync_file->file);
-}
-EXPORT_SYMBOL(sync_file_put);
-
-void sync_file_install(struct sync_file *sync_file, int fd)
-{
-   fd_install(fd, sync_file->file);
-}
-EXPORT_SYMBOL(sync_file_install);
-
 static void sync_file_add_pt(struct sync_file *sync_file, int *i,
 struct fence *fence)
 {
@@ -469,15 +457,15 @@ static long sync_file_ioctl_merge(struct sync_file 
*sync_file,
goto err_put_fence3;
}
 
-   sync_file_install(fence3, fd);
-   sync_file_put(fence2);
+   fd_install(fd, fence3->file);
+   fput(fence2->file);
return 0;
 
 err_put_fence3:
-   sync_file_put(fence3);
+   fput(fence3->file);
 
 err_put_fence2:
-   sync_file_put(fence2);
+   fput(fence2->file);
 
 err_put_fd:
put_unused_fd(fd);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index d2a1734..c45cc7b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -203,25 +203,6 @@ struct sync_file *sync_file_merge(const char *name,
  */
 struct sync_file *sync_file_fdget(int fd);
 
-/**
- * sync_file_put() - puts a reference of a sync_file
- * @sync_file: sync_file to put
- *
- * Puts a reference on @sync_fence.  If this is the last reference, the
- * sync_fil and all it's sync_pts will be freed
- */
-void sync_file_put(struct sync_file *sync_file);
-
-/**
- * sync_file_install() - installs a sync_file into a file descriptor
- * @sync_file: sync_file to install
- * @fd:file descriptor in which to install the fence
- *
- * Installs @sync_file into @fd.  @fd's should be acquired through
- * get_unused_fd_flags(O_CLOEXEC).
- */
-void sync_file_install(struct sync_file *sync_file, int fd);
-
 #ifdef CONFIG_DEBUG_FS
 
 void sync_timeline_debug_add(struct sync_timeline *obj);
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 5a7ec58..e4b0e41 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -272,12 +272,12 @@ static long sw_sync_ioctl_create_fence(struct 
sw_sync_timeline *obj,
 
data.fence = fd;
if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
-   sync_file_put(sync_file);
+   fput(sync_file->file);
err = -EFAULT;
goto err;
}
 
-   sync_file_install(sync_file, fd);
+   fd_install(fd, sync_file->file);
 
return 0;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 00/13] De-stage Sync File Framework

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Hi,

This patchset sits on top of Sync ABI Rework v13:

https://www.spinics.net/lists/dri-devel/msg105667.html

The first eight clean up and prepare sync_file for de-staging. The last four
patches do the de-staging, moving files to drivers/dma-buf/ and include/linux/
plus adding Documentation.

As the de-stage depends upon many changes on the staging tree it would
be good to get all the patches merged through the staging tree if Sumit
agrees with that.

The next step on the Sync de-stage is clean up the remaining bits
of the Sync Framework, mainly SW_SYNC, which is only used for testing.

v2: - Add Reviewed-by: tag from Daniel Vetter to all patches.
- Take in sugestions for the Sync File Documentation (Daniel)
- Remove name arg from sync_file_crate() (Daniel)
- Revome leftover EXPORT_SYMBOL(sync_file_merge) (Daniel)

Thanks,

Gustavo

Gustavo Padovan (13):
  staging/android: remove redundant comments on sync_merge_data
  staging/android: drop sync_file_install() and sync_file_put()
  staging/android: move sync_file functions comments to sync.c
  staging/android: make sync_file_merge() static
  staging/android: make sync_file_fdget() static
  staging/android: remove name arg from sync_file_create()
  staging/android: prepare sync_file for de-staging
  staging/android: improve documentation for sync_file
  staging/android: style fix: alignment to match the open parenthesis
  dma-buf/sync_file: de-stage sync_file headers
  dma-buf/sync_file: de-stage sync_file
  Documentation: include sync_file into DocBook
  Documentation: add Sync File doc

 Documentation/DocBook/device-drivers.tmpl |   2 +
 Documentation/sync_file.txt   |  69 ++
 drivers/Kconfig   |   2 +
 drivers/dma-buf/Kconfig   |  11 +
 drivers/dma-buf/Makefile  |   1 +
 drivers/dma-buf/sync_file.c   | 395 ++
 drivers/staging/android/Kconfig   |   1 +
 drivers/staging/android/sync.c| 362 ---
 drivers/staging/android/sync.h|  91 +--
 drivers/staging/android/sync_debug.c  |   8 +-
 drivers/staging/android/uapi/sync.h   | 100 
 include/linux/sync_file.h |  57 +
 include/uapi/linux/sync_file.h| 100 
 13 files changed, 644 insertions(+), 555 deletions(-)
 create mode 100644 Documentation/sync_file.txt
 create mode 100644 drivers/dma-buf/Kconfig
 create mode 100644 drivers/dma-buf/sync_file.c
 delete mode 100644 drivers/staging/android/uapi/sync.h
 create mode 100644 include/linux/sync_file.h
 create mode 100644 include/uapi/linux/sync_file.h

-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 06/13] staging/android: remove name arg from sync_file_create()

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

Simplifies the API to only receive the fence it needs to add to the
sync and create a name for the sync_file based on the fence context and
seqno.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.c   | 16 +---
 drivers/staging/android/sync.h   |  2 +-
 drivers/staging/android/sync_debug.c |  3 +--
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 7e0fa20..5470ae9 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -136,7 +136,7 @@ struct fence *sync_pt_create(struct sync_timeline *obj, int 
size)
 }
 EXPORT_SYMBOL(sync_pt_create);
 
-static struct sync_file *sync_file_alloc(int size, const char *name)
+static struct sync_file *sync_file_alloc(int size)
 {
struct sync_file *sync_file;
 
@@ -150,7 +150,6 @@ static struct sync_file *sync_file_alloc(int size, const 
char *name)
goto err;
 
kref_init(&sync_file->kref);
-   strlcpy(sync_file->name, name, sizeof(sync_file->name));
 
init_waitqueue_head(&sync_file->wq);
 
@@ -175,23 +174,25 @@ static void fence_check_cb_func(struct fence *f, struct 
fence_cb *cb)
 
 /**
  * sync_fence_create() - creates a sync fence
- * @name:  name of fence to create
  * @fence: fence to add to the sync_fence
  *
  * Creates a sync_file containg @fence. Once this is called, the sync_file
  * takes ownership of @fence.
  */
-struct sync_file *sync_file_create(const char *name, struct fence *fence)
+struct sync_file *sync_file_create(struct fence *fence)
 {
struct sync_file *sync_file;
 
-   sync_file = sync_file_alloc(offsetof(struct sync_file, cbs[1]),
-   name);
+   sync_file = sync_file_alloc(offsetof(struct sync_file, cbs[1]));
if (!sync_file)
return NULL;
 
sync_file->num_fences = 1;
atomic_set(&sync_file->status, 1);
+   snprintf(sync_file->name, sizeof(sync_file->name), "%s-%s%d-%d",
+fence->ops->get_driver_name(fence),
+fence->ops->get_timeline_name(fence), fence->context,
+fence->seqno);
 
sync_file->cbs[0].fence = fence;
sync_file->cbs[0].sync_file = sync_file;
@@ -260,7 +261,7 @@ static struct sync_file *sync_file_merge(const char *name, 
struct sync_file *a,
int i, i_a, i_b;
unsigned long size = offsetof(struct sync_file, cbs[num_fences]);
 
-   sync_file = sync_file_alloc(size, name);
+   sync_file = sync_file_alloc(size);
if (!sync_file)
return NULL;
 
@@ -306,6 +307,7 @@ static struct sync_file *sync_file_merge(const char *name, 
struct sync_file *a,
atomic_sub(num_fences - i, &sync_file->status);
sync_file->num_fences = i;
 
+   strlcpy(sync_file->name, name, sizeof(sync_file->name));
sync_file_debug_add(sync_file);
return sync_file;
 }
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 1f164df..7dee444 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -167,7 +167,7 @@ void sync_timeline_signal(struct sync_timeline *obj);
  */
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
-struct sync_file *sync_file_create(const char *name, struct fence *fence);
+struct sync_file *sync_file_create(struct fence *fence);
 
 #ifdef CONFIG_DEBUG_FS
 
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index e4b0e41..2cab40d 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -262,8 +262,7 @@ static long sw_sync_ioctl_create_fence(struct 
sw_sync_timeline *obj,
goto err;
}
 
-   data.name[sizeof(data.name) - 1] = '\0';
-   sync_file = sync_file_create(data.name, fence);
+   sync_file = sync_file_create(fence);
if (!sync_file) {
fence_put(fence);
err = -ENOMEM;
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 01/13] staging/android: remove redundant comments on sync_merge_data

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

struct sync_merge_data already have documentation on top of the
struct definition. No need to duplicate it.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Maarten Lankhorst 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/uapi/sync.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/android/uapi/sync.h 
b/drivers/staging/android/uapi/sync.h
index 7de5d6a..413303d 100644
--- a/drivers/staging/android/uapi/sync.h
+++ b/drivers/staging/android/uapi/sync.h
@@ -23,9 +23,9 @@
  * @pad:   padding for 64-bit alignment, should always be zero
  */
 struct sync_merge_data {
-   charname[32]; /* name of new fence */
-   __s32   fd2; /* fd of second fence */
-   __s32   fence; /* fd on newly created fence */
+   charname[32];
+   __s32   fd2;
+   __s32   fence;
__u32   flags;
__u32   pad;
 };
@@ -33,8 +33,8 @@ struct sync_merge_data {
 /**
  * struct sync_fence_info - detailed fence information
  * @obj_name:  name of parent sync_timeline
- * @driver_name:   name of driver implementing the parent
- * @status:status of the fence 0:active 1:signaled <0:error
+* @driver_name:name of driver implementing the parent
+* @status: status of the fence 0:active 1:signaled <0:error
  * @flags: fence_info flags
  * @timestamp_ns:  timestamp of status change in nanoseconds
  */
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 03/13] staging/android: move sync_file functions comments to sync.c

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

To keep comments in line with drivers/dma-buf/ move all sync_file comments
to sync.c.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.c | 26 +-
 drivers/staging/android/sync.h | 31 ---
 2 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index b965e2a..a89ded0 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -173,7 +173,14 @@ static void fence_check_cb_func(struct fence *f, struct 
fence_cb *cb)
wake_up_all(&sync_file->wq);
 }
 
-/* TODO: implement a create which takes more that one fence */
+/**
+ * sync_fence_create() - creates a sync fence
+ * @name:  name of fence to create
+ * @fence: fence to add to the sync_fence
+ *
+ * Creates a sync_file containg @fence. Once this is called, the sync_file
+ * takes ownership of @fence.
+ */
 struct sync_file *sync_file_create(const char *name, struct fence *fence)
 {
struct sync_file *sync_file;
@@ -198,6 +205,13 @@ struct sync_file *sync_file_create(const char *name, 
struct fence *fence)
 }
 EXPORT_SYMBOL(sync_file_create);
 
+/**
+ * sync_file_fdget() - get a sync_file from an fd
+ * @fd:fd referencing a fence
+ *
+ * Ensures @fd references a valid sync_file, increments the refcount of the
+ * backing file. Returns the sync_file or NULL in case of error.
+ */
 struct sync_file *sync_file_fdget(int fd)
 {
struct file *file = fget(fd);
@@ -229,6 +243,16 @@ static void sync_file_add_pt(struct sync_file *sync_file, 
int *i,
}
 }
 
+/**
+ * sync_file_merge() - merge two sync_files
+ * @name:  name of new fence
+ * @a: sync_file a
+ * @b: sync_file b
+ *
+ * Creates a new sync_file which contains copies of all the fences in both
+ * @a and @b.  @a and @b remain valid, independent sync_file. Returns the
+ * new merged sync_file or NULL in case of error.
+ */
 struct sync_file *sync_file_merge(const char *name,
  struct sync_file *a, struct sync_file *b)
 {
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index c45cc7b..925fba5 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -167,40 +167,9 @@ void sync_timeline_signal(struct sync_timeline *obj);
  */
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
-/**
- * sync_fence_create() - creates a sync fence
- * @name:  name of fence to create
- * @fence: fence to add to the sync_fence
- *
- * Creates a sync_file containg @fence. Once this is called, the sync_file
- * takes ownership of @fence.
- */
 struct sync_file *sync_file_create(const char *name, struct fence *fence);
-
-/*
- * API for sync_file consumers
- */
-
-/**
- * sync_file_merge() - merge two sync_files
- * @name:  name of new fence
- * @a: sync_file a
- * @b: sync_file b
- *
- * Creates a new sync_file which contains copies of all the fences in both
- * @a and @b.  @a and @b remain valid, independent sync_file. Returns the
- * new merged sync_file or NULL in case of error.
- */
 struct sync_file *sync_file_merge(const char *name,
struct sync_file *a, struct sync_file *b);
-
-/**
- * sync_file_fdget() - get a sync_file from an fd
- * @fd:fd referencing a fence
- *
- * Ensures @fd references a valid sync_file, increments the refcount of the
- * backing file. Returns the sync_file or NULL in case of error.
- */
 struct sync_file *sync_file_fdget(int fd);
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 04/13] staging/android: make sync_file_merge() static

2016-04-28 Thread Gustavo Padovan
From: Gustavo Padovan 

There is no plan in the near future to use this function outside of this
file so keep it as static.

Signed-off-by: Gustavo Padovan 
Reviewed-by: Daniel Vetter 
---
 drivers/staging/android/sync.c | 5 ++---
 drivers/staging/android/sync.h | 2 --
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index a89ded0..e9bf251 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -253,8 +253,8 @@ static void sync_file_add_pt(struct sync_file *sync_file, 
int *i,
  * @a and @b.  @a and @b remain valid, independent sync_file. Returns the
  * new merged sync_file or NULL in case of error.
  */
-struct sync_file *sync_file_merge(const char *name,
- struct sync_file *a, struct sync_file *b)
+static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
+struct sync_file *b)
 {
int num_fences = a->num_fences + b->num_fences;
struct sync_file *sync_file;
@@ -310,7 +310,6 @@ struct sync_file *sync_file_merge(const char *name,
sync_file_debug_add(sync_file);
return sync_file;
 }
-EXPORT_SYMBOL(sync_file_merge);
 
 static const char *android_fence_get_driver_name(struct fence *fence)
 {
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 925fba5..ffc6df6 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -168,8 +168,6 @@ void sync_timeline_signal(struct sync_timeline *obj);
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
 struct sync_file *sync_file_create(const char *name, struct fence *fence);
-struct sync_file *sync_file_merge(const char *name,
-   struct sync_file *a, struct sync_file *b);
 struct sync_file *sync_file_fdget(int fd);
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 00/12] De-stage Sync File Framework

2016-04-28 Thread Gustavo Padovan
2016-04-27 Daniel Vetter :

> On Wed, Apr 27, 2016 at 01:27:07PM -0300, Gustavo Padovan wrote:
> > From: Gustavo Padovan 
> > 
> > Hi,
> > 
> > This patchset sits on top of Sync ABI Rework v13:
> > 
> > https://www.spinics.net/lists/dri-devel/msg105667.html
> > 
> > The first eight clean up and prepare sync_file for de-staging. The last four
> > patches do the de-staging, moving files to drivers/dma-buf/ and 
> > include/linux/
> > plus adding Documentation.
> > 
> > As the de-stage depends upon many changes on the staging tree it would
> > be good to get all the patches merged through the staging tree if Sumit
> > agrees with that.
> > 
> > The next step on the Sync de-stage is clean up the remaining bits 
> > of the Sync Framework, mainly SW_SYNC, which is only used for testing.
> 
> Ok I looked once more at all this stuff, and there's some nitpicks I
> discussed with Gustavo on irc. But really their small, and I think
> perfectly ok to address them once sync_file is destaged. Especially since
> there's a lot more work pending on top of this, so we really want to get
> sync_file.[hc] destaged in 4.7. It'll take us a few iterations and a few
> drivers using this in anger in upstream to perfect the internal interfaces
> anyway, but let's get this started.
> 
> Had some real nitpicks on the docs patch, but that can also be merged
> later on imo. Except for that patch, on the series:
> 
> Reviewed-by: Daniel Vetter 
> 

Thanks for the review, I'm sending v2 fixing the nitpicks you pointed
out.

Gustavo
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 10/12] dma-buf/sync_file: de-stage sync_file

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

sync_file is useful to connect one or more fences to the file. The file is
used by userspace to track fences between drivers that share DMA bufs.

Signed-off-by: Gustavo Padovan 
---
 drivers/Kconfig  |  2 ++
 drivers/dma-buf/Kconfig  | 11 +++
 drivers/dma-buf/Makefile |  1 +
 drivers/{staging/android => dma-buf}/sync_file.c |  0
 drivers/staging/android/Kconfig  |  1 +
 drivers/staging/android/Makefile |  2 +-
 6 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma-buf/Kconfig
 rename drivers/{staging/android => dma-buf}/sync_file.c (100%)

diff --git a/drivers/Kconfig b/drivers/Kconfig
index d2ac339..430f761 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -114,6 +114,8 @@ source "drivers/rtc/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/dma-buf/Kconfig"
+
 source "drivers/dca/Kconfig"
 
 source "drivers/auxdisplay/Kconfig"
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
new file mode 100644
index 000..9824bc4
--- /dev/null
+++ b/drivers/dma-buf/Kconfig
@@ -0,0 +1,11 @@
+menu "DMABUF options"
+
+config SYNC_FILE
+   bool "sync_file support for fences"
+   default n
+   select ANON_INODES
+   select DMA_SHARED_BUFFER
+   ---help---
+ This option enables the fence framework synchronization to export
+ sync_files to userspace that can represent one or more fences.
+endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 57a675f..4a424ec 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1,2 @@
 obj-y := dma-buf.o fence.o reservation.o seqno-fence.o
+obj-$(CONFIG_SYNC_FILE)+= sync_file.o
diff --git a/drivers/staging/android/sync_file.c b/drivers/dma-buf/sync_file.c
similarity index 100%
rename from drivers/staging/android/sync_file.c
rename to drivers/dma-buf/sync_file.c
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 4244821..7a3a77e 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -38,6 +38,7 @@ config SW_SYNC
bool "Software synchronization objects"
default n
depends on SYNC
+   depends on SYNC_FILE
---help---
  A sync object driver that uses a 32bit counter to coordinate
  synchronization.  Useful when there is no hardware primitive backing
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index ebc2df1..980d6dc 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,5 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync_file.o sync.o sync_debug.o
+obj-$(CONFIG_SYNC) += sync.o sync_debug.o
 obj-$(CONFIG_SW_SYNC)  += sw_sync.o
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 07/12] staging/android: improve documentation for sync_file

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

num_fences was missing a colon mark and sync_file_create() now have
better description.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync_file.c | 3 ++-
 drivers/staging/android/sync_file.h | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index 3902538..5d77c08 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -71,7 +71,8 @@ static void fence_check_cb_func(struct fence *f, struct 
fence_cb *cb)
  * @fence: fence to add to the sync_fence
  *
  * Creates a sync_file containg @fence. Once this is called, the sync_file
- * takes ownership of @fence.
+ * takes ownership of @fence. The sync_file can be released with
+ * fput(sync_file->file). Returns the sync_file or NULL in case of error.
  */
 struct sync_file *sync_file_create(const char *name, struct fence *fence)
 {
diff --git a/drivers/staging/android/sync_file.h 
b/drivers/staging/android/sync_file.h
index a53259c..003db09 100644
--- a/drivers/staging/android/sync_file.h
+++ b/drivers/staging/android/sync_file.h
@@ -32,7 +32,7 @@ struct sync_file_cb {
  * @kref:  reference count on fence.
  * @name:  name of sync_file.  Useful for debugging
  * @sync_file_list:membership in global file list
- * @num_fences number of sync_pts in the fence
+ * @num_fences:number of sync_pts in the fence
  * @wq:wait queue for fence signaling
  * @status:0: signaled, >0:active, <0: error
  * @cbs:   sync_pts callback information
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/12] staging/android: style fix: alignment to match the open parenthesis

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

Fix checks reported by checkpatch.pl.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync_file.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index 5d77c08..0862c7f 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -241,7 +241,7 @@ static unsigned int sync_file_poll(struct file *file, 
poll_table *wait)
 }
 
 static long sync_file_ioctl_merge(struct sync_file *sync_file,
-  unsigned long arg)
+ unsigned long arg)
 {
int fd = get_unused_fd_flags(O_CLOEXEC);
int err;
@@ -296,7 +296,7 @@ err_put_fd:
 }
 
 static void sync_fill_fence_info(struct fence *fence,
-   struct sync_fence_info *info)
+struct sync_fence_info *info)
 {
strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
sizeof(info->obj_name));
@@ -310,7 +310,7 @@ static void sync_fill_fence_info(struct fence *fence,
 }
 
 static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
-   unsigned long arg)
+  unsigned long arg)
 {
struct sync_file_info info;
struct sync_fence_info *fence_info = NULL;
@@ -369,7 +369,7 @@ out:
 }
 
 static long sync_file_ioctl(struct file *file, unsigned int cmd,
-unsigned long arg)
+   unsigned long arg)
 {
struct sync_file *sync_file = file->private_data;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 12/12] Documentation: add Sync File doc

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

Add sync_file documentation on dma-buf-sync_file.txt
---
 Documentation/dma-buf-sync_file.txt | 65 +
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/dma-buf-sync_file.txt

diff --git a/Documentation/dma-buf-sync_file.txt 
b/Documentation/dma-buf-sync_file.txt
new file mode 100644
index 000..aa7320f
--- /dev/null
+++ b/Documentation/dma-buf-sync_file.txt
@@ -0,0 +1,65 @@
+DMA Buffer Sync File API Guide
+~~
+
+   Gustavo Padovan
+ 
+
+This document serves as a guide for device drivers writers on what is the
+dma-buf sync_file API, and how drivers can support it. Sync file is the
+carrier of the fences(struct fence) that needs to synchronized between drivers.
+
+The sync_file API is meant to be used to send and receive fence information
+to/from userspace. It enables userspace to do explicit fencing, where instead
+of attaching a fence to the buffer a Producer driver (such as GPU or V4L
+driver) it sends the fence related to the buffer to userspace. The fence then
+can be sent to the Consumer (DRM driver for example), that will not use the
+buffer for anything before the fence signals, i.e., the driver that issued the
+fence is not using/processing the buffer anymore, so it signals that the buffer
+is ready to use. And vice-versa for the Consumer -> Producer part of the cycle.
+Sync files allows userspace awareness on the DMA buffer sharing synchronization
+between drivers.
+
+Sync file was originally added in the Android kernel but current Linux Desktop
+can benefit a lot from it.
+
+in-fences and out-fences
+
+
+Sync files can go either to or from userspace. When a sync_file is sent from
+the driver to userspace we call the fences it contains 'out-fences'. They are
+related to a buffer that the driver is processing or is going to process, so
+the driver create out-fences to be able to notify, through fence_signal(), when
+it has finished using (or processing) that buffer. Out-fences are fences that
+the driver creates.
+
+On the other hand if the driver receives fence(s) through a sync_file from
+userspace we call these fence(s) 'in-fences'. Receiveing in-fences means that
+we need to wait for the fence(s) to signal before using any buffer related to
+the in-fences.
+
+Creating Sync Files
+---
+
+When a driver needs to send an out-fence userspace it creates a sync_file.
+
+Interface:
+   struct sync_file *sync_file_create(const char *name, struct fence 
*fence);
+
+The caller pass the name and the out-fence and gets back the sync_file. That is
+just the first step, next it needs to install an fd on sync_file->file. So it
+gets an fd:
+
+   fd = get_unused_fd_flags(O_CLOEXEC);
+
+and installs it on sync_file->file:
+
+   fd_install(fd, sync_file->file);
+
+The sync_file fd now can be sent to userspace.
+
+If the creation process fail, or the sync_file needs to be released by any
+other reason fput(sync_file->file) should be used.
+
+References:
+[1] struct sync_file in include/linux/sync_file.h
+[2] All interfaces mentioned above defined in include/linux/sync_file.h
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 11/12] Documentation: include sync_file into DocBook

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

Add entry in device-drivers.tmpl for sync_file documentation.

Signed-off-by: Gustavo Padovan 
---
 Documentation/DocBook/device-drivers.tmpl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/DocBook/device-drivers.tmpl 
b/Documentation/DocBook/device-drivers.tmpl
index 184f3c7..509a187 100644
--- a/Documentation/DocBook/device-drivers.tmpl
+++ b/Documentation/DocBook/device-drivers.tmpl
@@ -136,6 +136,8 @@ X!Edrivers/base/interface.c
 !Iinclude/linux/seqno-fence.h
 !Edrivers/dma-buf/reservation.c
 !Iinclude/linux/reservation.h
+!Edrivers/dma-buf/sync_file.c
+!Iinclude/linux/sync_file.h
 !Edrivers/base/dma-coherent.c
 !Edrivers/base/dma-mapping.c
  
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/12] staging/android: make sync_file_fdget() static

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

There is no plan in the near future to use this function outside of this
file so keep it as static.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c | 3 +--
 drivers/staging/android/sync.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c441fde..1239684 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -212,7 +212,7 @@ EXPORT_SYMBOL(sync_file_create);
  * Ensures @fd references a valid sync_file, increments the refcount of the
  * backing file. Returns the sync_file or NULL in case of error.
  */
-struct sync_file *sync_file_fdget(int fd)
+static struct sync_file *sync_file_fdget(int fd)
 {
struct file *file = fget(fd);
 
@@ -228,7 +228,6 @@ err:
fput(file);
return NULL;
 }
-EXPORT_SYMBOL(sync_file_fdget);
 
 static void sync_file_add_pt(struct sync_file *sync_file, int *i,
 struct fence *fence)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index ffc6df6..1f164df 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -168,7 +168,6 @@ void sync_timeline_signal(struct sync_timeline *obj);
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
 struct sync_file *sync_file_create(const char *name, struct fence *fence);
-struct sync_file *sync_file_fdget(int fd);
 
 #ifdef CONFIG_DEBUG_FS
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/12] dma-buf/sync_file: de-stage sync_file headers

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

Move sync_file headers file to include/ dir.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.h   | 4 ++--
 drivers/staging/android/sync_debug.c | 2 +-
 drivers/staging/android/sync_file.c  | 4 ++--
 {drivers/staging/android => include/linux}/sync_file.h   | 0
 {drivers/staging/android/uapi => include/uapi/linux}/sync_file.h | 0
 5 files changed, 5 insertions(+), 5 deletions(-)
 rename {drivers/staging/android => include/linux}/sync_file.h (100%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sync_file.h (100%)

diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index df44abb..b56885c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -20,8 +20,8 @@
 #include 
 #include 
 
-#include "sync_file.h"
-#include "uapi/sync_file.h"
+#include 
+#include 
 
 struct sync_timeline;
 
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 6589aba..9ce3c5d 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -26,7 +26,7 @@
 #include 
 #include 
 #include 
-#include "sync_file.h"
+#include 
 #include "sw_sync.h"
 
 #ifdef CONFIG_DEBUG_FS
diff --git a/drivers/staging/android/sync_file.c 
b/drivers/staging/android/sync_file.c
index 0862c7f..c4eec1c 100644
--- a/drivers/staging/android/sync_file.c
+++ b/drivers/staging/android/sync_file.c
@@ -23,8 +23,8 @@
 #include 
 #include 
 #include 
-#include "sync_file.h"
-#include "uapi/sync_file.h"
+#include 
+#include 
 
 static const struct file_operations sync_file_fops;
 
diff --git a/drivers/staging/android/sync_file.h b/include/linux/sync_file.h
similarity index 100%
rename from drivers/staging/android/sync_file.h
rename to include/linux/sync_file.h
diff --git a/drivers/staging/android/uapi/sync_file.h 
b/include/uapi/linux/sync_file.h
similarity index 100%
rename from drivers/staging/android/uapi/sync_file.h
rename to include/uapi/linux/sync_file.h
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/12] staging/android: prepare sync_file for de-staging

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

Move its functions and structs to their own file. Also moves function's
docs to the .c file.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/Makefile   |   2 +-
 drivers/staging/android/sync.c | 373 ---
 drivers/staging/android/sync.h |  38 +-
 drivers/staging/android/sync_debug.c   |   1 +
 drivers/staging/android/sync_file.c| 393 +
 drivers/staging/android/sync_file.h|  57 +++
 .../staging/android/uapi/{sync.h => sync_file.h}   |   0
 7 files changed, 454 insertions(+), 410 deletions(-)
 create mode 100644 drivers/staging/android/sync_file.c
 create mode 100644 drivers/staging/android/sync_file.h
 rename drivers/staging/android/uapi/{sync.h => sync_file.h} (100%)

diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc..ebc2df1 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,5 @@ obj-y   += ion/
 
 obj-$(CONFIG_ASHMEM)   += ashmem.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)+= lowmemorykiller.o
-obj-$(CONFIG_SYNC) += sync.o sync_debug.o
+obj-$(CONFIG_SYNC) += sync_file.o sync.o sync_debug.o
 obj-$(CONFIG_SW_SYNC)  += sw_sync.o
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 1239684..1d14c83 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -16,10 +16,7 @@
 
 #include 
 #include 
-#include 
-#include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -32,7 +29,6 @@
 #include "trace/sync.h"
 
 static const struct fence_ops android_fence_ops;
-static const struct file_operations sync_file_fops;
 
 struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
   int size, const char *name)
@@ -136,181 +132,6 @@ struct fence *sync_pt_create(struct sync_timeline *obj, 
int size)
 }
 EXPORT_SYMBOL(sync_pt_create);
 
-static struct sync_file *sync_file_alloc(int size, const char *name)
-{
-   struct sync_file *sync_file;
-
-   sync_file = kzalloc(size, GFP_KERNEL);
-   if (!sync_file)
-   return NULL;
-
-   sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops,
-sync_file, 0);
-   if (IS_ERR(sync_file->file))
-   goto err;
-
-   kref_init(&sync_file->kref);
-   strlcpy(sync_file->name, name, sizeof(sync_file->name));
-
-   init_waitqueue_head(&sync_file->wq);
-
-   return sync_file;
-
-err:
-   kfree(sync_file);
-   return NULL;
-}
-
-static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
-{
-   struct sync_file_cb *check;
-   struct sync_file *sync_file;
-
-   check = container_of(cb, struct sync_file_cb, cb);
-   sync_file = check->sync_file;
-
-   if (atomic_dec_and_test(&sync_file->status))
-   wake_up_all(&sync_file->wq);
-}
-
-/**
- * sync_fence_create() - creates a sync fence
- * @name:  name of fence to create
- * @fence: fence to add to the sync_fence
- *
- * Creates a sync_file containg @fence. Once this is called, the sync_file
- * takes ownership of @fence.
- */
-struct sync_file *sync_file_create(const char *name, struct fence *fence)
-{
-   struct sync_file *sync_file;
-
-   sync_file = sync_file_alloc(offsetof(struct sync_file, cbs[1]),
-   name);
-   if (!sync_file)
-   return NULL;
-
-   sync_file->num_fences = 1;
-   atomic_set(&sync_file->status, 1);
-
-   sync_file->cbs[0].fence = fence;
-   sync_file->cbs[0].sync_file = sync_file;
-   if (fence_add_callback(fence, &sync_file->cbs[0].cb,
-  fence_check_cb_func))
-   atomic_dec(&sync_file->status);
-
-   sync_file_debug_add(sync_file);
-
-   return sync_file;
-}
-EXPORT_SYMBOL(sync_file_create);
-
-/**
- * sync_file_fdget() - get a sync_file from an fd
- * @fd:fd referencing a fence
- *
- * Ensures @fd references a valid sync_file, increments the refcount of the
- * backing file. Returns the sync_file or NULL in case of error.
- */
-static struct sync_file *sync_file_fdget(int fd)
-{
-   struct file *file = fget(fd);
-
-   if (!file)
-   return NULL;
-
-   if (file->f_op != &sync_file_fops)
-   goto err;
-
-   return file->private_data;
-
-err:
-   fput(file);
-   return NULL;
-}
-
-static void sync_file_add_pt(struct sync_file *sync_file, int *i,
-struct fence *fence)
-{
-   sync_file->cbs[*i].fence =

[PATCH 04/12] staging/android: make sync_file_merge() static

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

There is no plan in the near future to use this function outside of this
file so keep it as static.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c | 4 ++--
 drivers/staging/android/sync.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index a89ded0..c441fde 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -253,8 +253,8 @@ static void sync_file_add_pt(struct sync_file *sync_file, 
int *i,
  * @a and @b.  @a and @b remain valid, independent sync_file. Returns the
  * new merged sync_file or NULL in case of error.
  */
-struct sync_file *sync_file_merge(const char *name,
- struct sync_file *a, struct sync_file *b)
+static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
+struct sync_file *b)
 {
int num_fences = a->num_fences + b->num_fences;
struct sync_file *sync_file;
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 925fba5..ffc6df6 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -168,8 +168,6 @@ void sync_timeline_signal(struct sync_timeline *obj);
 struct fence *sync_pt_create(struct sync_timeline *parent, int size);
 
 struct sync_file *sync_file_create(const char *name, struct fence *fence);
-struct sync_file *sync_file_merge(const char *name,
-   struct sync_file *a, struct sync_file *b);
 struct sync_file *sync_file_fdget(int fd);
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/12] staging/android: drop sync_file_install() and sync_file_put()

2016-04-27 Thread Gustavo Padovan
From: Gustavo Padovan 

These two functions are just wrappers for one line functions, they
call fd_install() and fput() respectively, so just get rid of them
and use fd_install() and fput() directly for more simplicity.

Signed-off-by: Gustavo Padovan 
---
 drivers/staging/android/sync.c   | 20 
 drivers/staging/android/sync.h   | 19 ---
 drivers/staging/android/sync_debug.c |  4 ++--
 3 files changed, 6 insertions(+), 37 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index f9c6094..b965e2a 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -216,18 +216,6 @@ err:
 }
 EXPORT_SYMBOL(sync_file_fdget);
 
-void sync_file_put(struct sync_file *sync_file)
-{
-   fput(sync_file->file);
-}
-EXPORT_SYMBOL(sync_file_put);
-
-void sync_file_install(struct sync_file *sync_file, int fd)
-{
-   fd_install(fd, sync_file->file);
-}
-EXPORT_SYMBOL(sync_file_install);
-
 static void sync_file_add_pt(struct sync_file *sync_file, int *i,
 struct fence *fence)
 {
@@ -469,15 +457,15 @@ static long sync_file_ioctl_merge(struct sync_file 
*sync_file,
goto err_put_fence3;
}
 
-   sync_file_install(fence3, fd);
-   sync_file_put(fence2);
+   fd_install(fd, fence3->file);
+   fput(fence2->file);
return 0;
 
 err_put_fence3:
-   sync_file_put(fence3);
+   fput(fence3->file);
 
 err_put_fence2:
-   sync_file_put(fence2);
+   fput(fence2->file);
 
 err_put_fd:
put_unused_fd(fd);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index d2a1734..c45cc7b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -203,25 +203,6 @@ struct sync_file *sync_file_merge(const char *name,
  */
 struct sync_file *sync_file_fdget(int fd);
 
-/**
- * sync_file_put() - puts a reference of a sync_file
- * @sync_file: sync_file to put
- *
- * Puts a reference on @sync_fence.  If this is the last reference, the
- * sync_fil and all it's sync_pts will be freed
- */
-void sync_file_put(struct sync_file *sync_file);
-
-/**
- * sync_file_install() - installs a sync_file into a file descriptor
- * @sync_file: sync_file to install
- * @fd:file descriptor in which to install the fence
- *
- * Installs @sync_file into @fd.  @fd's should be acquired through
- * get_unused_fd_flags(O_CLOEXEC).
- */
-void sync_file_install(struct sync_file *sync_file, int fd);
-
 #ifdef CONFIG_DEBUG_FS
 
 void sync_timeline_debug_add(struct sync_timeline *obj);
diff --git a/drivers/staging/android/sync_debug.c 
b/drivers/staging/android/sync_debug.c
index 5a7ec58..e4b0e41 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -272,12 +272,12 @@ static long sw_sync_ioctl_create_fence(struct 
sw_sync_timeline *obj,
 
data.fence = fd;
if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
-   sync_file_put(sync_file);
+   fput(sync_file->file);
err = -EFAULT;
goto err;
}
 
-   sync_file_install(sync_file, fd);
+   fd_install(fd, sync_file->file);
 
return 0;
 
-- 
2.5.5

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


  1   2   3   4   >