OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [tests/] [timeslice.c] - Blame information for rev 851

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        timeslice.c
4
//
5
//        Timeslice test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     nickg
43
// Contributors:  nickg
44
// Date:          2001-06-18
45
// Description:   A basic timeslicing test.
46
//
47
//####DESCRIPTIONEND####
48
//==========================================================================
49
 
50
#include <pkgconf/kernel.h>
51
#include <pkgconf/hal.h>
52
 
53
#include <cyg/hal/hal_arch.h>
54
 
55
#include <cyg/kernel/smp.hxx>
56
 
57
#include <cyg/kernel/kapi.h>
58
 
59
#include <cyg/infra/testcase.h>
60
#include <cyg/infra/diag.h>
61
#include CYGHWR_MEMORY_LAYOUT_H
62
 
63
//==========================================================================
64
 
65
#if defined(CYGSEM_KERNEL_SCHED_TIMESLICE) &&   \
66
    defined(CYGFUN_KERNEL_API_C) &&             \
67
    defined(CYGSEM_KERNEL_SCHED_MLQUEUE) &&     \
68
    defined(CYGVAR_KERNEL_COUNTERS_CLOCK) &&    \
69
    !defined(CYGDBG_INFRA_DIAG_USE_DEVICE) &&   \
70
    (CYGNUM_KERNEL_SCHED_PRIORITIES > 12)
71
 
72
//==========================================================================
73
 
74
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
75
 
76
#if (CYGMEM_REGION_ram_SIZE <= 32768)
77
#define NTHREADS_MAX (CYGNUM_KERNEL_CPU_MAX*4)
78
#else
79
#define NTHREADS_MAX (CYGNUM_KERNEL_CPU_MAX*6)
80
#endif
81
 
82
static int ncpus = CYGNUM_KERNEL_CPU_MAX;
83
 
84
static char test_stack[STACK_SIZE];
85
static cyg_thread test_thread;
86
static cyg_handle_t main_thread;
87
 
88
static char stacks[NTHREADS_MAX][STACK_SIZE];
89
static cyg_thread test_threads[NTHREADS_MAX];
90
static cyg_handle_t threads[NTHREADS_MAX];
91
 
92
static volatile int failed = false;
93
 
94
static volatile cyg_uint32 slicerun[NTHREADS_MAX][CYGNUM_KERNEL_CPU_MAX];
95
 
96
//==========================================================================
97
 
98
void
99
test_thread_timeslice(CYG_ADDRESS id)
100
{
101
    for(;;)
102
        slicerun[id][CYG_KERNEL_CPU_THIS()]++;
103
}
104
 
105
//==========================================================================
106
 
107
void run_test_timeslice(int nthread)
108
{
109
    int i,j;
110
    cyg_uint32 cpu_total[CYGNUM_KERNEL_CPU_MAX];
111
    cyg_uint32 cpu_threads[CYGNUM_KERNEL_CPU_MAX];
112
    cyg_uint32 thread_total[NTHREADS_MAX];
113
 
114
    CYG_TEST_INFO( "Timeslice Test: Check timeslicing works");
115
 
116
    // Init flags.
117
    for (i = 0;  i < nthread;  i++)
118
        for( j = 0; j < ncpus; j++ )
119
            slicerun[i][j] = 0;
120
 
121
    // Set my priority higher than any I plan to create
122
    cyg_thread_set_priority(cyg_thread_self(), 2);
123
 
124
    for (i = 0;  i < nthread;  i++) {
125
        cyg_thread_create(10,              // Priority - just a number
126
                          test_thread_timeslice, // entry
127
                          i,               // index
128
                          "test_thread",     // Name
129
                          &stacks[i][0],   // Stack
130
                          STACK_SIZE,      // Size
131
                          &threads[i],     // Handle
132
                          &test_threads[i] // Thread data structure
133
            );
134
        cyg_thread_resume( threads[i]);
135
    }
136
 
137
    // Just wait a while, until the threads have all run for a bit.
138
    cyg_thread_delay( CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS*100 );
139
 
140
    // Suspend all the threads
141
    for (i = 0;  i < nthread;  i++) {
142
        cyg_thread_suspend(threads[i]);
143
    }
144
 
145
 
146
    // And check that a thread ran on each CPU, and that each thread
147
    // ran.
148
 
149
 
150
    diag_printf(" Thread ");
151
    for( j = 0; j < ncpus; j++ )
152
    {
153
        cpu_total[j] = 0;
154
        cpu_threads[j] = 0;
155
        // "  %11d"  __123456789ab"
156
        diag_printf("       CPU %2d",j);
157
    }
158
    // "  %11d"  __123456789ab"
159
    diag_printf("        Total\n");
160
    for (i = 0;  i < nthread;  i++)
161
    {
162
        thread_total[i] = 0;
163
        diag_printf("     %2d ",i);
164
        for( j = 0; j < ncpus; j++ )
165
        {
166
            thread_total[i] += slicerun[i][j];
167
            cpu_total[j] += slicerun[i][j];
168
            if( slicerun[i][j] > 0 )
169
                cpu_threads[j]++;
170
            diag_printf("  %11d",slicerun[i][j]);
171
        }
172
        diag_printf("  %11d\n",thread_total[i]);
173
        if( thread_total[i] == 0 )
174
            failed++;
175
    }
176
 
177
    diag_printf(" Total  ");
178
    for( j = 0; j < ncpus; j++ )
179
        diag_printf("  %11d",cpu_total[j]);
180
    diag_printf("\n");
181
    diag_printf("Threads ");
182
    for( j = 0; j < ncpus; j++ )
183
    {
184
        diag_printf("  %11d",cpu_threads[j]);
185
        if( cpu_threads[j] < 2 )
186
            failed++;
187
    }
188
    diag_printf("\n");
189
 
190
    // Delete all the threads
191
    for (i = 0;  i < nthread;  i++) {
192
        cyg_thread_delete(threads[i]);
193
    }
194
 
195
    CYG_TEST_INFO( "Timeslice Test: done");
196
}
197
 
198
 
199
//==========================================================================
200
 
201
void
202
run_tests(CYG_ADDRESS id)
203
{
204
    int step;
205
    int nthread;
206
 
207
    // Try to run about 10 times in total, with varying numbers of threads
208
    // from only one extra up to the full set:
209
 
210
    step = (NTHREADS_MAX - (1 + CYG_KERNEL_CPU_COUNT()))/10;
211
    if( step == 0 ) step = 1;
212
 
213
    for( nthread = 1 + CYG_KERNEL_CPU_COUNT() ;
214
         nthread <= NTHREADS_MAX ;
215
         nthread += step )
216
            run_test_timeslice(nthread);
217
 
218
    if( failed )
219
        CYG_TEST_FAIL_FINISH("Timeslice test failed\n");
220
 
221
    CYG_TEST_PASS_FINISH("Timeslice test OK");
222
}
223
 
224
//==========================================================================
225
 
226
void timeslice_main( void )
227
{
228
    CYG_TEST_INIT();
229
 
230
    // Work out how many CPUs we actually have.
231
    ncpus = CYG_KERNEL_CPU_COUNT();
232
 
233
    cyg_thread_create(0,              // Priority - just a number
234
                      run_tests, // entry
235
                      0,               // index
236
                      "run_tests",     // Name
237
                      test_stack,   // Stack
238
                      STACK_SIZE,      // Size
239
                      &main_thread,     // Handle
240
                      &test_thread // Thread data structure
241
        );
242
    cyg_thread_resume( main_thread);
243
 
244
    cyg_scheduler_start();
245
}
246
 
247
//==========================================================================
248
 
249
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
250
externC void
251
cyg_hal_invoke_constructors();
252
#endif
253
 
254
externC void
255
cyg_start( void )
256
{
257
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
258
    cyg_hal_invoke_constructors();
259
#endif
260
    timeslice_main();
261
}
262
 
263
//==========================================================================
264
 
265
#else // CYGSEM_KERNEL_SCHED_TIMESLICE etc
266
 
267
externC void
268
cyg_start( void )
269
{
270
    CYG_TEST_INIT();
271
    CYG_TEST_INFO("Timeslice test requires:\n"
272
                "CYGSEM_KERNEL_SCHED_TIMESLICE &&\n"
273
                "CYGFUN_KERNEL_API_C && \n"
274
                "CYGSEM_KERNEL_SCHED_MLQUEUE &&\n"
275
                "CYGVAR_KERNEL_COUNTERS_CLOCK &&\n"
276
                "!CYGDBG_INFRA_DIAG_USE_DEVICE &&\n"
277
                "(CYGNUM_KERNEL_SCHED_PRIORITIES > 12)\n");
278
    CYG_TEST_NA("Timeslice test requirements");
279
}
280
 
281
#endif // CYGSEM_KERNEL_SCHED_TIMESLICE etc.
282
 
283
//==========================================================================
284
// EOF timeslice.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.