00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include<queue.h>
00013 #include <asmlink.h>
00014 #include <pridef.h>
00015 #include<ipldef.h>
00016 #include<lkbdef.h>
00017 #include<phddef.h>
00018 #include<ipl.h>
00019 #include <linux/linkage.h>
00020 #include <linux/sched.h>
00021
00022 #include <linux/errno.h>
00023 #include <linux/sched.h>
00024 #include <linux/kernel.h>
00025 #include <linux/param.h>
00026 #include <linux/string.h>
00027 #include <linux/mm.h>
00028 #include <linux/interrupt.h>
00029 #include <linux/time.h>
00030 #include <linux/delay.h>
00031 #include <linux/init.h>
00032 #include <linux/smp.h>
00033
00034 #include <asm/io.h>
00035 #include <asm/smp.h>
00036 #include <asm/irq.h>
00037 #include <asm/msr.h>
00038 #include <asm/delay.h>
00039 #include <asm/mpspec.h>
00040 #include <asm/uaccess.h>
00041 #include <asm/processor.h>
00042
00043 #include <linux/mc146818rtc.h>
00044 #include <linux/timex.h>
00045 #include <linux/config.h>
00046
00047 #include <asm/fixmap.h>
00048 #ifdef __i386__
00049 #include <asm/cobalt.h>
00050 #endif
00051
00052
00053
00054
00055 #include <linux/irq.h>
00056
00057 #include <linux/kernel_stat.h>
00058
00059 #include <asm/uaccess.h>
00060 #include <asm/hw_irq.h>
00061 #include <sysgen.h>
00062 #include <rse.h>
00063 #include <system_data_cells.h>
00064 #include <internals.h>
00065 #include <exe_routines.h>
00066 #include <misc_routines.h>
00067 #include <sch_routines.h>
00068 #include <ddbdef.h>
00069
00070 extern int pid1count;
00071 extern int pid0count;
00072
00073 extern int countme2;
00074
00075 #define TICK_SIZE tick
00076
00077 extern rwlock_t xtime_lock;
00078
00079 extern spinlock_t i8253_lock;
00080
00081 extern unsigned long last_tsc_low;
00082
00083 extern int mydebug5,mydebug6,in_idle_while;
00084
00085 extern int delay_at_last_interrupt;
00086
00087 extern long last_rtc_update;
00088
00089 extern int use_tsc;
00090
00091 int exetimeout=0;
00092
00093
00094
00095
00096
00097 void exe_timeout(void) {
00098
00099 sch_swpwake();
00100
00101 exe_gl_abstim++;
00102
00103
00104
00105 {
00106 struct _ddb * d=ioc_gl_devlist;
00107 if (d == 0) goto skip;
00108 do {
00109 #if 0
00110
00111 struct _sb * sb=d->ddb_ps_sb;
00112 if ((node==0) && sb)
00113 goto next;
00114 if (node && (sb==0))
00115 goto next;
00116 if (sb && 0!=strncmp(&sb->sb_t_nodename[1],node,nodelen))
00117 goto next;
00118 #endif
00119 struct _ucb * tmp = d->ddb_ps_ucb;
00120 do {
00121
00122 if (tmp->ucb_l_duetim && tmp->ucb$l_duetim < exe$gl_abstim) {
00123 if (tmp->ucb_l_fpc) {
00124
00125 printk("ucb timeout %x %x\n", tmp, tmp->ucb_l_irp);
00126
00127 tmp->ucb_l_fpc(tmp->ucb$l_fr3, tmp->ucb$l_fr4);
00128
00129 }
00130 }
00131 tmp=tmp->ucb_l_link;
00132 } while (tmp && tmp!=d->ddb_ps_ucb);
00133 next:
00134 d=d->ddb_ps_link;
00135 } while (d && d!=ioc_gl_devlist);
00136 skip:
00137 {}
00138 }
00139
00140
00141
00142
00143 if (lck_gq_timoutq)
00144 if (exe_gl_abstim>=((struct _lkb *)lck$gq_timoutq)->lkb$l_duetime)
00145 lck_searchdlck();
00146
00147 sch_one_sec();
00148
00149 #ifdef __i386__
00150 if (exetimeout) printk("exe_timeout %x %x %x\n",cur_task->pcb$l_pid,current->pcb$l_pid,current->thread.eip);
00151 #else
00152 if (exetimeout) printk("exe_timeout %x\n",current->pcb$l_pid);
00153 #endif
00154 }
00155
00156 extern int vmstimerconf;
00157
00158 void printtq(struct _tqe * t) {
00159 printk("%x %x %x %x\n",t,t->tqe_l_tqfl,t->tqe$q_delta,t->tqe$q_time);
00160 }
00161
00162
00163
00164
00165
00166 asmlinkage void exe_swtimint(void) {
00167 static signed int times=0;
00168
00169 #ifdef __x86_64__
00170 if (intr_blocked(IPL__TIMERFORK))
00171 return;
00172 regtrap(REG_INTR, IPL__TIMERFORK);
00173 #endif
00174
00175 setipl(IPL__TIMERFORK);
00176
00177
00178 times++;
00179
00180
00181
00182 if (current->pcb_w_quant>=0 && current->pcb$w_quant<128)
00183 sch_qend(current);
00184
00185
00186
00187
00188
00189 if (smp_processor_id()==0) {
00190
00191 vmslock(&SPIN_TIMER,IPL__TIMER);
00192 vmslock(&SPIN_HWCLK,IPL__HWCLK);
00193
00194
00195
00196
00197 while (vmstimerconf && exe_gq_systime>=exe$gq_1st_time) {
00198 struct _tqe * t, * dummy=0;
00199
00200
00201
00202
00203 t=remque(exe_gl_tqfl->tqe$l_tqfl,dummy);
00204
00205 vmsunlock(&SPIN_HWCLK,IPL__TIMER);
00206 vmsunlock(&SPIN_TIMER,-1);
00207
00208
00209
00210
00211 if ((t->tqe_b_rqtype & TQE$M_TQTYPE) == TQE$C_TMSNGL) {
00212
00213
00214 sch_postef(t->tqe$l_pid,PRI$_TIMER,t->tqe$b_efn);
00215
00216
00217
00218
00219
00220
00221 sch_qast(t->tqe$l_pid,PRI$_TIMER,(struct _acb *) t);
00222
00223
00224
00225
00226
00227 }
00228
00229 if ((t->tqe_b_rqtype & TQE$M_TQTYPE) == TQE$C_SSSNGL) {
00230 void (*f)(void);
00231 f=t->tqe_l_fpc;
00232
00233
00234 if (f) f();
00235
00236 }
00237
00238 if ((t->tqe_b_rqtype & TQE$M_TQTYPE) == TQE$C_WKSNGL) {
00239
00240 vmslock(&SPIN_SCHED,-1);
00241
00242
00243
00244
00245 sch_wake(t->tqe$l_pid);
00246
00247
00248 vmsunlock(&SPIN_SCHED,-1);
00249
00250
00251
00252 }
00253
00254 if (t->tqe_b_rqtype & TQE$M_REPEAT) {
00255 t->tqe_q_time=exe$gq_systime+t->tqe$q_delta;
00256
00257
00258
00259
00260 if (0 && times>1000 && times<1200) {
00261 printtq(t);
00262 printtq(exe_gl_tqfl);
00263 printtq(exe_gl_tqfl->tqe$l_tqfl);
00264 printtq(exe_gl_tqfl->tqe$l_tqfl->tqe$l_tqfl);
00265 }
00266 exe_instimq(t);
00267 if (0 && times>1000 && times<1200) {
00268 printtq(t);
00269 printtq(exe_gl_tqfl);
00270 printtq(exe_gl_tqfl->tqe$l_tqfl);
00271 printtq(exe_gl_tqfl->tqe$l_tqfl->tqe$l_tqfl);
00272 printk("i");
00273 }
00274
00275
00276
00277
00278
00279 }
00280
00281 vmslock(&SPIN_TIMER,IPL__TIMER);
00282 vmslock(&SPIN_HWCLK,IPL__HWCLK);
00283 exe_gq_1st_time=exe$gl_tqfl->tqe$l_tqfl->tqe$q_time;
00284 }
00285 vmsunlock(&SPIN_HWCLK,IPL__TIMER);
00286 vmsunlock(&SPIN_TIMER,-1);
00287 }
00288
00289
00290
00291
00292 }
00293
00294
00295 #ifdef __arch_um__
00296 #define QUANTADD 1
00297 #endif
00298 #ifdef __i386
00299
00300 #define QUANTADD 1
00301 #endif
00302 #ifdef __x86_64__
00303
00304 #define QUANTADD 1
00305 #endif
00306
00307 #ifdef __arch_um__
00308 extern int hwclkdone;
00309 #endif
00310
00311
00312
00313
00314
00315
00316 #ifdef __i386__
00317 void exe_hwclkint(int irq, void *dev_id, struct pt_regs *regs) {
00318
00319
00320
00321 #ifdef __arch_um__
00322 int hwclkdone=1;
00323 #endif
00324
00325 #if 0
00326
00327 if (intr_blocked(IPL__HWCLK))
00328 return;
00329
00330 regtrap(REG_INTR, IPL__HWCLK);
00331
00332 setipl(IPL__HWCLK);
00333 #endif
00334
00335
00336
00337
00338
00339
00340 if (smp_processor_id()==0) {
00341
00342 int count;
00343
00344 write_lock(&xtime_lock);
00345
00346 #ifndef __arch_um__
00347 if (use_tsc)
00348 {
00349 rdtscl(last_tsc_low);
00350
00351 spin_lock(&i8253_lock);
00352 outb_p(0x00, 0x43);
00353
00354 count = inb_p(0x40);
00355 count |= inb(0x40) << 8;
00356 spin_unlock(&i8253_lock);
00357
00358 count = ((LATCH-1) - count) * TICK_SIZE;
00359 delay_at_last_interrupt = (count + LATCH/2) / LATCH;
00360 }
00361
00362 #ifdef CONFIG_X86_IO_APIC
00363 extern int timer_ack;
00364 extern spinlock_t i8259A_lock;
00365 if (timer_ack) {
00366 spin_lock(&i8259A_lock);
00367 outb(0x0c, 0x20);
00368 inb(0x20);
00369 spin_unlock(&i8259A_lock);
00370 }
00371 #endif
00372 #endif
00373
00374
00375
00376
00377
00378 exe_gq_systime+=exe$gl_ticklength;
00379
00380 (*(unsigned long *)&jiffies)++;
00381 exe_gl_abstim_tics=jiffies;
00382
00383
00384
00385
00386 if (exe_gq_systime>=exe$gq_1st_time)
00387 SOFTINT_TIMERFORK_VECTOR;
00388
00389
00390
00391
00392
00393 #ifndef CONFIG_SMP_NOT_NOT
00394
00395 {
00396 int user_tick=user_mode(regs);
00397 struct task_struct *p = current;
00398 int cpu = smp_processor_id(), system = user_tick ^ 1;
00399
00400
00401 if (mydebug5 && !countme2--) {
00402 countme2=500; printk(",");
00403 printk("timer %x %x %x\n",p->pcb_l_pid,p->pcb$w_quant,p->pcb$b_pri);
00404 }
00405
00406
00407
00408
00409 update_one_process(p, user_tick, system, cpu);
00410 if (p->pcb_l_pid==0) { if (++pid0count>5) { pid0count=0; }}
00411 if (p->pcb_l_pid==INIT_PID) { if (++pid1count>5) { pid1count=0; }}
00412 if (p->pcb_l_pid) {
00413
00414 p->pcb_l_phd->phd$l_cputim++;
00415 p->pcb_w_quant+=QUANTADD;
00416
00417 if (++p->pcb_w_quant >= 0 ) {
00418 if (p->pcb_w_quant<128) {
00419 SOFTINT_TIMERFORK_VECTOR;
00420
00421 }
00422 }
00423
00424 if (p->pcb_b_prib == 31)
00425 kstat.per_cpu_nice[cpu] += user_tick;
00426 else
00427 kstat.per_cpu_user[cpu] += user_tick;
00428 kstat.per_cpu_system[cpu] += system;
00429 } else if (local_bh_count(cpu) || local_irq_count(cpu) > 1)
00430 kstat.per_cpu_system[cpu] += system;
00431 }
00432 #endif
00433
00434 #ifndef CONFIG_VMS
00435 mark_bh(TIMER_BH);
00436 if (TQ_ACTIVE(tq_timer))
00437 mark_bh(TQUEUE_BH);
00438 #endif
00439
00440 #ifdef __i386__
00441 #ifndef CONFIG_X86_LOCAL_APIC
00442 if (!user_mode(regs))
00443 x86_do_profile(regs->eip);
00444 #else
00445 if (!using_apic_timer)
00446 smp_local_timer_interrupt(regs);
00447 #endif
00448 #endif
00449
00450 if ((time_status & STA_UNSYNC) == 0 &&
00451 #ifndef __arch_um__
00452 xtime.tv_sec > last_rtc_update + 660 &&
00453 #endif
00454 xtime.tv_usec >= 500000 - ((unsigned) tick) / 2 &&
00455 xtime.tv_usec <= 500000 + ((unsigned) tick) / 2) {
00456 #ifndef __arch_um__
00457 if (set_rtc_mmss(xtime.tv_sec) == 0)
00458 last_rtc_update = xtime.tv_sec;
00459 else
00460 last_rtc_update = xtime.tv_sec - 600;
00461 #endif
00462 }
00463
00464 write_unlock(&xtime_lock);
00465 }
00466 }
00467 #endif
00468
00469
00470
00471
00472
00473
00474 #ifdef __x86_64__
00475 extern unsigned int hpet_tick;
00476 extern int report_lost_ticks;
00477 void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
00478 {
00479 static unsigned long rtc_update = 0;
00480
00481
00482
00483
00484
00485
00486
00487
00488 #if 0
00489
00490
00491 if (intr_blocked(IPL__HWCLK))
00492 return;
00493
00494 regtrap(REG_INTR, IPL__HWCLK);
00495
00496 setipl(IPL__HWCLK);
00497 #endif
00498
00499
00500
00501
00502
00503 write_lock(&xtime_lock);
00504 vxtime_lock();
00505
00506 {
00507 long tsc;
00508 int delay, offset = 0;
00509
00510 if (hpet_address) {
00511
00512 offset = hpet_readl(HPET_T0_CMP) - hpet_tick;
00513 delay = hpet_readl(HPET_COUNTER) - offset;
00514
00515 } else {
00516
00517 spin_lock(&i8253_lock);
00518 outb_p(0x00, 0x43);
00519 delay = inb_p(0x40);
00520 delay |= inb(0x40) << 8;
00521 spin_unlock(&i8253_lock);
00522 delay = LATCH - 1 - delay;
00523 }
00524
00525 rdtscll_sync(&tsc);
00526
00527 if (vxtime.mode == VXTIME_HPET) {
00528
00529 if (offset - vxtime.last > hpet_tick) {
00530 if (report_lost_ticks)
00531 printk(KERN_WARNING "time.c: Lost %d timer tick(s)! (rip %016lx)\n",
00532 (offset - vxtime.last) / hpet_tick - 1, regs->rip);
00533 jiffies += (offset - vxtime.last) / hpet_tick - 1;
00534 }
00535
00536 vxtime.last = offset;
00537
00538 } else {
00539
00540 offset = (((tsc - vxtime.last_tsc) * vxtime.tsc_quot) >> 32) - tick;
00541
00542 if (offset > tick) {
00543 if (report_lost_ticks)
00544 printk(KERN_WARNING "time.c: lost %ld tick(s) (rip %016lx)\n",
00545 offset / tick, regs->rip);
00546 jiffies += offset / tick;
00547 offset %= tick;
00548 }
00549
00550 vxtime.last_tsc = tsc - vxtime.quot * delay / vxtime.tsc_quot;
00551
00552 if ((((tsc - vxtime.last_tsc) * vxtime.tsc_quot) >> 32) < offset)
00553 vxtime.last_tsc = tsc - (((long)offset << 32) / vxtime.tsc_quot) - 1;
00554
00555 }
00556 }
00557
00558
00559
00560
00561
00562 exe_gq_systime+=exe$gl_ticklength;
00563
00564 exe_gl_abstim_tics=jiffies;
00565
00566
00567
00568
00569 if (exe_gq_systime>=exe$gq_1st_time)
00570 SOFTINT_TIMERFORK_VECTOR;
00571
00572
00573
00574
00575
00576 int cpu = smp_processor_id();
00577 struct _pcb * p = ctl_gl_pcb;
00578 if (p->pcb_l_pid==0) { if (++pid0count>5) { pid0count=0; }}
00579 if (p->pcb_l_pid==INIT_PID) { if (++pid1count>5) { pid1count=0; }}
00580 if (p->pcb_l_pid) {
00581
00582 p->pcb_l_phd->phd$l_cputim++;
00583 p->pcb_w_quant+=QUANTADD;
00584
00585 if (++p->pcb_w_quant >= 0 ) {
00586 if (p->pcb_w_quant<128) {
00587 SOFTINT_TIMERFORK_VECTOR;
00588
00589 }
00590 }
00591
00592 }
00593 #if 0
00594
00595 if (p->pcb_b_prib == 31)
00596 kstat.per_cpu_nice[cpu] += user_tick;
00597 else
00598 kstat.per_cpu_user[cpu] += user_tick;
00599 kstat.per_cpu_system[cpu] += system;
00600 #endif
00601
00602
00603
00604
00605
00606 do_timer(regs);
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 if ((~time_status & STA_UNSYNC) && xtime.tv_sec > rtc_update &&
00617 abs(xtime.tv_usec - 500000) <= tick / 2) {
00618 set_rtc_mmss(xtime.tv_sec);
00619 rtc_update = xtime.tv_sec + 660;
00620 }
00621
00622 vxtime_unlock();
00623 write_unlock(&xtime_lock);
00624 }
00625 #endif
00626