From: Arun Thomas Date: Sun, 7 Nov 2010 23:35:29 +0000 (+0000) Subject: Use int64 functions consistently X-Git-Tag: v3.2.0~751 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=aaaad892442a6b37a14930b4e799e6c764c7bc67;p=minix.git Use int64 functions consistently Instead of manipulating the u64_t type directly, use the ex64hi()/ex64lo()/make64() functions. --- diff --git a/drivers/hello/hello.c b/drivers/hello/hello.c index 1846468d0..daadad1f8 100644 --- a/drivers/hello/hello.c +++ b/drivers/hello/hello.c @@ -72,10 +72,8 @@ PRIVATE int hello_close(d, m) PRIVATE struct device * hello_prepare(dev) int dev; { - hello_device.dv_base.lo = 0; - hello_device.dv_base.hi = 0; - hello_device.dv_size.lo = strlen(HELLO_MESSAGE); - hello_device.dv_size.hi = 0; + hello_device.dv_base = make64(0, 0); + hello_device.dv_size = make64(strlen(HELLO_MESSAGE), 0); return &hello_device; } @@ -90,8 +88,8 @@ PRIVATE int hello_transfer(proc_nr, opcode, position, iov, nr_req) printf("hello_transfer()\n"); - bytes = strlen(HELLO_MESSAGE) - position.lo < iov->iov_size ? - strlen(HELLO_MESSAGE) - position.lo : iov->iov_size; + bytes = strlen(HELLO_MESSAGE) - ex64lo(position) < iov->iov_size ? + strlen(HELLO_MESSAGE) - ex64lo(position) : iov->iov_size; if (bytes <= 0) { @@ -101,7 +99,7 @@ PRIVATE int hello_transfer(proc_nr, opcode, position, iov, nr_req) { case DEV_GATHER_S: ret = sys_safecopyto(proc_nr, iov->iov_addr, 0, - (vir_bytes) (HELLO_MESSAGE + position.lo), + (vir_bytes) (HELLO_MESSAGE + ex64lo(position)), bytes, D); iov->iov_size -= bytes; break; diff --git a/kernel/arch/i386/apic.c b/kernel/arch/i386/apic.c index 4bd617bf2..4f04b8ef5 100644 --- a/kernel/arch/i386/apic.c +++ b/kernel/arch/i386/apic.c @@ -570,13 +570,12 @@ PRIVATE u32_t lapic_errstatus(void) PRIVATE int lapic_disable_in_msr(void) { - u64_t msr; - u32_t addr; + u32_t addr, msr_hi, msr_lo; - ia32_msr_read(IA32_APIC_BASE, &msr.hi, &msr.lo); + ia32_msr_read(IA32_APIC_BASE, &msr_hi, &msr_lo); - msr.lo &= ~(1 << IA32_APIC_BASE_ENABLE_BIT); - ia32_msr_write(IA32_APIC_BASE, msr.hi, msr.lo); + msr_lo &= ~(1 << IA32_APIC_BASE_ENABLE_BIT); + ia32_msr_write(IA32_APIC_BASE, msr_hi, msr_lo); return 1; } @@ -618,10 +617,9 @@ PUBLIC void lapic_disable(void) PRIVATE int lapic_enable_in_msr(void) { - u64_t msr; - u32_t addr; + u32_t addr, msr_hi, msr_lo; - ia32_msr_read(IA32_APIC_BASE, &msr.hi, &msr.lo); + ia32_msr_read(IA32_APIC_BASE, &msr_hi, &msr_lo); #if 0 /*FIXME this is a problem on AP */ @@ -629,18 +627,18 @@ PRIVATE int lapic_enable_in_msr(void) * FIXME if the location is different (unlikely) then the one we expect, * update it */ - addr = (msr.lo >> 12) | ((msr.hi & 0xf) << 20); + addr = (msr_lo >> 12) | ((msr_hi & 0xf) << 20); if (phys2vir(addr) != (lapic_addr >> 12)) { - if (msr.hi & 0xf) { + if (msr_hi & 0xf) { printf("ERROR : APIC address needs more then 32 bits\n"); return 0; } - lapic_addr = phys2vir(msr.lo & ~((1 << 12) - 1)); + lapic_addr = phys2vir(msr_lo & ~((1 << 12) - 1)); } #endif - msr.lo |= (1 << IA32_APIC_BASE_ENABLE_BIT); - ia32_msr_write(IA32_APIC_BASE, msr.hi, msr.lo); + msr_lo |= (1 << IA32_APIC_BASE_ENABLE_BIT); + ia32_msr_write(IA32_APIC_BASE, msr_hi, msr_lo); return 1; } diff --git a/kernel/arch/i386/arch_clock.c b/kernel/arch/i386/arch_clock.c index 2f6ff1eef..b07dacf91 100644 --- a/kernel/arch/i386/arch_clock.c +++ b/kernel/arch/i386/arch_clock.c @@ -251,9 +251,9 @@ PUBLIC void context_stop(struct proc * p) make_zero64(p->p_cpu_time_left); #else /* if (tsc_delta < p->p_cpu_time_left) in 64bit */ - if (tsc_delta.hi < p->p_cpu_time_left.hi || - (tsc_delta.hi == p->p_cpu_time_left.hi && - tsc_delta.lo < p->p_cpu_time_left.lo)) + if (ex64hi(tsc_delta) < ex64hi(p->p_cpu_time_left) || + (ex64hi(tsc_delta) == ex64hi(p->p_cpu_time_left) && + ex64lo(tsc_delta) < ex64lo(p->p_cpu_time_left))) p->p_cpu_time_left = sub64(p->p_cpu_time_left, tsc_delta); else { make_zero64(p->p_cpu_time_left); @@ -315,7 +315,7 @@ PUBLIC short cpu_load(void) busy = sub64(tsc_delta, idle_delta); busy = mul64(busy, make64(100, 0)); - load = div64(busy, tsc_delta).lo; + load = ex64lo(div64(busy, tsc_delta)); if (load > 100) load = 100; diff --git a/kernel/arch/i386/arch_system.c b/kernel/arch/i386/arch_system.c index 5b005c5c8..3200f5d1d 100644 --- a/kernel/arch/i386/arch_system.c +++ b/kernel/arch/i386/arch_system.c @@ -478,8 +478,10 @@ PRIVATE void dump_bkl_usage(void) printf("--- BKL usage ---\n"); for (cpu = 0; cpu < ncpus; cpu++) { printf("cpu %3d kernel ticks 0x%x%08x bkl ticks 0x%x%08x succ %d tries %d\n", cpu, - kernel_ticks[cpu].hi, kernel_ticks[cpu].lo, - bkl_ticks[cpu].hi, bkl_ticks[cpu].lo, + ex64hi(kernel_ticks[cpu]), + ex64lo(kernel_ticks[cpu]), + ex64hi(bkl_ticks[cpu]), + ex64lo(bkl_ticks[cpu]), bkl_succ[cpu], bkl_tries[cpu]); } } diff --git a/kernel/arch/i386/arch_watchdog.c b/kernel/arch/i386/arch_watchdog.c index 56861a11d..ac30dc4f6 100644 --- a/kernel/arch/i386/arch_watchdog.c +++ b/kernel/arch/i386/arch_watchdog.c @@ -37,12 +37,12 @@ PRIVATE void intel_arch_watchdog_init(const unsigned cpu) * lowest 31 bits writable :( */ cpuf = cpu_get_freq(cpu); - while (cpuf.hi || cpuf.lo > 0x7fffffffU) + while (ex64hi(cpuf) || ex64lo(cpuf) > 0x7fffffffU) cpuf = div64u64(cpuf, 2); - cpuf.lo = -cpuf.lo; + cpuf = make64(-ex64lo(cpuf), ex64hi(cpuf)); watchdog->resetval = watchdog->watchdog_resetval = cpuf; - ia32_msr_write(INTEL_MSR_PERFMON_CRT0, 0, cpuf.lo); + ia32_msr_write(INTEL_MSR_PERFMON_CRT0, 0, ex64lo(cpuf)); ia32_msr_write(INTEL_MSR_PERFMON_SEL0, 0, val | INTEL_MSR_PERFMON_SEL0_ENABLE); @@ -54,7 +54,7 @@ PRIVATE void intel_arch_watchdog_init(const unsigned cpu) PRIVATE void intel_arch_watchdog_reinit(const unsigned cpu) { lapic_write(LAPIC_LVTPCR, APIC_ICR_DM_NMI); - ia32_msr_write(INTEL_MSR_PERFMON_CRT0, 0, watchdog->resetval.lo); + ia32_msr_write(INTEL_MSR_PERFMON_CRT0, 0, ex64lo(watchdog->resetval)); } PUBLIC int arch_watchdog_init(void) @@ -170,12 +170,12 @@ PRIVATE int intel_arch_watchdog_profile_init(const unsigned freq) * if freq is too low and the cpu freq too high we may get in a range of * insane value which cannot be handled by the 31bit CPU perf counter */ - if (cpuf.hi != 0 || cpuf.lo > 0x7fffffffU) { + if (ex64hi(cpuf) != 0 || ex64lo(cpuf) > 0x7fffffffU) { printf("ERROR : nmi watchdog ticks exceed 31bits, use higher frequency\n"); return EINVAL; } - cpuf.lo = -cpuf.lo; + cpuf = make64(-ex64lo(cpuf), ex64hi(cpuf)); watchdog->profile_resetval = cpuf; return OK; @@ -207,7 +207,7 @@ PRIVATE void amd_watchdog_init(const unsigned cpu) watchdog->resetval = watchdog->watchdog_resetval = cpuf; ia32_msr_write(AMD_MSR_EVENT_CTR0, - watchdog->resetval.hi, watchdog->resetval.lo); + ex64hi(watchdog->resetval), ex64lo(watchdog->resetval)); ia32_msr_write(AMD_MSR_EVENT_SEL0, 0, val | AMD_MSR_EVENT_SEL0_ENABLE); @@ -220,7 +220,7 @@ PRIVATE void amd_watchdog_reinit(const unsigned cpu) { lapic_write(LAPIC_LVTPCR, APIC_ICR_DM_NMI); ia32_msr_write(AMD_MSR_EVENT_CTR0, - watchdog->resetval.hi, watchdog->resetval.lo); + ex64hi(watchdog->resetval), ex64lo(watchdog->resetval)); } PRIVATE int amd_watchdog_profile_init(const unsigned freq) diff --git a/kernel/debug.c b/kernel/debug.c index 4c1865c72..c946bc9ec 100644 --- a/kernel/debug.c +++ b/kernel/debug.c @@ -262,7 +262,8 @@ PUBLIC void print_proc(struct proc *pp) "cr3 0x%lx rts %s misc %s sched %s ", proc_nr(pp), pp->p_name, pp->p_endpoint, pp->p_priority, pp->p_user_time, - pp->p_sys_time, pp->p_cycles.hi, pp->p_cycles.lo, pp->p_cpu, + pp->p_sys_time, ex64hi(pp->p_cycles), + ex64lo(pp->p_cycles), pp->p_cpu, pp->p_seg.p_cr3, rtsflagstr(pp->p_rts_flags), miscflagstr(pp->p_misc_flags), schedulerstr(pp->p_scheduler)); diff --git a/lib/libc/ansi/malloc-debug.c b/lib/libc/ansi/malloc-debug.c index 7b5ffe61e..cb572cf34 100644 --- a/lib/libc/ansi/malloc-debug.c +++ b/lib/libc/ansi/malloc-debug.c @@ -126,7 +126,7 @@ static struct block *block_alloc(size_t size) read_tsc_64(&tsc); totalsize = block_get_totalsize(size); page_index_max = (ptr_max - ptr_min - totalsize) / PAGE_SIZE; - page_index = (page_index_max > 0) ? (tsc.lo % page_index_max) : 0; + page_index = (page_index_max > 0) ? (ex64lo(tsc) % page_index_max) : 0; ptr = ptr_min + page_index * PAGE_SIZE; /* allocate block */ diff --git a/lib/libsys/profile.c b/lib/libsys/profile.c index 48e063aa8..d325749d0 100644 --- a/lib/libsys/profile.c +++ b/lib/libsys/profile.c @@ -170,12 +170,14 @@ PUBLIC void procentry (char *name) PUBLIC void procexit (char *UNUSED(name)) { u64_t stop, spent; + u32_t tsc_lo, tsc_hi; /* Procexit is not reentrant. */ if (cprof_locked) return; else cprof_locked = 1; /* First thing: read CPU cycle count into local variable. */ - read_tsc(&stop.hi, &stop.lo); + read_tsc(&tsc_hi, &tsc_lo); + stop = make64(tsc_lo, tsc_hi); /* Only continue if sane. */ if (control.err) return; @@ -210,7 +212,8 @@ PUBLIC void procexit (char *UNUSED(name)) */ /* Read CPU cycle count. */ - read_tsc(&stop.hi, &stop.lo); + read_tsc(&tsc_hi, &tsc_lo); + stop = make64(tsc_lo, tsc_hi); /* Calculate "big" difference. */ spent = sub64(stop, cprof_stk[cprof_stk_top].start_1); @@ -263,8 +266,7 @@ PRIVATE void clear_tbl() memset(cprof_tbl[i].cpath, '\0', CPROF_CPATH_MAX_LEN); cprof_tbl[i].next = 0; cprof_tbl[i].calls = 0; - cprof_tbl[i].cycles.lo = 0; - cprof_tbl[i].cycles.hi = 0; + cprof_tbl[i].cycles = make64(0, 0); } }