I am sorry, i forget to include rt_process.c
Thanks.
__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com
/*
COPYRIGHT (C) 2000 Paolo Mantegazza ([EMAIL PROTECTED])
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.
*/
#include <linux/module.h>
#include <asm/io.h>
#include <asm/rtai.h>
#include <rtai_fifos.h>
#include <rtai_sched.h>
//#define DISTRIBUTE
#define SEM_TYPE (CNT_SEM | FIFO_Q)
#define STACK_SIZE 500
#define NR_TASKS 30
#define LOOPS 1000
RT_TASK thread[NR_TASKS];
static int cpu_used[NR_RT_CPUS];
static SEM sem;
static volatile int change;
static void rt_task(int t) {
while(1) {
if (change) {
rt_sem_wait(&sem);
} else {
// rt_sem_wait(&sem);
// rt_sem_signal(&sem);
rt_task_suspend(thread + t);
}
cpu_used[hard_cpu_id()]++;
}
}
int init_module(void)
{
volatile RTIME t;
int i, k;
printk("\nWait for it ...\n");
rt_typed_sem_init(&sem, 1, SEM_TYPE);
rt_linux_use_fpu(1);
for (i = 0; i < NR_TASKS; i++) {
#ifdef DISTRIBUTE
rt_task_init_cpuid(thread + i, rt_task, i, STACK_SIZE, 0, 1, 0, i%2);
#else
rt_task_init_cpuid(thread + i, rt_task, i, STACK_SIZE, 0, 1, 0,
hard_cpu_id());
#endif
}
change = 0;
hard_cli();
t = rdtsc();
for (i = 0; i < LOOPS; i++) {
for (k = 0; k < NR_TASKS; k++) {
rt_task_resume(thread + k);
rt_busy_sleep(100);
}
}
t = rdtsc() - t;
hard_sti();
printk("\n\nFOR %d TASKS: ", NR_TASKS);
printk("TIME %d (ms), SUSP/RES SWITCHES %d, ", (int)llimd(t, 1000, CPU_FREQ),
2*NR_TASKS*LOOPS);
printk("SWITCH TIME (INCLUDING FULL FP SUPPORT) %d (ns)\n",
(int)llimd(llimd(t, 1000000000, CPU_FREQ), 1, 2*NR_TASKS*LOOPS));
//
change = 1;
for (k = 0; k < NR_TASKS; k++) {
rt_task_resume(thread + k);
}
hard_cli();
t = rdtsc();
for (i = 0; i < LOOPS; i++) {
for (k = 0; k < NR_TASKS; k++) {
rt_sem_signal(&sem);
}
}
t = rdtsc() - t;
hard_sti();
printk("\nFOR %d TASKS: ", NR_TASKS);
printk("TIME %d (ms), SEM SIG/WAIT SWITCHES %d, ", (int)llimd(t, 1000,
CPU_FREQ), 2*NR_TASKS*LOOPS);
printk("SWITCH TIME (INCLUDING FULL FP SUPPORT) %d (ns)\n\n",
(int)llimd(llimd(t, 1000000000, CPU_FREQ), 1, 2*NR_TASKS*LOOPS));
//
return 0;
}
void cleanup_module(void)
{
int i;
for (i = 0; i < NR_TASKS; i++) {
rt_task_delete(thread + i);
}
printk("\nCPU USE SUMMARY\n");
for (i = 0; i < NR_RT_CPUS; i++) {
printk("# %d -> %d\n", i, cpu_used[i]);
}
printk("END OF CPU USE SUMMARY\n\n");
rt_sem_delete(&sem);
}