]> Zhao Yanbai Git Server - minix.git/commitdiff
Use int64 functions consistently
authorArun Thomas <arun@minix3.org>
Sun, 7 Nov 2010 23:35:29 +0000 (23:35 +0000)
committerArun Thomas <arun@minix3.org>
Sun, 7 Nov 2010 23:35:29 +0000 (23:35 +0000)
Instead of manipulating the u64_t type directly, use the
ex64hi()/ex64lo()/make64() functions.

drivers/hello/hello.c
kernel/arch/i386/apic.c
kernel/arch/i386/arch_clock.c
kernel/arch/i386/arch_system.c
kernel/arch/i386/arch_watchdog.c
kernel/debug.c
lib/libc/ansi/malloc-debug.c
lib/libsys/profile.c

index 1846468d0ec000f2d5ddc61ea0f6b84953c8e87b..daadad1f80e2111daec6b9e13141405caa2ccb0b 100644 (file)
@@ -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;
index 4bd617bf289b13517b0ede2b1aaa5cf566a41977..4f04b8ef56c0d3f4e3009ad4639d028aaa57ba12 100644 (file)
@@ -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;
 }
index 2f6ff1eef5dc45e905d9967f4decb4ac4ce53a52..b07dacf912a03d62a8ff9b0fc1f0e23e379379a4 100644 (file)
@@ -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;
index 5b005c5c80366b808b16ee7699ce0155ebcbd151..3200f5d1d4de4cede270a42278bef4fb8f97a2a6 100644 (file)
@@ -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]);
        }
 }
index 56861a11d45739ccb6b86934a7794fecdd856ae2..ac30dc4f646673050013cc04437b5ab71e3dbce2 100644 (file)
@@ -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)
index 4c1865c7248ed8d97597ed0194986ab8e9fde356..c946bc9ec55e572c698e955baa02b07ef31f48ba 100644 (file)
@@ -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));
index 7b5ffe61e098894a2a133848d9e7e32bee26e6e0..cb572cf34edbfbb5dd4b3358bae6e970a3ebeac6 100644 (file)
@@ -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 */
index 48e063aa8fb4d1a18f5067f0539dbc1057f901e3..d325749d0eadf99affc3e1dffb964e6aff8f8fe5 100644 (file)
@@ -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);
   }
 }