database.sarang.net
UserID
Passwd
Database
ㆍDBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DBMS Q&A 1247 게시물 읽기
No. 1247
컴파일링 에러
작성자
한동준(2000djhan)
작성일
2006-09-17 21:05
조회수
8,016

일단 이런곳에 올려도 모르겟네요 죄송합니다..

저는 컴퓨터 구조를 공부하는 학생인데요

사이클 카운터 측정 소스코드 공부하다가 정 말 모르는것이

생겨서 이렇게 질문드립니다

아시는분 있으시면 꼭 좀 답글좀 달아주세요..

헤더파일중에 unix용 unistd.h란게 있잔아여?

이걸 VC에서 하려고 msdn 찾아보니깐 windows.h 하고 process.h 로 바꾸면 된다고 한것 같아서 바꿨는데요..(맞는지 확실히 모름) 바꾸니까 본문에서 에러가 뜨네요.. DB고수님들의 명쾌한 답변 꼭 좀 부탁드립니다

소스코드

#include <stdio.h>

#include <stdlib.h>

//#include <unistd.h>

//#include <sys/times.h>

#include "time.h"

#include <windows.h>

#include <process.h>


/*

 * Routines for using the cycle counter

 */

/* Detect whether running on Alpha */

#ifdef __alpha

#define IS_ALPHA 1

#else

#define IS_ALPHA 0

#endif

/* Detect whether running on x86 */

#ifdef __i386__

#define IS_x86 1

#else

#define IS_x86 0

#endif

#if IS_ALPHA

/* Initialize the cycle counter */

static unsigned cyc_hi = 0;

static unsigned cyc_lo = 0;


/* Use Alpha cycle timer to compute cycles.  Then use

   measured clock speed to compute seconds

*/

/*

 * counterRoutine is an array of Alpha instructions to access

 * the Alpha's processor cycle counter. It uses the rpcc

 * instruction to access the counter. This 64 bit register is

 * divided into two parts. The lower 32 bits are the cycles

 * used by the current process. The upper 32 bits are wall

 * clock cycles. These instructions read the counter, and

 * convert the lower 32 bits into an unsigned int - this is the

 * user space counter value.

 * NOTE: The counter has a very limited time span. With a

 * 450MhZ clock the counter can time things for about 9

 * seconds. */

static unsigned int counterRoutine[] =

{

    0x601fc000u,

    0x401f0000u,

    0x6bfa8001u

};

/* Cast the above instructions into a function. */

static unsigned int (*counter)(void)= (void *)counterRoutine;


void start_counter()

{

    /* Get cycle counter */

    cyc_hi = 0;

    cyc_lo = counter();

}

double get_counter()

{

    unsigned ncyc_hi, ncyc_lo;

    unsigned hi, lo, borrow;

    double result;

    ncyc_lo = counter();

    ncyc_hi = 0;

    lo = ncyc_lo - cyc_lo;

    borrow = lo > ncyc_lo;

    hi = ncyc_hi - cyc_hi - borrow;

    result = (double) hi * (1 << 30) * 4 + lo;

    if (result < 0) {

 fprintf(stderr, "Error: Cycle counter returning negative value: %.0f\n", result);

    }

    return result;

}

#endif /* Alpha */

#if IS_x86

/* $begin x86cyclecounter */

/* Initialize the cycle counter */

static unsigned cyc_hi = 0;

static unsigned cyc_lo = 0;


/* Set *hi and *lo to the high and low order bits  of the cycle counter. 

   Implementation requires assembly code to use the rdtsc instruction. */

void access_counter(unsigned *hi, unsigned *lo)

{

    asm("rdtsc; movl %%edx,%0; movl %%eax,%1"   /* Read cycle counter */

 : "=r" (*hi), "=r" (*lo)                /* and move results to */

 : /* No input */                        /* the two outputs */

 : "%edx", "%eax");

}

/* Record the current value of the cycle counter. */

void start_counter()

{

    access_counter(&cyc_hi, &cyc_lo);

}

/* Return the number of cycles since the last call to start_counter. */

double get_counter()

{

    unsigned ncyc_hi, ncyc_lo;

    unsigned hi, lo, borrow;

    double result;

    /* Get cycle counter */

    access_counter(&ncyc_hi, &ncyc_lo);

    /* Do double precision subtraction */

    lo = ncyc_lo - cyc_lo;

    borrow = lo > ncyc_lo;

    hi = ncyc_hi - cyc_hi - borrow;

    result = (double) hi * (1 << 30) * 4 + lo;

    if (result < 0) {

 fprintf(stderr, "Error: counter returns neg value: %.0f\n", result);

    }

    return result;

}

/* $end x86cyclecounter */

#endif /* x86 */

double ovhd()

{

    /* Do it twice to eliminate cache effects */

    int i;

    double result;

    for (i = 0; i < 2; i++) {

 start_counter();

 result = get_counter();

    }

    return result;

}

/* $begin mhz */

/* Estimate the clock rate by measuring the cycles that elapse */

/* while sleeping for sleeptime seconds */

double mhz(int verbose, int sleeptime)

{

    double rate;

    start_counter();

    sleep(sleeptime);

    rate = get_counter() / (1e6*sleeptime);

    if (verbose)

 printf("Processor clock rate ~= %.1f MHz\n", rate);

    return rate;

}

/* $end mhz */

/* Version using a default sleeptime */

double mhz_def(int verbose)

{

    return mhz(verbose, 2);

}

/** Special counters that compensate for timer interrupt overhead */

static double cyc_per_tick = 0.0;

#define NEVENT 100

#define THRESHOLD 1000

#define RECORDTHRESH 3000

/* Attempt to see how much time is used by timer interrupt */

static void callibrate(int verbose)

{

    double oldt;

    struct tms t;

    clock_t oldc;

    int e = 0;

    times(&t);

    oldc = t.tms_utime;

    start_counter();

    oldt = get_counter();

    while (e <NEVENT) {

 double newt = get_counter();

 if (newt-oldt >= THRESHOLD) {

     clock_t newc;

     times(&t);

     newc = t.tms_utime;

     if (newc > oldc) {

  double cpt = (newt-oldt)/(newc-oldc);

  if ((cyc_per_tick == 0.0 || cyc_per_tick > cpt) && cpt > RECORDTHRESH)

      cyc_per_tick = cpt;

  /*

    if (verbose)

    printf("Saw event lasting %.0f cycles and %d ticks.  Ratio = %f\n",

    newt-oldt, (int) (newc-oldc), cpt);

  */

  e++;

  oldc = newc;

     }

     oldt = newt;

 }

    }

    if (verbose)

 printf("Setting cyc_per_tick to %f\n", cyc_per_tick);

}

static clock_t start_tick = 0;

void start_comp_counter()

{

    struct tms t;

    if (cyc_per_tick == 0.0)

 callibrate(1);

    times(&t);

    start_tick = t.tms_utime;

    start_counter();

}

double get_comp_counter()

{

    double time = get_counter();

    double ctime;

    struct tms t;

    clock_t ticks;

    times(&t);

    ticks = t.tms_utime - start_tick;

    ctime = time - ticks*cyc_per_tick;

    /*

      printf("Measured %.0f cycles.  Ticks = %d.  Corrected %.0f cycles\n",

      time, (int) ticks, ctime);

    */

    return ctime;

}

헤더파일 //"time.h"

/* Routines for using cycle counter */

/* Start the counter */

void start_counter();

/* Get # cycles since counter started */

double get_counter();

/* Measure overhead for counter */

double ovhd();

/* Determine clock rate of processor (using a default sleeptime) */

double mhz_def(int verbose);

/* Determine clock rate of processor, having more control over accuracy */

double mhz(int verbose, int sleeptime);

/** Special counters that compensate for timer interrupt overhead */

void start_comp_counter();

double get_comp_counter();

 

 

[Top]
No.
제목
작성자
작성일
조회
1250펀드에 관한 DB를 만들까 하는데..
쭈구리
2006-10-08
7336
1249er 다이어그램 막히는 부분이 있습니다. [2]
MP38
2006-10-04
8066
1248DB관련 세미나 정보를 얻을 수 있는 곳이 있을까요?
박기원
2006-09-22
7045
1247컴파일링 에러
한동준
2006-09-17
8016
1246DBMS의 4가지 기능좀 가르쳐주세요
박무성
2006-09-14
9986
1245무결성제약조건이 무엇이고 용도에 대해 알고싶습니다 [1]
김대봉
2006-09-14
8486
1243정말 궁금해서 초보적인 질문합니다.. [1]
초짜
2006-09-12
8191
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2020 DSN, All rights reserved.
작업시간: 0.013초, 이곳 서비스는
	PostgreSQL v13.0으로 자료를 관리합니다