[Xenomai-git] Philippe Gerum : boilerplate, copperplate: introduce API to manipulate tunables

2015-05-22 Thread git repository hosting
Module: xenomai-3
Branch: master
Commit: 6044426913c0447db6c4658092cb7674c1d1aa9d
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=6044426913c0447db6c4658092cb7674c1d1aa9d

Author: Philippe Gerum r...@xenomai.org
Date:   Tue May 12 10:11:18 2015 +0200

boilerplate, copperplate: introduce API to manipulate tunables

The core libraries define a set of tunable parameters, this commit
provides an API for applications to assign and fetch their current
value.

Parameters are divided in 'config' and 'runtime' tunable sets. The
former may be assigned new values until the core starts running the
-init() handlers from the setup descriptors, at which point any
attempt to change them triggers an assertion when --enable-assert is
in effect. The latter can be changed at any point in time.

A single API is provided in order to frame all possible manipulations
within a small set of generic helpers, so that we can do basic error
detection at build time and runtime, and keep options open for later
extending this API, such as automated tracing and reporting.

---

 include/boilerplate/Makefile.am |3 +-
 include/boilerplate/setup.h |   10 ++--
 include/boilerplate/tunables.h  |  116 +++
 include/copperplate/Makefile.am |1 +
 include/copperplate/tunables.h  |   81 +++
 include/xenomai/Makefile.am |4 +-
 include/xenomai/init.h  |6 +-
 include/xenomai/tunables.h  |   24 
 lib/boilerplate/setup.c |   13 -
 lib/copperplate/internal.h  |   16 +-
 lib/smokey/init.c   |5 +-
 11 files changed, 251 insertions(+), 28 deletions(-)

diff --git a/include/boilerplate/Makefile.am b/include/boilerplate/Makefile.am
index b611364..2d3ace8 100644
--- a/include/boilerplate/Makefile.am
+++ b/include/boilerplate/Makefile.am
@@ -14,4 +14,5 @@ includesub_HEADERS =  \
scope.h \
setup.h \
shared-list.h   \
-   time.h
+   time.h  \
+   tunables.h
diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 0879618..f1ff7b1 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -95,15 +95,17 @@ void __register_setup_call(struct setup_descriptor *p, int 
id);
 
 extern pid_t __node_id;
 
-extern struct base_setup_data __base_setup_data;
+extern int __config_done;
 
-#ifdef __cplusplus
-}
-#endif
+extern struct base_setup_data __base_setup_data;
 
 static inline const char *get_program_name(void)
 {
return basename(__base_setup_data.arg0 ?: program);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* !_BOILERPLATE_SETUP_H */
diff --git a/include/boilerplate/tunables.h b/include/boilerplate/tunables.h
new file mode 100644
index 000..796a19c
--- /dev/null
+++ b/include/boilerplate/tunables.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 Philippe Gerum r...@xenomai.org.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _BOILERPLATE_TUNABLES_H
+#define _BOILERPLATE_TUNABLES_H
+
+#include assert.h
+#include boilerplate/setup.h
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+static inline int __may_change_config_tunable(void)
+{
+   return !__config_done;
+}
+
+#define __tunable_set_call(__name, __scope)\
+   __assign_ ## __name ## _ ## __scope
+
+#define __tunable_get_call(__name, __scope)\
+   __read_ ## __name ## _ ## __scope
+
+#define __define_tunable(__name, __type, __val, __scope)   \
+   void __tunable_set_call(__name, __scope)(typeof(__type) __val)
+
+#define __read_tunable(__name, __type, __scope)\
+   typeof(__type) __tunable_get_call(__name, __scope)(void)
+
+#define define_config_tunable(__name, __type, __val)   \
+   __define_tunable(__name, __type, __val, config)
+
+#define define_runtime_tunable(__name, __type, __val)  \
+   __define_tunable(__name, __type, __val, runtime)
+
+#define read_config_tunable(__name, __type)\
+   __read_tunable(__name, __type, config)
+
+#define read_runtime_tunable(__name, __type)   \
+   __read_tunable(__name, __type, runtime)
+
+#define set_config_tunable(__name, __val)  \
+   do {\
+   

[Xenomai-git] Philippe Gerum : boilerplate, copperplate: introduce API to manipulate tunables

2015-05-12 Thread git repository hosting
Module: xenomai-3
Branch: next
Commit: 16acbe910d06d3fdea14133ccb43e838a05d4934
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=16acbe910d06d3fdea14133ccb43e838a05d4934

Author: Philippe Gerum r...@xenomai.org
Date:   Tue May 12 10:11:18 2015 +0200

boilerplate, copperplate: introduce API to manipulate tunables

The core libraries define a set of tunable parameters, this commit
provides an API for applications to assign and fetch their current
value.

Parameters are divided in 'config' and 'runtime' tunable sets. The
former may be assigned new values until the core starts running the
-init() handlers from the setup descriptors, at which point any
attempt to change them triggers an assertion when --enable-assert is
in effect. The latter can be changed at any point in time.

A single API is provided in order to frame all possible manipulations
within a small set of generic helpers, so that we can do basic error
detection at build time and runtime, and keep options open for later
extending this API, such as automated tracing and reporting.

---

 include/boilerplate/Makefile.am |3 +-
 include/boilerplate/setup.h |   10 ++--
 include/boilerplate/tunables.h  |  116 +++
 include/copperplate/Makefile.am |1 +
 include/copperplate/tunables.h  |   91 ++
 include/xenomai/Makefile.am |4 +-
 include/xenomai/init.h  |6 +-
 include/xenomai/tunables.h  |   24 
 lib/boilerplate/setup.c |   13 -
 lib/copperplate/internal.h  |   16 +-
 lib/smokey/init.c   |5 +-
 11 files changed, 261 insertions(+), 28 deletions(-)

diff --git a/include/boilerplate/Makefile.am b/include/boilerplate/Makefile.am
index b611364..2d3ace8 100644
--- a/include/boilerplate/Makefile.am
+++ b/include/boilerplate/Makefile.am
@@ -14,4 +14,5 @@ includesub_HEADERS =  \
scope.h \
setup.h \
shared-list.h   \
-   time.h
+   time.h  \
+   tunables.h
diff --git a/include/boilerplate/setup.h b/include/boilerplate/setup.h
index 0879618..f1ff7b1 100644
--- a/include/boilerplate/setup.h
+++ b/include/boilerplate/setup.h
@@ -95,15 +95,17 @@ void __register_setup_call(struct setup_descriptor *p, int 
id);
 
 extern pid_t __node_id;
 
-extern struct base_setup_data __base_setup_data;
+extern int __config_done;
 
-#ifdef __cplusplus
-}
-#endif
+extern struct base_setup_data __base_setup_data;
 
 static inline const char *get_program_name(void)
 {
return basename(__base_setup_data.arg0 ?: program);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* !_BOILERPLATE_SETUP_H */
diff --git a/include/boilerplate/tunables.h b/include/boilerplate/tunables.h
new file mode 100644
index 000..796a19c
--- /dev/null
+++ b/include/boilerplate/tunables.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2015 Philippe Gerum r...@xenomai.org.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
+ */
+#ifndef _BOILERPLATE_TUNABLES_H
+#define _BOILERPLATE_TUNABLES_H
+
+#include assert.h
+#include boilerplate/setup.h
+
+#ifdef __cplusplus
+extern C {
+#endif
+
+static inline int __may_change_config_tunable(void)
+{
+   return !__config_done;
+}
+
+#define __tunable_set_call(__name, __scope)\
+   __assign_ ## __name ## _ ## __scope
+
+#define __tunable_get_call(__name, __scope)\
+   __read_ ## __name ## _ ## __scope
+
+#define __define_tunable(__name, __type, __val, __scope)   \
+   void __tunable_set_call(__name, __scope)(typeof(__type) __val)
+
+#define __read_tunable(__name, __type, __scope)\
+   typeof(__type) __tunable_get_call(__name, __scope)(void)
+
+#define define_config_tunable(__name, __type, __val)   \
+   __define_tunable(__name, __type, __val, config)
+
+#define define_runtime_tunable(__name, __type, __val)  \
+   __define_tunable(__name, __type, __val, runtime)
+
+#define read_config_tunable(__name, __type)\
+   __read_tunable(__name, __type, config)
+
+#define read_runtime_tunable(__name, __type)   \
+   __read_tunable(__name, __type, runtime)
+
+#define set_config_tunable(__name, __val)  \
+   do {\
+