Module: xenomai-forge
Branch: next
Commit: 210cd3bbc5b19639e9b1c5c23a1db67b4d87b66e
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=210cd3bbc5b19639e9b1c5c23a1db67b4d87b66e

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Sep 18 09:15:16 2014 +0200

drivers/timerbench, drivers/switchtest: instantiate a single device

Those drivers can already multiplex any number of connections on a
single device, so we don't need them to instantiate more than a single
device.

As a result of this change, the /dev/rtdm/{switchtest,
timerbench}[0-9] series of devices become single devnodes
/dev/rtdm/{switchtest, timerbench}.

---

 doc/asciidoc/man1/latency.adoc      |    3 --
 kernel/drivers/testing/switchtest.c |   66 ++++++++++++-----------------------
 kernel/drivers/testing/timerbench.c |   30 +++-------------
 testsuite/latency/latency.c         |   18 ++--------
 testsuite/switchtest/switchtest.c   |   43 ++++++-----------------
 5 files changed, 42 insertions(+), 118 deletions(-)

diff --git a/doc/asciidoc/man1/latency.adoc b/doc/asciidoc/man1/latency.adoc
index 3931a4f..42a1ae1 100644
--- a/doc/asciidoc/man1/latency.adoc
+++ b/doc/asciidoc/man1/latency.adoc
@@ -64,9 +64,6 @@ default=0, so ^C to end
 *-q*::
 suppresses RTD, RTH lines if -T is used
 
-*-D <testing_device_no>*::
-number of testing device, default=0
-
 *-t <test_mode>*::
 0=user task (default), 1=kernel task, 2=timer IRQ
 
diff --git a/kernel/drivers/testing/switchtest.c 
b/kernel/drivers/testing/switchtest.c
index f32782d..0bb5981 100644
--- a/kernel/drivers/testing/switchtest.c
+++ b/kernel/drivers/testing/switchtest.c
@@ -26,8 +26,6 @@
 #include <rtdm/driver.h>
 #include <asm/xenomai/fptest.h>
 
-#define NR_DEVICES  4
-
 #define RTSWITCH_RT      0x10000
 #define RTSWITCH_NRT     0
 #define RTSWITCH_KERNEL  0x20000
@@ -37,22 +35,22 @@ struct rtswitch_task {
        rtdm_event_t rt_synch;
        struct semaphore nrt_synch;
        struct xnthread ktask;          /* For kernel-space real-time tasks. */
-       unsigned last_switch;
+       unsigned int last_switch;
 };
 
 struct rtswitch_context {
        struct rtswitch_task *tasks;
-       unsigned tasks_count;
-       unsigned next_index;
+       unsigned int tasks_count;
+       unsigned int next_index;
        struct semaphore lock;
-       unsigned cpu;
-       unsigned switches_count;
+       unsigned int cpu;
+       unsigned int switches_count;
 
        unsigned long pause_us;
-       unsigned next_task;
+       unsigned int next_task;
        rtdm_timer_t wake_up_delay;
 
-       unsigned failed;
+       unsigned int failed;
        struct rttst_swtest_error error;
 
        struct rtswitch_task *utask;
@@ -76,10 +74,10 @@ static int report(const char *fmt, ...)
        return ret;
 }
 
-static void handle_ktask_error(struct rtswitch_context *ctx, unsigned fp_val)
+static void handle_ktask_error(struct rtswitch_context *ctx, unsigned int 
fp_val)
 {
        struct rtswitch_task *cur = &ctx->tasks[ctx->error.last_switch.to];
-       unsigned i;
+       unsigned int i;
 
        ctx->failed = 1;
        ctx->error.fp_val = fp_val;
@@ -110,7 +108,7 @@ static void handle_ktask_error(struct rtswitch_context 
*ctx, unsigned fp_val)
 }
 
 static int rtswitch_pend_rt(struct rtswitch_context *ctx,
-                           unsigned idx)
+                           unsigned int idx)
 {
        struct rtswitch_task *task;
        int rc;
@@ -151,8 +149,8 @@ static void timed_wake_up(rtdm_timer_t *timer)
 }
 
 static int rtswitch_to_rt(struct rtswitch_context *ctx,
-                         unsigned from_idx,
-                         unsigned to_idx)
+                         unsigned int from_idx,
+                         unsigned int to_idx)
 {
        struct rtswitch_task *from, *to;
        int rc;
@@ -212,7 +210,7 @@ static int rtswitch_to_rt(struct rtswitch_context *ctx,
 }
 
 static int rtswitch_pend_nrt(struct rtswitch_context *ctx,
-                            unsigned idx)
+                            unsigned int idx)
 {
        struct rtswitch_task *task;
 
@@ -233,11 +231,11 @@ static int rtswitch_pend_nrt(struct rtswitch_context *ctx,
 }
 
 static int rtswitch_to_nrt(struct rtswitch_context *ctx,
-                          unsigned from_idx,
-                          unsigned to_idx)
+                          unsigned int from_idx,
+                          unsigned int to_idx)
 {
        struct rtswitch_task *from, *to;
-       unsigned expected, fp_val;
+       unsigned int expected, fp_val;
        int fp_check;
 
        if (from_idx > ctx->tasks_count || to_idx > ctx->tasks_count)
@@ -348,7 +346,7 @@ static int rtswitch_to_nrt(struct rtswitch_context *ctx,
        return 0;
 }
 
-static int rtswitch_set_tasks_count(struct rtswitch_context *ctx, unsigned 
count)
+static int rtswitch_set_tasks_count(struct rtswitch_context *ctx, unsigned int 
count)
 {
        struct rtswitch_task *tasks;
 
@@ -550,7 +548,7 @@ static int rtswitch_open(struct rtdm_fd *fd, int oflags)
 static void rtswitch_close(struct rtdm_fd *fd)
 {
        struct rtswitch_context *ctx = rtdm_fd_to_private(fd);
-       unsigned i;
+       unsigned int i;
 
        if (ctx->tasks) {
                set_cpus_allowed(current, cpumask_of_cpu(ctx->cpu));
@@ -737,45 +735,27 @@ static struct rtdm_device_class switchtest = {
        .provider_name = "Gilles Chanteperdrix",
 };
 
-static struct rtdm_device devices[NR_DEVICES] = {
-       [ 0 ... NR_DEVICES - 1] = {
-               .class = &switchtest,
-               .label = "switchtest%d",
-       },
+static struct rtdm_device device = {
+       .class = &switchtest,
+       .label = "switchtest",
 };
 
 int __init __switchtest_init(void)
 {
-       int minor, ret;
-
        if (!realtime_core_enabled())
                return 0;
 
        fp_features = fp_detect();
 
-       for (minor = 0; minor < NR_DEVICES; minor++) {
-               ret = rtdm_dev_register(devices + minor);
-               if (ret)
-                       goto fail;
-       }
-
-       return 0;
-fail:
-       while (minor-- > 0)
-               rtdm_dev_unregister(devices + minor, 0);
-
-       return ret;
+       return rtdm_dev_register(&device);
 }
 
 void __switchtest_exit(void)
 {
-       int minor;
-
        if (!realtime_core_enabled())
                return;
 
-       for (minor = 0; minor < NR_DEVICES; minor++)
-               rtdm_dev_unregister(devices + minor, 1000);
+       rtdm_dev_unregister(&device, 1000);
 }
 
 module_init(__switchtest_init);
diff --git a/kernel/drivers/testing/timerbench.c 
b/kernel/drivers/testing/timerbench.c
index 644177b..bec6f8c 100644
--- a/kernel/drivers/testing/timerbench.c
+++ b/kernel/drivers/testing/timerbench.c
@@ -24,8 +24,6 @@
 #include <rtdm/testing.h>
 #include <rtdm/driver.h>
 
-#define NR_DEVICES  4
-
 struct rt_tmbench_context {
        int mode;
        unsigned long period;
@@ -470,43 +468,25 @@ static struct rtdm_device_class timerbench = {
        .provider_name          = "Jan Kiszka",
 };
 
-static struct rtdm_device devices[NR_DEVICES] = {
-       [ 0 ... NR_DEVICES - 1] = {
-               .class = &timerbench,
-               .label = "timerbench%d",
-       },
+static struct rtdm_device device = {
+       .class = &timerbench,
+       .label = "timerbench",
 };
 
 static int __init __timerbench_init(void)
 {
-       int minor, ret;
-
        if (!realtime_core_enabled())
                return 0;
 
-       for (minor = 0; minor < NR_DEVICES; minor++) {
-               ret = rtdm_dev_register(devices + minor);
-               if (ret)
-                       goto fail;
-       }
-
-       return 0;
-fail:
-       while (minor-- > 0)
-               rtdm_dev_unregister(devices + minor, 0);
-
-       return ret;
+       return rtdm_dev_register(&device);
 }
 
 static void __timerbench_exit(void)
 {
-       int minor;
-
        if (!realtime_core_enabled())
                return;
 
-       for (minor = 0; minor < NR_DEVICES; minor++)
-               rtdm_dev_unregister(devices + minor, 1000);
+       rtdm_dev_unregister(&device, 1000);
 }
 
 module_init(__timerbench_init);
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index 20ccd48..9e6aefd 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -35,7 +35,6 @@ long long period_ns = 0;
 int test_duration = 0;         /* sec of testing, via -T <sec>, 0 is inf */
 int data_lines = 21;           /* data lines per header line, -l <lines> to 
change */
 int quiet = 0;                 /* suppress printing of RTH, RTD lines when -T 
given */
-int benchdev_no = 0;
 int benchdev = -1;
 int freeze_max = 0;
 int priority = HIPRIO;
@@ -630,11 +629,6 @@ int main(int argc, char *const *argv)
                        quiet = 1;
                        break;
 
-               case 'D':
-
-                       benchdev_no = atoi(optarg);
-                       break;
-
                case 't':
 
                        test_mode = atoi(optarg);
@@ -743,17 +737,11 @@ int main(int argc, char *const *argv)
        mlockall(MCL_CURRENT | MCL_FUTURE);
 
        if (test_mode != USER_TASK) {
-               char devname[RTDM_MAX_DEVNAME_LEN];
-
-               snprintf(devname, RTDM_MAX_DEVNAME_LEN,
-                        "/dev/rtdm/timerbench%d",
-                        benchdev_no);
-               benchdev = open(devname, O_RDWR);
-
+               benchdev = open("/dev/rtdm/timerbench", O_RDWR);
                if (benchdev < 0) {
                        fprintf(stderr,
-                               "latency: cannot open %s: %m\n"
-                               "(modprobe xeno_timerbench?)\n", devname);
+                               "latency: cannot open /dev/rtdm/timerbench: 
%m\n"
+                               "(modprobe xeno_timerbench?)\n");
                        return 0;
                }
        }
diff --git a/testsuite/switchtest/switchtest.c 
b/testsuite/switchtest/switchtest.c
index 8232cb2..4784ece 100644
--- a/testsuite/switchtest/switchtest.c
+++ b/testsuite/switchtest/switchtest.c
@@ -891,43 +891,22 @@ static int task_create(struct cpu_tasks *cpu,
        return err;
 }
 
-#define DEV_NR_MAX 256
-
 static int open_rttest(char *buf, size_t size, unsigned count)
 {
-       static unsigned dev_nr = 0;
-       int fd, status;
-
-       do {
-               snprintf(buf, size, "/dev/rtdm/switchtest%d", dev_nr);
-
-               status = fd = open(buf, O_RDWR);
-
-               if (fd == -1)
-                       goto next_dev;
-
-               status = ioctl(fd, RTTST_RTIOC_SWTEST_SET_TASKS_COUNT, count);
-
-               if (status == 0)
-                       break;
-
-               if (errno != ENOSYS && errno != ENOTTY) {
-                       fprintf(stderr, "switchtest: ioctl: %m\n");
-                       return -1;
-               }
-
-         next_dev:
-               if (fd != -1)
-                       close(fd);
-
-               if (++dev_nr != DEV_NR_MAX)
-                       continue;
+       int fd, ret;
 
-               fprintf(stderr, "switchtest: cannot open %s\n"
-                       "(modprobe xeno_switchtest?)\n", buf);
+       fd = open("/dev/rtdm/switchtest", O_RDWR);
+       if (fd < 0) {
+               fprintf(stderr, "switchtest: cannot open /dev/rtdm/switchtest\n"
+                       "(modprobe xeno_switchtest?)\n");
+               return -1;
+       }
 
+       ret = ioctl(fd, RTTST_RTIOC_SWTEST_SET_TASKS_COUNT, count);
+       if (ret) {
+               fprintf(stderr, "switchtest: ioctl: %m\n");
                return -1;
-       } while (status == -1);
+       }
 
        return fd;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to