[Xenomai-git] Philippe Gerum : drivers/testing: move to new-style atomic sections
Module: xenomai-forge Branch: rtdm-api-waitqueues Commit: beffa57f594604b9e4804a154691081a784bfdd5 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=beffa57f594604b9e4804a154691081a784bfdd5 Author: Philippe Gerum r...@xenomai.org Date: Thu Apr 10 11:41:22 2014 +0200 drivers/testing: move to new-style atomic sections --- kernel/drivers/testing/timerbench.c | 33 +++-- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/kernel/drivers/testing/timerbench.c b/kernel/drivers/testing/timerbench.c index efb5ca2..d6f2b64 100644 --- a/kernel/drivers/testing/timerbench.c +++ b/kernel/drivers/testing/timerbench.c @@ -141,22 +141,19 @@ static void eval_outer_loop(struct rt_tmbench_context *ctx) static void timer_task_proc(void *arg) { struct rt_tmbench_context *ctx = arg; - int count; + int count, err; + spl_t s; /* first event: one millisecond from now. */ ctx-date = rtdm_clock_read_monotonic() + 100; while (1) { - int err; - for (count = 0; count ctx-samples_per_sec; count++) { - RTDM_EXECUTE_ATOMICALLY( - ctx-start_time = rtdm_clock_read_monotonic(); - err = - rtdm_task_sleep_abs(ctx-date, - RTDM_TIMERMODE_ABSOLUTE); - ); - + rtdm_atomic_enter(s); + ctx-start_time = rtdm_clock_read_monotonic(); + err = rtdm_task_sleep_abs(ctx-date, + RTDM_TIMERMODE_ABSOLUTE); + rtdm_atomic_leave(s); if (err) return; @@ -237,6 +234,7 @@ static int rt_tmbench_start(struct rtdm_dev_context *context, struct rttst_tmbench_config __user *user_config) { int err = 0; + spl_t s; struct rttst_tmbench_config config_buf; struct rttst_tmbench_config *config = @@ -311,16 +309,15 @@ static int rt_tmbench_start(struct rtdm_dev_context *context, if (!test_bit(RTDM_CLOSING, context-context_flags)) { ctx-mode = RTTST_TMBENCH_HANDLER; - RTDM_EXECUTE_ATOMICALLY( - ctx-start_time = rtdm_clock_read_monotonic(); + rtdm_atomic_enter(s); + ctx-start_time = rtdm_clock_read_monotonic(); - /* first event: one millisecond from now. */ - ctx-date = ctx-start_time + 100; + /* first event: one millisecond from now. */ + ctx-date = ctx-start_time + 100; - err = - rtdm_timer_start(ctx-timer, ctx-date, 0, -RTDM_TIMERMODE_ABSOLUTE); - ); + err = rtdm_timer_start(ctx-timer, ctx-date, 0, + RTDM_TIMERMODE_ABSOLUTE); + rtdm_atomic_leave(s); } } ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : rtdm: introduce lock name as RTDM_LOCK_UNLOCK() argument
Module: xenomai-forge Branch: rtdm-api-waitqueues Commit: 8efcdffc376d235fd699ad9ee91494e8f5a08f58 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=8efcdffc376d235fd699ad9ee91494e8f5a08f58 Author: Philippe Gerum r...@xenomai.org Date: Sat Apr 12 17:35:51 2014 +0200 rtdm: introduce lock name as RTDM_LOCK_UNLOCK() argument Mapping RTDM locks over native spinlocks will require to pass the lock name to the native spinlock initializer, so make sure we receive it from the RTDM client code. This change is propagated to all driver stacks concerned (i.e. analogy and CAN). --- include/analogy/os_facilities.h |5 - include/cobalt/kernel/rtdm/driver.h |7 +-- kernel/drivers/analogy/testing/fake.c |2 +- kernel/drivers/can/rtcan_dev.c|2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/analogy/os_facilities.h b/include/analogy/os_facilities.h index 0f99cbf..35f4155 100644 --- a/include/analogy/os_facilities.h +++ b/include/analogy/os_facilities.h @@ -85,7 +85,10 @@ typedef rtdm_lock_t a4l_lock_t; -#define A4L_LOCK_UNLOCKED RTDM_LOCK_UNLOCKED +#define A4L_LOCK_UNLOCKED(__name) RTDM_LOCK_UNLOCKED(__name) + +#define DEFINE_A4L_LOCK(__name)\ + a4l_lock_t __name = A4L_LOCK_UNLOCKED(__name) #define a4l_lock_init(lock) rtdm_lock_init(lock) #define a4l_lock(lock) rtdm_lock_get(lock) diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h index 9aa0637..3bf7f2b 100644 --- a/include/cobalt/kernel/rtdm/driver.h +++ b/include/cobalt/kernel/rtdm/driver.h @@ -688,7 +688,10 @@ int rtdm_select_bind(int fd, rtdm_selector_t *selector, /** * Static lock initialisation */ -#define RTDM_LOCK_UNLOCKED IPIPE_SPIN_LOCK_UNLOCKED +#define RTDM_LOCK_UNLOCKED(__name) IPIPE_SPIN_LOCK_UNLOCKED + +#define DEFINE_RTDM_LOCK(__name) \ + rtdm_lock_t __name = RTDM_LOCK_UNLOCKED(__name) /** Lock variable */ typedef ipipe_spinlock_t rtdm_lock_t; @@ -1441,7 +1444,7 @@ int rtdm_ratelimit(struct rtdm_ratelimit_state *rs, const char *func); #define DEFINE_RTDM_RATELIMIT_STATE(name, interval_init, burst_init) \ struct rtdm_ratelimit_state name = {\ - .lock = RTDM_LOCK_UNLOCKED, \ + .lock = RTDM_LOCK_UNLOCKED((name).lock), \ .interval = interval_init,\ .burst = burst_init, \ } diff --git a/kernel/drivers/analogy/testing/fake.c b/kernel/drivers/analogy/testing/fake.c index 3871cc5..a2390aa 100644 --- a/kernel/drivers/analogy/testing/fake.c +++ b/kernel/drivers/analogy/testing/fake.c @@ -116,7 +116,7 @@ static inline uint16_t ai_value_output(struct ai_priv *priv) 0x8000, 0xa000, 0xc000, 0x }; static unsigned int output_idx; - static a4l_lock_t output_lock = A4L_LOCK_UNLOCKED; + static DEFINE_A4L_LOCK(output_lock); unsigned long flags; unsigned int idx; diff --git a/kernel/drivers/can/rtcan_dev.c b/kernel/drivers/can/rtcan_dev.c index c3e9e5e..10d3a53 100644 --- a/kernel/drivers/can/rtcan_dev.c +++ b/kernel/drivers/can/rtcan_dev.c @@ -34,7 +34,7 @@ static struct rtcan_device *rtcan_devices[RTCAN_MAX_DEVICES]; -static rtdm_lock_t rtcan_devices_rt_lock = RTDM_LOCK_UNLOCKED; +static DEFINE_RTDM_LOCK(rtcan_devices_rt_lock); static int rtcan_global_init_done; ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : analogy/device: sanitize device release handler
Module: xenomai-forge Branch: next Commit: e00fedb370e914aec531abf306b43558075f5306 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=e00fedb370e914aec531abf306b43558075f5306 Author: Philippe Gerum r...@xenomai.org Date: Fri Apr 11 15:16:02 2014 +0200 analogy/device: sanitize device release handler This change fixes a crash when a zero-sized private area is specified for the driver: http://www.xenomai.org/pipermail/xenomai/2014-April/030628.html More fixups are included to sanitize this handler a bit further. --- kernel/drivers/analogy/device.c | 27 --- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/kernel/drivers/analogy/device.c b/kernel/drivers/analogy/device.c index b93ae72..60b2977 100644 --- a/kernel/drivers/analogy/device.c +++ b/kernel/drivers/analogy/device.c @@ -278,17 +278,15 @@ int a4l_assign_driver(a4l_cxt_t * cxt, a4l_dev_t *dev = a4l_get_dev(cxt); dev-driver = drv; + INIT_LIST_HEAD(dev-subdvsq); if (drv-privdata_size == 0) __a4l_dbg(1, core_dbg, a4l_assign_driver: warning! the field priv will not be usable\n); else { - - INIT_LIST_HEAD(dev-subdvsq); - dev-priv = rtdm_malloc(drv-privdata_size); - if (dev-priv == NULL drv-privdata_size != 0) { + if (dev-priv == NULL) { __a4l_err(a4l_assign_driver: call(alloc) failed\n); ret = -ENOMEM; @@ -325,27 +323,26 @@ out_assign_driver: int a4l_release_driver(a4l_cxt_t * cxt) { - int ret = 0; a4l_dev_t *dev = a4l_get_dev(cxt); + a4l_subd_t *subd, *tmp; + int ret = 0; if ((ret = dev-driver-detach(dev)) != 0) goto out_release_driver; - /* Decrease module's count - so as to allow module unloading */ module_put(dev-driver-owner); /* In case, the driver developer did not free the subdevices */ - while (dev-subdvsq != dev-subdvsq.next) { - struct list_head *this = dev-subdvsq.next; - a4l_subd_t *tmp = list_entry(this, a4l_subd_t, list); - - list_del(this); - rtdm_free(tmp); - } + if (!list_empty(dev-subdvsq)) + list_for_each_entry_safe(subd, tmp, dev-subdvsq, list) { + list_del(subd-list); + rtdm_free(subd); + } /* Free the private field */ - rtdm_free(dev-priv); + if (dev-priv) + rtdm_free(dev-priv); + dev-driver = NULL; out_release_driver: ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git
[Xenomai-git] Philippe Gerum : analogy/device: sanitize device release handler
Module: xenomai-2.6 Branch: master Commit: 0f1ae8401ceaa8af387062b1e126a66e0c7c9c1f URL: http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=0f1ae8401ceaa8af387062b1e126a66e0c7c9c1f Author: Philippe Gerum r...@xenomai.org Date: Fri Apr 11 15:16:02 2014 +0200 analogy/device: sanitize device release handler The main change fixes a crash when a zero-sized private area is specified for the driver: http://www.xenomai.org/pipermail/xenomai/2014-April/030628.html Signed-off-by: Andreas Glatz andi.gl...@gmail.com More fixups are included to sanitize this handler a bit further. Signed-off-by: Philippe Gerum r...@xenomai.org --- ksrc/drivers/analogy/device.c | 27 --- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/ksrc/drivers/analogy/device.c b/ksrc/drivers/analogy/device.c index b93ae72..60b2977 100644 --- a/ksrc/drivers/analogy/device.c +++ b/ksrc/drivers/analogy/device.c @@ -278,17 +278,15 @@ int a4l_assign_driver(a4l_cxt_t * cxt, a4l_dev_t *dev = a4l_get_dev(cxt); dev-driver = drv; + INIT_LIST_HEAD(dev-subdvsq); if (drv-privdata_size == 0) __a4l_dbg(1, core_dbg, a4l_assign_driver: warning! the field priv will not be usable\n); else { - - INIT_LIST_HEAD(dev-subdvsq); - dev-priv = rtdm_malloc(drv-privdata_size); - if (dev-priv == NULL drv-privdata_size != 0) { + if (dev-priv == NULL) { __a4l_err(a4l_assign_driver: call(alloc) failed\n); ret = -ENOMEM; @@ -325,27 +323,26 @@ out_assign_driver: int a4l_release_driver(a4l_cxt_t * cxt) { - int ret = 0; a4l_dev_t *dev = a4l_get_dev(cxt); + a4l_subd_t *subd, *tmp; + int ret = 0; if ((ret = dev-driver-detach(dev)) != 0) goto out_release_driver; - /* Decrease module's count - so as to allow module unloading */ module_put(dev-driver-owner); /* In case, the driver developer did not free the subdevices */ - while (dev-subdvsq != dev-subdvsq.next) { - struct list_head *this = dev-subdvsq.next; - a4l_subd_t *tmp = list_entry(this, a4l_subd_t, list); - - list_del(this); - rtdm_free(tmp); - } + if (!list_empty(dev-subdvsq)) + list_for_each_entry_safe(subd, tmp, dev-subdvsq, list) { + list_del(subd-list); + rtdm_free(subd); + } /* Free the private field */ - rtdm_free(dev-priv); + if (dev-priv) + rtdm_free(dev-priv); + dev-driver = NULL; out_release_driver: ___ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git