int __init calibrate_APIC_clock(void) { int apic, apic_start, tsc, tsc_start; int result; /* * Put whatever arbitrary (but long enough) timeout * value into the APIC clock, we just want to get the * counter running for calibration. */ __setup_APIC_LVTT(1000000000); apic_start = apic_read(APIC_TMCCT); rdtscl(tsc_start); do { apic = apic_read(APIC_TMCCT); rdtscl(tsc); } while ((tsc - tsc_start) < TICK_COUNT && (apic - apic_start) < TICK_COUNT); result = (apic_start - apic) * 1000L * cpu_khz / (tsc - tsc_start); printk("Detected %d.%03d MHz APIC timer.\n", result / 1000 / 1000, result / 1000 % 1000); return result * APIC_DIVISOR / HZ; }
void __delay(unsigned long loops) { unsigned bclock, now; int cpu; preempt_disable(); cpu = smp_processor_id(); rdtscl(bclock); for (;;) { rdtscl(now); if ((now - bclock) >= loops) break; /* Allow RT tasks to run */ preempt_enable(); rep_nop(); preempt_disable(); /* * It is possible that we moved to another CPU, and * since TSC's are per-cpu we need to calculate * that. The delay must guarantee that we wait "at * least" the amount of time. Being moved to another * CPU could make the wait longer but we just need to * make sure we waited long enough. Rebalance the * counter for this CPU. */ if (unlikely(cpu != smp_processor_id())) { loops -= (now - bclock); cpu = smp_processor_id(); rdtscl(bclock); } } preempt_enable(); }
int main() { unsigned long ini,end; rdtscl(ini);rdtscl(end); printf("\n Time Diff:[%ld - %ld]= %d",end,ini,(end-ini)); return 0; }
static int __init calibrate_APIC_clock(void) { int apic, apic_start, tsc, tsc_start; int result; u64 wallclock_nsecs; /* * Put whatever arbitrary (but long enough) timeout * value into the APIC clock, we just want to get the * counter running for calibration. */ __setup_APIC_LVTT(1000000000, 0); apic_start = apic_read(APIC_TMCCT); #ifdef CONFIG_X86_PM_TIMER if (apic_calibrate_pmtmr && pmtmr_ioport) { pmtimer_wait(5000); /* 5ms wait */ apic = apic_read(APIC_TMCCT); result = (apic_start - apic) * 1000L / 5; printk("using pmtimer for lapic calibration\n"); wallclock_nsecs = 5000000; } else #endif { rdtscl(tsc_start); do { apic = apic_read(APIC_TMCCT); rdtscl(tsc); } while ((tsc - tsc_start) < TICK_COUNT && (apic - apic_start) < TICK_COUNT); result = (apic_start - apic) * 1000L * cpu_khz / (tsc - tsc_start); wallclock_nsecs = ((u64)tsc - (u64)tsc_start) * 1000000 / (u64)cpu_khz; } printk("result %d\n", result); printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n", result / 1000 / 1000, result / 1000 % 1000); /* Calculate the scaled math multiplication factor */ lapic_clockevent.mult = div_sc(apic_start - apic, wallclock_nsecs, 32); lapic_clockevent.max_delta_ns = clockevent_delta2ns(0x7FFFFF, &lapic_clockevent); printk("lapic max_delta_ns: %ld\n", lapic_clockevent.max_delta_ns); lapic_clockevent.min_delta_ns = clockevent_delta2ns(0xF, &lapic_clockevent); return result * APIC_DIVISOR / HZ; }
/* TSC based delay: */ static notrace void delay_tsc(unsigned long loops) { unsigned long bclock, now; rdtscl(bclock); do { rep_nop(); rdtscl(now); } while ((now-bclock) < loops); }
void __delay(unsigned long loops) { unsigned bclock, now; rdtscl(bclock); do { rep_nop(); rdtscl(now); } while((now-bclock) < loops); }
static int word_count_init(void) { ret = misc_register(&misc); //成功注册,返回非0整数,失败返回0 printk("word_count_init_success:%d\n",ret); unsigned long start, end; rdtscl(start); rdtscl(end); printk("time:%li\n",end - start); return ret; }
static void RdtscDelay(unsigned long loops) { unsigned beginClock, now; rdtscl(beginClock); do { asm volatile("rep; nop"); rdtscl(now); }while ((now-beginClock) < loops); }
/* TSC based delay: */ static void delay_tsc(unsigned long loops) { unsigned long bclock, now; preempt_disable(); /* TSC's are per-cpu */ rdtscl(bclock); do { rep_nop(); rdtscl(now); } while ((now-bclock) < loops); preempt_enable(); }
uint32_t arch_cycle_count(void) { uint32_t timestamp; rdtscl(timestamp); return timestamp; }
int __devinit read_current_timer(unsigned long *timer_val) { if (delay_fn == delay_tsc) { rdtscl(*timer_val); return 0; } return -1; }
/** Determine cpu ticks per microsecond. */ double get_cycles_per_usec(void) { unsigned long pre, post; struct timespec start_t, end_t; unsigned long tsc_start, tsc_end; double elapsed; int i; load_cpu(); /* read timestamp counter before and after getting wall time */ pre = rdtscl(); clock_gettime(CLOCK_MONOTONIC, &start_t); post = rdtscl(); /* average timestamps */ tsc_start = ((double)pre + (double)post)/2; /* pass some time burning CPU */ for (i = 0; i<10; i++) load_cpu(); /* get another reading */ pre = rdtscl(); clock_gettime(CLOCK_MONOTONIC, &end_t); post = rdtscl(); tsc_end =((double)pre + (double)post)/2; /* get elapsed wall time */ struct timespec delta; delta.tv_sec = end_t.tv_sec - start_t.tv_sec; delta.tv_nsec = end_t.tv_nsec - start_t.tv_nsec; /* handle nsec wrapping */ if (delta.tv_nsec < 0) { delta.tv_nsec += 1e9; delta.tv_sec--; } /* In usec */ elapsed = delta.tv_nsec / 1000 + delta.tv_sec * 1e6; return (tsc_end - tsc_start) / elapsed; }
uint osl_getcycles(void) { uint cycles; #if defined(__i386__) rdtscl(cycles); #else cycles = 0; #endif return cycles; }
void test_ralign (const char *src, size_t len) { unsigned long t1, t2; char *r1 = malloc(2048); char *r2 = malloc(2048); char *r3 = malloc(2048); old_str_pad_to_r(r1, src, len); rdtscl(t1); old_str_pad_to_r(r1, src, len); rdtscl(t2); printf("old - %5lu:\n%s\n\n", t2 - t1, r1); new_str_pad_to_r(r2, src, len); rdtscl(t1); new_str_pad_to_r(r2, src, len); rdtscl(t2); printf("new - %5lu:\n%s\n\n", t2 - t1, r2); asm_str_pad_to_r(r3, src, len); rdtscl(t1); asm_str_pad_to_r(r3, src, len); rdtscl(t2); printf("asm - %5lu:\n%s\n\n", t2 - t1, r3); free(r1); free(r2); free(r3); }
static int __init calibrate_APIC_clock(void) { int apic, apic_start, tsc, tsc_start; int result; /* * Put whatever arbitrary (but long enough) timeout * value into the APIC clock, we just want to get the * counter running for calibration. */ __setup_APIC_LVTT(1000000000); apic_start = apic_read(APIC_TMCCT); #ifdef CONFIG_X86_PM_TIMER if (apic_calibrate_pmtmr && pmtmr_ioport) { pmtimer_wait(5000); /* 5ms wait */ apic = apic_read(APIC_TMCCT); result = (apic_start - apic) * 1000L / 5; } else #endif { rdtscl(tsc_start); do { apic = apic_read(APIC_TMCCT); rdtscl(tsc); } while ((tsc - tsc_start) < TICK_COUNT && (apic - apic_start) < TICK_COUNT); result = (apic_start - apic) * 1000L * cpu_khz / (tsc - tsc_start); } printk("result %d\n", result); printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n", result / 1000 / 1000, result / 1000 % 1000); return result * APIC_DIVISOR / HZ; }
uint osl_getcycles(void) { uint cycles; #if defined(mips) cycles = read_c0_count() * 2; #elif defined(__i386__) rdtscl(cycles); #else cycles = 0; #endif return cycles; }
static inline long send_pulse_homebrew_softcarrier(unsigned long length) { int flag; unsigned long target, start, now; /* Get going quick as we can */ rdtscl(start);on(); /* Convert length from microseconds to clocks */ length*=conv_us_to_clocks; /* And loop till time is up - flipping at right intervals */ now=start; target=pulse_width; flag=1; while((now-start)<length) { /* Delay till flip time */ do { rdtscl(now); } while ((now-start)<target); /* flip */ if(flag) { rdtscl(now);off(); target+=space_width; } else { rdtscl(now);on(); target+=pulse_width; } flag=!flag; } rdtscl(now); return(((now-start)-length)/conv_us_to_clocks); }
void timerCallback() { count++; if (count == 1000/50) { unsigned long now ; char buffer[200]; count = 0; rdtscl(now); itoa(now, buffer,10); videocpy(0,22,buffer); strcat(buffer, " "); } eoi(master); }
int search_file (const char *path, const char *term) { int i; char *text; int text_len; size_t term_len = strlen(term); int rk_found, kp_found, am_found; size_t *rk_pos_array, *kp_pos_array, *am_pos_array; unsigned long t1, t2; if ((text_len = read_file(path, &text)) <= 0) perror("file read"); printf("read %d bytes, searching for \"%s\" in \"%s\"\n", text_len, term, path); rdtscl(t1); if ((rk_found = rk_search(text, term, text_len, term_len, &rk_pos_array)) <= 0) printf("error searching\n"); rdtscl(t2); printf("rk: found %d in %ld cycles\n", rk_found, t2 - t1); rdtscl(t1); if ((kp_found = kmp_search(text, term, text_len, term_len, &kp_pos_array)) <= 0) printf("error searching\n"); rdtscl(t2); printf("kmp: found %d in %ld cycles\n", kp_found, t2 - t1); rdtscl(t1); if ((am_found = am_search(text, term, text_len, term_len, &am_pos_array)) <= 0) printf("error searching\n"); rdtscl(t2); printf("am: found %d in %ld cycles\n", am_found, t2 - t1); if (kp_found != rk_found || kp_found != am_found) { printf("error!\n"); } for (i = 0; i < kp_found; i++) { if (kp_pos_array[i] != rk_pos_array[i] || kp_pos_array[i] != am_pos_array[i]) printf("search term %d error\n", i); // printf("%ld/%ld/%ld: %.10s\n", kp_pos_array[i], rk_pos_array[i], am_pos_array[i], text + rk_pos_array[i]); } free(kp_pos_array); free(rk_pos_array); free(am_pos_array); free(text); return 0; }
void test_str(const char *s1, const char *s2) { char *o1, *o2, *o3; uint64_t t1, t2; rdtscl(t1); o1 = old_str_str(s1, s2); rdtscl(t2); printf("old - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o1); rdtscl(t1); o2 = new_str_str(s1, s2); rdtscl(t2); printf("new - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o2); rdtscl(t1); o3 = asm_str_str(s1, s2); rdtscl(t2); printf("asm - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o3); }
static int gameport_measure_speed(struct gameport *gameport) { #if defined(__i386__) unsigned int i, t, t1, t2, t3, tx; unsigned long flags; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; tx = 1 << 30; for(i = 0; i < 50; i++) { local_irq_save(flags); GET_TIME(t1); for (t = 0; t < 50; t++) gameport_read(gameport); GET_TIME(t2); GET_TIME(t3); local_irq_restore(flags); udelay(i * 10); if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t; } gameport_close(gameport); return 59659 / (tx < 1 ? 1 : tx); #elif defined (__x86_64__) unsigned int i, t; unsigned long tx, t1, t2, flags; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; tx = 1 << 30; for(i = 0; i < 50; i++) { local_irq_save(flags); rdtscl(t1); for (t = 0; t < 50; t++) gameport_read(gameport); rdtscl(t2); local_irq_restore(flags); udelay(i * 10); if (t2 - t1 < tx) tx = t2 - t1; } gameport_close(gameport); return (this_cpu_read(cpu_info.loops_per_jiffy) * (unsigned long)HZ / (1000 / 50)) / (tx < 1 ? 1 : tx); #else unsigned int j, t = 0; if (gameport_open(gameport, NULL, GAMEPORT_MODE_RAW)) return 0; j = jiffies; while (j == jiffies); j = jiffies; while (j == jiffies) { t++; gameport_read(gameport); } gameport_close(gameport); return t * HZ / 1000; #endif }
int main(int argc,char* argv[]) { static size_t x; x=23; atomic_add(&x,3); printf("%u\n",x); printf("%u\n",atomic_add_return(&x,-3)); printf("%u\n",compare_and_swap(&x,26,17)); printf("%u\n",compare_and_swap(&x,23,17)); #if 0 atomic_add(&x,3); printf("%u\n",x); x=23; atomic_add(&x,3); assert(x==26); atomic_or(&x,1); assert(x==27); atomic_and(&x,-2); assert(x==26); #endif #if 0 iarray a; char* c; iarray_init(&a,sizeof(io_entry)); printf("15 -> %p\n",c=iarray_allocate(&a,15)); printf("23 -> %p\n",c=iarray_allocate(&a,23)); printf("1234567 -> %p\n",c=iarray_allocate(&a,1234567)); printf("23 -> %p\n",iarray_get(&a,23)); #endif #if 0 io_batch* b=iob_new(1234); int64 fd=open("t.c",0); iob_addbuf(b,"fnord",5); iob_addfile_close(b,fd,0,7365); iob_write(1,b,writecb); #endif #if 0 char dest[1024]; unsigned long len; scan_urlencoded2("libstdc++.tar.gz",dest,&len); buffer_putmflush(buffer_1,dest,"\n"); #endif #if 0 static stralloc sa; stralloc_copym(&sa,"foo ","bar ","baz.\n"); write(1,sa.s,sa.len); #endif #if 0 buffer_putmflush(buffer_1,"foo ","bar ","baz.\n"); #endif #if 0 char* c="fnord"; int fd=open_read(c); errmsg_iam(argv[0]); carp("could not open file `",c,"'"); diesys(23,"could not open file `",c,"'"); #endif #if 0 errmsg_warn("could not open file `",c,"'",0); errmsg_warnsys("could not open file `",c,"'",0); #endif #if 0 char buf[100]="/usr/bin/sh"; int len=str_len(buf); assert(byte_rchr(buf,len,'/')==8); assert(byte_rchr(buf,len,'@')==len); assert(byte_rchr(buf,len,'h')==len-1); printf("%d\n",byte_rchr("x",1,'x')); #endif #if 0 char buf[IP6_FMT+100]; int i; char ip[16]; uint32 scope_id; char* s="fec0::1:220:e0ff:fe69:ad92%eth0/64"; char blubip[16]="\0\0\0\0\0\0\0\0\0\0\xff\xff\x7f\0\0\001"; i=scan_ip6if(s,ip,&scope_id); assert(s[i]=='/'); buffer_put(buffer_1,buf,fmt_ip6if(buf,ip,scope_id)); buffer_putnlflush(buffer_1); buffer_put(buffer_1,buf,fmt_ip6ifc(buf,blubip,scope_id)); buffer_putnlflush(buffer_1); scan_ip6("2001:7d0:0:f015:0:0:0:1",ip); buffer_put(buffer_1,buf,fmt_ip6(buf,ip)); buffer_putnlflush(buffer_1); #endif #if 0 char buf[100]; int i; printf("%d\n",i=fmt_pad(buf,"fnord",5,7,10)); buf[i]=0; puts(buf); #endif #if 0 char ip[16]; char buf[32]; printf("%d (expect 2)\n",scan_ip6("::",ip)); printf("%d (expect 3)\n",scan_ip6("::1",ip)); printf("%d (expect 16)\n",scan_ip6("fec0:0:0:ffff::1/0",ip)); printf("%.*s\n",fmt_ip6(buf,ip),buf); #endif #if 0 static stralloc s,t; stralloc_copys(&s,"fnord"); stralloc_copys(&t,"abc"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnor"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnord"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"fnordh"); printf("%d\n",stralloc_diff(&s,&t)); stralloc_copys(&t,"hausen"); printf("%d\n",stralloc_diff(&s,&t)); #endif #if 0 static stralloc s; stralloc_copys(&s,"fnord"); printf("%d\n",stralloc_diffs(&s,"abc")); printf("%d\n",stralloc_diffs(&s,"fnor")); printf("%d\n",stralloc_diffs(&s,"fnord")); printf("%d\n",stralloc_diffs(&s,"fnordh")); printf("%d\n",stralloc_diffs(&s,"hausen")); #endif #if 0 printf("%d\n",case_starts("fnordhausen","FnOrD")); printf("%d\n",case_starts("fnordhausen","blah")); #endif #if 0 char buf[]="FnOrD"; case_lowers(buf); puts(buf); #endif #if 0 char buf[100]="foo bar baz"; printf("%d (expect 7)\n",byte_rchr(buf,11,' ')); #endif #if 0 unsigned long size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_yenc(0,buf,size); unsigned int y; char* tmp=malloc(x+1); y=fmt_yenc(tmp,buf,size); write(1,tmp,x); } #endif #if 0 char buf[100]; char buf2[100]; unsigned int len,len2; buf[fmt_yenc(buf,"http://localhost/~fefe",22)]=0; buffer_puts(buffer_1,buf); buffer_putsflush(buffer_1,"\n"); if ((buf[len2=scan_yenc(buf,buf2,&len)])!='\n') { buffer_putsflush(buffer_2,"parse error!\n"); return 1; } buffer_put(buffer_1,buf2,len2); buffer_putsflush(buffer_1,"\n"); return 0; #endif #if 0 char buf[100]; char buf2[100]; unsigned int len,len2; buf[fmt_base64(buf,"foo:bar",7)]=0; buffer_puts(buffer_1,buf); buffer_putsflush(buffer_1,"\n"); if ((buf[len2=scan_base64(buf,buf2,&len)])!=0) { buffer_putsflush(buffer_2,"parse error!\n"); return 1; } buffer_put(buffer_1,buf2,len2); buffer_putsflush(buffer_1,"\n"); return 0; #endif #if 0 unsigned long size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_uuencoded(0,buf,size); unsigned int y; char* tmp=malloc(x+1); y=fmt_uuencoded(tmp,buf,size); write(1,tmp,x); } #endif #if 0 char buf[]="00000000000000000000000000000001"; char ip[16]; if (scan_ip6_flat(buf,ip) != str_len(buf)) buffer_putsflush(buffer_2,"parse error!\n"); #endif #if 0 int fd=open_read("t.c"); buffer b; char buf[1024]; char line[20]; int i; buffer_init(&b,read,fd,buf,1024); i=buffer_getline(&b,line,19); buffer_puts(buffer_1,"getline returned "); buffer_putulong(buffer_1,i); buffer_puts(buffer_1,"\n"); buffer_puts(buffer_1,line); buffer_flush(buffer_1); #endif #if 0 buffer_putulong(buffer_1,23); // buffer_putspace(buffer_1); buffer_putsflush(buffer_1,"\n"); // buffer_flush(buffer_1); #endif #if 0 long a,b,c; char buf[4096]; char buf2[4096]; memcpy(buf,buf2,4096); byte_copy(buf,4096,buf2); rdtscl(a); memcpy(buf,buf2,4096); rdtscl(b); byte_copy(buf,4096,buf2); rdtscl(c); printf("memcpy: %d - byte_copy: %d\n",b-a,c-b); #endif #if 0 char ip[16]; int i; if ((i=scan_ip6(argv[1],ip))) { char buf[128]; buf[fmt_ip6(buf,ip)]=0; puts(buf); } #endif #if 0 char buf[100]; strcpy(buf,"foobarbaz"); buf[fmt_fill(buf,3,5,100)]=0; printf("\"%s\"\n",buf); #endif #if 0 unsigned long len; char *c=mmap_read("/etc/passwd",&len); printf("got map %p of len %lu\n",c,len); #endif #if 0 char c; printf("%d\n",buffer_getc(buffer_0,&c)); printf("%c\n",c); #endif #if 0 char buf[100]="01234567890123456789012345678901234567890123456789"; long a,b,c; #endif #if 0 buf[ip4_fmt(buf,ip4loopback)]=0; buffer_puts(buffer_1small,buf); buffer_flush(buffer_1small); #endif #if 0 buf[0]=0; buf[fmt_8long(buf,0)]=0; puts(buf); rdtscl(a); c=str_len(buf); rdtscl(b); /*byte_zero_djb(buf,j); */ // printf("\n%lu %d\n",b-a,c); #endif #if 0 buffer_puts(buffer_1small,"hello, world\n"); buffer_flush(buffer_1small); #endif #if 0 int s=socket_tcp4(); char ip[4]={127,0,0,1}; int t=socket_connect4(s,ip,80); #endif #if 0 char buf[100]="foo bar baz fnord "; char buf2[100]="foo braz fnord"; long a,b,c; long i=0,j=0,k=0; double d; uint32 l,m,n; stralloc sa={0}; stralloc_copys(&sa,"fnord"); stralloc_catlong0(&sa,-23,5); stralloc_append(&sa,"\n"); printf("%d %d\n",str_equal("fnord","fnord1"),str_equal("fnord1","fnord")); write(1,sa.s,sa.len); printf("%d %d\n",stralloc_starts(&sa,"fnord"),stralloc_starts(&sa,"fnord\na")); l=0xdeadbeef; uint32_pack_big((char*)&m,l); uint32_unpack_big((char*)&m,&n); printf("%x %x %x\n",l,m,n); rdtscl(a); /* i=scan_double("3.1415",&d); */ rdtscl(b); /*byte_zero_djb(buf,j); */ rdtscl(c); printf("%lu %lu\n",b-a,c-b); #endif #if 0 size_t size; char* buf=mmap_read(argv[1],&size); if (buf) { unsigned int x=fmt_urlencoded2(0,buf,size,"x"); unsigned int y; char* tmp=malloc(x+1); y=fmt_urlencoded2(tmp,buf,size,"x"); write(1,tmp,x); } #endif #if 0 printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar")); printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar")); #endif #if 0 { int16 a; int32 b; int64 c; assert(imult16(4,10000,&a)==0); assert(imult16(-4,10000,&a)==0); assert(imult16(5,10,&a)==1 && a==50); assert(imult16(-3,10000,&a)==1 && a==-30000); assert(imult32(0x40000000,2,&b)==0); assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe); assert(imult64(0x4000000000000000ll,2,&c)==0); assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell); } #endif #if 0 stralloc a; printf("%d\n",stralloc_copym(&a,"fnord",", ","foo")); #endif return 0; }
static void __cpuinit init_amd(struct cpuinfo_x86 *c) { u32 l, h; int mbytes = num_physpages >> (20-PAGE_SHIFT); int r; #ifdef CONFIG_SMP unsigned long long value; /* Disable TLB flush filter by setting HWCR.FFDIS on K8 * bit 6 of msr C001_0015 * * Errata 63 for SH-B3 steppings * Errata 122 for all steppings (F+ have it disabled by default) */ if (c->x86 == 15) { rdmsrl(MSR_K7_HWCR, value); value |= 1 << 6; wrmsrl(MSR_K7_HWCR, value); } #endif early_init_amd(c); /* * FIXME: We should handle the K5 here. Set up the write * range and also turn on MSR 83 bits 4 and 31 (write alloc, * no bus pipeline) */ /* Bit 31 in normal CPUID used for nonstandard 3DNow ID; 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */ clear_bit(0*32+31, c->x86_capability); r = get_model_name(c); switch(c->x86) { case 4: /* * General Systems BIOSen alias the cpu frequency registers * of the Elan at 0x000df000. Unfortuantly, one of the Linux * drivers subsequently pokes it, and changes the CPU speed. * Workaround : Remove the unneeded alias. */ #define CBAR (0xfffc) /* Configuration Base Address (32-bit) */ #define CBAR_ENB (0x80000000) #define CBAR_KEY (0X000000CB) if (c->x86_model==9 || c->x86_model == 10) { if (inl (CBAR) & CBAR_ENB) outl (0 | CBAR_KEY, CBAR); } break; case 5: if( c->x86_model < 6 ) { /* Based on AMD doc 20734R - June 2000 */ if ( c->x86_model == 0 ) { clear_bit(X86_FEATURE_APIC, c->x86_capability); set_bit(X86_FEATURE_PGE, c->x86_capability); } break; } if ( c->x86_model == 6 && c->x86_mask == 1 ) { const int K6_BUG_LOOP = 1000000; int n; void (*f_vide)(void); unsigned long d, d2; printk(KERN_INFO "AMD K6 stepping B detected - "); /* * It looks like AMD fixed the 2.6.2 bug and improved indirect * calls at the same time. */ n = K6_BUG_LOOP; f_vide = vide; rdtscl(d); while (n--) f_vide(); rdtscl(d2); d = d2-d; if (d > 20*K6_BUG_LOOP) printk("system stability may be impaired when more than 32 MB are used.\n"); else printk("probably OK (after B9730xxxx).\n"); printk(KERN_INFO "Please see http://membres.lycos.fr/poulot/k6bug.html\n"); } /* K6 with old style WHCR */ if (c->x86_model < 8 || (c->x86_model== 8 && c->x86_mask < 8)) { /* We can only write allocate on the low 508Mb */ if(mbytes>508) mbytes=508; rdmsr(MSR_K6_WHCR, l, h); if ((l&0x0000FFFF)==0) { unsigned long flags; l=(1<<0)|((mbytes/4)<<1); local_irq_save(flags); wbinvd(); wrmsr(MSR_K6_WHCR, l, h); local_irq_restore(flags); printk(KERN_INFO "Enabling old style K6 write allocation for %d Mb\n", mbytes); } break; } if ((c->x86_model == 8 && c->x86_mask >7) || c->x86_model == 9 || c->x86_model == 13) { /* The more serious chips .. */ if(mbytes>4092) mbytes=4092; rdmsr(MSR_K6_WHCR, l, h); if ((l&0xFFFF0000)==0) { unsigned long flags; l=((mbytes>>2)<<22)|(1<<16); local_irq_save(flags); wbinvd(); wrmsr(MSR_K6_WHCR, l, h); local_irq_restore(flags); printk(KERN_INFO "Enabling new style K6 write allocation for %d Mb\n", mbytes); } /* Set MTRR capability flag if appropriate */ if (c->x86_model == 13 || c->x86_model == 9 || (c->x86_model == 8 && c->x86_mask >= 8)) set_bit(X86_FEATURE_K6_MTRR, c->x86_capability); break; } if (c->x86_model == 10) { /* AMD Geode LX is model 10 */ /* placeholder for any needed mods */ break; } break; case 6: /* An Athlon/Duron */ /* Bit 15 of Athlon specific MSR 15, needs to be 0 * to enable SSE on Palomino/Morgan/Barton CPU's. * If the BIOS didn't enable it already, enable it here. */ if (c->x86_model >= 6 && c->x86_model <= 10) { if (!cpu_has(c, X86_FEATURE_XMM)) { printk(KERN_INFO "Enabling disabled K7/SSE Support.\n"); rdmsr(MSR_K7_HWCR, l, h); l &= ~0x00008000; wrmsr(MSR_K7_HWCR, l, h); set_bit(X86_FEATURE_XMM, c->x86_capability); } } /* It's been determined by AMD that Athlons since model 8 stepping 1 * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx * As per AMD technical note 27212 0.2 */ if ((c->x86_model == 8 && c->x86_mask>=1) || (c->x86_model > 8)) { rdmsr(MSR_K7_CLK_CTL, l, h); if ((l & 0xfff00000) != 0x20000000) { printk ("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", l, ((l & 0x000fffff)|0x20000000)); wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h); } } break; }
int main(int argc,char* argv[]) { unsigned long count=1000; int v6; v6=0; { struct rlimit rl; rl.rlim_cur=RLIM_INFINITY; rl.rlim_max=RLIM_INFINITY; setrlimit(RLIMIT_NOFILE,&rl); #ifdef RLIMIT_NPROC setrlimit(RLIMIT_NPROC,&rl); #endif } for (;;) { int i; int c=getopt(argc,argv,"h6c:"); if (c==-1) break; switch (c) { case 'c': i=scan_ulong(optarg,&count); if (i==0 || optarg[i]) { buffer_puts(buffer_2,"httpbench: warning: could not parse count: "); buffer_puts(buffer_2,optarg+i+1); buffer_putsflush(buffer_2,"\n"); } break; case '6': v6=1; break; case 'h': buffer_putsflush(buffer_2, "usage: bindbench [-h] [-6] [-c count]\n" "\n" "\t-h\tprint this help\n" "\t-c n\tbind n sockets to port 0 (default: 1000)\n" "\t-6\tbind IPv6 sockets instead of IPV4\n"); return 0; } } { int i,r; char ip[16]; int port; #ifdef __i386__ unsigned long long a,b,c; #else struct timeval a,b,c; unsigned long d; #endif int *socks=alloca(count*sizeof(int)); port=0; byte_zero(ip,16); for (i=0; i<count; ++i) { #ifdef __i386__ rdtscl(a); #else gettimeofday(&a,0); #endif socks[i]=v6?socket_tcp6():socket_tcp4(); #ifdef __i386__ rdtscl(b); #else gettimeofday(&b,0); #endif if (socks[i]==-1) { buffer_puts(buffer_2,"socket() failed: "); buffer_puterror(buffer_2); buffer_putnlflush(buffer_2); exit(1); } if (v6) r=socket_bind6(socks[i],ip,port,0); else r=socket_bind4(socks[i],ip,port); if (r==-1) { buffer_puts(buffer_2,"bind() failed: "); buffer_puterror(buffer_2); buffer_putnlflush(buffer_2); exit(1); } #ifdef __i386__ rdtscl(c); buffer_putulong(buffer_1,b-a); #else gettimeofday(&c,0); d=(b.tv_sec-a.tv_sec)*1000000; d=d+b.tv_usec-a.tv_usec; buffer_putulong(buffer_1,d); #endif buffer_putspace(buffer_1); #ifdef __i386__ buffer_putulong(buffer_1,c-b); #else d=(c.tv_sec-b.tv_sec)*1000000; d=d+c.tv_usec-b.tv_usec; buffer_putulong(buffer_1,d); #endif buffer_puts(buffer_1,"\n"); if (i>50) { close(socks[10]); socks[10]=v6?socket_tcp6():socket_tcp4(); } } } buffer_flush(buffer_1); return 0; }
int main(int argc,char *argv[]) { int i; for (i=0; i<1024; ++i) { printf("%08x%c",arc4random(),(i&15)==15 ? '\n' : ' '); } perror("write"); #if 0 int n; struct ucontext uc; n=0; getcontext(&uc); puts("getcontext returned"); if (n==0) { ++n; setcontext(&uc); puts("should not get here"); exit(1); } puts("all ok"); return 0; #endif #if 0 char* a=malloc(-3); char* b=malloc(0xffffffffull+1); printf("%p %p\n",a,b); #endif #if 0 printf("%u\n",getpagesize()); #endif #if 0 struct stat s; time_t t=time(0); struct tm* T; stat("/tmp/nyt.html",&s); T=gmtime(&s.st_mtime); #endif #if 0 static struct mq_attr x; mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x); mqd_t b=mq_open("fnord",O_RDONLY); #endif #if 0 struct statfs s; if (statfs("/tmp",&s)!=-1) { printf("%llu blocks, %llu free\n",(unsigned long long)s.f_blocks,(unsigned long long)s.f_bfree); } #endif #if 0 char* c=strndupa("fnord",3); puts(c); #endif #if 0 char buf[100]; __write2("foo!\n"); memset(buf,0,200); #endif #if 0 printf("%+05d\n",500); #endif #if 0 char* c; printf("%d\n",asprintf(&c,"foo %d",23)); puts(c); #endif #if 0 struct winsize ws; if (!ioctl(0, TIOCGWINSZ, &ws)) { printf("%dx%d\n",ws.ws_col,ws.ws_row); } #endif #if 0 struct termios t; if (tcgetattr(1,&t)) { puts("tcgetattr failed!"); return 1; } printf("%d\n",cfgetospeed(&t)); #endif #if 0 printf("%p\n",malloc(0)); #endif #if 0 char* argv[]= {"sh","-i",0}; char buf[PATH_MAX+100]; int i; for (i=0; i<PATH_MAX+20; ++i) buf[i]='a'; memmove(buf,"PATH=/",6); strcpy(buf+i,"/bin:/bin"); putenv(buf); execvp("sh",argv); printf("%d\n",islower(0xfc)); #endif #if 0 char buf[101]; __dtostr(-123456789.456,buf,100,6,2); puts(buf); return 0; #endif #if 0 time_t t=1009921588; puts(asctime(localtime(&t))); #endif #if 0 printf("%g\n",atof("30")); #endif #if 0 char* buf[]= {"FOO=FNORD","A=B","C=D","PATH=/usr/bin:/bin",0}; environ=buf; putenv("FOO=BAR"); putenv("FOO=BAZ"); putenv("BLUB=DUH"); system("printenv"); #endif #if 0 char buf[1024]; time_t t1=time(0); struct tm* t=localtime(&t1); printf("%d %s\n",strftime(buf,sizeof buf,"%b %d %H:%M",t),buf); #endif #if 0 tzset(); printf("%d\n",daylight); #endif #if 0 struct in_addr addr; inet_aton("10.0.0.100\t",&addr); printf("%s\n",inet_ntoa(addr)); #endif #if 0 printf("%u\n",getuid32()); #endif #if 0 FILE *f; int i; char addr6p[8][5]; int plen, scope, dad_status, if_idx; char addr6[40], devname[20]; if ((f = fopen("/proc/net/if_inet6", "r")) != NULL) { while ((i=fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", addr6p[0], addr6p[1], addr6p[2], addr6p[3], addr6p[4], addr6p[5], addr6p[6], addr6p[7], &if_idx, &plen, &scope, &dad_status, devname)) != EOF) { printf("i=%d\n",i); } } #endif #if 0 printf("%s\n",crypt("test","$1$")); #endif #if 0 MD5_CTX x; unsigned char md5[16]; MD5Init(&x); MD5Update(&x,"a",1); MD5Final(md5,&x); { int i; for (i=0; i<16; ++i) { printf("%02x",md5[i]); } putchar('\n'); } #endif #if 0 long a,b,c; char buf[20]="fnord"; strcpy(buf,"Fnordhausen"); strcpy2(buf,"Fnordhausen"); rdtscl(a); strcpy(buf,"Fnordhausen"); rdtscl(b); strcpy2(buf,"Fnordhausen"); rdtscl(c); printf("C: %d ticks, asm: %d ticks\n",b-a,c-b); #endif /* printf("%d\n",strcmp(buf,"fnord")); */ #if 0 regex_t r; // printf("regcomp %d\n",regcomp(&r,"^(re([\\[0-9\\]+])*|aw):[ \t]*",REG_EXTENDED)); printf("regcomp %d\n",regcomp(&r,"^([A-Za-z ]+>|[]>:|}-][]>:|}-]*)",REG_EXTENDED)); printf("regexec %d\n",regexec(&r,"Marketing-Laufbahn hinterdir.",1,0,REG_NOSUB)); #endif #if 0 FILE *f=fopen("/home/leitner/Mail/outbox","r"); char buf[1024]; int i=0; if (f) { while (fgets(buf,1023,f)) { ++i; printf("%d %lu %s",i,ftell(f),buf); } } #endif #if 0 char template[]="/tmp/duh/fnord-XXXXXX";