source: network-demos/ttcp/rtems_ttcp.c @ 5ee0701

4.11network-demos-4-10-branchnetwork-demos-4-8-branchnetwork-demos-4-9-branch
Last change on this file since 5ee0701 was 5ee0701, checked in by Joel Sherrill <joel.sherrill@…>, on 08/16/07 at 17:27:52

2007-08-16 Joel Sherrill <joel.sherrill@…>

  • init.c: Change clock tick to 1 millisecond.
  • rtems_ttcp.c: Add CPU usage reporting.
  • ttcp_orig/ttcp.c: Add -m option for delaying between writes.
  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[c87143a]1/*
2 * A collection of hacks, glue, and patches to
3 * provide a `UNIX-like' environment to ttcp.
4 *
[0c9330e]5 * Some of the code here may migrate to the libc
[c87143a]6 * support routines some day.  Some of the more sleazy
7 * hacks should never make it outside this file!
8 *
9 * This program may be distributed and used for any purpose.
10 * I ask only that you:
11 *      1. Leave this author information intact.
12 *      2. Document any changes you make.
13 *
14 * W. Eric Norum
15 * Saskatchewan Accelerator Laboratory
16 * University of Saskatchewan
17 * Saskatoon, Saskatchewan, CANADA
18 * eric@skatter.usask.ca
[7ba2ac5]19 *
20 *  $Id$
[c87143a]21 */
22
23#include <stdio.h>
[2b13801]24#include <string.h>
[0c9330e]25#include <ctype.h>
[c87143a]26#include <rtems.h>
[0c9330e]27#include <rtems/rtems_bsdnet.h>
[c87143a]28#include <rtems/error.h>
[0c9330e]29#include <sys/types.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <netdb.h>
[c87143a]33#include <sys/time.h>
[6a19a29]34#include <stdlib.h>
35#include <signal.h>
[c87143a]36
37/*
38 * Glue between UNIX-style ttcp code and RTEMS
39 */
40int rtems_ttcp_main (int argc, char **argv);
41
42static int
43select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
44{
[6a19a29]45  rtems_panic ("select()");
46  return 0;
[c87143a]47}
48
49#define _SYS_RESOURCE_H_
50#define RUSAGE_SELF     0               /* calling process */
51#define RUSAGE_CHILDREN -1              /* terminated child processes */
52struct rusage {
53        struct timeval ru_utime;        /* user time used */
54        struct timeval ru_stime;        /* system time used */
55        int ru_maxrss;          /* maximum resident set size */
56        int ru_ixrss;           /* currently 0 */
57        int ru_idrss;           /* integral resident set size */
58        int ru_isrss;           /* currently 0 */
59        int ru_minflt;          /* page faults not requiring physical I/O */
60        int ru_majflt;          /* page faults requiring physical I/O */
61        int ru_nswap;           /* swaps */
62        int ru_inblock;         /* block input operations */
63        int ru_oublock;         /* block output operations */
64        int ru_msgsnd;          /* messages sent */
65        int ru_msgrcv;          /* messages received */
66        int ru_nsignals;        /* signals received */
67        int ru_nvcsw;           /* voluntary context switches */
68        int ru_nivcsw;          /* involuntary context switches */
69};
70int
71getrusage(int ignored, struct rusage *ru)
72{
73        rtems_clock_time_value now;
74        static struct rusage nullUsage;
75
76        rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now);
77        *ru = nullUsage;
78        ru->ru_stime.tv_sec  = now.seconds;
79        ru->ru_stime.tv_usec = now.microseconds;
80        ru->ru_utime.tv_sec  = 0;
81        ru->ru_utime.tv_usec = 0;
82        return 0;
83}
84
85static void
86rtems_ttcp_exit (int code)
87{
[5ee0701]88        rtems_cpu_usage_report();
[2b13801]89        rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) );
[0c9330e]90        rtems_bsdnet_show_mbuf_stats ();
91        rtems_bsdnet_show_if_stats ();
92        rtems_bsdnet_show_ip_stats ();
93        rtems_bsdnet_show_tcp_stats ();
[c87143a]94        exit (code);
95}
96
97/*
98 * Task to run UNIX ttcp command
99 */
100char *__progname;
101static void
102ttcpTask (rtems_task_argument arg)
103{
104        int code;
105        int argc;
106        char arg0[10];
107        char *argv[20];
108        char linebuf[200];
109
110        for (;;) {
111                char *cp;
112
113                /*
114                 * Set up first argument
115                 */
116                argc = 1;
117                strcpy (arg0, "ttcp");
118                argv[0] = __progname = arg0;
119
[0c9330e]120#if (defined (WRITE_TEST_ONLY))
121                strcpy (linebuf, "-s -t crux");
122#elif (defined (READ_TEST_ONLY))
123                strcpy (linebuf, "-s -r");
124#else
[c87143a]125                /*
126                 * Read a line
127                 */
128                printf (">>> %s ", argv[0]);
129                fflush (stdout);
130                fgets (linebuf, sizeof linebuf, stdin);
[0c9330e]131#endif
[c87143a]132
133                /*
134                 * Break line into arguments
135                 */
136                cp = linebuf;
137                for (;;) {
138                        while (isspace (*cp))
139                                *cp++ = '\0';
140                        if (*cp == '\0')
141                                break;
142                        if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) {
143                                printf ("Too many arguments.\n");
144                                argc = 0;
145                                break;
146                        }
147                        argv[argc++] = cp;
148                        while (!isspace (*cp)) {
149                                if (*cp == '\0')
150                                        break;
151                                cp++;
152                        }
153                }
154                if (argc > 1) {
155                        argv[argc] = NULL;
156                        break;
157                }
158                printf ("You must give some arguments!\n");
159                printf ("At the very least, you must provide\n");
160                printf ("         -r\n");
161                printf ("or\n");
162                printf ("         -t destination.internet.address\n");
163        }
[5ee0701]164        rtems_cpu_usage_reset();
[c87143a]165        code = rtems_ttcp_main (argc, argv);
166        rtems_ttcp_exit (code);
167}
168
169/*
170 * Test network throughput
171 */
172void
173test_network (void)
174{
175        rtems_id tid;
176        rtems_status_code sc;
177        rtems_time_of_day now;
178        rtems_task_priority my_priority;
179
180        /*
181         * Set up time-of-day clock
182         */
183        now.year = 1997;
184        now.month = 1;
185        now.day = 1;
186        now.hour = 0;
187        now.minute = 0;
188        now.second = 0;
189        now.ticks = 0;
190        sc = rtems_clock_set (&now);
191        if (sc != RTEMS_SUCCESSFUL) {
192                printf ("Can't set date/time; %s\n", rtems_status_text (sc));
193                return;
194        }
195
196        /*
197         * Spawn test task
198         */
199        rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &my_priority);
200        sc = rtems_task_create (rtems_build_name ('T', 'T', 'C', 'P'),
201                        my_priority,
202                        32*1024,
203                        RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
204                        RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
205                        &tid);
206        if (sc != RTEMS_SUCCESSFUL) {
207                printf ("Can't create task; %s\n", rtems_status_text (sc));
208                return;
209        }
210        sc = rtems_task_start (tid, ttcpTask, 0);
211        if (sc != RTEMS_SUCCESSFUL) {
212                printf ("Can't start task; %s\n", rtems_status_text (sc));
213                return;
214        }
[0c9330e]215        rtems_task_suspend (RTEMS_SELF);
[c87143a]216}
217
218#define main            rtems_ttcp_main
219#define exit(code)      close(fd),rtems_ttcp_exit(code)
220
221#include "ttcp_orig/ttcp.c"
Note: See TracBrowser for help on using the repository browser.