[Xenomai-git] 3.x build test report

2016-03-02 Thread git

next branch build test:
git hash: 64a3e0a9891138ee9fb835765502306c08910560
Building 
/work/build/bx3/build-forge-next/at91/3.10-arm-none-linux-gnueabi-gcc-4.8.3: 
failed
Building 
/work/build/bx3/build-forge-next/bf537-stamp/3.10-bfin-linux-uclibc-gcc-4.3.5: 
failed
Building 
/work/build/bx3/build-forge-next/bf561-ezkit/3.10-bfin-linux-uclibc-gcc-4.3.5: 
failed
Building /work/build/bx3/build-forge-next/i686/3.10-gcc-4.8.2: failed
Building /work/build/bx3/build-forge-next/i686-smp/3.10-gcc-4.8.2: failed
Building 
/work/build/bx3/build-forge-next/imx_v4_v5/3.10-arm-none-linux-gnueabi-gcc-4.8.3:
 failed
Building 
/work/build/bx3/build-forge-next/imx_v6_v7/3.10-arm-linux-gnueabihf-gcc-4.9.3: 
failed
Building 
/work/build/bx3/build-forge-next/ixp4xx/3.10-arm-none-linux-gnueabi-gcc-4.8.3: 
failed
Building 
/work/build/bx3/build-forge-next/lite5200/3.10-powerpc-linux-gcc-4.6.4: failed
Building 
/work/build/bx3/build-forge-next/mpc8641_hpcn/3.10-powerpc-linux-gcc-4.6.4: 
failed
Building 
/work/build/bx3/build-forge-next/mpc8641_hpcn/4.1-powerpc-linux-gcc-4.6.4: 
failed
Building 
/work/build/bx3/build-forge-next/omap/3.10-arm-linux-gnueabihf-gcc-4.9.3: failed
Building 
/work/build/bx3/build-forge-next/pasemi/3.10-powerpc64-unknown-linux-gnu-gcc-4.4.3:
 failed
Building 
/work/build/bx3/build-forge-next/pasemi/4.1-powerpc64-unknown-linux-gnu-gcc-4.4.3:
 failed
Building 
/work/build/bx3/build-forge-next/sama5/3.10-arm-linux-gnueabihf-gcc-4.9.3: 
failed
Building /work/build/bx3/build-forge-next/x86_64/3.10-gcc-4.8.2: failed
at91/3.10-arm-none-linux-gnueabi-gcc-4.8.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/at91/3.10-arm-none-linux-gnueabi-gcc-4.8.3/log.html#1
bf537-stamp/3.10-bfin-linux-uclibc-gcc-4.3.5: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/bf537-stamp/3.10-bfin-linux-uclibc-gcc-4.3.5/log.html#1
bf561-ezkit/3.10-bfin-linux-uclibc-gcc-4.3.5: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/bf561-ezkit/3.10-bfin-linux-uclibc-gcc-4.3.5/log.html#1
i686/3.10-gcc-4.8.2: failed with 1 warnings/errors
See http://xenomai.org/build-test-next/i686/3.10-gcc-4.8.2/log.html#1
i686-smp/3.10-gcc-4.8.2: failed with 1 warnings/errors
See http://xenomai.org/build-test-next/i686-smp/3.10-gcc-4.8.2/log.html#1
imx_v4_v5/3.10-arm-none-linux-gnueabi-gcc-4.8.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/imx_v4_v5/3.10-arm-none-linux-gnueabi-gcc-4.8.3/log.html#1
imx_v6_v7/3.10-arm-linux-gnueabihf-gcc-4.9.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/imx_v6_v7/3.10-arm-linux-gnueabihf-gcc-4.9.3/log.html#1
ixp4xx/3.10-arm-none-linux-gnueabi-gcc-4.8.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/ixp4xx/3.10-arm-none-linux-gnueabi-gcc-4.8.3/log.html#1
lite5200/3.10-powerpc-linux-gcc-4.6.4: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/lite5200/3.10-powerpc-linux-gcc-4.6.4/log.html#1
mpc8641_hpcn/3.10-powerpc-linux-gcc-4.6.4: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/mpc8641_hpcn/3.10-powerpc-linux-gcc-4.6.4/log.html#1
mpc8641_hpcn/4.1-powerpc-linux-gcc-4.6.4: failed with 4 warnings/errors
See 
http://xenomai.org/build-test-next/mpc8641_hpcn/4.1-powerpc-linux-gcc-4.6.4/log.html#1
mpc8641_hpcn/4.1-powerpc-linux-gcc-4.6.4: failed with 4 warnings/errors
See 
http://xenomai.org/build-test-next/mpc8641_hpcn/4.1-powerpc-linux-gcc-4.6.4/log.html#1
omap/3.10-arm-linux-gnueabihf-gcc-4.9.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/omap/3.10-arm-linux-gnueabihf-gcc-4.9.3/log.html#1
pasemi/3.10-powerpc64-unknown-linux-gnu-gcc-4.4.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/pasemi/3.10-powerpc64-unknown-linux-gnu-gcc-4.4.3/log.html#1
pasemi/4.1-powerpc64-unknown-linux-gnu-gcc-4.4.3: failed with 5 warnings/errors
See 
http://xenomai.org/build-test-next/pasemi/4.1-powerpc64-unknown-linux-gnu-gcc-4.4.3/log.html#1
pasemi/4.1-powerpc64-unknown-linux-gnu-gcc-4.4.3: failed with 5 warnings/errors
See 
http://xenomai.org/build-test-next/pasemi/4.1-powerpc64-unknown-linux-gnu-gcc-4.4.3/log.html#1
sama5/3.10-arm-linux-gnueabihf-gcc-4.9.3: failed with 1 warnings/errors
See 
http://xenomai.org/build-test-next/sama5/3.10-arm-linux-gnueabihf-gcc-4.9.3/log.html#1
x86_64/3.10-gcc-4.8.2: failed with 1 warnings/errors
See http://xenomai.org/build-test-next/x86_64/3.10-gcc-4.8.2/log.html#1

stable branch build test:
git hash: 80f7710f5c954e4afa3f369b9e3c57ecfc563c07
Building 
/work/build/bx3/build-forge-stable/at91/3.10-arm-none-linux-gnueabi-gcc-4.8.3: 
failed
Building 
/work/build/bx3/build-forge-stable/bf537-stamp/3.10-bfin-linux-uclibc-gcc-4.3.5:
 failed
Building 
/work/build/bx3/build-forge-stable/bf561-ezkit/3.10-bfin-linux-uclibc-gcc-4.3.5:
 failed
Building /work/build/bx3/build-forge-stable/i686/3.10-gcc-4.8.2: failed
Building /work/build/bx3/build-forge-stable/i686-smp/3.10-gcc-4.8.2: failed
Building 
/

[Xenomai-git] Philippe Gerum : config: bump version code

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 09413e26bec6cfae6c0b5aaa7cb61b288f0a397a
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=09413e26bec6cfae6c0b5aaa7cb61b288f0a397a

Author: Philippe Gerum 
Date:   Wed Mar  2 17:05:17 2016 +0100

config: bump version code

---

 config/version-code  |2 +-
 config/version-label |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/config/version-code b/config/version-code
index cb2b00e..b502146 100644
--- a/config/version-code
+++ b/config/version-code
@@ -1 +1 @@
-3.0.1
+3.0.2
diff --git a/config/version-label b/config/version-label
index cb2b00e..b502146 100644
--- a/config/version-label
+++ b/config/version-label
@@ -1 +1 @@
-3.0.1
+3.0.2


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : doc: prebuild

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 80f7710f5c954e4afa3f369b9e3c57ecfc563c07
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=80f7710f5c954e4afa3f369b9e3c57ecfc563c07

Author: Philippe Gerum 
Date:   Wed Mar  2 17:16:48 2016 +0100

doc: prebuild

---

 doc/prebuilt/html/MIGRATION/index.html |6 +-
 doc/prebuilt/html/README.APPLICATIONS/index.html   |2 +-
 doc/prebuilt/html/README.INSTALL/index.html|2 +-
 .../html/TROUBLESHOOTING.COBALT/index.html |2 +-
 .../html/TROUBLESHOOTING.MERCURY/index.html|2 +-
 doc/prebuilt/html/man1/autotune/index.html |2 +-
 doc/prebuilt/html/man1/clocktest/index.html|2 +-
 doc/prebuilt/html/man1/corectl/index.html  |2 +-
 doc/prebuilt/html/man1/dohell/index.html   |2 +-
 doc/prebuilt/html/man1/latency/index.html  |2 +-
 doc/prebuilt/html/man1/rtcanconfig/index.html  |2 +-
 doc/prebuilt/html/man1/rtcanrecv/index.html|2 +-
 doc/prebuilt/html/man1/rtcansend/index.html|2 +-
 doc/prebuilt/html/man1/slackspot/index.html|2 +-
 doc/prebuilt/html/man1/switchtest/index.html   |2 +-
 doc/prebuilt/html/man1/xeno-config/index.html  |2 +-
 doc/prebuilt/html/man1/xeno-test/index.html|2 +-
 doc/prebuilt/html/man1/xeno/index.html |2 +-
 .../html/xeno3prm/16550A__io_8h_source.html|2 +-
 .../html/xeno3prm/16550A__pci_8h_source.html   |2 +-
 .../html/xeno3prm/16550A__pnp_8h_source.html   |2 +-
 doc/prebuilt/html/xeno3prm/8255_8h_source.html |2 +-
 doc/prebuilt/html/xeno3prm/af__inet_8h_source.html |2 +-
 .../html/xeno3prm/alchemy_2compat_8h_source.html   |2 +-
 doc/prebuilt/html/xeno3prm/analogy_2driver_8h.html |   60 +-
 .../html/xeno3prm/analogy_2driver_8h__incl.map |   58 +-
 .../html/xeno3prm/analogy_2driver_8h__incl.md5 |2 +-
 .../html/xeno3prm/analogy_2driver_8h__incl.png |  Bin 271875 -> 289554 
bytes
 .../html/xeno3prm/analogy_2driver_8h_source.html   |2 +-
 doc/prebuilt/html/xeno3prm/analogy_8h.html |2 +-
 doc/prebuilt/html/xeno3prm/analogy_8h_source.html  |2 +-
 doc/prebuilt/html/xeno3prm/annotated.html  |2 +-
 doc/prebuilt/html/xeno3prm/apc_8h_source.html  |2 +-
 doc/prebuilt/html/xeno3prm/api-tags.html   |2 +-
 ..._2include_2asm_2xenomai_2machine_8h_source.html |2 +-
 ...include_2asm_2xenomai_2syscall32_8h_source.html |2 +-
 ..._2include_2asm_2xenomai_2machine_8h_source.html |2 +-
 ...include_2asm_2xenomai_2syscall32_8h_source.html |2 +-
 ..._2include_2asm_2xenomai_2machine_8h_source.html |2 +-
 ...include_2asm_2xenomai_2syscall32_8h_source.html |2 +-
 ..._2include_2asm_2xenomai_2machine_8h_source.html |2 +-
 ...include_2asm_2xenomai_2syscall32_8h_source.html |2 +-
 ...m_2include_2asm_2xenomai_2fptest_8h_source.html |2 +-
 ...lude_2asm_2xenomai_2uapi_2fptest_8h_source.html |2 +-
 doc/prebuilt/html/xeno3prm/arp_8h_source.html  |2 +-
 doc/prebuilt/html/xeno3prm/assert_8h_source.html   |2 +-
 doc/prebuilt/html/xeno3prm/async_8c.html   |2 +-
 doc/prebuilt/html/xeno3prm/atomic_8h_source.html   |2 +-
 doc/prebuilt/html/xeno3prm/bheap_8h_source.html|2 +-
 ...n_2include_2asm_2xenomai_2fptest_8h_source.html |2 +-
 ...lude_2asm_2xenomai_2uapi_2fptest_8h_source.html |2 +-
 .../boilerplate_2ancillaries_8h_source.html|  209 ++--
 .../html/xeno3prm/boilerplate_2list_8h_source.html |2 +-
 .../html/xeno3prm/boilerplate_2lock_8h_source.html |2 +-
 .../html/xeno3prm/boilerplate_2time_8h_source.html |2 +-
 .../xeno3prm/boilerplate_2tunables_8h_source.html  |2 +-
 doc/prebuilt/html/xeno3prm/bufd_8h_source.html |2 +-
 .../html/xeno3prm/bufp-label_8c-example.html   |2 +-
 .../html/xeno3prm/bufp-readwrite_8c-example.html   |2 +-
 doc/prebuilt/html/xeno3prm/c1e_8h_source.html  |2 +-
 doc/prebuilt/html/xeno3prm/calibration_8c.html |2 +-
 doc/prebuilt/html/xeno3prm/can-rtt_8c-example.html |2 +-
 doc/prebuilt/html/xeno3prm/channel__range_8h.html  |2 +-
 .../html/xeno3prm/channel__range_8h_source.html|2 +-
 doc/prebuilt/html/xeno3prm/classes.html|2 +-
 doc/prebuilt/html/xeno3prm/clockobj_8h_source.html |2 +-
 doc/prebuilt/html/xeno3prm/cluster_8h_source.html  |2 +-
 .../html/xeno3prm/cobalt-core_8h_source.html   | 1221 ++--
 .../html/xeno3prm/cobalt-posix_8h_source.html  |2 +-
 .../html/xeno3prm/cobalt-rtdm_8h_source.html   |  993 
 .../cobalt_2boilerplate_2limits_8h_source.html |2 +-
 .../cobalt_2boilerplate_2trace_8h_source.html  |2 +-
 .../cobalt_2kernel_2ancillaries_8h_source.html |2 +-
 .../xeno3prm/cobalt_2kernel_2compat_8h_source.html |2 +-
 .../xeno3prm/cobalt_2kernel_2init_8h_source.html   |2 +-
 .../xeno3prm/cobalt

[Xenomai-git] Philippe Gerum : cobalt/powerpc: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: fa916f9c245a72480de7b98d555bb05087971c6c
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=fa916f9c245a72480de7b98d555bb05087971c6c

Author: Philippe Gerum 
Date:   Wed Mar  2 17:02:11 2016 +0100

cobalt/powerpc: upgrade I-pipe support

---

 ...powerpc-1.patch => ipipe-core-4.1.18-powerpc-2.patch} |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch 
b/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
similarity index 99%
rename from kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch
rename to kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
index a5f320d..97fd4a6 100644
--- a/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch
+++ b/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
@@ -304,7 +304,7 @@ index b59ac27..9cc1d25 100644
   * or should we not care like we do now ? --BenH.
 diff --git a/arch/powerpc/include/asm/ipipe.h 
b/arch/powerpc/include/asm/ipipe.h
 new file mode 100644
-index 000..af33819
+index 000..837a554
 --- /dev/null
 +++ b/arch/powerpc/include/asm/ipipe.h
 @@ -0,0 +1,151 @@
@@ -349,7 +349,7 @@ index 000..af33819
 +#include 
 +#include 
 +
-+#define IPIPE_CORE_RELEASE1
++#define IPIPE_CORE_RELEASE2
 +
 +struct ipipe_domain;
 +
@@ -2437,7 +2437,7 @@ index 112ccf4..5dd70f7 100644
li  r0,0
 diff --git a/arch/powerpc/kernel/ipipe.c b/arch/powerpc/kernel/ipipe.c
 new file mode 100644
-index 000..d628fd56
+index 000..9a5702a
 --- /dev/null
 +++ b/arch/powerpc/kernel/ipipe.c
 @@ -0,0 +1,372 @@
@@ -2556,7 +2556,7 @@ index 000..d628fd56
 +  if (WARN_ON_ONCE(irq_get_chip(irq)->irq_set_affinity == NULL))
 +  return;
 +
-+  if (WARN_ON_ONCE(cpumask_any_and(&cpumask, &cpu_online_mask) >= 
nr_cpu_ids))
++  if (WARN_ON_ONCE(cpumask_any_and(&cpumask, cpu_online_mask) >= 
nr_cpu_ids))
 +  return;
 +
 +  irq_get_chip(irq)->irq_set_affinity(irq_get_irq_data(irq), &cpumask, 
true);
@@ -2581,7 +2581,7 @@ index 000..d628fd56
 +  goto out;
 +
 +  me = ipipe_processor_id();
-+  for_each_cpu_mask_nr(cpu, cpumask) {
++  for_each_cpu(cpu, &cpumask) {
 +  if (cpu != me)
 +  smp_ops->message_pass(cpu, PPC_MSG_IPIPE_DEMUX);
 +  }
@@ -3300,7 +3300,7 @@ index c69671c..66ac366 100644
  #endif
  
 diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
-index ec9ec20..ebe3c2b 100644
+index ec9ec20..a17ba31 100644
 --- a/arch/powerpc/kernel/smp.c
 +++ b/arch/powerpc/kernel/smp.c
 @@ -179,7 +179,7 @@ const char *smp_ipi_name[] = {
@@ -3334,7 +3334,7 @@ index ec9ec20..ebe3c2b 100644
 -  if (cpu != me)
 +  if (cpu != me) {
 +#ifdef CONFIG_IPIPE
-+  cpu_set(cpu, __ipipe_dbrk_pending);
++  cpumask_set_cpu(cpu, &__ipipe_dbrk_pending);
 +#endif
do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
 +  }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/powerpc: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 64a3e0a9891138ee9fb835765502306c08910560
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=64a3e0a9891138ee9fb835765502306c08910560

Author: Philippe Gerum 
Date:   Wed Mar  2 17:02:11 2016 +0100

cobalt/powerpc: upgrade I-pipe support

---

 ...powerpc-1.patch => ipipe-core-4.1.18-powerpc-2.patch} |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch 
b/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
similarity index 99%
rename from kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch
rename to kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
index a5f320d..97fd4a6 100644
--- a/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-1.patch
+++ b/kernel/cobalt/arch/powerpc/patches/ipipe-core-4.1.18-powerpc-2.patch
@@ -304,7 +304,7 @@ index b59ac27..9cc1d25 100644
   * or should we not care like we do now ? --BenH.
 diff --git a/arch/powerpc/include/asm/ipipe.h 
b/arch/powerpc/include/asm/ipipe.h
 new file mode 100644
-index 000..af33819
+index 000..837a554
 --- /dev/null
 +++ b/arch/powerpc/include/asm/ipipe.h
 @@ -0,0 +1,151 @@
@@ -349,7 +349,7 @@ index 000..af33819
 +#include 
 +#include 
 +
-+#define IPIPE_CORE_RELEASE1
++#define IPIPE_CORE_RELEASE2
 +
 +struct ipipe_domain;
 +
@@ -2437,7 +2437,7 @@ index 112ccf4..5dd70f7 100644
li  r0,0
 diff --git a/arch/powerpc/kernel/ipipe.c b/arch/powerpc/kernel/ipipe.c
 new file mode 100644
-index 000..d628fd56
+index 000..9a5702a
 --- /dev/null
 +++ b/arch/powerpc/kernel/ipipe.c
 @@ -0,0 +1,372 @@
@@ -2556,7 +2556,7 @@ index 000..d628fd56
 +  if (WARN_ON_ONCE(irq_get_chip(irq)->irq_set_affinity == NULL))
 +  return;
 +
-+  if (WARN_ON_ONCE(cpumask_any_and(&cpumask, &cpu_online_mask) >= 
nr_cpu_ids))
++  if (WARN_ON_ONCE(cpumask_any_and(&cpumask, cpu_online_mask) >= 
nr_cpu_ids))
 +  return;
 +
 +  irq_get_chip(irq)->irq_set_affinity(irq_get_irq_data(irq), &cpumask, 
true);
@@ -2581,7 +2581,7 @@ index 000..d628fd56
 +  goto out;
 +
 +  me = ipipe_processor_id();
-+  for_each_cpu_mask_nr(cpu, cpumask) {
++  for_each_cpu(cpu, &cpumask) {
 +  if (cpu != me)
 +  smp_ops->message_pass(cpu, PPC_MSG_IPIPE_DEMUX);
 +  }
@@ -3300,7 +3300,7 @@ index c69671c..66ac366 100644
  #endif
  
 diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
-index ec9ec20..ebe3c2b 100644
+index ec9ec20..a17ba31 100644
 --- a/arch/powerpc/kernel/smp.c
 +++ b/arch/powerpc/kernel/smp.c
 @@ -179,7 +179,7 @@ const char *smp_ipi_name[] = {
@@ -3334,7 +3334,7 @@ index ec9ec20..ebe3c2b 100644
 -  if (cpu != me)
 +  if (cpu != me) {
 +#ifdef CONFIG_IPIPE
-+  cpu_set(cpu, __ipipe_dbrk_pending);
++  cpumask_set_cpu(cpu, &__ipipe_dbrk_pending);
 +#endif
do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
 +  }


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/synch: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: baf99f253fbd9a94b33af36cc500b4cd2c58ae61
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=baf99f253fbd9a94b33af36cc500b4cd2c58ae61

Author: Philippe Gerum 
Date:   Tue Feb 16 10:12:55 2016 +0100

cobalt/synch: add support for priority ceiling protocol

---

 include/cobalt/kernel/heap.h   |   11 +
 include/cobalt/kernel/sched-idle.h |   12 +-
 include/cobalt/kernel/sched-rt.h   |   55 ++-
 include/cobalt/kernel/sched.h  |   94 +++-
 include/cobalt/kernel/synch.h  |   51 ++-
 include/cobalt/kernel/thread.h |   54 ++-
 include/cobalt/uapi/asm-generic/features.h |   27 +-
 include/cobalt/uapi/kernel/synch.h |8 +-
 include/cobalt/uapi/kernel/thread.h|3 +-
 include/cobalt/uapi/kernel/types.h |5 +-
 include/cobalt/uapi/mutex.h|1 +
 include/cobalt/uapi/thread.h   |1 +
 kernel/cobalt/posix/cond.c |2 +-
 kernel/cobalt/posix/memory.h   |6 +
 kernel/cobalt/posix/monitor.c  |   29 +-
 kernel/cobalt/posix/mqueue.c   |4 +-
 kernel/cobalt/posix/mutex.c|  103 +++--
 kernel/cobalt/posix/process.c  |   21 +-
 kernel/cobalt/posix/process.h  |3 +-
 kernel/cobalt/posix/syscall.c  |6 +-
 kernel/cobalt/posix/timerfd.c  |2 +-
 kernel/cobalt/rtdm/drvlib.c|2 +-
 kernel/cobalt/sched-idle.c |   12 +-
 kernel/cobalt/sched-quota.c|   24 +-
 kernel/cobalt/sched-rt.c   |   14 +-
 kernel/cobalt/sched-sporadic.c |   35 +-
 kernel/cobalt/sched-tp.c   |   42 +-
 kernel/cobalt/sched-weak.c |   16 +-
 kernel/cobalt/sched.c  |  126 +-
 kernel/cobalt/synch.c  |  636 +++-
 kernel/cobalt/thread.c |  115 ++---
 31 files changed, 1038 insertions(+), 482 deletions(-)

diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index a1cea69..d89f25d 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -147,6 +147,17 @@ void xnheap_free(struct xnheap *heap, void *block);
 
 int xnheap_check_block(struct xnheap *heap, void *block);
 
+static inline void *xnheap_zalloc(struct xnheap *heap, u32 size)
+{
+   void *p;
+
+   p = xnheap_alloc(heap, size);
+   if (p)
+   memset(p, 0, size);
+
+   return p;
+}
+
 static inline char *xnstrdup(const char *s)
 {
char *p;
diff --git a/include/cobalt/kernel/sched-idle.h 
b/include/cobalt/kernel/sched-idle.h
index 732ff84..75efdec 100644
--- a/include/cobalt/kernel/sched-idle.h
+++ b/include/cobalt/kernel/sched-idle.h
@@ -33,11 +33,11 @@
 
 extern struct xnsched_class xnsched_class_idle;
 
-static inline void __xnsched_idle_setparam(struct xnthread *thread,
+static inline bool __xnsched_idle_setparam(struct xnthread *thread,
   const union xnsched_policy_param *p)
 {
xnthread_clear_state(thread, XNWEAK);
-   thread->cprio = p->idle.prio;
+   return xnsched_set_effective_priority(thread, p->idle.prio);
 }
 
 static inline void __xnsched_idle_getparam(struct xnthread *thread,
@@ -50,11 +50,17 @@ static inline void __xnsched_idle_trackprio(struct xnthread 
*thread,
const union xnsched_policy_param *p)
 {
if (p)
-   __xnsched_idle_setparam(thread, p);
+   /* Inheriting a priority-less class makes no sense. */
+   XENO_WARN_ON_ONCE(COBALT, 1);
else
thread->cprio = XNSCHED_IDLE_PRIO;
 }
 
+static inline void __xnsched_idle_protectprio(struct xnthread *thread, int 
prio)
+{
+   XENO_WARN_ON_ONCE(COBALT, 1);
+}
+
 static inline int xnsched_idle_init_thread(struct xnthread *thread)
 {
return 0;
diff --git a/include/cobalt/kernel/sched-rt.h b/include/cobalt/kernel/sched-rt.h
index ffb7223..9049449 100644
--- a/include/cobalt/kernel/sched-rt.h
+++ b/include/cobalt/kernel/sched-rt.h
@@ -67,20 +67,33 @@ static inline void __xnsched_rt_dequeue(struct xnthread 
*thread)
xnsched_delq(&thread->sched->rt.runnable, thread);
 }
 
-static inline void __xnsched_rt_setparam(struct xnthread *thread,
-const union xnsched_policy_param *p)
+static inline void __xnsched_rt_track_weakness(struct xnthread *thread)
 {
-   thread->cprio = p->rt.prio;
-   if (!xnthread_test_state(thread, XNBOOST)) {
-#ifdef CONFIG_XENO_OPT_SCHED_WEAK
+   /*
+* We have to track threads exiting weak scheduling, i.e. any
+* thread leaving the WEAK class code is compiled in, or
+* assigned a zero priority if weak threads are hosted by the
+* RT class.
+*
+* CAUTION: since we need to check

[Xenomai-git] Jan Kiszka : smokey/posix-mutex: Fix test case /wrt mutex object reuse

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 8e963986b971d8d8693a7213f9c5c5a7b0cd75a9
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8e963986b971d8d8693a7213f9c5c5a7b0cd75a9

Author: Jan Kiszka 
Date:   Thu Feb 25 11:29:00 2016 +0100

smokey/posix-mutex: Fix test case /wrt mutex object reuse

Mutex objects created on the stack must be properly destroyed after use.
Otherwise, succeeding tests that use the same stack layout will consider
them busy and refuse to recreate the mutexes.

Signed-off-by: Jan Kiszka 

---

 testsuite/smokey/posix-mutex/posix-mutex.c |   26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ae82fc1..151c2f3 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -623,7 +623,10 @@ static int protect_raise(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -651,7 +654,10 @@ static int protect_lower(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -699,7 +705,10 @@ static int protect_weak(void)
if (!__T(ret, pthread_setschedparam(pthread_self(),
old_policy, &old_param)))
return ret;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -745,7 +754,11 @@ static int protect_nesting_protect(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_high)) ||
+   !__T(ret, pthread_mutex_destroy(&mutex_very_high)))
+   return ret;
+
return 0;
 }
 
@@ -782,7 +795,10 @@ static int protect_nesting_pi(void)
/* PP boost just dropped: HIGH -> MEDIUM. */
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_pp)))
+   return ret;
+
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/kernel: use standard accessor to global pid

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 9be99a6d95b24b732a671b713e0c70b62304aac2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=9be99a6d95b24b732a671b713e0c70b62304aac2

Author: Philippe Gerum 
Date:   Wed Mar  2 16:03:24 2016 +0100

cobalt/kernel: use standard accessor to global pid

---

 include/cobalt/kernel/thread.h|2 +-
 kernel/cobalt/posix/mqueue.c  |3 ++-
 kernel/cobalt/posix/process.c |   18 +++---
 kernel/cobalt/posix/signal.c  |5 +++--
 kernel/cobalt/posix/syscall.c |5 +++--
 kernel/cobalt/posix/thread.c  |2 +-
 kernel/cobalt/rtdm/core.c |3 ++-
 kernel/cobalt/rtdm/fd.c   |3 ++-
 kernel/cobalt/sched.c |5 +++--
 kernel/cobalt/timer.c |2 +-
 kernel/cobalt/trace/cobalt-core.h |7 ---
 kernel/cobalt/trace/cobalt-rtdm.h |7 ---
 12 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index e08a0a2..b45de8e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -265,7 +265,7 @@ static inline pid_t xnthread_host_pid(struct xnthread 
*thread)
if (xnthread_test_state(thread, XNROOT))
return 0;
 
-   return xnthread_host_task(thread)->pid;
+   return task_pid_nr(xnthread_host_task(thread));
 }
 
 #define xnthread_for_each_claimed(__pos, __thread) \
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 0f5e19e..77dabce 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "internal.h"
@@ -713,7 +714,7 @@ mq_notify(struct cobalt_mqd *mqd, unsigned index, const 
struct sigevent *evp)
 * receiver's namespaces. We pass the receiver's creds
 * into the init namespace instead.
 */
-   mq->si.si_pid = current->pid;
+   mq->si.si_pid = task_pid_nr(current);
mq->si.si_uid = get_current_uuid();
}
 
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 5b80521..28fde9e 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1138,17 +1139,20 @@ no_ptrace:
if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
   "hardened thread %s[%d] running in Linux domain?! "
   "(status=0x%x, sig=%d, prev=%s[%d])",
-  next->name, next_task->pid, xnthread_get_state(next),
-  signal_pending(next_task), prev_task->comm, 
prev_task->pid))
+  next->name, task_pid_nr(next_task),
+  xnthread_get_state(next),
+  signal_pending(next_task),
+  prev_task->comm, task_pid_nr(prev_task)))
XENO_WARN(COBALT,
  !(next_task->ptrace & PT_PTRACED) &&
   !xnthread_test_state(next, XNDORMANT)
  && xnthread_test_state(next, XNPEND),
  "blocked thread %s[%d] rescheduled?! "
  "(status=0x%x, sig=%d, prev=%s[%d])",
- next->name, next_task->pid, xnthread_get_state(next),
+ next->name, task_pid_nr(next_task),
+ xnthread_get_state(next),
  signal_pending(next_task), prev_task->comm,
- prev_task->pid);
+ task_pid_nr(prev_task));
 out:
return KEVENT_PROPAGATE;
 }
@@ -1315,13 +1319,13 @@ static int attach_process(struct cobalt_process 
*process)
if (ret)
return ret;
 
-   cobalt_umm_set_name(&p->umm, "private heap[%d]", current->pid);
+   cobalt_umm_set_name(&p->umm, "private heap[%d]", task_pid_nr(current));
 
p->mayday_tramp = map_mayday_page();
if (p->mayday_tramp == 0) {
printk(XENO_WARNING
   "%s[%d] cannot map MAYDAY page\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
ret = -ENOMEM;
goto fail_mayday;
}
@@ -1330,7 +1334,7 @@ static int attach_process(struct cobalt_process *process)
if (IS_ERR(exe_path)) {
printk(XENO_WARNING
   "%s[%d] can't find exe path\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
exe_path = NULL; /* Not lethal, but weird. */
}
p->exe_path = exe_path;
diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index dc16bc8..a3ec756 100644
--- a/kernel/cobalt/posix/signal.c
+++

[Xenomai-git] Philippe Gerum : testsuite/smokey: mutex: simplify, introduce PP tests

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: ba5c234c08a46f0a31ae8219bd6d4f23fc7639a5
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ba5c234c08a46f0a31ae8219bd6d4f23fc7639a5

Author: Philippe Gerum 
Date:   Wed Feb 17 09:21:27 2016 +0100

testsuite/smokey: mutex: simplify, introduce PP tests

At this chance, the lock stealing test is also fixed.

---

 testsuite/smokey/posix-mutex/posix-mutex.c | 1357 ++--
 1 file changed, 670 insertions(+), 687 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ac71b31..ae82fc1 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -4,6 +4,7 @@
  * Copyright (C) Gilles Chanteperdrix  ,
  *   Marion Deveaud ,
  *   Jan Kiszka 
+ *   Philippe Gerum 
  *
  * Released under the terms of GPLv2.
  */
@@ -17,8 +18,6 @@
 #include 
 #include 
 #include 
-#include 
-#include "lib/cobalt/current.h"
 #include 
 
 smokey_test_plugin(posix_mutex,
@@ -26,886 +25,870 @@ smokey_test_plugin(posix_mutex,
   "Check POSIX mutex services"
 );
 
-#define MUTEX_CREATE   1
-#define MUTEX_LOCK 2
-#define MUTEX_TRYLOCK  3
-#define MUTEX_TIMED_LOCK   4
-#define MUTEX_UNLOCK   5
-#define MUTEX_DESTROY  6
-#define COND_CREATE7
-#define COND_SIGNAL8
-#define COND_WAIT  9
-#define COND_DESTROY   10
-#define THREAD_DETACH  11
-#define THREAD_CREATE  12
-#define THREAD_JOIN13
-#define THREAD_RENICE   14
-
-#define NS_PER_MS  100
-
 static const char *reason_str[] = {
-   [SIGDEBUG_UNDEFINED] = "undefined",
+   [SIGDEBUG_UNDEFINED] = "received SIGDEBUG for unknown reason",
[SIGDEBUG_MIGRATE_SIGNAL] = "received signal",
[SIGDEBUG_MIGRATE_SYSCALL] = "invoked syscall",
[SIGDEBUG_MIGRATE_FAULT] = "triggered fault",
[SIGDEBUG_MIGRATE_PRIOINV] = "affected by priority inversion",
-   [SIGDEBUG_NOMLOCK] = "missing mlockall",
-   [SIGDEBUG_WATCHDOG] = "runaway thread",
+   [SIGDEBUG_NOMLOCK] = "process memory not locked",
+   [SIGDEBUG_WATCHDOG] = "watchdog triggered (period too short?)",
+   [SIGDEBUG_LOCK_BREAK] = "scheduler lock break",
 };
 
 static void sigdebug(int sig, siginfo_t *si, void *context)
 {
+   const char fmt[] = "%s, this is unexpected.\n"
+   "(enabling CONFIG_XENO_OPT_DEBUG_TRACE_RELAX may help)\n";
unsigned int reason = sigdebug_reason(si);
+   int n __attribute__ ((unused));
+   static char buffer[256];
 
-   smokey_trace("\nSIGDEBUG received, reason %d: %s\n", reason,
-reason <= SIGDEBUG_WATCHDOG ? reason_str[reason] : 
"");
-}
+   if (reason > SIGDEBUG_WATCHDOG)
+   reason = SIGDEBUG_UNDEFINED;
 
-static inline unsigned long long timer_get_tsc(void)
-{
-   return clockobj_get_tsc();
+   n = snprintf(buffer, sizeof(buffer), fmt, reason_str[reason]);
+   n = write(STDERR_FILENO, buffer, n);
 }
 
-static inline unsigned long long timer_tsc2ns(unsigned long long tsc)
-{
-   return clockobj_tsc_to_ns(tsc);
-}
+#define THREAD_PRIO_WEAK   0
+#define THREAD_PRIO_LOW1
+#define THREAD_PRIO_MEDIUM 2
+#define THREAD_PRIO_HIGH   3
+#define THREAD_PRIO_VERY_HIGH  4
 
-static void add_timespec(struct timespec *ts, unsigned long long value)
-{
-   ts->tv_sec += value / 10;
-   ts->tv_nsec += value % 10;
-   if (ts->tv_nsec > 10) {
-   ts->tv_sec++;
-   ts->tv_nsec -= 10;
-   }
-}
+#define MAX_100_MS  1ULL
+
+struct locker_context {
+   pthread_mutex_t *mutex;
+   struct smokey_barrier *barrier;
+   int lock_acquired;
+};
 
-static void ms_sleep(int time)
+static void sleep_ms(unsigned int ms)  /* < 1000 */
 {
struct timespec ts;
-
+   
ts.tv_sec = 0;
-   ts.tv_nsec = time*NS_PER_MS;
-
-   nanosleep(&ts, NULL);
+   ts.tv_nsec = ms * 100;
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
 }
 
-static void check_current_prio(int expected_prio)
+static int get_effective_prio(void) 
 {
struct cobalt_threadstat stat;
int ret;
 
ret = cobalt_thread_stat(0, &stat);
-   if (ret) {
-   fprintf(stderr,
-   "FAILURE: cobalt_threadstat (%s)\n", strerror(-ret));
-   exit(EXIT_FAILURE);
-   }
+   if (ret)
+   return ret;
 
-   if (stat.cprio != expected_prio) {
-   fprintf(stderr,
-   "FAILURE: current prio (%d) != expected prio (%d)\n",
-   stat.cprio, expected_prio);
-   exit(EXIT_FAILURE);
-   }
+   return stat.cprio;
 }
 
-static void __check_current_mode(const char *file, int line,
-

[Xenomai-git] Philippe Gerum : lib/cobalt/mutex: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: e317c6ec6988ae3e48257c86d5cc4d22cdb486d7
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e317c6ec6988ae3e48257c86d5cc4d22cdb486d7

Author: Philippe Gerum 
Date:   Tue Feb 16 10:13:03 2016 +0100

lib/cobalt/mutex: add support for priority ceiling protocol

---

 configure.ac   |2 +
 include/boilerplate/libc.h |   19 +++
 include/cobalt/pthread.h   |7 ++
 lib/cobalt/cobalt.wrappers |2 +
 lib/cobalt/init.c  |1 +
 lib/cobalt/internal.h  |8 ++
 lib/cobalt/mutex.c |  301 +++-
 lib/cobalt/sched.c |   33 -
 lib/cobalt/thread.c|7 +-
 9 files changed, 311 insertions(+), 69 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8bbeeef..578327e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -504,6 +504,8 @@ save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
 AC_CHECK_FUNCS([pthread_mutexattr_setprotocol  \
pthread_mutexattr_getprotocol   \
+   pthread_mutexattr_getprioceiling \
+   pthread_mutexattr_setprioceiling \
pthread_mutexattr_setrobust_np  \
pthread_condattr_getclock   \
pthread_condattr_setclock   \
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
index 0e51b86..3a5af8c 100644
--- a/include/boilerplate/libc.h
+++ b/include/boilerplate/libc.h
@@ -108,6 +108,25 @@ int pthread_mutexattr_getprotocol(const 
pthread_mutexattr_t *
 }
 #endif /* !HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL */
 
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING
+static inline
+int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
+int prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING
+static inline
+int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *
+ __restrict attr,
+int *__restrict prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING */
+
 #ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
 #include 
 static inline
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 386c337..f1b1c8a 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -67,6 +67,13 @@ COBALT_DECL(int, pthread_mutex_trylock(pthread_mutex_t 
*mutex));
 
 COBALT_DECL(int, pthread_mutex_unlock(pthread_mutex_t *mutex));
 
+COBALT_DECL(int, pthread_mutex_setprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int prioceiling,
+ int *__restrict old_ceiling));
+  
+COBALT_DECL(int, pthread_mutex_getprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int *__restrict old_ceiling));
+
 COBALT_DECL(int, pthread_cond_init (pthread_cond_t *cond,
const pthread_condattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 9480f34..75f29d6 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -32,6 +32,8 @@
 --wrap pthread_mutex_trylock
 --wrap pthread_mutex_timedlock
 --wrap pthread_mutex_unlock
+--wrap pthread_mutex_setprioceiling
+--wrap pthread_mutex_getprioceiling
 --wrap pthread_cond_init
 --wrap pthread_cond_destroy
 --wrap pthread_cond_wait
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index f260744..69d4763 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -177,6 +177,7 @@ static void __cobalt_init(void)
sizeof(struct cobalt_sem_shadow));
 
cobalt_mutex_init();
+   cobalt_sched_init();
cobalt_thread_init();
cobalt_print_init();
 }
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 69ec7d1..cdb2eee 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -47,6 +47,8 @@ void cobalt_thread_init(void);
 
 int cobalt_thread_probe(pid_t pid);
 
+void cobalt_sched_init(void);
+
 void cobalt_print_init(void);
 
 void cobalt_print_init_atfork(void);
@@ -68,4 +70,10 @@ void cobalt_check_features(struct cobalt_featinfo *finfo);
 
 extern struct sigaction __cobalt_orig_sigdebug;
 
+extern int __cobalt_std_fifo_minpri,
+  __cobalt_std_fifo_maxpri;
+
+extern int __cobalt_std_rr_minpri,
+  __cobalt_std_rr_maxpri;
+
 #endif /* _LIB_COBALT_INTERNAL_H */
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 9d8a914..1456099 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -99,6 +99,9 @@ void cobalt_mutex_init(void)
  *   mutex, increase CONFIG_XENO_OPT_SHARED_HEAPSZ for a process-shared
  *   mutex, or CONFIG_XENO_OPT_PRIVATE_HEAPSZ for a process-private mutex.
  * - EAGAIN, no registry slot available, check/raise 
CONFIG_XENO_OPT_REGISTRY_NRSLOTS.
+ * - ENOSYS, @a attr mentions priority p

[Xenomai-git] Philippe Gerum : cobalt/kernel: use standard accessor to global pid

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 5b921a067208271525fa2226bd8e4bf23809c8ca
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5b921a067208271525fa2226bd8e4bf23809c8ca

Author: Philippe Gerum 
Date:   Wed Mar  2 16:03:24 2016 +0100

cobalt/kernel: use standard accessor to global pid

---

 include/cobalt/kernel/thread.h|2 +-
 kernel/cobalt/posix/mqueue.c  |3 ++-
 kernel/cobalt/posix/process.c |   18 +++---
 kernel/cobalt/posix/signal.c  |5 +++--
 kernel/cobalt/posix/syscall.c |5 +++--
 kernel/cobalt/posix/thread.c  |2 +-
 kernel/cobalt/rtdm/core.c |3 ++-
 kernel/cobalt/rtdm/fd.c   |3 ++-
 kernel/cobalt/sched.c |5 +++--
 kernel/cobalt/timer.c |2 +-
 kernel/cobalt/trace/cobalt-core.h |7 ---
 kernel/cobalt/trace/cobalt-rtdm.h |7 ---
 12 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index e08a0a2..b45de8e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -265,7 +265,7 @@ static inline pid_t xnthread_host_pid(struct xnthread 
*thread)
if (xnthread_test_state(thread, XNROOT))
return 0;
 
-   return xnthread_host_task(thread)->pid;
+   return task_pid_nr(xnthread_host_task(thread));
 }
 
 #define xnthread_for_each_claimed(__pos, __thread) \
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 0f5e19e..77dabce 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "internal.h"
@@ -713,7 +714,7 @@ mq_notify(struct cobalt_mqd *mqd, unsigned index, const 
struct sigevent *evp)
 * receiver's namespaces. We pass the receiver's creds
 * into the init namespace instead.
 */
-   mq->si.si_pid = current->pid;
+   mq->si.si_pid = task_pid_nr(current);
mq->si.si_uid = get_current_uuid();
}
 
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 5b80521..28fde9e 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1138,17 +1139,20 @@ no_ptrace:
if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
   "hardened thread %s[%d] running in Linux domain?! "
   "(status=0x%x, sig=%d, prev=%s[%d])",
-  next->name, next_task->pid, xnthread_get_state(next),
-  signal_pending(next_task), prev_task->comm, 
prev_task->pid))
+  next->name, task_pid_nr(next_task),
+  xnthread_get_state(next),
+  signal_pending(next_task),
+  prev_task->comm, task_pid_nr(prev_task)))
XENO_WARN(COBALT,
  !(next_task->ptrace & PT_PTRACED) &&
   !xnthread_test_state(next, XNDORMANT)
  && xnthread_test_state(next, XNPEND),
  "blocked thread %s[%d] rescheduled?! "
  "(status=0x%x, sig=%d, prev=%s[%d])",
- next->name, next_task->pid, xnthread_get_state(next),
+ next->name, task_pid_nr(next_task),
+ xnthread_get_state(next),
  signal_pending(next_task), prev_task->comm,
- prev_task->pid);
+ task_pid_nr(prev_task));
 out:
return KEVENT_PROPAGATE;
 }
@@ -1315,13 +1319,13 @@ static int attach_process(struct cobalt_process 
*process)
if (ret)
return ret;
 
-   cobalt_umm_set_name(&p->umm, "private heap[%d]", current->pid);
+   cobalt_umm_set_name(&p->umm, "private heap[%d]", task_pid_nr(current));
 
p->mayday_tramp = map_mayday_page();
if (p->mayday_tramp == 0) {
printk(XENO_WARNING
   "%s[%d] cannot map MAYDAY page\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
ret = -ENOMEM;
goto fail_mayday;
}
@@ -1330,7 +1334,7 @@ static int attach_process(struct cobalt_process *process)
if (IS_ERR(exe_path)) {
printk(XENO_WARNING
   "%s[%d] can't find exe path\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
exe_path = NULL; /* Not lethal, but weird. */
}
p->exe_path = exe_path;
diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index dc16bc8..a3ec756 100644
--- a/kernel/cobalt/posix/sign

[Xenomai-git] Philippe Gerum : cobalt/kernel: use standard accessor to global pid

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 5b921a067208271525fa2226bd8e4bf23809c8ca
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5b921a067208271525fa2226bd8e4bf23809c8ca

Author: Philippe Gerum 
Date:   Wed Mar  2 16:03:24 2016 +0100

cobalt/kernel: use standard accessor to global pid

---

 include/cobalt/kernel/thread.h|2 +-
 kernel/cobalt/posix/mqueue.c  |3 ++-
 kernel/cobalt/posix/process.c |   18 +++---
 kernel/cobalt/posix/signal.c  |5 +++--
 kernel/cobalt/posix/syscall.c |5 +++--
 kernel/cobalt/posix/thread.c  |2 +-
 kernel/cobalt/rtdm/core.c |3 ++-
 kernel/cobalt/rtdm/fd.c   |3 ++-
 kernel/cobalt/sched.c |5 +++--
 kernel/cobalt/timer.c |2 +-
 kernel/cobalt/trace/cobalt-core.h |7 ---
 kernel/cobalt/trace/cobalt-rtdm.h |7 ---
 12 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index e08a0a2..b45de8e 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -265,7 +265,7 @@ static inline pid_t xnthread_host_pid(struct xnthread 
*thread)
if (xnthread_test_state(thread, XNROOT))
return 0;
 
-   return xnthread_host_task(thread)->pid;
+   return task_pid_nr(xnthread_host_task(thread));
 }
 
 #define xnthread_for_each_claimed(__pos, __thread) \
diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 0f5e19e..77dabce 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "internal.h"
@@ -713,7 +714,7 @@ mq_notify(struct cobalt_mqd *mqd, unsigned index, const 
struct sigevent *evp)
 * receiver's namespaces. We pass the receiver's creds
 * into the init namespace instead.
 */
-   mq->si.si_pid = current->pid;
+   mq->si.si_pid = task_pid_nr(current);
mq->si.si_uid = get_current_uuid();
}
 
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 5b80521..28fde9e 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1138,17 +1139,20 @@ no_ptrace:
if (!XENO_WARN(COBALT, !xnthread_test_state(next, XNRELAX),
   "hardened thread %s[%d] running in Linux domain?! "
   "(status=0x%x, sig=%d, prev=%s[%d])",
-  next->name, next_task->pid, xnthread_get_state(next),
-  signal_pending(next_task), prev_task->comm, 
prev_task->pid))
+  next->name, task_pid_nr(next_task),
+  xnthread_get_state(next),
+  signal_pending(next_task),
+  prev_task->comm, task_pid_nr(prev_task)))
XENO_WARN(COBALT,
  !(next_task->ptrace & PT_PTRACED) &&
   !xnthread_test_state(next, XNDORMANT)
  && xnthread_test_state(next, XNPEND),
  "blocked thread %s[%d] rescheduled?! "
  "(status=0x%x, sig=%d, prev=%s[%d])",
- next->name, next_task->pid, xnthread_get_state(next),
+ next->name, task_pid_nr(next_task),
+ xnthread_get_state(next),
  signal_pending(next_task), prev_task->comm,
- prev_task->pid);
+ task_pid_nr(prev_task));
 out:
return KEVENT_PROPAGATE;
 }
@@ -1315,13 +1319,13 @@ static int attach_process(struct cobalt_process 
*process)
if (ret)
return ret;
 
-   cobalt_umm_set_name(&p->umm, "private heap[%d]", current->pid);
+   cobalt_umm_set_name(&p->umm, "private heap[%d]", task_pid_nr(current));
 
p->mayday_tramp = map_mayday_page();
if (p->mayday_tramp == 0) {
printk(XENO_WARNING
   "%s[%d] cannot map MAYDAY page\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
ret = -ENOMEM;
goto fail_mayday;
}
@@ -1330,7 +1334,7 @@ static int attach_process(struct cobalt_process *process)
if (IS_ERR(exe_path)) {
printk(XENO_WARNING
   "%s[%d] can't find exe path\n",
-  current->comm, current->pid);
+  current->comm, task_pid_nr(current));
exe_path = NULL; /* Not lethal, but weird. */
}
p->exe_path = exe_path;
diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index dc16bc8..a3ec756 100644
--- a/kernel/cobalt/posix/sign

[Xenomai-git] Philippe Gerum : cobalt/posix/corectl: clarify argument types for mixed ABI support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 580d1ed8be53b10041c6bed15a47395543970b2a
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=580d1ed8be53b10041c6bed15a47395543970b2a

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:15 2016 +0100

cobalt/posix/corectl: clarify argument types for mixed ABI support

---

 kernel/cobalt/posix/corectl.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/cobalt/posix/corectl.c b/kernel/cobalt/posix/corectl.c
index f01a562..6ec9934 100644
--- a/kernel/cobalt/posix/corectl.c
+++ b/kernel/cobalt/posix/corectl.c
@@ -110,9 +110,10 @@ static int do_conf_option(int option, void __user *u_buf, 
size_t u_bufsz)
 
 static int stop_services(const void __user *u_buf, size_t u_bufsz)
 {
-   const int final_grace_period = 3; /* seconds */
+   const u32 final_grace_period = 3; /* seconds */
enum cobalt_run_states state;
-   int ret, timeout;
+   __u32 grace_period;
+   int ret;
 
/*
 * XXX: we don't have any syscall for unbinding a thread from
@@ -123,10 +124,11 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
if (xnthread_current())
return -EPERM;
 
-   if (u_bufsz != sizeof(int))
+   if (u_bufsz != sizeof(__u32))
return -EINVAL;
 
-   ret = cobalt_copy_from_user(&timeout, u_buf, sizeof(timeout));
+   ret = cobalt_copy_from_user(&grace_period,
+   u_buf, sizeof(grace_period));
if (ret)
return ret;
 
@@ -138,7 +140,7 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
break;
case COBALT_STATE_RUNNING:
/* Kill user threads. */
-   ret = xnthread_killall(timeout, XNUSER);
+   ret = xnthread_killall(grace_period, XNUSER);
if (ret) {
set_realtime_core_state(state);
return ret;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : utils/corectl: fix handling of argument to --stop ( grace period)

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: a7cfe3bac1d2de12537f5461d7be37ec00f2d4c2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a7cfe3bac1d2de12537f5461d7be37ec00f2d4c2

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:53 2016 +0100

utils/corectl: fix handling of argument to --stop (grace period)

---

 utils/corectl/corectl.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/utils/corectl/corectl.c b/utils/corectl/corectl.c
index 1e82e99..41b8773 100644
--- a/utils/corectl/corectl.c
+++ b/utils/corectl/corectl.c
@@ -62,10 +62,10 @@ void application_usage(void)
fprintf(stderr, "--status   query Xenomai/cobalt 
status\n");
 }
 
-static int core_stop(int grace_period)
+static int core_stop(__u32 grace_period)
 {
return cobalt_corectl(_CC_COBALT_STOP_CORE,
- &grace_period, sizeof(&grace_period));
+ &grace_period, sizeof(grace_period));
 }
 
 static int core_start(void)
@@ -106,7 +106,8 @@ static int core_status(void)
 
 int main(int argc, char *const argv[])
 {
-   int lindex, c, grace_period = 0, ret;
+   __u32 grace_period = 0;
+   int lindex, c, ret;

for (;;) {
c = getopt_long_only(argc, argv, "", options, &lindex);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/thread: wait for RCU grace period after killall

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 655a7fc6ce1e2b50de22947dbb4f54c765a26047
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=655a7fc6ce1e2b50de22947dbb4f54c765a26047

Author: Philippe Gerum 
Date:   Wed Mar  2 15:09:11 2016 +0100

cobalt/thread: wait for RCU grace period after killall

---

 kernel/cobalt/thread.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 3e29b3e..a13ecaf 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1598,7 +1598,7 @@ static void grace_elapsed(struct rcu_head *head)
complete(&wgs->done);
 }
 
-static void wait_grace_period(struct pid *pid)
+static void wait_for_rcu_grace_period(struct pid *pid)
 {
struct wait_grace_struct wait = {
.done = COMPLETION_INITIALIZER_ONSTACK(wait.done),
@@ -1610,6 +1610,8 @@ static void wait_grace_period(struct pid *pid)
for (;;) {
call_rcu(&wait.rcu, grace_elapsed);
wait_for_completion(&wait.done);
+   if (pid == NULL)
+   break;
rcu_read_lock();
p = pid_task(pid, PIDTYPE_PID);
rcu_read_unlock();
@@ -1728,7 +1730,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
 * (__xnthread_cleanup), then waits for a full RCU grace
 * period to have elapsed. Since the completion signal is sent
 * on behalf of do_exit(), we may assume that the joinee has
-* scheduled away before the grace period ends.
+* scheduled away before the RCU grace period ends.
 */
if (uninterruptible)
wait_for_completion(&thread->exited);
@@ -1741,7 +1743,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
}
 
/* Make sure the joinee has scheduled away ultimately. */
-   wait_grace_period(pid);
+   wait_for_rcu_grace_period(pid);
 
put_pid(pid);
 done:
@@ -2636,10 +2638,10 @@ int xnthread_killall(int grace, int mask)
xnlock_put_irqrestore(&nklock, s);
 
/*
-* Cancel then join all existing user threads during the grace
+* Cancel then join all existing threads during the grace
 * period. It is the caller's responsibility to prevent more
-* user threads to bind to the system if required, we won't
-* make any provision for this here.
+* threads to bind to the system if required, we won't make
+* any provision for this here.
 */
count = nrthreads - nrkilled;
if (XENO_DEBUG(COBALT))
@@ -2656,6 +2658,9 @@ int xnthread_killall(int grace, int mask)
ret = wait_event_interruptible(join_all,
   cobalt_nrthreads == count);
 
+   /* Wait for a full RCU grace period to expire. */
+   wait_for_rcu_grace_period(NULL);
+
if (XENO_DEBUG(COBALT))
printk(XENO_INFO "joined %d threads\n",
   count + nrkilled - cobalt_nrthreads);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/thread: wait for RCU grace period after killall

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 655a7fc6ce1e2b50de22947dbb4f54c765a26047
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=655a7fc6ce1e2b50de22947dbb4f54c765a26047

Author: Philippe Gerum 
Date:   Wed Mar  2 15:09:11 2016 +0100

cobalt/thread: wait for RCU grace period after killall

---

 kernel/cobalt/thread.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 3e29b3e..a13ecaf 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1598,7 +1598,7 @@ static void grace_elapsed(struct rcu_head *head)
complete(&wgs->done);
 }
 
-static void wait_grace_period(struct pid *pid)
+static void wait_for_rcu_grace_period(struct pid *pid)
 {
struct wait_grace_struct wait = {
.done = COMPLETION_INITIALIZER_ONSTACK(wait.done),
@@ -1610,6 +1610,8 @@ static void wait_grace_period(struct pid *pid)
for (;;) {
call_rcu(&wait.rcu, grace_elapsed);
wait_for_completion(&wait.done);
+   if (pid == NULL)
+   break;
rcu_read_lock();
p = pid_task(pid, PIDTYPE_PID);
rcu_read_unlock();
@@ -1728,7 +1730,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
 * (__xnthread_cleanup), then waits for a full RCU grace
 * period to have elapsed. Since the completion signal is sent
 * on behalf of do_exit(), we may assume that the joinee has
-* scheduled away before the grace period ends.
+* scheduled away before the RCU grace period ends.
 */
if (uninterruptible)
wait_for_completion(&thread->exited);
@@ -1741,7 +1743,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
}
 
/* Make sure the joinee has scheduled away ultimately. */
-   wait_grace_period(pid);
+   wait_for_rcu_grace_period(pid);
 
put_pid(pid);
 done:
@@ -2636,10 +2638,10 @@ int xnthread_killall(int grace, int mask)
xnlock_put_irqrestore(&nklock, s);
 
/*
-* Cancel then join all existing user threads during the grace
+* Cancel then join all existing threads during the grace
 * period. It is the caller's responsibility to prevent more
-* user threads to bind to the system if required, we won't
-* make any provision for this here.
+* threads to bind to the system if required, we won't make
+* any provision for this here.
 */
count = nrthreads - nrkilled;
if (XENO_DEBUG(COBALT))
@@ -2656,6 +2658,9 @@ int xnthread_killall(int grace, int mask)
ret = wait_event_interruptible(join_all,
   cobalt_nrthreads == count);
 
+   /* Wait for a full RCU grace period to expire. */
+   wait_for_rcu_grace_period(NULL);
+
if (XENO_DEBUG(COBALT))
printk(XENO_INFO "joined %d threads\n",
   count + nrkilled - cobalt_nrthreads);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/synch: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: a654dd2aa0ba8b07df636ccf653b3319ae16feef
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a654dd2aa0ba8b07df636ccf653b3319ae16feef

Author: Philippe Gerum 
Date:   Tue Feb 16 10:12:55 2016 +0100

cobalt/synch: add support for priority ceiling protocol

---

 include/cobalt/kernel/heap.h   |   11 +
 include/cobalt/kernel/sched-idle.h |   12 +-
 include/cobalt/kernel/sched-rt.h   |   55 ++-
 include/cobalt/kernel/sched.h  |   94 +++-
 include/cobalt/kernel/synch.h  |   51 ++-
 include/cobalt/kernel/thread.h |   54 ++-
 include/cobalt/uapi/asm-generic/features.h |   27 +-
 include/cobalt/uapi/kernel/synch.h |8 +-
 include/cobalt/uapi/kernel/thread.h|3 +-
 include/cobalt/uapi/kernel/types.h |5 +-
 include/cobalt/uapi/mutex.h|1 +
 include/cobalt/uapi/thread.h   |1 +
 kernel/cobalt/posix/cond.c |2 +-
 kernel/cobalt/posix/memory.h   |6 +
 kernel/cobalt/posix/monitor.c  |   29 +-
 kernel/cobalt/posix/mqueue.c   |4 +-
 kernel/cobalt/posix/mutex.c|  103 +++--
 kernel/cobalt/posix/process.c  |   21 +-
 kernel/cobalt/posix/process.h  |3 +-
 kernel/cobalt/posix/syscall.c  |6 +-
 kernel/cobalt/posix/timerfd.c  |2 +-
 kernel/cobalt/rtdm/drvlib.c|2 +-
 kernel/cobalt/sched-idle.c |   12 +-
 kernel/cobalt/sched-quota.c|   24 +-
 kernel/cobalt/sched-rt.c   |   14 +-
 kernel/cobalt/sched-sporadic.c |   35 +-
 kernel/cobalt/sched-tp.c   |   42 +-
 kernel/cobalt/sched-weak.c |   16 +-
 kernel/cobalt/sched.c  |  126 +-
 kernel/cobalt/synch.c  |  636 +++-
 kernel/cobalt/thread.c |  115 ++---
 31 files changed, 1038 insertions(+), 482 deletions(-)

diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index a1cea69..d89f25d 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -147,6 +147,17 @@ void xnheap_free(struct xnheap *heap, void *block);
 
 int xnheap_check_block(struct xnheap *heap, void *block);
 
+static inline void *xnheap_zalloc(struct xnheap *heap, u32 size)
+{
+   void *p;
+
+   p = xnheap_alloc(heap, size);
+   if (p)
+   memset(p, 0, size);
+
+   return p;
+}
+
 static inline char *xnstrdup(const char *s)
 {
char *p;
diff --git a/include/cobalt/kernel/sched-idle.h 
b/include/cobalt/kernel/sched-idle.h
index 732ff84..75efdec 100644
--- a/include/cobalt/kernel/sched-idle.h
+++ b/include/cobalt/kernel/sched-idle.h
@@ -33,11 +33,11 @@
 
 extern struct xnsched_class xnsched_class_idle;
 
-static inline void __xnsched_idle_setparam(struct xnthread *thread,
+static inline bool __xnsched_idle_setparam(struct xnthread *thread,
   const union xnsched_policy_param *p)
 {
xnthread_clear_state(thread, XNWEAK);
-   thread->cprio = p->idle.prio;
+   return xnsched_set_effective_priority(thread, p->idle.prio);
 }
 
 static inline void __xnsched_idle_getparam(struct xnthread *thread,
@@ -50,11 +50,17 @@ static inline void __xnsched_idle_trackprio(struct xnthread 
*thread,
const union xnsched_policy_param *p)
 {
if (p)
-   __xnsched_idle_setparam(thread, p);
+   /* Inheriting a priority-less class makes no sense. */
+   XENO_WARN_ON_ONCE(COBALT, 1);
else
thread->cprio = XNSCHED_IDLE_PRIO;
 }
 
+static inline void __xnsched_idle_protectprio(struct xnthread *thread, int 
prio)
+{
+   XENO_WARN_ON_ONCE(COBALT, 1);
+}
+
 static inline int xnsched_idle_init_thread(struct xnthread *thread)
 {
return 0;
diff --git a/include/cobalt/kernel/sched-rt.h b/include/cobalt/kernel/sched-rt.h
index ffb7223..9049449 100644
--- a/include/cobalt/kernel/sched-rt.h
+++ b/include/cobalt/kernel/sched-rt.h
@@ -67,20 +67,33 @@ static inline void __xnsched_rt_dequeue(struct xnthread 
*thread)
xnsched_delq(&thread->sched->rt.runnable, thread);
 }
 
-static inline void __xnsched_rt_setparam(struct xnthread *thread,
-const union xnsched_policy_param *p)
+static inline void __xnsched_rt_track_weakness(struct xnthread *thread)
 {
-   thread->cprio = p->rt.prio;
-   if (!xnthread_test_state(thread, XNBOOST)) {
-#ifdef CONFIG_XENO_OPT_SCHED_WEAK
+   /*
+* We have to track threads exiting weak scheduling, i.e. any
+* thread leaving the WEAK class code is compiled in, or
+* assigned a zero priority if weak threads are hosted by the
+* RT class.
+*
+* CAUTION: since we need to check

[Xenomai-git] Philippe Gerum : cobalt/thread: wait for RCU grace period after killall

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 248297b3e7ae5516140b836eda749099cbecd1f8
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=248297b3e7ae5516140b836eda749099cbecd1f8

Author: Philippe Gerum 
Date:   Wed Mar  2 15:09:11 2016 +0100

cobalt/thread: wait for RCU grace period after killall

---

 kernel/cobalt/thread.c |   17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index b758d50..7983165 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1594,7 +1594,7 @@ static void grace_elapsed(struct rcu_head *head)
complete(&wgs->done);
 }
 
-static void wait_grace_period(struct pid *pid)
+static void wait_for_rcu_grace_period(struct pid *pid)
 {
struct wait_grace_struct wait = {
.done = COMPLETION_INITIALIZER_ONSTACK(wait.done),
@@ -1606,6 +1606,8 @@ static void wait_grace_period(struct pid *pid)
for (;;) {
call_rcu(&wait.rcu, grace_elapsed);
wait_for_completion(&wait.done);
+   if (pid == NULL)
+   break;
rcu_read_lock();
p = pid_task(pid, PIDTYPE_PID);
rcu_read_unlock();
@@ -1724,7 +1726,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
 * (__xnthread_cleanup), then waits for a full RCU grace
 * period to have elapsed. Since the completion signal is sent
 * on behalf of do_exit(), we may assume that the joinee has
-* scheduled away before the grace period ends.
+* scheduled away before the RCU grace period ends.
 */
if (uninterruptible)
wait_for_completion(&thread->exited);
@@ -1737,7 +1739,7 @@ int xnthread_join(struct xnthread *thread, bool 
uninterruptible)
}
 
/* Make sure the joinee has scheduled away ultimately. */
-   wait_grace_period(pid);
+   wait_for_rcu_grace_period(pid);
 
put_pid(pid);
 done:
@@ -2632,10 +2634,10 @@ int xnthread_killall(int grace, int mask)
xnlock_put_irqrestore(&nklock, s);
 
/*
-* Cancel then join all existing user threads during the grace
+* Cancel then join all existing threads during the grace
 * period. It is the caller's responsibility to prevent more
-* user threads to bind to the system if required, we won't
-* make any provision for this here.
+* threads to bind to the system if required, we won't make
+* any provision for this here.
 */
count = nrthreads - nrkilled;
if (XENO_DEBUG(COBALT))
@@ -2652,6 +2654,9 @@ int xnthread_killall(int grace, int mask)
ret = wait_event_interruptible(join_all,
   cobalt_nrthreads == count);
 
+   /* Wait for a full RCU grace period to expire. */
+   wait_for_rcu_grace_period(NULL);
+
if (XENO_DEBUG(COBALT))
printk(XENO_INFO "joined %d threads\n",
   count + nrkilled - cobalt_nrthreads);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/posix/corectl: clarify argument types for mixed ABI support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 75c95c08da6384dfea241cc639357608c93b9917
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=75c95c08da6384dfea241cc639357608c93b9917

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:15 2016 +0100

cobalt/posix/corectl: clarify argument types for mixed ABI support

---

 kernel/cobalt/posix/corectl.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/cobalt/posix/corectl.c b/kernel/cobalt/posix/corectl.c
index f01a562..6ec9934 100644
--- a/kernel/cobalt/posix/corectl.c
+++ b/kernel/cobalt/posix/corectl.c
@@ -110,9 +110,10 @@ static int do_conf_option(int option, void __user *u_buf, 
size_t u_bufsz)
 
 static int stop_services(const void __user *u_buf, size_t u_bufsz)
 {
-   const int final_grace_period = 3; /* seconds */
+   const u32 final_grace_period = 3; /* seconds */
enum cobalt_run_states state;
-   int ret, timeout;
+   __u32 grace_period;
+   int ret;
 
/*
 * XXX: we don't have any syscall for unbinding a thread from
@@ -123,10 +124,11 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
if (xnthread_current())
return -EPERM;
 
-   if (u_bufsz != sizeof(int))
+   if (u_bufsz != sizeof(__u32))
return -EINVAL;
 
-   ret = cobalt_copy_from_user(&timeout, u_buf, sizeof(timeout));
+   ret = cobalt_copy_from_user(&grace_period,
+   u_buf, sizeof(grace_period));
if (ret)
return ret;
 
@@ -138,7 +140,7 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
break;
case COBALT_STATE_RUNNING:
/* Kill user threads. */
-   ret = xnthread_killall(timeout, XNUSER);
+   ret = xnthread_killall(grace_period, XNUSER);
if (ret) {
set_realtime_core_state(state);
return ret;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : utils/corectl: fix handling of argument to --stop ( grace period)

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: a7cfe3bac1d2de12537f5461d7be37ec00f2d4c2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=a7cfe3bac1d2de12537f5461d7be37ec00f2d4c2

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:53 2016 +0100

utils/corectl: fix handling of argument to --stop (grace period)

---

 utils/corectl/corectl.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/utils/corectl/corectl.c b/utils/corectl/corectl.c
index 1e82e99..41b8773 100644
--- a/utils/corectl/corectl.c
+++ b/utils/corectl/corectl.c
@@ -62,10 +62,10 @@ void application_usage(void)
fprintf(stderr, "--status   query Xenomai/cobalt 
status\n");
 }
 
-static int core_stop(int grace_period)
+static int core_stop(__u32 grace_period)
 {
return cobalt_corectl(_CC_COBALT_STOP_CORE,
- &grace_period, sizeof(&grace_period));
+ &grace_period, sizeof(grace_period));
 }
 
 static int core_start(void)
@@ -106,7 +106,8 @@ static int core_status(void)
 
 int main(int argc, char *const argv[])
 {
-   int lindex, c, grace_period = 0, ret;
+   __u32 grace_period = 0;
+   int lindex, c, ret;

for (;;) {
c = getopt_long_only(argc, argv, "", options, &lindex);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: mutex: simplify, introduce PP tests

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: e9aaa7bc9e1ffcfa30b09c08fbc71f11607778cc
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e9aaa7bc9e1ffcfa30b09c08fbc71f11607778cc

Author: Philippe Gerum 
Date:   Wed Feb 17 09:21:27 2016 +0100

testsuite/smokey: mutex: simplify, introduce PP tests

At this chance, the lock stealing test is also fixed.

---

 testsuite/smokey/posix-mutex/posix-mutex.c | 1357 ++--
 1 file changed, 670 insertions(+), 687 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ac71b31..ae82fc1 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -4,6 +4,7 @@
  * Copyright (C) Gilles Chanteperdrix  ,
  *   Marion Deveaud ,
  *   Jan Kiszka 
+ *   Philippe Gerum 
  *
  * Released under the terms of GPLv2.
  */
@@ -17,8 +18,6 @@
 #include 
 #include 
 #include 
-#include 
-#include "lib/cobalt/current.h"
 #include 
 
 smokey_test_plugin(posix_mutex,
@@ -26,886 +25,870 @@ smokey_test_plugin(posix_mutex,
   "Check POSIX mutex services"
 );
 
-#define MUTEX_CREATE   1
-#define MUTEX_LOCK 2
-#define MUTEX_TRYLOCK  3
-#define MUTEX_TIMED_LOCK   4
-#define MUTEX_UNLOCK   5
-#define MUTEX_DESTROY  6
-#define COND_CREATE7
-#define COND_SIGNAL8
-#define COND_WAIT  9
-#define COND_DESTROY   10
-#define THREAD_DETACH  11
-#define THREAD_CREATE  12
-#define THREAD_JOIN13
-#define THREAD_RENICE   14
-
-#define NS_PER_MS  100
-
 static const char *reason_str[] = {
-   [SIGDEBUG_UNDEFINED] = "undefined",
+   [SIGDEBUG_UNDEFINED] = "received SIGDEBUG for unknown reason",
[SIGDEBUG_MIGRATE_SIGNAL] = "received signal",
[SIGDEBUG_MIGRATE_SYSCALL] = "invoked syscall",
[SIGDEBUG_MIGRATE_FAULT] = "triggered fault",
[SIGDEBUG_MIGRATE_PRIOINV] = "affected by priority inversion",
-   [SIGDEBUG_NOMLOCK] = "missing mlockall",
-   [SIGDEBUG_WATCHDOG] = "runaway thread",
+   [SIGDEBUG_NOMLOCK] = "process memory not locked",
+   [SIGDEBUG_WATCHDOG] = "watchdog triggered (period too short?)",
+   [SIGDEBUG_LOCK_BREAK] = "scheduler lock break",
 };
 
 static void sigdebug(int sig, siginfo_t *si, void *context)
 {
+   const char fmt[] = "%s, this is unexpected.\n"
+   "(enabling CONFIG_XENO_OPT_DEBUG_TRACE_RELAX may help)\n";
unsigned int reason = sigdebug_reason(si);
+   int n __attribute__ ((unused));
+   static char buffer[256];
 
-   smokey_trace("\nSIGDEBUG received, reason %d: %s\n", reason,
-reason <= SIGDEBUG_WATCHDOG ? reason_str[reason] : 
"");
-}
+   if (reason > SIGDEBUG_WATCHDOG)
+   reason = SIGDEBUG_UNDEFINED;
 
-static inline unsigned long long timer_get_tsc(void)
-{
-   return clockobj_get_tsc();
+   n = snprintf(buffer, sizeof(buffer), fmt, reason_str[reason]);
+   n = write(STDERR_FILENO, buffer, n);
 }
 
-static inline unsigned long long timer_tsc2ns(unsigned long long tsc)
-{
-   return clockobj_tsc_to_ns(tsc);
-}
+#define THREAD_PRIO_WEAK   0
+#define THREAD_PRIO_LOW1
+#define THREAD_PRIO_MEDIUM 2
+#define THREAD_PRIO_HIGH   3
+#define THREAD_PRIO_VERY_HIGH  4
 
-static void add_timespec(struct timespec *ts, unsigned long long value)
-{
-   ts->tv_sec += value / 10;
-   ts->tv_nsec += value % 10;
-   if (ts->tv_nsec > 10) {
-   ts->tv_sec++;
-   ts->tv_nsec -= 10;
-   }
-}
+#define MAX_100_MS  1ULL
+
+struct locker_context {
+   pthread_mutex_t *mutex;
+   struct smokey_barrier *barrier;
+   int lock_acquired;
+};
 
-static void ms_sleep(int time)
+static void sleep_ms(unsigned int ms)  /* < 1000 */
 {
struct timespec ts;
-
+   
ts.tv_sec = 0;
-   ts.tv_nsec = time*NS_PER_MS;
-
-   nanosleep(&ts, NULL);
+   ts.tv_nsec = ms * 100;
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
 }
 
-static void check_current_prio(int expected_prio)
+static int get_effective_prio(void) 
 {
struct cobalt_threadstat stat;
int ret;
 
ret = cobalt_thread_stat(0, &stat);
-   if (ret) {
-   fprintf(stderr,
-   "FAILURE: cobalt_threadstat (%s)\n", strerror(-ret));
-   exit(EXIT_FAILURE);
-   }
+   if (ret)
+   return ret;
 
-   if (stat.cprio != expected_prio) {
-   fprintf(stderr,
-   "FAILURE: current prio (%d) != expected prio (%d)\n",
-   stat.cprio, expected_prio);
-   exit(EXIT_FAILURE);
-   }
+   return stat.cprio;
 }
 
-static void __check_current_mode(const char *file, int line,
-

[Xenomai-git] Philippe Gerum : utils/corectl: fix handling of argument to --stop ( grace period)

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: b09e20cc82f6c79cf982d13cfcb176221800a306
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=b09e20cc82f6c79cf982d13cfcb176221800a306

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:53 2016 +0100

utils/corectl: fix handling of argument to --stop (grace period)

---

 utils/corectl/corectl.c |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/utils/corectl/corectl.c b/utils/corectl/corectl.c
index 1e82e99..41b8773 100644
--- a/utils/corectl/corectl.c
+++ b/utils/corectl/corectl.c
@@ -62,10 +62,10 @@ void application_usage(void)
fprintf(stderr, "--status   query Xenomai/cobalt 
status\n");
 }
 
-static int core_stop(int grace_period)
+static int core_stop(__u32 grace_period)
 {
return cobalt_corectl(_CC_COBALT_STOP_CORE,
- &grace_period, sizeof(&grace_period));
+ &grace_period, sizeof(grace_period));
 }
 
 static int core_start(void)
@@ -106,7 +106,8 @@ static int core_status(void)
 
 int main(int argc, char *const argv[])
 {
-   int lindex, c, grace_period = 0, ret;
+   __u32 grace_period = 0;
+   int lindex, c, ret;

for (;;) {
c = getopt_long_only(argc, argv, "", options, &lindex);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : smokey/posix-mutex: Fix test case /wrt mutex object reuse

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: d22526cdc58bb784d246a077768cfeb6185194e1
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d22526cdc58bb784d246a077768cfeb6185194e1

Author: Jan Kiszka 
Date:   Thu Feb 25 11:29:00 2016 +0100

smokey/posix-mutex: Fix test case /wrt mutex object reuse

Mutex objects created on the stack must be properly destroyed after use.
Otherwise, succeeding tests that use the same stack layout will consider
them busy and refuse to recreate the mutexes.

Signed-off-by: Jan Kiszka 

---

 testsuite/smokey/posix-mutex/posix-mutex.c |   26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ae82fc1..151c2f3 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -623,7 +623,10 @@ static int protect_raise(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -651,7 +654,10 @@ static int protect_lower(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -699,7 +705,10 @@ static int protect_weak(void)
if (!__T(ret, pthread_setschedparam(pthread_self(),
old_policy, &old_param)))
return ret;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -745,7 +754,11 @@ static int protect_nesting_protect(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_high)) ||
+   !__T(ret, pthread_mutex_destroy(&mutex_very_high)))
+   return ret;
+
return 0;
 }
 
@@ -782,7 +795,10 @@ static int protect_nesting_pi(void)
/* PP boost just dropped: HIGH -> MEDIUM. */
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_pp)))
+   return ret;
+
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : lib/cobalt/mutex: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 8df8a403a09c8cf9ddc07c8e8fb589e43715bde6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8df8a403a09c8cf9ddc07c8e8fb589e43715bde6

Author: Philippe Gerum 
Date:   Tue Feb 16 10:13:03 2016 +0100

lib/cobalt/mutex: add support for priority ceiling protocol

---

 configure.ac   |2 +
 include/boilerplate/libc.h |   19 +++
 include/cobalt/pthread.h   |7 ++
 lib/cobalt/cobalt.wrappers |2 +
 lib/cobalt/init.c  |1 +
 lib/cobalt/internal.h  |8 ++
 lib/cobalt/mutex.c |  301 +++-
 lib/cobalt/sched.c |   33 -
 lib/cobalt/thread.c|7 +-
 9 files changed, 311 insertions(+), 69 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8bbeeef..578327e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -504,6 +504,8 @@ save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
 AC_CHECK_FUNCS([pthread_mutexattr_setprotocol  \
pthread_mutexattr_getprotocol   \
+   pthread_mutexattr_getprioceiling \
+   pthread_mutexattr_setprioceiling \
pthread_mutexattr_setrobust_np  \
pthread_condattr_getclock   \
pthread_condattr_setclock   \
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
index 0e51b86..3a5af8c 100644
--- a/include/boilerplate/libc.h
+++ b/include/boilerplate/libc.h
@@ -108,6 +108,25 @@ int pthread_mutexattr_getprotocol(const 
pthread_mutexattr_t *
 }
 #endif /* !HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL */
 
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING
+static inline
+int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
+int prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING
+static inline
+int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *
+ __restrict attr,
+int *__restrict prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING */
+
 #ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
 #include 
 static inline
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 386c337..f1b1c8a 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -67,6 +67,13 @@ COBALT_DECL(int, pthread_mutex_trylock(pthread_mutex_t 
*mutex));
 
 COBALT_DECL(int, pthread_mutex_unlock(pthread_mutex_t *mutex));
 
+COBALT_DECL(int, pthread_mutex_setprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int prioceiling,
+ int *__restrict old_ceiling));
+  
+COBALT_DECL(int, pthread_mutex_getprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int *__restrict old_ceiling));
+
 COBALT_DECL(int, pthread_cond_init (pthread_cond_t *cond,
const pthread_condattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 9480f34..75f29d6 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -32,6 +32,8 @@
 --wrap pthread_mutex_trylock
 --wrap pthread_mutex_timedlock
 --wrap pthread_mutex_unlock
+--wrap pthread_mutex_setprioceiling
+--wrap pthread_mutex_getprioceiling
 --wrap pthread_cond_init
 --wrap pthread_cond_destroy
 --wrap pthread_cond_wait
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index f260744..69d4763 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -177,6 +177,7 @@ static void __cobalt_init(void)
sizeof(struct cobalt_sem_shadow));
 
cobalt_mutex_init();
+   cobalt_sched_init();
cobalt_thread_init();
cobalt_print_init();
 }
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 69ec7d1..cdb2eee 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -47,6 +47,8 @@ void cobalt_thread_init(void);
 
 int cobalt_thread_probe(pid_t pid);
 
+void cobalt_sched_init(void);
+
 void cobalt_print_init(void);
 
 void cobalt_print_init_atfork(void);
@@ -68,4 +70,10 @@ void cobalt_check_features(struct cobalt_featinfo *finfo);
 
 extern struct sigaction __cobalt_orig_sigdebug;
 
+extern int __cobalt_std_fifo_minpri,
+  __cobalt_std_fifo_maxpri;
+
+extern int __cobalt_std_rr_minpri,
+  __cobalt_std_rr_maxpri;
+
 #endif /* _LIB_COBALT_INTERNAL_H */
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 9d8a914..1456099 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -99,6 +99,9 @@ void cobalt_mutex_init(void)
  *   mutex, increase CONFIG_XENO_OPT_SHARED_HEAPSZ for a process-shared
  *   mutex, or CONFIG_XENO_OPT_PRIVATE_HEAPSZ for a process-private mutex.
  * - EAGAIN, no registry slot available, check/raise 
CONFIG_XENO_OPT_REGISTRY_NRSLOTS.
+ * - ENOSYS, @a attr mentions priority p

[Xenomai-git] Philippe Gerum : cobalt/posix/corectl: clarify argument types for mixed ABI support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 580d1ed8be53b10041c6bed15a47395543970b2a
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=580d1ed8be53b10041c6bed15a47395543970b2a

Author: Philippe Gerum 
Date:   Wed Mar  2 15:22:15 2016 +0100

cobalt/posix/corectl: clarify argument types for mixed ABI support

---

 kernel/cobalt/posix/corectl.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/kernel/cobalt/posix/corectl.c b/kernel/cobalt/posix/corectl.c
index f01a562..6ec9934 100644
--- a/kernel/cobalt/posix/corectl.c
+++ b/kernel/cobalt/posix/corectl.c
@@ -110,9 +110,10 @@ static int do_conf_option(int option, void __user *u_buf, 
size_t u_bufsz)
 
 static int stop_services(const void __user *u_buf, size_t u_bufsz)
 {
-   const int final_grace_period = 3; /* seconds */
+   const u32 final_grace_period = 3; /* seconds */
enum cobalt_run_states state;
-   int ret, timeout;
+   __u32 grace_period;
+   int ret;
 
/*
 * XXX: we don't have any syscall for unbinding a thread from
@@ -123,10 +124,11 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
if (xnthread_current())
return -EPERM;
 
-   if (u_bufsz != sizeof(int))
+   if (u_bufsz != sizeof(__u32))
return -EINVAL;
 
-   ret = cobalt_copy_from_user(&timeout, u_buf, sizeof(timeout));
+   ret = cobalt_copy_from_user(&grace_period,
+   u_buf, sizeof(grace_period));
if (ret)
return ret;
 
@@ -138,7 +140,7 @@ static int stop_services(const void __user *u_buf, size_t 
u_bufsz)
break;
case COBALT_STATE_RUNNING:
/* Kill user threads. */
-   ret = xnthread_killall(timeout, XNUSER);
+   ret = xnthread_killall(grace_period, XNUSER);
if (ret) {
set_realtime_core_state(state);
return ret;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/blackfin: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: b6e2a1d29d88e31cbf417678ae522d360963787c
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=b6e2a1d29d88e31cbf417678ae522d360963787c

Author: Philippe Gerum 
Date:   Mon Feb 29 10:12:26 2016 +0100

cobalt/blackfin: upgrade I-pipe support

---

 .../patches/ipipe-core-4.1.18-blackfin-1.patch |12078 
 1 file changed, 12078 insertions(+)

Diff:   
http://git.xenomai.org/?p=xenomai-3.git;a=commitdiff;h=b6e2a1d29d88e31cbf417678ae522d360963787c

___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: cpu-affinity: silence unused_result warning

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 80916b70e7bed4125db27b6a27931579f7f91cd2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=80916b70e7bed4125db27b6a27931579f7f91cd2

Author: Philippe Gerum 
Date:   Sun Feb 28 15:41:38 2016 +0100

testsuite/smokey: cpu-affinity: silence unused_result warning

---

 testsuite/smokey/cpu-affinity/cpu-affinity.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/testsuite/smokey/cpu-affinity/cpu-affinity.c 
b/testsuite/smokey/cpu-affinity/cpu-affinity.c
index 2674f76..4a59ff6 100644
--- a/testsuite/smokey/cpu-affinity/cpu-affinity.c
+++ b/testsuite/smokey/cpu-affinity/cpu-affinity.c
@@ -88,8 +88,11 @@ static int load_test_module(void)
 
 static void unload_test_module(int fd)
 {
+   int status;
+   
close(fd);
-   system("rmmod xeno_rtdmtest");
+   status = system("rmmod xeno_rtdmtest");
+   (void)status;
 }
 
 static void *__run_cpu_affinity(void *arg)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/posix/signal: get buffer memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: cd90cd71d59e828952dc2e98a501b65ada52b818
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cd90cd71d59e828952dc2e98a501b65ada52b818

Author: Philippe Gerum 
Date:   Sun Feb 28 08:17:30 2016 +0100

cobalt/posix/signal: get buffer memory from vmalloc()

---

 kernel/cobalt/posix/signal.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/signal.c b/kernel/cobalt/posix/signal.c
index d6cda8e..dc16bc8 100644
--- a/kernel/cobalt/posix/signal.c
+++ b/kernel/cobalt/posix/signal.c
@@ -593,7 +593,7 @@ __init int cobalt_signal_init(void)
 {
struct cobalt_sigpending *sigp;
 
-   sigpending_mem = alloc_pages_exact(__SIGPOOL_SIZE, GFP_KERNEL);
+   sigpending_mem = xnheap_vmalloc(__SIGPOOL_SIZE);
if (sigpending_mem == NULL)
return -ENOMEM;
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/synch: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 750901d965748695d7d4d93bbabd3960ad6d2e87
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=750901d965748695d7d4d93bbabd3960ad6d2e87

Author: Philippe Gerum 
Date:   Tue Feb 16 10:12:55 2016 +0100

cobalt/synch: add support for priority ceiling protocol

---

 include/cobalt/kernel/heap.h   |   11 +
 include/cobalt/kernel/sched-idle.h |   12 +-
 include/cobalt/kernel/sched-rt.h   |   55 ++-
 include/cobalt/kernel/sched.h  |   94 +++-
 include/cobalt/kernel/synch.h  |   51 ++-
 include/cobalt/kernel/thread.h |   54 ++-
 include/cobalt/uapi/asm-generic/features.h |   27 +-
 include/cobalt/uapi/kernel/synch.h |8 +-
 include/cobalt/uapi/kernel/thread.h|3 +-
 include/cobalt/uapi/kernel/types.h |5 +-
 include/cobalt/uapi/mutex.h|1 +
 include/cobalt/uapi/thread.h   |1 +
 kernel/cobalt/posix/cond.c |2 +-
 kernel/cobalt/posix/memory.h   |6 +
 kernel/cobalt/posix/monitor.c  |   29 +-
 kernel/cobalt/posix/mqueue.c   |4 +-
 kernel/cobalt/posix/mutex.c|  103 +++--
 kernel/cobalt/posix/process.c  |   21 +-
 kernel/cobalt/posix/process.h  |3 +-
 kernel/cobalt/posix/syscall.c  |6 +-
 kernel/cobalt/posix/timerfd.c  |2 +-
 kernel/cobalt/rtdm/drvlib.c|2 +-
 kernel/cobalt/sched-idle.c |   12 +-
 kernel/cobalt/sched-quota.c|   24 +-
 kernel/cobalt/sched-rt.c   |   14 +-
 kernel/cobalt/sched-sporadic.c |   35 +-
 kernel/cobalt/sched-tp.c   |   42 +-
 kernel/cobalt/sched-weak.c |   16 +-
 kernel/cobalt/sched.c  |  126 +-
 kernel/cobalt/synch.c  |  636 +++-
 kernel/cobalt/thread.c |  115 ++---
 31 files changed, 1038 insertions(+), 482 deletions(-)

diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index a1cea69..d89f25d 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -147,6 +147,17 @@ void xnheap_free(struct xnheap *heap, void *block);
 
 int xnheap_check_block(struct xnheap *heap, void *block);
 
+static inline void *xnheap_zalloc(struct xnheap *heap, u32 size)
+{
+   void *p;
+
+   p = xnheap_alloc(heap, size);
+   if (p)
+   memset(p, 0, size);
+
+   return p;
+}
+
 static inline char *xnstrdup(const char *s)
 {
char *p;
diff --git a/include/cobalt/kernel/sched-idle.h 
b/include/cobalt/kernel/sched-idle.h
index 732ff84..75efdec 100644
--- a/include/cobalt/kernel/sched-idle.h
+++ b/include/cobalt/kernel/sched-idle.h
@@ -33,11 +33,11 @@
 
 extern struct xnsched_class xnsched_class_idle;
 
-static inline void __xnsched_idle_setparam(struct xnthread *thread,
+static inline bool __xnsched_idle_setparam(struct xnthread *thread,
   const union xnsched_policy_param *p)
 {
xnthread_clear_state(thread, XNWEAK);
-   thread->cprio = p->idle.prio;
+   return xnsched_set_effective_priority(thread, p->idle.prio);
 }
 
 static inline void __xnsched_idle_getparam(struct xnthread *thread,
@@ -50,11 +50,17 @@ static inline void __xnsched_idle_trackprio(struct xnthread 
*thread,
const union xnsched_policy_param *p)
 {
if (p)
-   __xnsched_idle_setparam(thread, p);
+   /* Inheriting a priority-less class makes no sense. */
+   XENO_WARN_ON_ONCE(COBALT, 1);
else
thread->cprio = XNSCHED_IDLE_PRIO;
 }
 
+static inline void __xnsched_idle_protectprio(struct xnthread *thread, int 
prio)
+{
+   XENO_WARN_ON_ONCE(COBALT, 1);
+}
+
 static inline int xnsched_idle_init_thread(struct xnthread *thread)
 {
return 0;
diff --git a/include/cobalt/kernel/sched-rt.h b/include/cobalt/kernel/sched-rt.h
index ffb7223..9049449 100644
--- a/include/cobalt/kernel/sched-rt.h
+++ b/include/cobalt/kernel/sched-rt.h
@@ -67,20 +67,33 @@ static inline void __xnsched_rt_dequeue(struct xnthread 
*thread)
xnsched_delq(&thread->sched->rt.runnable, thread);
 }
 
-static inline void __xnsched_rt_setparam(struct xnthread *thread,
-const union xnsched_policy_param *p)
+static inline void __xnsched_rt_track_weakness(struct xnthread *thread)
 {
-   thread->cprio = p->rt.prio;
-   if (!xnthread_test_state(thread, XNBOOST)) {
-#ifdef CONFIG_XENO_OPT_SCHED_WEAK
+   /*
+* We have to track threads exiting weak scheduling, i.e. any
+* thread leaving the WEAK class code is compiled in, or
+* assigned a zero priority if weak threads are hosted by the
+* RT class.
+*
+* CAUTION: since we need to check

[Xenomai-git] Philippe Gerum : lib/cobalt/mutex: add support for priority ceiling protocol

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 8d05b534f1eddf25203a07ef3aef29f9094da7ff
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=8d05b534f1eddf25203a07ef3aef29f9094da7ff

Author: Philippe Gerum 
Date:   Tue Feb 16 10:13:03 2016 +0100

lib/cobalt/mutex: add support for priority ceiling protocol

---

 configure.ac   |2 +
 include/boilerplate/libc.h |   19 +++
 include/cobalt/pthread.h   |7 ++
 lib/cobalt/cobalt.wrappers |2 +
 lib/cobalt/init.c  |1 +
 lib/cobalt/internal.h  |8 ++
 lib/cobalt/mutex.c |  301 +++-
 lib/cobalt/sched.c |   33 -
 lib/cobalt/thread.c|7 +-
 9 files changed, 311 insertions(+), 69 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8bbeeef..578327e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -504,6 +504,8 @@ save_LIBS="$LIBS"
 LIBS="$LIBS -lrt -lpthread"
 AC_CHECK_FUNCS([pthread_mutexattr_setprotocol  \
pthread_mutexattr_getprotocol   \
+   pthread_mutexattr_getprioceiling \
+   pthread_mutexattr_setprioceiling \
pthread_mutexattr_setrobust_np  \
pthread_condattr_getclock   \
pthread_condattr_setclock   \
diff --git a/include/boilerplate/libc.h b/include/boilerplate/libc.h
index 0e51b86..3a5af8c 100644
--- a/include/boilerplate/libc.h
+++ b/include/boilerplate/libc.h
@@ -108,6 +108,25 @@ int pthread_mutexattr_getprotocol(const 
pthread_mutexattr_t *
 }
 #endif /* !HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL */
 
+#ifndef HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING
+static inline
+int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
+int prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING */
+
+#ifndef HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING
+static inline
+int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *
+ __restrict attr,
+int *__restrict prioceiling)
+{
+   return ENOSYS;
+}
+#endif /* !HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING */
+
 #ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
 #include 
 static inline
diff --git a/include/cobalt/pthread.h b/include/cobalt/pthread.h
index 386c337..f1b1c8a 100644
--- a/include/cobalt/pthread.h
+++ b/include/cobalt/pthread.h
@@ -67,6 +67,13 @@ COBALT_DECL(int, pthread_mutex_trylock(pthread_mutex_t 
*mutex));
 
 COBALT_DECL(int, pthread_mutex_unlock(pthread_mutex_t *mutex));
 
+COBALT_DECL(int, pthread_mutex_setprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int prioceiling,
+ int *__restrict old_ceiling));
+  
+COBALT_DECL(int, pthread_mutex_getprioceiling(pthread_mutex_t *__restrict 
mutex,
+ int *__restrict old_ceiling));
+
 COBALT_DECL(int, pthread_cond_init (pthread_cond_t *cond,
const pthread_condattr_t *attr));
 
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 9480f34..75f29d6 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -32,6 +32,8 @@
 --wrap pthread_mutex_trylock
 --wrap pthread_mutex_timedlock
 --wrap pthread_mutex_unlock
+--wrap pthread_mutex_setprioceiling
+--wrap pthread_mutex_getprioceiling
 --wrap pthread_cond_init
 --wrap pthread_cond_destroy
 --wrap pthread_cond_wait
diff --git a/lib/cobalt/init.c b/lib/cobalt/init.c
index f260744..69d4763 100644
--- a/lib/cobalt/init.c
+++ b/lib/cobalt/init.c
@@ -177,6 +177,7 @@ static void __cobalt_init(void)
sizeof(struct cobalt_sem_shadow));
 
cobalt_mutex_init();
+   cobalt_sched_init();
cobalt_thread_init();
cobalt_print_init();
 }
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 69ec7d1..cdb2eee 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -47,6 +47,8 @@ void cobalt_thread_init(void);
 
 int cobalt_thread_probe(pid_t pid);
 
+void cobalt_sched_init(void);
+
 void cobalt_print_init(void);
 
 void cobalt_print_init_atfork(void);
@@ -68,4 +70,10 @@ void cobalt_check_features(struct cobalt_featinfo *finfo);
 
 extern struct sigaction __cobalt_orig_sigdebug;
 
+extern int __cobalt_std_fifo_minpri,
+  __cobalt_std_fifo_maxpri;
+
+extern int __cobalt_std_rr_minpri,
+  __cobalt_std_rr_maxpri;
+
 #endif /* _LIB_COBALT_INTERNAL_H */
diff --git a/lib/cobalt/mutex.c b/lib/cobalt/mutex.c
index 9d8a914..1456099 100644
--- a/lib/cobalt/mutex.c
+++ b/lib/cobalt/mutex.c
@@ -99,6 +99,9 @@ void cobalt_mutex_init(void)
  *   mutex, increase CONFIG_XENO_OPT_SHARED_HEAPSZ for a process-shared
  *   mutex, or CONFIG_XENO_OPT_PRIVATE_HEAPSZ for a process-private mutex.
  * - EAGAIN, no registry slot available, check/raise 
CONFIG_XENO_OPT_REGISTRY_NRSLOTS.
+ * - ENOSYS, @a attr mentions priority p

[Xenomai-git] Philippe Gerum : cobalt/thread: do not demote kthreads when cancelling

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 67db5a44c8aabc902227401815feaae2036de0f2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=67db5a44c8aabc902227401815feaae2036de0f2

Author: Philippe Gerum 
Date:   Tue Mar  1 08:36:18 2016 +0100

cobalt/thread: do not demote kthreads when cancelling

There is no point in switching a kthread to weak scheduling when
cancelling it, as it must reach a cancellation point asap as part of
its work loop anyway. Would it omit testing for cancellation, weak
scheduling would not help enforcing the exit request anyway.

---

 kernel/cobalt/thread.c |   19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index a8edece..5f404ed 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1566,16 +1566,21 @@ check_self_cancel:
return;
}
 
-   __xnthread_demote(thread);
-
/*
-* A userland thread undergoing the weak scheduling policy is
-* unlikely to issue Cobalt syscalls frequently, which may
-* defer cancellation significantly: send it a regular
-* termination signal too.
+* Force the non-current thread to exit:
+*
+* - unblock a user thread, switch it to weak scheduling,
+* then send it SIGTERM.
+*
+* - just unblock a kernel thread, it is expected to reach a
+* cancellation point soon after
+* (i.e. xnthread_test_cancel()).
 */
-   if (xnthread_test_state(thread, XNWEAK|XNUSER) == (XNWEAK|XNUSER))
+   if (xnthread_test_state(thread, XNUSER)) {
+   __xnthread_demote(thread);
xnthread_signal(thread, SIGTERM, 0);
+   } else
+   __xnthread_kick(thread);
 out:
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : lib/smokey: init: fix regression introduced by #9489274

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 3d1b80263cf6bf547accf86790c4670e006726dc
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=3d1b80263cf6bf547accf86790c4670e006726dc

Author: Philippe Gerum 
Date:   Mon Feb 29 11:53:22 2016 +0100

lib/smokey: init: fix regression introduced by #9489274

---

 lib/smokey/init.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/smokey/init.c b/lib/smokey/init.c
index 0db3ec9..b69f24c 100644
--- a/lib/smokey/init.c
+++ b/lib/smokey/init.c
@@ -508,7 +508,8 @@ static int smokey_parse_option(int optnum, const char 
*optarg)
 {
switch (optnum) {
case run_opt:
-   include_arg = strdup(optarg);
+   if (optarg)
+   include_arg = strdup(optarg);
break;
case exclude_opt:
exclude_arg = strdup(optarg);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/timer: allow binding core timers to passive CPUs

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 7d2d5b81f7aafb87458f2fc77b32eb68ebdba010
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7d2d5b81f7aafb87458f2fc77b32eb68ebdba010

Author: Philippe Gerum 
Date:   Wed Mar  2 12:08:32 2016 +0100

cobalt/timer: allow binding core timers to passive CPUs

Some timers initialized by the Cobalt core may have a valid reason to
live on CPUs excluded from the real-time set. A typical example would
be the host timer from the scheduler slot, which relays ticks to the
regular kernel. Other core timers are just better dealt with when
created and left passive on those CPUs.

Mark all core timers specifically, and exclude them from the LART
detection code in __xntimer_init(). This fixes a spurious Cobalt debug
assertion seen on SMP at boot, when the real-time CPU set is
restricted to a subset of the online CPU set.

---

 include/cobalt/kernel/timer.h |4 +++-
 kernel/cobalt/sched.c |6 +++---
 kernel/cobalt/thread.c|2 ++
 kernel/cobalt/timer.c |9 ++---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 00aa411..5868fcb 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -51,11 +51,13 @@ typedef enum xntmode {
 #define XNTIMER_RUNNING   0x0040
 #define XNTIMER_KGRAVITY  0x0080
 #define XNTIMER_UGRAVITY  0x0100
-#define XNTIMER_IGRAVITY  0/* most conservative */
+#define XNTIMER_IGRAVITY  0 /* most conservative */
 
 #define XNTIMER_GRAVITY_MASK   (XNTIMER_KGRAVITY|XNTIMER_UGRAVITY)
 #define XNTIMER_INIT_MASK  (XNTIMER_GRAVITY_MASK|XNTIMER_NOBLCK)
 
+#define __XNTIMER_CORE0x1000
+
 /* These flags are available to the real-time interfaces */
 #define XNTIMER_SPARE0  0x0100
 #define XNTIMER_SPARE1  0x0200
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index d8c594c..033b124 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -193,11 +193,11 @@ void xnsched_init(struct xnsched *sched, int cpu)
 * exit code.
 */
xntimer_init(&sched->htimer, &nkclock, NULL,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_priority(&sched->htimer, XNTIMER_LOPRIO);
xntimer_set_name(&sched->htimer, htimer_name);
xntimer_init(&sched->rrbtimer, &nkclock, roundrobin_handler,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->rrbtimer, rrbtimer_name);
xntimer_set_priority(&sched->rrbtimer, XNTIMER_LOPRIO);
 
@@ -212,7 +212,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
 
 #ifdef CONFIG_XENO_OPT_WATCHDOG
xntimer_init(&sched->wdtimer, &nkclock, watchdog_handler,
-sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY);
+sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->wdtimer, "[watchdog]");
xntimer_set_priority(&sched->wdtimer, XNTIMER_LOPRIO);
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index aaf868a..3e29b3e 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -202,6 +202,8 @@ int __xnthread_init(struct xnthread *thread,
init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
+   if (flags & XNROOT)
+   gravity |= __XNTIMER_CORE;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
 sched, gravity);
xntimer_set_name(&thread->rtimer, thread->name);
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 3e85a53..ee16198 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -363,10 +363,13 @@ void __xntimer_init(struct xntimer *timer,
 * clock device on the CPU served by the specified
 * scheduler slot. This reveals a CPU affinity
 * mismatch between the clock hardware and the client
-* code initializing the timer.
+* code initializing the timer. This check excludes
+* core timers which may have their own reason to bind
+* to a passive CPU (e.g. host timer).
 */
-   XENO_WARN_ON_SMP(COBALT, !cpumask_test_cpu(xnsched_cpu(sched),
-  &clock->affinity));
+   XENO_WARN_ON_SMP(COBALT, !(flags & __XNTIMER_CORE) &&
+!cpumask_test_cpu(xnsched_cpu(sched),
+  &clock->affinity));
timer->sched = sched;
} else {
cpu = xnclock_get_default_cpu(clock, 0);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mai

[Xenomai-git] Philippe Gerum : drivers/ipc: bufp: get buffer memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: cbc7bd503fa295579fbd2ae86d04dedd41ceb1ce
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cbc7bd503fa295579fbd2ae86d04dedd41ceb1ce

Author: Philippe Gerum 
Date:   Sun Feb 28 08:19:47 2016 +0100

drivers/ipc: bufp: get buffer memory from vmalloc()

---

 kernel/drivers/ipc/bufp.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/drivers/ipc/bufp.c b/kernel/drivers/ipc/bufp.c
index ecce4f9..6fc51d4 100644
--- a/kernel/drivers/ipc/bufp.c
+++ b/kernel/drivers/ipc/bufp.c
@@ -20,12 +20,11 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "internal.h"
 
@@ -149,7 +148,7 @@ static void bufp_close(struct rtdm_fd *fd)
xnregistry_remove(sk->handle);
 
if (sk->bufmem)
-   free_pages_exact(sk->bufmem, sk->bufsz);
+   xnheap_vfree(sk->bufmem);
 
kfree(sk);
 }
@@ -704,7 +703,7 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
if (sk->bufsz == 0)
return -ENOBUFS;
 
-   sk->bufmem = alloc_pages_exact(sk->bufsz, GFP_KERNEL);
+   sk->bufmem = xnheap_vmalloc(sk->bufsz);
if (sk->bufmem == NULL) {
ret = -ENOMEM;
goto fail;
@@ -719,7 +718,7 @@ static int __bufp_bind_socket(struct rtipc_private *priv,
ret = xnregistry_enter(sk->label, sk,
   &sk->handle, &__bufp_pnode.node);
if (ret) {
-   free_pages_exact(sk->bufmem, sk->bufsz);
+   xnheap_vfree(sk->bufmem);
goto fail;
}
}


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : drivers/ipc: iddp: get buffer memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: eb1be425b3322abec5c1ad780d79ba83232900e7
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=eb1be425b3322abec5c1ad780d79ba83232900e7

Author: Philippe Gerum 
Date:   Sun Feb 28 08:20:45 2016 +0100

drivers/ipc: iddp: get buffer memory from vmalloc()

---

 kernel/drivers/ipc/iddp.c |9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/drivers/ipc/iddp.c b/kernel/drivers/ipc/iddp.c
index ed09f76..59508f6 100644
--- a/kernel/drivers/ipc/iddp.c
+++ b/kernel/drivers/ipc/iddp.c
@@ -20,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -209,7 +208,7 @@ static void iddp_close(struct rtdm_fd *fd)
poolmem = xnheap_get_membase(&sk->privpool);
poolsz = xnheap_get_size(&sk->privpool);
xnheap_destroy(&sk->privpool);
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
return;
}
 
@@ -567,7 +566,7 @@ static int __iddp_bind_socket(struct rtdm_fd *fd,
poolsz = sk->poolsz;
if (poolsz > 0) {
poolsz = xnheap_rounded_size(poolsz);
-   poolmem = alloc_pages_exact(poolsz, GFP_KERNEL);
+   poolmem = xnheap_vmalloc(poolsz);
if (poolmem == NULL) {
ret = -ENOMEM;
goto fail;
@@ -575,7 +574,7 @@ static int __iddp_bind_socket(struct rtdm_fd *fd,
 
ret = xnheap_init(&sk->privpool, poolmem, poolsz);
if (ret) {
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
goto fail;
}
xnheap_set_name(&sk->privpool, "iddp-pool@%d", port);
@@ -594,7 +593,7 @@ static int __iddp_bind_socket(struct rtdm_fd *fd,
if (ret) {
if (poolsz > 0) {
xnheap_destroy(&sk->privpool);
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
}
goto fail;
}


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/posix/mqueue: get buffer memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: cb66a10c39618e2bc943b9dd5f4a4bd5619eb99f
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cb66a10c39618e2bc943b9dd5f4a4bd5619eb99f

Author: Philippe Gerum 
Date:   Sun Feb 28 08:16:18 2016 +0100

cobalt/posix/mqueue: get buffer memory from vmalloc()

---

 kernel/cobalt/posix/mqueue.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index 5ffa5f9..0f5e19e 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -126,7 +126,7 @@ static inline int mq_init(struct cobalt_mq *mq, const 
struct mq_attr *attr)
if (get_order(memsize) > MAX_ORDER)
return -ENOSPC;
 
-   mem = alloc_pages_exact(memsize, GFP_KERNEL);
+   mem = xnheap_vmalloc(memsize);
if (mem == NULL)
return -ENOSPC;
 
@@ -167,7 +167,7 @@ static inline void mq_destroy(struct cobalt_mq *mq)
xnselect_destroy(&mq->read_select);
xnselect_destroy(&mq->write_select);
xnregistry_remove(mq->handle);
-   free_pages_exact(mq->mem, mq->memsize);
+   xnheap_vfree(mq->mem);
kfree(mq);
 
if (resched)


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Jan Kiszka : smokey/posix-mutex: Fix test case /wrt mutex object reuse

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 819ccd02fedbaa45d1afb52c267d0609ae3b776c
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=819ccd02fedbaa45d1afb52c267d0609ae3b776c

Author: Jan Kiszka 
Date:   Thu Feb 25 11:29:00 2016 +0100

smokey/posix-mutex: Fix test case /wrt mutex object reuse

Mutex objects created on the stack must be properly destroyed after use.
Otherwise, succeeding tests that use the same stack layout will consider
them busy and refuse to recreate the mutexes.

Signed-off-by: Jan Kiszka 

---

 testsuite/smokey/posix-mutex/posix-mutex.c |   26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ae82fc1..151c2f3 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -623,7 +623,10 @@ static int protect_raise(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -651,7 +654,10 @@ static int protect_lower(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -699,7 +705,10 @@ static int protect_weak(void)
if (!__T(ret, pthread_setschedparam(pthread_self(),
old_policy, &old_param)))
return ret;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex)))
+   return ret;
+
return 0;
 }
 
@@ -745,7 +754,11 @@ static int protect_nesting_protect(void)
 
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_high)) ||
+   !__T(ret, pthread_mutex_destroy(&mutex_very_high)))
+   return ret;
+
return 0;
 }
 
@@ -782,7 +795,10 @@ static int protect_nesting_pi(void)
/* PP boost just dropped: HIGH -> MEDIUM. */
if (!__Tassert(get_effective_prio() == THREAD_PRIO_MEDIUM))
return -EINVAL;
-   
+
+   if (!__T(ret, pthread_mutex_destroy(&mutex_pp)))
+   return ret;
+
return 0;
 }
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: mutex: simplify, introduce PP tests

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 52896bfa81ce1b8ee83f29321d37b1bd36e8adfd
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=52896bfa81ce1b8ee83f29321d37b1bd36e8adfd

Author: Philippe Gerum 
Date:   Wed Feb 17 09:21:27 2016 +0100

testsuite/smokey: mutex: simplify, introduce PP tests

At this chance, the lock stealing test is also fixed.

---

 testsuite/smokey/posix-mutex/posix-mutex.c | 1357 ++--
 1 file changed, 670 insertions(+), 687 deletions(-)

diff --git a/testsuite/smokey/posix-mutex/posix-mutex.c 
b/testsuite/smokey/posix-mutex/posix-mutex.c
index ac71b31..ae82fc1 100644
--- a/testsuite/smokey/posix-mutex/posix-mutex.c
+++ b/testsuite/smokey/posix-mutex/posix-mutex.c
@@ -4,6 +4,7 @@
  * Copyright (C) Gilles Chanteperdrix  ,
  *   Marion Deveaud ,
  *   Jan Kiszka 
+ *   Philippe Gerum 
  *
  * Released under the terms of GPLv2.
  */
@@ -17,8 +18,6 @@
 #include 
 #include 
 #include 
-#include 
-#include "lib/cobalt/current.h"
 #include 
 
 smokey_test_plugin(posix_mutex,
@@ -26,886 +25,870 @@ smokey_test_plugin(posix_mutex,
   "Check POSIX mutex services"
 );
 
-#define MUTEX_CREATE   1
-#define MUTEX_LOCK 2
-#define MUTEX_TRYLOCK  3
-#define MUTEX_TIMED_LOCK   4
-#define MUTEX_UNLOCK   5
-#define MUTEX_DESTROY  6
-#define COND_CREATE7
-#define COND_SIGNAL8
-#define COND_WAIT  9
-#define COND_DESTROY   10
-#define THREAD_DETACH  11
-#define THREAD_CREATE  12
-#define THREAD_JOIN13
-#define THREAD_RENICE   14
-
-#define NS_PER_MS  100
-
 static const char *reason_str[] = {
-   [SIGDEBUG_UNDEFINED] = "undefined",
+   [SIGDEBUG_UNDEFINED] = "received SIGDEBUG for unknown reason",
[SIGDEBUG_MIGRATE_SIGNAL] = "received signal",
[SIGDEBUG_MIGRATE_SYSCALL] = "invoked syscall",
[SIGDEBUG_MIGRATE_FAULT] = "triggered fault",
[SIGDEBUG_MIGRATE_PRIOINV] = "affected by priority inversion",
-   [SIGDEBUG_NOMLOCK] = "missing mlockall",
-   [SIGDEBUG_WATCHDOG] = "runaway thread",
+   [SIGDEBUG_NOMLOCK] = "process memory not locked",
+   [SIGDEBUG_WATCHDOG] = "watchdog triggered (period too short?)",
+   [SIGDEBUG_LOCK_BREAK] = "scheduler lock break",
 };
 
 static void sigdebug(int sig, siginfo_t *si, void *context)
 {
+   const char fmt[] = "%s, this is unexpected.\n"
+   "(enabling CONFIG_XENO_OPT_DEBUG_TRACE_RELAX may help)\n";
unsigned int reason = sigdebug_reason(si);
+   int n __attribute__ ((unused));
+   static char buffer[256];
 
-   smokey_trace("\nSIGDEBUG received, reason %d: %s\n", reason,
-reason <= SIGDEBUG_WATCHDOG ? reason_str[reason] : 
"");
-}
+   if (reason > SIGDEBUG_WATCHDOG)
+   reason = SIGDEBUG_UNDEFINED;
 
-static inline unsigned long long timer_get_tsc(void)
-{
-   return clockobj_get_tsc();
+   n = snprintf(buffer, sizeof(buffer), fmt, reason_str[reason]);
+   n = write(STDERR_FILENO, buffer, n);
 }
 
-static inline unsigned long long timer_tsc2ns(unsigned long long tsc)
-{
-   return clockobj_tsc_to_ns(tsc);
-}
+#define THREAD_PRIO_WEAK   0
+#define THREAD_PRIO_LOW1
+#define THREAD_PRIO_MEDIUM 2
+#define THREAD_PRIO_HIGH   3
+#define THREAD_PRIO_VERY_HIGH  4
 
-static void add_timespec(struct timespec *ts, unsigned long long value)
-{
-   ts->tv_sec += value / 10;
-   ts->tv_nsec += value % 10;
-   if (ts->tv_nsec > 10) {
-   ts->tv_sec++;
-   ts->tv_nsec -= 10;
-   }
-}
+#define MAX_100_MS  1ULL
+
+struct locker_context {
+   pthread_mutex_t *mutex;
+   struct smokey_barrier *barrier;
+   int lock_acquired;
+};
 
-static void ms_sleep(int time)
+static void sleep_ms(unsigned int ms)  /* < 1000 */
 {
struct timespec ts;
-
+   
ts.tv_sec = 0;
-   ts.tv_nsec = time*NS_PER_MS;
-
-   nanosleep(&ts, NULL);
+   ts.tv_nsec = ms * 100;
+   clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
 }
 
-static void check_current_prio(int expected_prio)
+static int get_effective_prio(void) 
 {
struct cobalt_threadstat stat;
int ret;
 
ret = cobalt_thread_stat(0, &stat);
-   if (ret) {
-   fprintf(stderr,
-   "FAILURE: cobalt_threadstat (%s)\n", strerror(-ret));
-   exit(EXIT_FAILURE);
-   }
+   if (ret)
+   return ret;
 
-   if (stat.cprio != expected_prio) {
-   fprintf(stderr,
-   "FAILURE: current prio (%d) != expected prio (%d)\n",
-   stat.cprio, expected_prio);
-   exit(EXIT_FAILURE);
-   }
+   return stat.cprio;
 }
 
-static void __check_current_mode(const char *file, int line,
-

[Xenomai-git] Philippe Gerum : cobalt/init: get main heap memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 214615bed1eb697fd55fa224d7786733c9b08c0a
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=214615bed1eb697fd55fa224d7786733c9b08c0a

Author: Philippe Gerum 
Date:   Sun Feb 28 08:23:32 2016 +0100

cobalt/init: get main heap memory from vmalloc()

There is no reason to ask for physically contiguous memory from
alloc_pages[_exact]() for the main heap: real-time heaps are certainly
no place for getting DMA-suitable buffers from.

Using alloc_pages*() for common Cobalt heaps is a problem:

- this raises the probability of getting allocation failures in case
  of memory fragmentation (although seldom at boot time, some
  Cobalt-based modules also using such services could fail allocating
  their heap later on).

- this restricts the maximum heap size to MAX_ORDER (currently 4Mb),
  which may be too small in some configurations.

Therefore, switch from alloc_pages_exact() to vmalloc().

---

 include/cobalt/kernel/heap.h |4 
 kernel/cobalt/heap.c |   28 
 kernel/cobalt/init.c |7 +++
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/include/cobalt/kernel/heap.h b/include/cobalt/kernel/heap.h
index 988004f..a1cea69 100644
--- a/include/cobalt/kernel/heap.h
+++ b/include/cobalt/kernel/heap.h
@@ -130,6 +130,10 @@ static inline void xnheap_cleanup_proc(void) { }
 
 /* Public interface. */
 
+void *xnheap_vmalloc(size_t size);
+
+void xnheap_vfree(void *p);
+
 int xnheap_init(struct xnheap *heap, void *membase, u32 size);
 
 void xnheap_set_name(struct xnheap *heap,
diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 70f1c8f..2fcb6ba 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -21,6 +21,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -655,4 +657,30 @@ out:
 }
 EXPORT_SYMBOL_GPL(xnheap_check_block);
 
+void *xnheap_vmalloc(size_t size)
+{
+   /*
+* We want memory used in real-time context to be pulled from
+* ZONE_NORMAL, however we don't need it to be physically
+* contiguous.
+*
+* 32bit systems which would need HIGHMEM for running a Cobalt
+* configuration would also be required to support PTE
+* pinning, which not all architectures provide.  Moreover,
+* pinning PTEs eagerly for a potentially (very) large amount
+* of memory may quickly degrade performance.
+*
+* If using a different kernel/user memory split cannot be the
+* answer for those configs, it's likely that basing such
+* software on a 32bit system had to be wrong in the first
+* place anyway.
+*/
+   return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL);
+}
+
+void xnheap_vfree(void *p)
+{
+   vfree(p);
+}
+
 /** @} */
diff --git a/kernel/cobalt/init.c b/kernel/cobalt/init.c
index 0eab3be..6cbb67b 100644
--- a/kernel/cobalt/init.c
+++ b/kernel/cobalt/init.c
@@ -18,6 +18,7 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -127,7 +128,6 @@ static void sys_shutdown(void)
struct xnthread *thread, *tmp;
struct xnsched *sched;
void *membase;
-   u32 memsize;
int cpu;
spl_t s;
 
@@ -155,9 +155,8 @@ static void sys_shutdown(void)
 
xnregistry_cleanup();
membase = xnheap_get_membase(&cobalt_heap);
-   memsize = xnheap_get_size(&cobalt_heap);
xnheap_destroy(&cobalt_heap);
-   free_pages_exact(membase, memsize);
+   vfree(membase);
 }
 
 static int __init mach_setup(void)
@@ -290,7 +289,7 @@ static __init int sys_init(void)
if (sysheap_size_arg == 0)
sysheap_size_arg = CONFIG_XENO_OPT_SYS_HEAPSZ;
 
-   heapaddr = alloc_pages_exact(sysheap_size_arg * 1024, GFP_KERNEL);
+   heapaddr = vmalloc(sysheap_size_arg * 1024);
if (heapaddr == NULL ||
xnheap_init(&cobalt_heap, heapaddr, sysheap_size_arg * 1024)) {
return -ENOMEM;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/x86: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 42f136842b2be5aadced6739c6516af6f006d074
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=42f136842b2be5aadced6739c6516af6f006d074

Author: Philippe Gerum 
Date:   Mon Feb 29 10:10:50 2016 +0100

cobalt/x86: upgrade I-pipe support

---

 .../arch/x86/patches/ipipe-core-4.1.18-x86-1.patch |15641 
 1 file changed, 15641 insertions(+)

Diff:   
http://git.xenomai.org/?p=xenomai-3.git;a=commitdiff;h=42f136842b2be5aadced6739c6516af6f006d074

___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/thread: fix SMP race with xnthread_join()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 5902ea95bccd08d2b5161cfd61fcfb5709941cc6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5902ea95bccd08d2b5161cfd61fcfb5709941cc6

Author: Philippe Gerum 
Date:   Tue Mar  1 12:50:29 2016 +0100

cobalt/thread: fix SMP race with xnthread_join()

The situation below would cause a kernel crash on any earlier 3.x
release, with ktask implemented in a dynamically loaded/unloaded
module:

CPU0:  rtdm_task_destroy(ktask)
   ...
   rmmod(module)

CPU1:  ktask()
   ...
   ...
   __xnthread_test_cancel()
   do_exit()
  (last) schedule()
 OOPS: prev still treading on stale memory

In this case, the module would be unmapped too early, before the
cancelled task can ultimately schedule away.

The changes also fix a stale reference from the joiner thread to the
former ->idtag field, after the joinee's TCB has been dropped.

---

 include/cobalt/kernel/thread.h |6 +-
 kernel/cobalt/thread.c |  136 
 2 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index f25c6d0..e08a0a2 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -19,6 +19,7 @@
 #ifndef _COBALT_KERNEL_THREAD_H
 #define _COBALT_KERNEL_THREAD_H
 
+#include 
 #include 
 #include 
 #include 
@@ -107,9 +108,6 @@ struct xnthread {
struct list_head quota_expired;
struct list_head quota_next;
 #endif
-
-   unsigned int idtag; /* Unique ID tag */
-
cpumask_t affinity; /* Processor affinity. */
 
int bprio;  /* Base priority (before PIP boost) */
@@ -184,6 +182,8 @@ struct xnthread {
 
struct xnthread_personality *personality;
 
+   struct completion exited;
+
 #ifdef CONFIG_XENO_OPT_DEBUG
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index ca02e94..aaf868a 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,16 +41,14 @@
 #include 
 #include "debug.h"
 
+static DECLARE_WAIT_QUEUE_HEAD(join_all);
+
 /**
  * @ingroup cobalt_core
  * @defgroup cobalt_core_thread Thread services
  * @{
  */
 
-static DECLARE_WAIT_QUEUE_HEAD(nkjoinq);
-
-static unsigned int idtags;
-
 static void timeout_handler(struct xntimer *timer)
 {
struct xnthread *thread = container_of(timer, struct xnthread, rtimer);
@@ -158,20 +157,13 @@ int __xnthread_init(struct xnthread *thread,
const union xnsched_policy_param *sched_param)
 {
int flags = attr->flags, ret, gravity;
-   spl_t s;
 
flags &= ~XNSUSP;
 #ifndef CONFIG_XENO_ARCH_FPU
flags &= ~XNFPU;
 #endif
-   if (flags & XNROOT)
-   thread->idtag = 0;
-   else {
-   xnlock_get_irqsave(&nklock, s);
-   thread->idtag = ++idtags ?: 1;
-   xnlock_put_irqrestore(&nklock, s);
+   if ((flags & XNROOT) == 0)
flags |= XNDORMANT;
-   }
 
if (attr->name)
ksformat(thread->name,
@@ -207,6 +199,7 @@ int __xnthread_init(struct xnthread *thread,
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
+   init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
@@ -484,8 +477,6 @@ static inline void cleanup_tcb(struct xnthread *thread) /* 
nklock held, irqs off
xnthread_clear_state(thread, XNREADY);
}
 
-   thread->idtag = 0;
-
if (xnthread_test_state(thread, XNPEND))
xnsynch_forget_sleeper(thread);
 
@@ -525,10 +516,15 @@ void __xnthread_cleanup(struct xnthread *curr)
cleanup_tcb(curr);
xnlock_put_irqrestore(&nklock, s);
 
+   /* Wake up the joiner if any (we can't have more than one). */
+   complete(&curr->exited);
+
+   /* Notify our exit to xnthread_killall() if need be. */
+   if (waitqueue_active(&join_all))
+   wake_up(&join_all);
+
/* Finalize last since this incurs releasing the TCB. */
xnthread_run_handler_stack(curr, finalize_thread);
-
-   wake_up(&nkjoinq);
 }
 
 /*
@@ -1587,6 +1583,40 @@ out:
 }
 EXPORT_SYMBOL_GPL(xnthread_cancel);
 
+struct wait_grace_struct {
+   struct completion done;
+   struct rcu_head rcu;
+};
+
+static void grace_elapsed(struct rcu_head *head)
+{
+   struct wait_grace_struct *wgs;
+
+   wgs = container_of(head, struct wait_grace_struct, rcu);
+   complete(&wgs->done);
+}
+
+static void wait_grace_period(struct pid *pid)
+{
+   struct wait_grace_struct wait = {
+   .d

[Xenomai-git] Philippe Gerum : cobalt/thread: force secondary mode for joining threads

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 738d0d123602b80cb485b930318af8bc2111d818
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=738d0d123602b80cb485b930318af8bc2111d818

Author: Philippe Gerum 
Date:   Tue Mar  1 10:00:59 2016 +0100

cobalt/thread: force secondary mode for joining threads

Make xnthread_join() switch the caller to secondary mode prior to
waiting for the target thread termination. The original runtime mode
is restored upon return.

Since the joiner was already synchronized on an event that may be sent
by the joinee from secondary mode exclusively, this change does not
drop any real-time guarantee for the joiner: there has never been any
in the first place.

This is a preparation step to a stricter synchronization between the
joiner and the joinee, especially in the SMP case.

---

 include/cobalt/kernel/thread.h |2 --
 kernel/cobalt/posix/process.c  |2 --
 kernel/cobalt/thread.c |   75 +---
 3 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 59d6027..f25c6d0 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -188,8 +188,6 @@ struct xnthread {
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
 #endif
-   /** Exit event for joining the thread. */
-   struct xnsynch join_synch;
 };
 
 static inline int xnthread_get_state(const struct xnthread *thread)
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 788a24a..5b80521 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -1048,8 +1048,6 @@ static void __handle_taskexit_event(struct task_struct *p)
unregister_debugged_thread(thread);
 
xnthread_run_handler_stack(thread, exit_thread);
-   /* Waiters will receive EIDRM */
-   xnsynch_destroy(&thread->join_synch);
xnsched_run();
 
if (xnthread_test_state(thread, XNUSER)) {
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5f404ed..ca02e94 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -204,7 +204,6 @@ int __xnthread_init(struct xnthread *thread,
memset(&thread->stat, 0, sizeof(thread->stat));
thread->selector = NULL;
INIT_LIST_HEAD(&thread->claimq);
-   xnsynch_init(&thread->join_synch, XNSYNCH_FIFO, NULL);
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
@@ -1598,7 +1597,9 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  * immediately.
  *
  * xnthread_join() adapts to the calling context (primary or
- * secondary).
+ * secondary), switching to secondary mode if needed for the duration
+ * of the wait. Upon return, the original runtime mode is restored,
+ * unless a Linux signal is pending.
  *
  * @param thread The descriptor address of the thread to join with.
  *
@@ -1621,62 +1622,48 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  */
 int xnthread_join(struct xnthread *thread, bool uninterruptible)
 {
+   struct xnthread *curr = xnthread_current();
+   int ret = 0, switched = 0;
unsigned int tag;
spl_t s;
-   int ret;
 
XENO_BUG_ON(COBALT, xnthread_test_state(thread, XNROOT));
 
+   if (thread == curr)
+   return -EDEADLK;
+
xnlock_get_irqsave(&nklock, s);
 
-   tag = thread->idtag;
-   if (xnthread_test_info(thread, XNDORMANT) || tag == 0) {
-   xnlock_put_irqrestore(&nklock, s);
-   return 0;
+   if (xnthread_test_state(thread, XNJOINED)) {
+   ret = -EBUSY;
+   goto out;
}
 
+   tag = thread->idtag;
+   if (xnthread_test_info(thread, XNDORMANT) || tag == 0)
+   goto out;
+
trace_cobalt_thread_join(thread);
 
-   if (ipipe_root_p) {
-   if (xnthread_test_state(thread, XNJOINED)) {
-   ret = -EBUSY;
-   goto out;
-   }
-   xnthread_set_state(thread, XNJOINED);
+   xnthread_set_state(thread, XNJOINED);
+   
+   if (!xnthread_test_state(curr, XNRELAX|XNROOT)) {
+   xnlock_put_irqrestore(&nklock, s);
+   xnthread_relax(0, 0);
+   switched = 1;
+   } else
xnlock_put_irqrestore(&nklock, s);
-   /*
-* Only a very few threads are likely to terminate within a
-* short time frame at any point in time, so experiencing a
-* thundering herd effect due to synchronizing on a single
-* wait queue is quite unlikely. In any case, we run in
-* secondary mode.
-*/
-   if (uninterruptible)
-   wait_event(nkjoinq, thread->idtag != tag);
-   else if (wait_event_interruptible(nkjoinq,
-

[Xenomai-git] Philippe Gerum : cobalt/heap: export *vmalloc helpers

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: ec65be24018d958f6a9febf628d82a9bf7932010
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ec65be24018d958f6a9febf628d82a9bf7932010

Author: Philippe Gerum 
Date:   Tue Mar  1 08:08:02 2016 +0100

cobalt/heap: export *vmalloc helpers

---

 kernel/cobalt/heap.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/cobalt/heap.c b/kernel/cobalt/heap.c
index 2fcb6ba..ce4ef54 100644
--- a/kernel/cobalt/heap.c
+++ b/kernel/cobalt/heap.c
@@ -677,10 +677,12 @@ void *xnheap_vmalloc(size_t size)
 */
return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL);
 }
+EXPORT_SYMBOL_GPL(xnheap_vmalloc);
 
 void xnheap_vfree(void *p)
 {
vfree(p);
 }
+EXPORT_SYMBOL_GPL(xnheap_vfree);
 
 /** @} */


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/powerpc: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: 621daa15292e8be2593eea0496a5d4cb86bdbed9
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=621daa15292e8be2593eea0496a5d4cb86bdbed9

Author: Philippe Gerum 
Date:   Mon Feb 29 10:12:06 2016 +0100

cobalt/powerpc: upgrade I-pipe support

---

 .../patches/ipipe-core-4.1.18-powerpc-1.patch  |15898 
 1 file changed, 15898 insertions(+)

Diff:   
http://git.xenomai.org/?p=xenomai-3.git;a=commitdiff;h=621daa15292e8be2593eea0496a5d4cb86bdbed9

___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : drivers/ipc: xddp: get buffer memory from vmalloc()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: d458f46a9afdd1bdc8b903c9c9eadb79212838b3
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d458f46a9afdd1bdc8b903c9c9eadb79212838b3

Author: Philippe Gerum 
Date:   Sun Feb 28 08:21:24 2016 +0100

drivers/ipc: xddp: get buffer memory from vmalloc()

---

 kernel/drivers/ipc/xddp.c |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/drivers/ipc/xddp.c b/kernel/drivers/ipc/xddp.c
index 9bd3644..a528061 100644
--- a/kernel/drivers/ipc/xddp.c
+++ b/kernel/drivers/ipc/xddp.c
@@ -19,11 +19,11 @@
  */
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "internal.h"
 
@@ -206,7 +206,7 @@ static void __xddp_release_handler(void *skarg) /* nklock 
free */
poolmem = xnheap_get_membase(&sk->privpool);
poolsz = xnheap_get_size(&sk->privpool);
xnheap_destroy(&sk->privpool);
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
} else if (sk->buffer)
xnfree(sk->buffer);
 
@@ -691,7 +691,7 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
if (poolsz > 0) {
poolsz = xnheap_rounded_size(poolsz);
poolsz += xnheap_rounded_size(sk->reqbufsz);
-   poolmem = alloc_pages_exact(poolsz, GFP_KERNEL);
+   poolmem = xnheap_vmalloc(poolsz);
if (poolmem == NULL) {
ret = -ENOMEM;
goto fail;
@@ -699,7 +699,7 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
 
ret = xnheap_init(&sk->privpool, poolmem, poolsz);
if (ret) {
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
goto fail;
}
 
@@ -732,7 +732,7 @@ static int __xddp_bind_socket(struct rtipc_private *priv,
fail_freeheap:
if (poolsz > 0) {
xnheap_destroy(&sk->privpool);
-   free_pages_exact(poolmem, poolsz);
+   xnheap_vfree(poolmem);
}
fail:
clear_bit(_XDDP_BINDING, &sk->status);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/arm: upgrade I-pipe support

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: wip/prioceil
Commit: d43c70baccf2feac65730d11698083db2d152f80
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d43c70baccf2feac65730d11698083db2d152f80

Author: Philippe Gerum 
Date:   Mon Feb 29 10:10:20 2016 +0100

cobalt/arm: upgrade I-pipe support

---

 .../arch/arm/patches/ipipe-core-4.1.18-arm-1.patch |23942 
 1 file changed, 23942 insertions(+)

Diff:   
http://git.xenomai.org/?p=xenomai-3.git;a=commitdiff;h=d43c70baccf2feac65730d11698083db2d152f80

___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/thread: force secondary mode for joining threads

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 738d0d123602b80cb485b930318af8bc2111d818
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=738d0d123602b80cb485b930318af8bc2111d818

Author: Philippe Gerum 
Date:   Tue Mar  1 10:00:59 2016 +0100

cobalt/thread: force secondary mode for joining threads

Make xnthread_join() switch the caller to secondary mode prior to
waiting for the target thread termination. The original runtime mode
is restored upon return.

Since the joiner was already synchronized on an event that may be sent
by the joinee from secondary mode exclusively, this change does not
drop any real-time guarantee for the joiner: there has never been any
in the first place.

This is a preparation step to a stricter synchronization between the
joiner and the joinee, especially in the SMP case.

---

 include/cobalt/kernel/thread.h |2 --
 kernel/cobalt/posix/process.c  |2 --
 kernel/cobalt/thread.c |   75 +---
 3 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 59d6027..f25c6d0 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -188,8 +188,6 @@ struct xnthread {
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
 #endif
-   /** Exit event for joining the thread. */
-   struct xnsynch join_synch;
 };
 
 static inline int xnthread_get_state(const struct xnthread *thread)
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 788a24a..5b80521 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -1048,8 +1048,6 @@ static void __handle_taskexit_event(struct task_struct *p)
unregister_debugged_thread(thread);
 
xnthread_run_handler_stack(thread, exit_thread);
-   /* Waiters will receive EIDRM */
-   xnsynch_destroy(&thread->join_synch);
xnsched_run();
 
if (xnthread_test_state(thread, XNUSER)) {
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 5f404ed..ca02e94 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -204,7 +204,6 @@ int __xnthread_init(struct xnthread *thread,
memset(&thread->stat, 0, sizeof(thread->stat));
thread->selector = NULL;
INIT_LIST_HEAD(&thread->claimq);
-   xnsynch_init(&thread->join_synch, XNSYNCH_FIFO, NULL);
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
@@ -1598,7 +1597,9 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  * immediately.
  *
  * xnthread_join() adapts to the calling context (primary or
- * secondary).
+ * secondary), switching to secondary mode if needed for the duration
+ * of the wait. Upon return, the original runtime mode is restored,
+ * unless a Linux signal is pending.
  *
  * @param thread The descriptor address of the thread to join with.
  *
@@ -1621,62 +1622,48 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  */
 int xnthread_join(struct xnthread *thread, bool uninterruptible)
 {
+   struct xnthread *curr = xnthread_current();
+   int ret = 0, switched = 0;
unsigned int tag;
spl_t s;
-   int ret;
 
XENO_BUG_ON(COBALT, xnthread_test_state(thread, XNROOT));
 
+   if (thread == curr)
+   return -EDEADLK;
+
xnlock_get_irqsave(&nklock, s);
 
-   tag = thread->idtag;
-   if (xnthread_test_info(thread, XNDORMANT) || tag == 0) {
-   xnlock_put_irqrestore(&nklock, s);
-   return 0;
+   if (xnthread_test_state(thread, XNJOINED)) {
+   ret = -EBUSY;
+   goto out;
}
 
+   tag = thread->idtag;
+   if (xnthread_test_info(thread, XNDORMANT) || tag == 0)
+   goto out;
+
trace_cobalt_thread_join(thread);
 
-   if (ipipe_root_p) {
-   if (xnthread_test_state(thread, XNJOINED)) {
-   ret = -EBUSY;
-   goto out;
-   }
-   xnthread_set_state(thread, XNJOINED);
+   xnthread_set_state(thread, XNJOINED);
+   
+   if (!xnthread_test_state(curr, XNRELAX|XNROOT)) {
+   xnlock_put_irqrestore(&nklock, s);
+   xnthread_relax(0, 0);
+   switched = 1;
+   } else
xnlock_put_irqrestore(&nklock, s);
-   /*
-* Only a very few threads are likely to terminate within a
-* short time frame at any point in time, so experiencing a
-* thundering herd effect due to synchronizing on a single
-* wait queue is quite unlikely. In any case, we run in
-* secondary mode.
-*/
-   if (uninterruptible)
-   wait_event(nkjoinq, thread->idtag != tag);
-   else if (wait_event_interruptible(nkjoinq,
-

[Xenomai-git] Philippe Gerum : cobalt/thread: fix SMP race with xnthread_join()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 6bb194a5f0dc6fcfb0979d45d45fb2c6a5a62463
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=6bb194a5f0dc6fcfb0979d45d45fb2c6a5a62463

Author: Philippe Gerum 
Date:   Tue Mar  1 12:50:29 2016 +0100

cobalt/thread: fix SMP race with xnthread_join()

The situation below would cause a kernel crash on any earlier 3.x
release, with ktask implemented in a dynamically loaded/unloaded
module:

CPU0:  rtdm_task_destroy(ktask)
   ...
   rmmod(module)

CPU1:  ktask()
   ...
   ...
   __xnthread_test_cancel()
   do_exit()
  (last) schedule()
 OOPS: prev still treading on stale memory

In this case, the module would be unmapped too early, before the
cancelled task can ultimately schedule away.

The changes also fix a stale reference from the joiner thread to the
former ->idtag field, after the joinee's TCB has been dropped.

---

 include/cobalt/kernel/thread.h |6 +-
 kernel/cobalt/thread.c |  136 
 2 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index f25c6d0..e08a0a2 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -19,6 +19,7 @@
 #ifndef _COBALT_KERNEL_THREAD_H
 #define _COBALT_KERNEL_THREAD_H
 
+#include 
 #include 
 #include 
 #include 
@@ -107,9 +108,6 @@ struct xnthread {
struct list_head quota_expired;
struct list_head quota_next;
 #endif
-
-   unsigned int idtag; /* Unique ID tag */
-
cpumask_t affinity; /* Processor affinity. */
 
int bprio;  /* Base priority (before PIP boost) */
@@ -184,6 +182,8 @@ struct xnthread {
 
struct xnthread_personality *personality;
 
+   struct completion exited;
+
 #ifdef CONFIG_XENO_OPT_DEBUG
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 462d917..07b0c8f 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,16 +41,14 @@
 #include 
 #include "debug.h"
 
+static DECLARE_WAIT_QUEUE_HEAD(join_all);
+
 /**
  * @ingroup cobalt_core
  * @defgroup cobalt_core_thread Thread services
  * @{
  */
 
-static DECLARE_WAIT_QUEUE_HEAD(nkjoinq);
-
-static unsigned int idtags;
-
 static void timeout_handler(struct xntimer *timer)
 {
struct xnthread *thread = container_of(timer, struct xnthread, rtimer);
@@ -158,20 +157,13 @@ int __xnthread_init(struct xnthread *thread,
const union xnsched_policy_param *sched_param)
 {
int flags = attr->flags, ret, gravity;
-   spl_t s;
 
flags &= ~XNSUSP;
 #ifndef CONFIG_XENO_ARCH_FPU
flags &= ~XNFPU;
 #endif
-   if (flags & XNROOT)
-   thread->idtag = 0;
-   else {
-   xnlock_get_irqsave(&nklock, s);
-   thread->idtag = ++idtags ?: 1;
-   xnlock_put_irqrestore(&nklock, s);
+   if ((flags & XNROOT) == 0)
flags |= XNDORMANT;
-   }
 
if (attr->name)
ksformat(thread->name,
@@ -207,6 +199,7 @@ int __xnthread_init(struct xnthread *thread,
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
+   init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
@@ -480,8 +473,6 @@ static inline void cleanup_tcb(struct xnthread *thread) /* 
nklock held, irqs off
xnthread_clear_state(thread, XNREADY);
}
 
-   thread->idtag = 0;
-
if (xnthread_test_state(thread, XNPEND))
xnsynch_forget_sleeper(thread);
 
@@ -521,10 +512,15 @@ void __xnthread_cleanup(struct xnthread *curr)
cleanup_tcb(curr);
xnlock_put_irqrestore(&nklock, s);
 
+   /* Wake up the joiner if any (we can't have more than one). */
+   complete(&curr->exited);
+
+   /* Notify our exit to xnthread_killall() if need be. */
+   if (waitqueue_active(&join_all))
+   wake_up(&join_all);
+
/* Finalize last since this incurs releasing the TCB. */
xnthread_run_handler_stack(curr, finalize_thread);
-
-   wake_up(&nkjoinq);
 }
 
 /*
@@ -1583,6 +1579,40 @@ out:
 }
 EXPORT_SYMBOL_GPL(xnthread_cancel);
 
+struct wait_grace_struct {
+   struct completion done;
+   struct rcu_head rcu;
+};
+
+static void grace_elapsed(struct rcu_head *head)
+{
+   struct wait_grace_struct *wgs;
+
+   wgs = container_of(head, struct wait_grace_struct, rcu);
+   complete(&wgs->done);
+}
+
+static void wait_grace_period(struct pid *pid)
+{
+   struct wait_grace_struct wait = {
+   .done = CO

[Xenomai-git] Philippe Gerum : cobalt/timer: allow binding core timers to passive CPUs

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: c2026a16156529357940cd16d6340f18b360ae52
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=c2026a16156529357940cd16d6340f18b360ae52

Author: Philippe Gerum 
Date:   Wed Mar  2 12:08:32 2016 +0100

cobalt/timer: allow binding core timers to passive CPUs

Some timers initialized by the Cobalt core may have a valid reason to
live on CPUs excluded from the real-time set. A typical example would
be the host timer from the scheduler slot, which relays ticks to the
regular kernel. Other core timers are just better dealt with when
created and left passive on those CPUs.

Mark all core timers specifically, and exclude them from the LART
detection code in __xntimer_init(). This fixes a spurious Cobalt debug
assertion seen on SMP at boot, when the real-time CPU set is
restricted to a subset of the online CPU set.

---

 include/cobalt/kernel/timer.h |4 +++-
 kernel/cobalt/sched.c |6 +++---
 kernel/cobalt/thread.c|2 ++
 kernel/cobalt/timer.c |9 ++---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 00aa411..5868fcb 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -51,11 +51,13 @@ typedef enum xntmode {
 #define XNTIMER_RUNNING   0x0040
 #define XNTIMER_KGRAVITY  0x0080
 #define XNTIMER_UGRAVITY  0x0100
-#define XNTIMER_IGRAVITY  0/* most conservative */
+#define XNTIMER_IGRAVITY  0 /* most conservative */
 
 #define XNTIMER_GRAVITY_MASK   (XNTIMER_KGRAVITY|XNTIMER_UGRAVITY)
 #define XNTIMER_INIT_MASK  (XNTIMER_GRAVITY_MASK|XNTIMER_NOBLCK)
 
+#define __XNTIMER_CORE0x1000
+
 /* These flags are available to the real-time interfaces */
 #define XNTIMER_SPARE0  0x0100
 #define XNTIMER_SPARE1  0x0200
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index 3863dab..dfb8ce7 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -193,11 +193,11 @@ void xnsched_init(struct xnsched *sched, int cpu)
 * exit code.
 */
xntimer_init(&sched->htimer, &nkclock, NULL,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_priority(&sched->htimer, XNTIMER_LOPRIO);
xntimer_set_name(&sched->htimer, htimer_name);
xntimer_init(&sched->rrbtimer, &nkclock, roundrobin_handler,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->rrbtimer, rrbtimer_name);
xntimer_set_priority(&sched->rrbtimer, XNTIMER_LOPRIO);
 
@@ -212,7 +212,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
 
 #ifdef CONFIG_XENO_OPT_WATCHDOG
xntimer_init(&sched->wdtimer, &nkclock, watchdog_handler,
-sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY);
+sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->wdtimer, "[watchdog]");
xntimer_set_priority(&sched->wdtimer, XNTIMER_LOPRIO);
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 07b0c8f..b758d50 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -202,6 +202,8 @@ int __xnthread_init(struct xnthread *thread,
init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
+   if (flags & XNROOT)
+   gravity |= __XNTIMER_CORE;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
 sched, gravity);
xntimer_set_name(&thread->rtimer, thread->name);
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 3e85a53..ee16198 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -363,10 +363,13 @@ void __xntimer_init(struct xntimer *timer,
 * clock device on the CPU served by the specified
 * scheduler slot. This reveals a CPU affinity
 * mismatch between the clock hardware and the client
-* code initializing the timer.
+* code initializing the timer. This check excludes
+* core timers which may have their own reason to bind
+* to a passive CPU (e.g. host timer).
 */
-   XENO_WARN_ON_SMP(COBALT, !cpumask_test_cpu(xnsched_cpu(sched),
-  &clock->affinity));
+   XENO_WARN_ON_SMP(COBALT, !(flags & __XNTIMER_CORE) &&
+!cpumask_test_cpu(xnsched_cpu(sched),
+  &clock->affinity));
timer->sched = sched;
} else {
cpu = xnclock_get_default_cpu(clock, 0);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/lis

[Xenomai-git] Philippe Gerum : cobalt/thread: force secondary mode for joining threads

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: e4c9b3d581f3ee349c52f39c321c0dc82b2a4ad1
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e4c9b3d581f3ee349c52f39c321c0dc82b2a4ad1

Author: Philippe Gerum 
Date:   Tue Mar  1 10:00:59 2016 +0100

cobalt/thread: force secondary mode for joining threads

Make xnthread_join() switch the caller to secondary mode prior to
waiting for the target thread termination. The original runtime mode
is restored upon return.

Since the joiner was already synchronized on an event that may be sent
by the joinee from secondary mode exclusively, this change does not
drop any real-time guarantee for the joiner: there has never been any
in the first place.

This is a preparation step to a stricter synchronization between the
joiner and the joinee, especially in the SMP case.

---

 include/cobalt/kernel/thread.h |2 --
 kernel/cobalt/posix/process.c  |2 --
 kernel/cobalt/thread.c |   75 +---
 3 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 59d6027..f25c6d0 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -188,8 +188,6 @@ struct xnthread {
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
 #endif
-   /** Exit event for joining the thread. */
-   struct xnsynch join_synch;
 };
 
 static inline int xnthread_get_state(const struct xnthread *thread)
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 788a24a..5b80521 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -1048,8 +1048,6 @@ static void __handle_taskexit_event(struct task_struct *p)
unregister_debugged_thread(thread);
 
xnthread_run_handler_stack(thread, exit_thread);
-   /* Waiters will receive EIDRM */
-   xnsynch_destroy(&thread->join_synch);
xnsched_run();
 
if (xnthread_test_state(thread, XNUSER)) {
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 2b0cf60..462d917 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -204,7 +204,6 @@ int __xnthread_init(struct xnthread *thread,
memset(&thread->stat, 0, sizeof(thread->stat));
thread->selector = NULL;
INIT_LIST_HEAD(&thread->claimq);
-   xnsynch_init(&thread->join_synch, XNSYNCH_FIFO, NULL);
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
@@ -1594,7 +1593,9 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  * immediately.
  *
  * xnthread_join() adapts to the calling context (primary or
- * secondary).
+ * secondary), switching to secondary mode if needed for the duration
+ * of the wait. Upon return, the original runtime mode is restored,
+ * unless a Linux signal is pending.
  *
  * @param thread The descriptor address of the thread to join with.
  *
@@ -1617,62 +1618,48 @@ EXPORT_SYMBOL_GPL(xnthread_cancel);
  */
 int xnthread_join(struct xnthread *thread, bool uninterruptible)
 {
+   struct xnthread *curr = xnthread_current();
+   int ret = 0, switched = 0;
unsigned int tag;
spl_t s;
-   int ret;
 
XENO_BUG_ON(COBALT, xnthread_test_state(thread, XNROOT));
 
+   if (thread == curr)
+   return -EDEADLK;
+
xnlock_get_irqsave(&nklock, s);
 
-   tag = thread->idtag;
-   if (xnthread_test_info(thread, XNDORMANT) || tag == 0) {
-   xnlock_put_irqrestore(&nklock, s);
-   return 0;
+   if (xnthread_test_state(thread, XNJOINED)) {
+   ret = -EBUSY;
+   goto out;
}
 
+   tag = thread->idtag;
+   if (xnthread_test_info(thread, XNDORMANT) || tag == 0)
+   goto out;
+
trace_cobalt_thread_join(thread);
 
-   if (ipipe_root_p) {
-   if (xnthread_test_state(thread, XNJOINED)) {
-   ret = -EBUSY;
-   goto out;
-   }
-   xnthread_set_state(thread, XNJOINED);
+   xnthread_set_state(thread, XNJOINED);
+   
+   if (!xnthread_test_state(curr, XNRELAX|XNROOT)) {
+   xnlock_put_irqrestore(&nklock, s);
+   xnthread_relax(0, 0);
+   switched = 1;
+   } else
xnlock_put_irqrestore(&nklock, s);
-   /*
-* Only a very few threads are likely to terminate within a
-* short time frame at any point in time, so experiencing a
-* thundering herd effect due to synchronizing on a single
-* wait queue is quite unlikely. In any case, we run in
-* secondary mode.
-*/
-   if (uninterruptible)
-   wait_event(nkjoinq, thread->idtag != tag);
-   else if (wait_event_interruptible(nkjoinq,
-

[Xenomai-git] Philippe Gerum : cobalt/thread: do not demote kthreads when cancelling

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 17ba6d91ade9b8a3e1d0c132645d1e925cca3458
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=17ba6d91ade9b8a3e1d0c132645d1e925cca3458

Author: Philippe Gerum 
Date:   Tue Mar  1 08:36:18 2016 +0100

cobalt/thread: do not demote kthreads when cancelling

There is no point in switching a kthread to weak scheduling when
cancelling it, as it must reach a cancellation point asap as part of
its work loop anyway. Would it omit testing for cancellation, weak
scheduling would not help enforcing the exit request anyway.

---

 kernel/cobalt/thread.c |   19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 26ce90f..2b0cf60 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1562,16 +1562,21 @@ check_self_cancel:
return;
}
 
-   __xnthread_demote(thread);
-
/*
-* A userland thread undergoing the weak scheduling policy is
-* unlikely to issue Cobalt syscalls frequently, which may
-* defer cancellation significantly: send it a regular
-* termination signal too.
+* Force the non-current thread to exit:
+*
+* - unblock a user thread, switch it to weak scheduling,
+* then send it SIGTERM.
+*
+* - just unblock a kernel thread, it is expected to reach a
+* cancellation point soon after
+* (i.e. xnthread_test_cancel()).
 */
-   if (xnthread_test_state(thread, XNWEAK|XNUSER) == (XNWEAK|XNUSER))
+   if (xnthread_test_state(thread, XNUSER)) {
+   __xnthread_demote(thread);
xnthread_signal(thread, SIGTERM, 0);
+   } else
+   __xnthread_kick(thread);
 out:
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/thread: do not demote kthreads when cancelling

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 67db5a44c8aabc902227401815feaae2036de0f2
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=67db5a44c8aabc902227401815feaae2036de0f2

Author: Philippe Gerum 
Date:   Tue Mar  1 08:36:18 2016 +0100

cobalt/thread: do not demote kthreads when cancelling

There is no point in switching a kthread to weak scheduling when
cancelling it, as it must reach a cancellation point asap as part of
its work loop anyway. Would it omit testing for cancellation, weak
scheduling would not help enforcing the exit request anyway.

---

 kernel/cobalt/thread.c |   19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index a8edece..5f404ed 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1566,16 +1566,21 @@ check_self_cancel:
return;
}
 
-   __xnthread_demote(thread);
-
/*
-* A userland thread undergoing the weak scheduling policy is
-* unlikely to issue Cobalt syscalls frequently, which may
-* defer cancellation significantly: send it a regular
-* termination signal too.
+* Force the non-current thread to exit:
+*
+* - unblock a user thread, switch it to weak scheduling,
+* then send it SIGTERM.
+*
+* - just unblock a kernel thread, it is expected to reach a
+* cancellation point soon after
+* (i.e. xnthread_test_cancel()).
 */
-   if (xnthread_test_state(thread, XNWEAK|XNUSER) == (XNWEAK|XNUSER))
+   if (xnthread_test_state(thread, XNUSER)) {
+   __xnthread_demote(thread);
xnthread_signal(thread, SIGTERM, 0);
+   } else
+   __xnthread_kick(thread);
 out:
xnlock_put_irqrestore(&nklock, s);
 


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : cobalt/timer: allow binding core timers to passive CPUs

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 7d2d5b81f7aafb87458f2fc77b32eb68ebdba010
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7d2d5b81f7aafb87458f2fc77b32eb68ebdba010

Author: Philippe Gerum 
Date:   Wed Mar  2 12:08:32 2016 +0100

cobalt/timer: allow binding core timers to passive CPUs

Some timers initialized by the Cobalt core may have a valid reason to
live on CPUs excluded from the real-time set. A typical example would
be the host timer from the scheduler slot, which relays ticks to the
regular kernel. Other core timers are just better dealt with when
created and left passive on those CPUs.

Mark all core timers specifically, and exclude them from the LART
detection code in __xntimer_init(). This fixes a spurious Cobalt debug
assertion seen on SMP at boot, when the real-time CPU set is
restricted to a subset of the online CPU set.

---

 include/cobalt/kernel/timer.h |4 +++-
 kernel/cobalt/sched.c |6 +++---
 kernel/cobalt/thread.c|2 ++
 kernel/cobalt/timer.c |9 ++---
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/kernel/timer.h b/include/cobalt/kernel/timer.h
index 00aa411..5868fcb 100644
--- a/include/cobalt/kernel/timer.h
+++ b/include/cobalt/kernel/timer.h
@@ -51,11 +51,13 @@ typedef enum xntmode {
 #define XNTIMER_RUNNING   0x0040
 #define XNTIMER_KGRAVITY  0x0080
 #define XNTIMER_UGRAVITY  0x0100
-#define XNTIMER_IGRAVITY  0/* most conservative */
+#define XNTIMER_IGRAVITY  0 /* most conservative */
 
 #define XNTIMER_GRAVITY_MASK   (XNTIMER_KGRAVITY|XNTIMER_UGRAVITY)
 #define XNTIMER_INIT_MASK  (XNTIMER_GRAVITY_MASK|XNTIMER_NOBLCK)
 
+#define __XNTIMER_CORE0x1000
+
 /* These flags are available to the real-time interfaces */
 #define XNTIMER_SPARE0  0x0100
 #define XNTIMER_SPARE1  0x0200
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index d8c594c..033b124 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -193,11 +193,11 @@ void xnsched_init(struct xnsched *sched, int cpu)
 * exit code.
 */
xntimer_init(&sched->htimer, &nkclock, NULL,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_priority(&sched->htimer, XNTIMER_LOPRIO);
xntimer_set_name(&sched->htimer, htimer_name);
xntimer_init(&sched->rrbtimer, &nkclock, roundrobin_handler,
-sched, XNTIMER_IGRAVITY);
+sched, XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->rrbtimer, rrbtimer_name);
xntimer_set_priority(&sched->rrbtimer, XNTIMER_LOPRIO);
 
@@ -212,7 +212,7 @@ void xnsched_init(struct xnsched *sched, int cpu)
 
 #ifdef CONFIG_XENO_OPT_WATCHDOG
xntimer_init(&sched->wdtimer, &nkclock, watchdog_handler,
-sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY);
+sched, XNTIMER_NOBLCK|XNTIMER_IGRAVITY|__XNTIMER_CORE);
xntimer_set_name(&sched->wdtimer, "[watchdog]");
xntimer_set_priority(&sched->wdtimer, XNTIMER_LOPRIO);
 #endif /* CONFIG_XENO_OPT_WATCHDOG */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index aaf868a..3e29b3e 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -202,6 +202,8 @@ int __xnthread_init(struct xnthread *thread,
init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
+   if (flags & XNROOT)
+   gravity |= __XNTIMER_CORE;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
 sched, gravity);
xntimer_set_name(&thread->rtimer, thread->name);
diff --git a/kernel/cobalt/timer.c b/kernel/cobalt/timer.c
index 3e85a53..ee16198 100644
--- a/kernel/cobalt/timer.c
+++ b/kernel/cobalt/timer.c
@@ -363,10 +363,13 @@ void __xntimer_init(struct xntimer *timer,
 * clock device on the CPU served by the specified
 * scheduler slot. This reveals a CPU affinity
 * mismatch between the clock hardware and the client
-* code initializing the timer.
+* code initializing the timer. This check excludes
+* core timers which may have their own reason to bind
+* to a passive CPU (e.g. host timer).
 */
-   XENO_WARN_ON_SMP(COBALT, !cpumask_test_cpu(xnsched_cpu(sched),
-  &clock->affinity));
+   XENO_WARN_ON_SMP(COBALT, !(flags & __XNTIMER_CORE) &&
+!cpumask_test_cpu(xnsched_cpu(sched),
+  &clock->affinity));
timer->sched = sched;
} else {
cpu = xnclock_get_default_cpu(clock, 0);


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mai

[Xenomai-git] Philippe Gerum : cobalt/thread: fix SMP race with xnthread_join()

2016-03-02 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 5902ea95bccd08d2b5161cfd61fcfb5709941cc6
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=5902ea95bccd08d2b5161cfd61fcfb5709941cc6

Author: Philippe Gerum 
Date:   Tue Mar  1 12:50:29 2016 +0100

cobalt/thread: fix SMP race with xnthread_join()

The situation below would cause a kernel crash on any earlier 3.x
release, with ktask implemented in a dynamically loaded/unloaded
module:

CPU0:  rtdm_task_destroy(ktask)
   ...
   rmmod(module)

CPU1:  ktask()
   ...
   ...
   __xnthread_test_cancel()
   do_exit()
  (last) schedule()
 OOPS: prev still treading on stale memory

In this case, the module would be unmapped too early, before the
cancelled task can ultimately schedule away.

The changes also fix a stale reference from the joiner thread to the
former ->idtag field, after the joinee's TCB has been dropped.

---

 include/cobalt/kernel/thread.h |6 +-
 kernel/cobalt/thread.c |  136 
 2 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index f25c6d0..e08a0a2 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -19,6 +19,7 @@
 #ifndef _COBALT_KERNEL_THREAD_H
 #define _COBALT_KERNEL_THREAD_H
 
+#include 
 #include 
 #include 
 #include 
@@ -107,9 +108,6 @@ struct xnthread {
struct list_head quota_expired;
struct list_head quota_next;
 #endif
-
-   unsigned int idtag; /* Unique ID tag */
-
cpumask_t affinity; /* Processor affinity. */
 
int bprio;  /* Base priority (before PIP boost) */
@@ -184,6 +182,8 @@ struct xnthread {
 
struct xnthread_personality *personality;
 
+   struct completion exited;
+
 #ifdef CONFIG_XENO_OPT_DEBUG
const char *exe_path;   /* Executable path */
u32 proghash;   /* Hash value for exe_path */
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index ca02e94..aaf868a 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -40,16 +41,14 @@
 #include 
 #include "debug.h"
 
+static DECLARE_WAIT_QUEUE_HEAD(join_all);
+
 /**
  * @ingroup cobalt_core
  * @defgroup cobalt_core_thread Thread services
  * @{
  */
 
-static DECLARE_WAIT_QUEUE_HEAD(nkjoinq);
-
-static unsigned int idtags;
-
 static void timeout_handler(struct xntimer *timer)
 {
struct xnthread *thread = container_of(timer, struct xnthread, rtimer);
@@ -158,20 +157,13 @@ int __xnthread_init(struct xnthread *thread,
const union xnsched_policy_param *sched_param)
 {
int flags = attr->flags, ret, gravity;
-   spl_t s;
 
flags &= ~XNSUSP;
 #ifndef CONFIG_XENO_ARCH_FPU
flags &= ~XNFPU;
 #endif
-   if (flags & XNROOT)
-   thread->idtag = 0;
-   else {
-   xnlock_get_irqsave(&nklock, s);
-   thread->idtag = ++idtags ?: 1;
-   xnlock_put_irqrestore(&nklock, s);
+   if ((flags & XNROOT) == 0)
flags |= XNDORMANT;
-   }
 
if (attr->name)
ksformat(thread->name,
@@ -207,6 +199,7 @@ int __xnthread_init(struct xnthread *thread,
/* These will be filled by xnthread_start() */
thread->entry = NULL;
thread->cookie = NULL;
+   init_completion(&thread->exited);
 
gravity = flags & XNUSER ? XNTIMER_UGRAVITY : XNTIMER_KGRAVITY;
xntimer_init(&thread->rtimer, &nkclock, timeout_handler,
@@ -484,8 +477,6 @@ static inline void cleanup_tcb(struct xnthread *thread) /* 
nklock held, irqs off
xnthread_clear_state(thread, XNREADY);
}
 
-   thread->idtag = 0;
-
if (xnthread_test_state(thread, XNPEND))
xnsynch_forget_sleeper(thread);
 
@@ -525,10 +516,15 @@ void __xnthread_cleanup(struct xnthread *curr)
cleanup_tcb(curr);
xnlock_put_irqrestore(&nklock, s);
 
+   /* Wake up the joiner if any (we can't have more than one). */
+   complete(&curr->exited);
+
+   /* Notify our exit to xnthread_killall() if need be. */
+   if (waitqueue_active(&join_all))
+   wake_up(&join_all);
+
/* Finalize last since this incurs releasing the TCB. */
xnthread_run_handler_stack(curr, finalize_thread);
-
-   wake_up(&nkjoinq);
 }
 
 /*
@@ -1587,6 +1583,40 @@ out:
 }
 EXPORT_SYMBOL_GPL(xnthread_cancel);
 
+struct wait_grace_struct {
+   struct completion done;
+   struct rcu_head rcu;
+};
+
+static void grace_elapsed(struct rcu_head *head)
+{
+   struct wait_grace_struct *wgs;
+
+   wgs = container_of(head, struct wait_grace_struct, rcu);
+   complete(&wgs->done);
+}
+
+static void wait_grace_period(struct pid *pid)
+{
+   struct wait_grace_struct wait = {
+   .d