static int __switches_init(void) { int i; int e; printk("\nWait for it ...\n"); rt_typed_sem_init(&sem, 1, SEM_TYPE); rt_linux_use_fpu(1); thread = (RT_TASK *)kmalloc(ntasks*sizeof(RT_TASK), GFP_KERNEL); for (i = 0; i < ntasks; i++) { #ifdef DISTRIBUTE e = rt_task_init_cpuid(thread + i, pend_task, i, stack_size, 0, use_fpu, 0, i%2); #else e = rt_task_init_cpuid(thread + i, pend_task, i, stack_size, 0, use_fpu, 0, hard_cpu_id()); #endif if (e < 0) { task_init_has_failed: rt_printk("switches: failed to initialize task %d, error=%d\n", i, e); while (--i >= 0) rt_task_delete(thread + i); return -1; } } e = rt_task_init_cpuid(&task, sched_task, i, stack_size, 1, use_fpu, 0, hard_cpu_id()); if (e < 0) goto task_init_has_failed; rt_task_resume(&task); return 0; }
static void ClockChrono_Read(long t) { char ch; unsigned int run = 0; while(1) { cpu_used[hard_cpu_id()]++; rt_sem_wait(&keybrd_sem); rtf_get(Keyboard, &ch, 1); ch = toupper(ch); switch(ch) { case 'T': case 'R': case 'H': case 'M': case 'S': CommandClock_Put(ch); break; case 'C': case 'I': case 'E': CommandChrono_Put(ch); break; case 'N': hide = ~hide; break; case 'P': pause = TRUE; rt_fractionated_sleep(nano2count(FIVE_SECONDS)); pause = FALSE; break; case 'K': case 'D': run += ch; if (run == ('K' + 'D')) { rt_send(&clock, run); rt_send(&chrono, run); } break; } } }
static void bfun(long t) { unsigned long long msg; unsigned long long name = 0xccccccccccccccccLL; while (1) { cpu_used[hard_cpu_id()]++; msg = 0LL; bstat = 'r'; rt_mbx_receive(&smbx, &msg, sizeof(msg)); if (msg == 0x1122334455667788LL) { t = 0; } else { if (msg == 0x99aabbccddeeff00LL) { t = 1; } else { rt_printk("SERVER RECEIVED AN UNKNOWN MSG: %x%x, STAT: %c %c %c.\n", ((int *)&msg)[1], ((int *)&msg)[0], mstat[0], mstat[1], bstat); t = 0; goto prem; } } bstat = '0' + t; rt_mbx_send(&rmbx[t], &name, sizeof(name)); } prem: premature = PREMATURE; rt_printk("SERVER TASK ENDS PREMATURELY.\n"); }
static void Display_task(long t) { unsigned long command; int ackn = 0; RT_TASK *get = (RT_TASK *)0, *tput = (RT_TASK *)0, *hput = (RT_TASK *)0, *task; while (ackn != ('g' + 'p' + 'P')) { task = rt_receive((RT_TASK *)0, &command); switch (command) { case 'g': get = task; ackn += command; break; case 'p': tput = task; ackn += command; break; case 'P': hput = task; ackn += command; break; } } rt_return(get, command); rt_return(tput, command); rt_return(hput, command); while(1) { cpu_used[hard_cpu_id()]++; task = rt_receive(0, &command); if (task == tput || task == hput) { rt_send(get, command); } } }
static void ClockChrono_Write(long t) { Display_tDest receiver; MenageHmsh_tChain11 chain; char buf[25] = "00:00:00 00:00:00:00"; int i; while(1) { cpu_used[hard_cpu_id()]++; Display_Get(&chain, &receiver); if (receiver == destChrono) { for (i = 0; i < 11; i++) { buf[i+11] = chain.chain[i+1]; } } else { for (i = 0; i < 8; i++) { buf[i] = chain.chain[i+1]; } } /* printk("\r%s K ",buf); */ if (!hide && !pause) { rtf_put(Screen, chain.chain, 12); } } }
static void driver(int t) { RT_TASK *thread[NTASKS]; int i, l; unsigned int msg = 0; RTIME now; for (i = 1; i < NTASKS; i++) { thread[0] = rt_receive(0, &msg); thread[msg] = thread[0]; } for (i = 1; i < NTASKS; i++) { rt_return(thread[i], i); } now = rt_get_time(); rt_task_make_periodic(rt_whoami(), now + NTASKS*tick_period, tick_period); msg = 0; l = LOOPS; while(l--) { for (i = 1; i < NTASKS; i++) { cpu_used[hard_cpu_id()]++; if (i%2) { rt_rpc(thread[i], msg, &msg); } else { rt_send(thread[i], msg); msg = 1 - msg; } rt_task_wait_period(); } } for (i = 1; i < NTASKS; i++) { rt_send(thread[i], END); } }
static void CommandChrono_task(long t) { RTIME fiveSeconds = nano2count(FIVE_SECONDS); unsigned long command; unsigned int buffered = 0; unsigned int C = 'C'; unsigned int R = 'R'; int ackn = 0; RT_TASK *get = (RT_TASK *)0, *put = (RT_TASK *)0, *task; Chronostatus = stoppedInitial; while (ackn != ('c' + 'd')) { task = rt_receive((RT_TASK *)0, &command); switch (command) { case 'd': get = task; ackn += command; break; case 'c': put = task; ackn += command; break; } } rt_return(put, command); rt_return(get, command); while(1) { cpu_used[hard_cpu_id()]++; switch (Chronostatus) { case stoppedInitial: if (buffered) { command = buffered; buffered = 0; } else { rt_receive(put, &command); } Chronostatus = running; break; case running: if (rt_receive_if(put, &command)) { if (command == 'E') { Chronostatus = stoppedFinal; } } else { command = C; } break; case stoppedFinal: Chronostatus = stoppedInitial; if (rt_receive_timed(put, &command, fiveSeconds) > 0) { buffered = command; } command = R; break; } rt_send(get, command); } }
void fun(int t) { unsigned int loops = LOOPS; while(loops--) { cpu_used[hard_cpu_id()]++; outb(t, LPT); rt_task_wait_period(); } }
static void intr_handler(long t) { char wakeup; while(1) { cpu_used[hard_cpu_id()]++; rtf_put(CMDF, &wakeup, sizeof(wakeup)); rt_task_wait_period(); } }
int init_module(void) { RESET_COUNT = SECS*100; rt_mount_rtai(); rt_assign_irq_to_cpu(TIMER_8254_IRQ, 1 << hard_cpu_id()); rt_request_timer(just_ret, COUNT, 1); rt_request_global_irq(TIMER_8254_IRQ, calibrate); printk("\n->>> HERE WE GO (PRINTING EVERY %d SECONDS, 'make stop' to end calibrating) <<<-\n\n", RESET_COUNT/100); return 0; }
static void ClockChrono_Chrono(long t) { RTIME OneUnit = nano2count(ONE_UNIT); MenageHmsh_tHour times; MenageHmsh_tChain11 timesChain; BOOLEAN Intermediatetimes = FALSE; MenageHmsh_tHour endIntermediateTimes; BOOLEAN display; BOOLEAN hundredthes = FALSE; char command; unsigned long msg; rt_receive(&read, &msg); command = 'R'; while(1) { cpu_used[hard_cpu_id()]++; switch(command) { case 'R': MenageHmsh_Initialise(×); display = TRUE; hundredthes = FALSE; Intermediatetimes = FALSE; break; case 'C': rt_fractionated_sleep(OneUnit); MenageHmsh_PlusOneUnit(×, &display); if (Intermediatetimes) { Intermediatetimes = !MenageHmsh_Equal( times, endIntermediateTimes); display = !Intermediatetimes; hundredthes = FALSE; } break; case 'I': Intermediatetimes = TRUE; endIntermediateTimes = times; MenageHmsh_PlusNSeconds(3, &endIntermediateTimes); display = TRUE; hundredthes = TRUE; break; case 'E': display = TRUE; hundredthes = TRUE; } if (display) { MenageHmsh_Convert(times, hundredthes, ×Chain); Display_PutTimes(timesChain); } CommandChrono_Get(&command); } }
static void fun(int t) { unsigned int msg; rt_rpc(&thread[0], t, &msg); while(msg != END) { cpu_used[hard_cpu_id()]++; rt_receive(&thread[0], &msg); rt_leds_set_mask(1,msg); if (rt_isrpc(&thread[0])) { rt_return(&thread[0], 1 - msg); } } rt_leds_set_mask(1,0); }
static void Fast_Thread(long dummy) { int jit; RTIME svt, t; svt = rt_get_cpu_time_ns() - FASTMUL*TICK_TIME; while (1) { jit = (int) ((t = rt_get_cpu_time_ns()) - svt - FASTMUL*TICK_TIME); svt = t; if (jit) { jit = - jit; } if (jit > fastjit) { fastjit = jit; } cpu_used[hard_cpu_id()]++; rt_busy_sleep(FASTMUL/2*TICK_TIME); rt_task_wait_period(); } }
static void intr_handler(int t) { while(1) { cpu_used[hard_cpu_id()]++; t = imuldiv(maxj, 1000000, CPU_FREQ); rtf_put(CMDF, &t, sizeof(int)); if (Mode) { if (rt_sem_wait(&sem) >= SEM_TIMOUT) { return; } } else { rt_task_suspend(&thread); } } }
static void fun(long thread) { struct sample { long min, max, avrg, jitters[2]; } samp; int diff; int skip; int average; int min_diff; int max_diff; RTIME svt, t; t = 0; min_diff = 1000000000; max_diff = -1000000000; while (1) { unsigned long flags; average = 0; svt = rt_get_cpu_time_ns(); for (skip = 0; skip < NAVRG; skip++) { cpu_used[hard_cpu_id()]++; expected += period; rt_task_wait_period(); rt_global_save_flags(&flags); #ifndef ONESHOT_MODE diff = (int) ((t = rt_get_cpu_time_ns()) - svt - TICK_TIME); svt = t; #else diff = (int) count2nano(rt_get_time() - expected); #endif if (diff < min_diff) { min_diff = diff; } if (diff > max_diff) { max_diff = diff; } average += diff; } samp.min = min_diff; samp.max = max_diff; samp.avrg = average/NAVRG; samp.jitters[0] = fastjit; samp.jitters[1] = slowjit; rtf_ovrwr_put(FIFO, &samp, sizeof(samp)); } }
static void pend_task (long t) { unsigned long msg; while(1) { switch (change) { case 0: rt_task_suspend(thread + t); break; case 1: rt_sem_wait(&sem); break; case 2: rt_return(rt_receive(NULL, &msg), 0); break; } cpu_used[hard_cpu_id()]++; } }
static int lock_thread(void *null) { int cpu; sprintf(current->comm, "RTAI_LOCK"); current->nice = -20; cpu = -1; do { if (cpu != rtai_cpu) { current->cpus_allowed = 1 << (cpu = rtai_cpu); while (rtai_cpu != hard_cpu_id()) { current->state = TASK_INTERRUPTIBLE; schedule_timeout(2); } } } while (!signal_pending(current)); return 0; complete_and_exit(&lock_thread_exited, 0); }
static void ClockChrono_Clock(long t) { const int hundredthes = FALSE; MenageHmsh_tHour hour; MenageHmsh_tChain11 hourChain; char command; BOOLEAN display; rt_sem_wait(&sync); MenageHmsh_Initialise(&hour); /* MenageHmsh_Convert(hour, hundredthes, &hourChain); Display_PutHour(hourChain); */ while(1) { cpu_used[hard_cpu_id()]++; CommandClock_Get(&command); switch(command) { case 'R': rt_fractionated_sleep(OneUnit); MenageHmsh_PlusOneUnit(&hour, &display); break; case 'T': MenageHmsh_InitialiseHundredthes(&hour); display = FALSE; break; case 'H': MenageHmsh_AdvanceHours(&hour); display = TRUE; break; case 'M': MenageHmsh_AdvanceMinutes(&hour); display = TRUE; break; case 'S': MenageHmsh_AdvanceSeconds(&hour); display = TRUE; } if (display) { MenageHmsh_Convert(hour, hundredthes, &hourChain); Display_PutHour(hourChain); } } }
static void ClockChrono_Clock(long t) { RTIME OneUnit = nano2count(ONE_UNIT); const int hundredthes = FALSE; MenageHmsh_tHour hour; MenageHmsh_tChain11 hourChain; char command; BOOLEAN display; unsigned long msg; rt_receive(&read, &msg); MenageHmsh_Initialise(&hour); MenageHmsh_Convert(hour, hundredthes, &hourChain); Display_PutHour(hourChain); while(1) { cpu_used[hard_cpu_id()]++; CommandClock_Get(&command); switch(command) { case 'R': rt_fractionated_sleep(OneUnit); MenageHmsh_PlusOneUnit(&hour, &display); break; case 'T': MenageHmsh_InitialiseHundredthes(&hour); display = FALSE; break; case 'H': MenageHmsh_AdvanceHours(&hour); display = TRUE; break; case 'M': MenageHmsh_AdvanceMinutes(&hour); display = TRUE; break; case 'S': MenageHmsh_AdvanceSeconds(&hour); display = TRUE; } if (display) { MenageHmsh_Convert(hour, hundredthes, &hourChain); Display_PutHour(hourChain); } } }
static void mfun(long t) { RTIME time; unsigned long long msg; int size, maxt = 0, itime; while (1) { time = rt_get_cpu_time_ns(); cpu_used[hard_cpu_id()]++; mstat[t] = 's'; if ((size = rt_mbx_send_timed(&smbx, &name[t], sizeof(long long), nano2count(TIMEOUT)))) { rt_printk("SEND TIMEDOUT TASK: %d, UNSENT: %d, STAT: %c %c %c, OVERTIME: %d.\n", t, size, mstat[0], mstat[1], bstat, (int)(rt_get_cpu_time_ns() - time)); goto prem; } msg = 0; mstat[t] = 'r'; if ((size = rt_mbx_receive_timed(&rmbx[t], &msg, sizeof(msg), nano2count(TIMEOUT)))) { rt_printk("RECEIVE TIMEDOUT TIME: %d, NOTRECEIVED: %d, MSG: %x%x, STAT: %c %c %c, OVERTIME: %d.\n", t, size, ((int *)&msg)[1], ((int *)&msg)[0], mstat[0], mstat[1], bstat, (int)(rt_get_cpu_time_ns() - time)); goto prem; } if (msg != 0xccccccccccccccccLL) { rt_printk("WRONG REPLY TO TASK: %d, MSG: %x %x.\n", t, ((int *)&msg)[0], ((int *)&msg)[1]); goto prem; } mstat[t] = 'd'; if ((itime = rt_get_cpu_time_ns() - time) > maxt) { rt_printk("TASK: %d, MAXWAITIME: %d.\n", t, maxt = itime); } meant[t] = (itime + meant[t]) >> 1; rt_sleep(nano2count(SLEEP_TIME)); } prem: premature = PREMATURE; rt_printk("TASK # %d ENDS PREMATURELY\n", t); }
void fun(long thread) { int diff = 0; int i; int average; int min_diff = 0; int max_diff = 0; RTIME t, svt; #ifdef CONFIG_RTAI_FPU_SUPPORT if (use_fpu) { for(i = 0; i < MAXDIM; i++) { a[i] = b[i] = 3.141592; } } #endif svt = rt_get_cpu_time_ns(); samp.ovrn = 0; while (1) { min_diff = 1000000000; max_diff = -1000000000; average = 0; for (i = 0; i < loops; i++) { cpu_used[hard_cpu_id()]++; expected += period_counts; if (!rt_task_wait_period()) { if (timer_mode) { diff = (int) ((t = rt_get_cpu_time_ns()) - svt - period); svt = t; } else { diff = (int) count2nano(rt_get_time() - expected); } } else { samp.ovrn++; diff = 0; if (timer_mode) { svt = rt_get_cpu_time_ns(); } } if (diff < min_diff) { min_diff = diff; } if (diff > max_diff) { max_diff = diff; } average += diff; #ifdef CONFIG_RTAI_FPU_SUPPORT if (use_fpu) { dotres = dot(a, b, MAXDIM); } #endif } samp.min = min_diff; samp.max = max_diff; samp.index = average / loops; rtf_put(DEBUG_FIFO, &samp, sizeof (samp)); } rt_printk("\nDOT PRODUCT RESULT = %lu\n", (unsigned long)dotres); }
static long long user_srq(unsigned long whatever) { extern int calibrate_8254(void); unsigned long args[MAXARGS]; int ret; ret = copy_from_user(args, (unsigned long *)whatever, MAXARGS*sizeof(unsigned long)); switch (args[0]) { case CAL_8254: { return calibrate_8254(); break; } case KTHREADS: case KLATENCY: { rt_set_oneshot_mode(); period = start_rt_timer(nano2count(args[1])); if (args[0] == KLATENCY) { rt_task_init_cpuid(&rtask, spv, args[2], STACKSIZE, 0, 0, 0, hard_cpu_id()); } else { // rt_kthread_init_cpuid(&rtask, spv, args[2], STACKSIZE, 0, 0, 0, hard_cpu_id()); } expected = rt_get_time() + 100*period; rt_task_make_periodic(&rtask, expected, period); break; } case END_KLATENCY: { stop_rt_timer(); rt_task_delete(&rtask); break; } case FREQ_CAL: { times.intrs = -1; reset_count = args[1]*HZ; count = 0; rt_assign_irq_to_cpu(TIMER_8254_IRQ, 1 << hard_cpu_id()); rt_request_timer(just_ret, COUNT, 1); rt_request_global_irq(TIMER_8254_IRQ, calibrate); break; } case END_FREQ_CAL: { rt_free_timer(); rt_reset_irq_to_sym_mode(TIMER_8254_IRQ); rt_free_global_irq(TIMER_8254_IRQ); break; } case BUS_CHECK: { loops = maxj = 0; bus_period = imuldiv(args[1], CPU_FREQ, 1000000000); bus_threshold = imuldiv(args[2], CPU_FREQ, 1000000000); use_parport = args[3]; rt_assign_irq_to_cpu(TIMER_8254_IRQ, 1 << hard_cpu_id()); rt_request_timer((void *)rt_timer_tick_ext, imuldiv(args[1], FREQ_8254, 1000000000), 0); rt_set_global_irq_ext(TIMER_8254_IRQ, 1, 0); break; } case END_BUS_CHECK: { rt_free_timer(); rt_reset_irq_to_sym_mode(TIMER_8254_IRQ); break; } case GET_PARAMS: { rtf_put(0, ¶ms, sizeof(params)); break; } } return 0; }
void fun(long thread) { int diff = 0; int i; int average; int min_diff = 0; int max_diff = 0; RTIME t, svt; /* If we want to make overall statistics */ /* we have to reset min/max here */ if (overall) { min_diff = 1000000000; max_diff = -1000000000; } #ifdef CONFIG_RTAI_FPU_SUPPORT if (use_fpu) { for(i = 0; i < MAXDIM; i++) { a[i] = b[i] = 3.141592; } } refres = dot(a, b, MAXDIM); #endif svt = rt_get_cpu_time_ns(); while (1) { /* Not overall statistics: reset min/max */ if (!overall) { min_diff = 1000000000; max_diff = -1000000000; } average = 0; for (i = 0; i < loops; i++) { cpu_used[hard_cpu_id()]++; expected += period_counts; rt_task_wait_period(); if (timer_mode) { diff = (int) ((t = rt_get_cpu_time_ns()) - svt - period); svt = t; } else { diff = (int) count2nano(rt_get_time() - expected); } if (diff < min_diff) { min_diff = diff; } if (diff > max_diff) { max_diff = diff; } average += diff; #ifdef CONFIG_RTAI_FPU_SUPPORT if (use_fpu) { dotres = dot(a, b, MAXDIM); if ((tdif = dotres/refres - 1.0) < 0.0) { tdif = -tdif; } if (tdif > 1.0e-16) { rt_printk("\nDOT PRODUCT ERROR\n"); return; } } #endif } samp.min = min_diff; samp.max = max_diff; samp.index = average / loops; rtf_put(DEBUG_FIFO, &samp, sizeof (samp)); //while(1); } }