コード例 #1
0
ファイル: steptest.c プロジェクト: alisheikh/hornet
static mps_addr_t make(void)
{
    size_t length = rnd() % (avLEN * 2);
    size_t size = (length+2) * sizeof(mps_word_t);
    mps_addr_t p;
    mps_res_t res;

    alloc_bytes += size;

    for(;;) {
        mps_bool_t commit_res;
        double t1, t2;
        t1 = my_clock();
        MPS_RESERVE_BLOCK(res, p, ap, size);
        t1 = time_since(t1); /* reserve time */
        if(res)
            die(res, "MPS_RESERVE_BLOCK");
        res = dylan_init(p, size, exactRoots, exactRootsCOUNT);
        if(res)
            die(res, "dylan_init");
        t2 = my_clock();
        commit_res = mps_commit(ap, p, size);
        t2 = time_since(t2); /* commit time */
        t1 += t2; /* total MPS time for this allocation */
        alloc_time += t1;
        if (t1 > max_alloc_time)
            max_alloc_time = t1;
        if (commit_res)
            break;
        else
            ++ commit_failures;
    }

    return p;
}
コード例 #2
0
ファイル: mpi_hello.c プロジェクト: surajpkn/flux-core
int
main(int argc, char *argv[])
{
        int id, ntasks;
	struct timespec ts0;
        //char hostname[64];

	clock_gettime (CLOCK_MONOTONIC, &ts0);

        MPI_Init(&argc, &argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &id);
        MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
        if (id == 0) {
                fprintf(stderr,
		  "0: completed MPI_Init in %0.3fs.  There are %d tasks\n",
		   time_since (ts0)/1000, ntasks);
                fflush(stdout);
        }

        MPI_Barrier(MPI_COMM_WORLD);
        if (id == 0) {
                printf("0: completed first barrier\n");
                fflush(stdout);
        }

        MPI_Finalize();
        if (id == 0) {
                printf("0: completed MPI_Finalize\n");
                fflush(stdout);
        }
        return 0;
}
コード例 #3
0
ファイル: nixie.c プロジェクト: MGraefe/nixie-clock
// The test program (function is called in an endless loop)
// Used to display all digits
// Activated when both buttons are pressed during system startup
// Button 0 switches between continous running mode (where
// digits just get incremented every 250ms) and selective mode where
// Button 1 is used to increment the digits
void test_program(void)
{
	update_buttons();
	
	if(g_buttons[0] && !g_last_buttons[0])
		g_last_blink_state = 1 - g_last_blink_state;
	
	if(g_last_blink_state == 0)
	{
		if(g_buttons[1] && !g_last_buttons[1])
		{
			g_last_blink_action = g_ticks;
			g_blink_numbers = (g_blink_numbers + 1) % 10;
		}
	}
	else if(time_since(g_last_blink_action) > 25)
	{	
		g_last_blink_action = g_ticks;
		g_blink_numbers = (g_blink_numbers + 1) % 10;
	}
	
	set_number(pins_d1, g_blink_numbers);
	set_number(pins_d2, g_blink_numbers);
	set_number(pins_d3, g_blink_numbers);
	set_number(pins_d4, g_blink_numbers);
}
コード例 #4
0
ファイル: nixie.c プロジェクト: MGraefe/nixie-clock
//Update button states, I implemented a kind of cooldown
//on button actions (high pass filter) to prevent rapid changes
//in case the button voltage changes rapidly
void update_button(uint8_t index)
{
	g_last_buttons[index] = g_buttons[index];
	
	if(button_pressed(index))
	{
		g_buttons[index] = 1;
		g_last_button_action[index] = g_ticks;
	}
	else if(time_since(g_last_button_action[index]) > 8)
	{
		g_buttons[index] = 0;
	}
}
コード例 #5
0
/* Health state machine:
 * Initial state is UNLOCK.
 * If Rb, PLL, and GPS are all OK, state becomes OK.
 * If Rb and PLL are OK, but GPS is UNLOCK, enter HOLDOVER.
 * If in HOLDOVER and FLL solution becomes too old, enter UNLOCK.
 * If Rb or PLL are UNLOCK, state is UNLOCK.
 * Can't go from UNLOCK or HOLDOVER to OK if GPS has MINOR_ALARM,
 * but if we're currently OK then a MINOR_ALARM won't make us leave.
 */
void health_update() {
  health_status_t new_status = health_status;

  if (health_status == HEALTH_OK && gps_status == GPS_UNLOCK) {
    if (fll_status == FLL_OK) {
      new_status = HEALTH_HOLDOVER;
    } else {
      new_status = HEALTH_UNLOCK;
    }
  }

  if (health_status == HEALTH_HOLDOVER) {
    if (fll_status == FLL_UNLOCK) {
      new_status = HEALTH_UNLOCK;
    }
  }

  if (health_status != HEALTH_UNLOCK) {
    if (pll_status == PLL_UNLOCK) {
      new_status = HEALTH_UNLOCK;
    }
    if (rb_status == RB_UNLOCK) {
      new_status = HEALTH_UNLOCK;
    }
  }

  if (health_status != HEALTH_OK) {
    if (pll_status == PLL_OK && gps_status == GPS_OK && rb_status == RB_OK) {
      new_status = HEALTH_OK;
    }
  }

  if (new_status != health_status) {
    health_notify_change("Health", health_status_description, health_status, new_status);
    if (new_status == HEALTH_OK) {
      if (entered_holdover_lower != ~0UL || entered_holdover_upper != ~0UL)
        pll_leave_holdover(time_since(entered_holdover_upper, entered_holdover_lower));
      pps_output_enable();
    } else if (new_status == HEALTH_HOLDOVER) {
      entered_holdover_upper = reftime_upper;
      entered_holdover_lower = reftime_lower;
      pll_enter_holdover();
    } else {
      pps_output_disable();
    }
    health_status = new_status;
  }
}
コード例 #6
0
ファイル: steptest.c プロジェクト: alisheikh/hornet
static void test_step(mps_arena_t arena, double multiplier)
{
    mps_bool_t res;
    double t1 = my_clock();
    res = mps_arena_step(arena, 0.1, multiplier);
    cdie(ArenaGlobals(arena)->clamped, "arena was unclamped");
    t1 = time_since(t1);
    if (res) {
        if (t1 > max_step_time)
            max_step_time = t1;
        step_time += t1;
        ++ steps;
    } else {
        if (t1 > max_no_step_time)
            max_no_step_time = t1;
        no_step_time += t1;
        ++ no_steps;
    }
}
コード例 #7
0
ファイル: aio-stress.c プロジェクト: Johnfan888/xfstests
/*
 * Add latency info to latency struct 
 */
static void calc_latency(struct timeval *start_tv, struct timeval *stop_tv,
			struct io_latency *lat)
{
    double delta;
    int i;
    delta = time_since(start_tv, stop_tv);
    delta = delta * 1000;

    if (delta > lat->max)
    	lat->max = delta;
    if (!lat->min || delta < lat->min)
    	lat->min = delta;
    lat->total_io++;
    lat->total_lat += delta;
    for (i = 0 ; i < DEVIATIONS ; i++) {
        if (delta < deviations[i]) {
	    lat->deviations[i]++;
	    break;
	}
    }
}
コード例 #8
0
ファイル: aio-stress.c プロジェクト: Johnfan888/xfstests
/*
 * return seconds between start_tv and now in double precision
 */
static double time_since_now(struct timeval *start_tv)
{
    struct timeval stop_time;
    gettimeofday(&stop_time, NULL);
    return time_since(start_tv, &stop_time);
}
コード例 #9
0
static int
authenticate(int sockfd, const char *username, const char *passwd)
{
    AUTH_HDR *auth;
    u_short total_length;
    u_char *ptr;
    int length;
    char passbuf[MAXPASS];
    u_char md5buf[256];
    int secretlen;
    u_char cbc[AUTH_VECTOR_LEN];
    int i, j;
    u_int32_t ui;
    struct sockaddr_in saremote;
    fd_set readfds;
    socklen_t salen;
    int retry = retries;

    /*
     *    Build an authentication request
     */
    auth = (AUTH_HDR *) send_buffer;
    auth->code = PW_AUTHENTICATION_REQUEST;
    auth->id = ++request_id;
    random_vector(vector);
    memcpy(auth->vector, vector, AUTH_VECTOR_LEN);
    total_length = AUTH_HDR_LEN;
    ptr = auth->data;

    /*
     *    User Name
     */
    *ptr++ = PW_USER_NAME;
    length = strlen(username);
    if (length > MAXPWNAM) {
	length = MAXPWNAM;
    }
    *ptr++ = length + 2;
    memcpy(ptr, username, length);
    ptr += length;
    total_length += length + 2;

    /*
     *    Password
     */
    length = strlen(passwd);
    if (length > MAXPASS) {
	length = MAXPASS;
    }
    memset(passbuf, 0, MAXPASS);
    memcpy(passbuf, passwd, length);

    /* 
     * Length is rounded up to multiple of 16,
     * and the password is encoded in blocks of 16 
     * with cipher block chaining
     */
    length = ((length / AUTH_VECTOR_LEN) + 1) * AUTH_VECTOR_LEN;

    *ptr++ = PW_PASSWORD;
    *ptr++ = length + 2;

    secretlen = strlen(secretkey);
    /* Set up the Cipher block chain */
    memcpy(cbc, auth->vector, AUTH_VECTOR_LEN);
    for (j = 0; j < length; j += AUTH_VECTOR_LEN) {
	/* Calculate the MD5 Digest */
	strcpy((char *)md5buf, secretkey);
	memcpy(md5buf + secretlen, cbc, AUTH_VECTOR_LEN);
	md5_calc(cbc, md5buf, secretlen + AUTH_VECTOR_LEN);

	/* Xor the password into the MD5 digest */
	for (i = 0; i < AUTH_VECTOR_LEN; i++) {
	    *ptr++ = (cbc[i] ^= passbuf[j + i]);
	}
    }
    total_length += length + 2;

    *ptr++ = PW_NAS_PORT_ID;
    *ptr++ = 6;

    ui = htonl(nasport);
    memcpy(ptr, &ui, 4);
    ptr += 4;
    total_length += 6;

    *ptr++ = PW_NAS_PORT_TYPE;
    *ptr++ = 6;

    ui = htonl(nasporttype);
    memcpy(ptr, &ui, 4);
    ptr += 4;
    total_length += 6;

    if (*identifier) {
	int len = strlen(identifier);
	*ptr++ = PW_NAS_ID;
	*ptr++ = len + 2;
	memcpy(ptr, identifier, len);
	ptr += len;
    } else {
	*ptr++ = PW_NAS_IP_ADDRESS;
	*ptr++ = 6;

	ui = htonl(nas_ipaddr);
	memcpy(ptr, &ui, 4);
	ptr += 4;
	total_length += 6;
    }

    /* Klaus Weidner <*****@*****.**> changed this
     * from htonl to htons. It might have caused
     * you trouble or not. That depends on the byte
     * order of your system.
     * The symptom was that the radius server
     * ignored the requests, because they had zero 
     * length according to the data header.
     */
    auth->length = htons(total_length);

    while(retry--) {
	int time_spent;
	struct timeval sent;
	/*
	 *    Send the request we've built.
	 */
	gettimeofday(&sent, NULL);
	send(sockfd, (char *) auth, total_length, 0);
	while ((time_spent = time_since(&sent)) < 1000000) {
	    struct timeval tv;
	    int rc, len;
	    if (!time_spent) {
		tv.tv_sec = 1;
		tv.tv_usec = 0;
	    } else {
		tv.tv_sec = 0;
		tv.tv_usec = 1000000 - time_spent;
	    }
	    FD_ZERO(&readfds);
	    FD_SET(sockfd, &readfds);
	    if (select(sockfd + 1, &readfds, NULL, NULL, &tv) == 0)	/* Select timeout */
		break;
	    salen = sizeof(saremote);
	    len = recvfrom(sockfd, recv_buffer, sizeof(i_recv_buffer),
		0, (struct sockaddr *) &saremote, &salen);

	    if (len < 0)
		continue;

	    rc = result_recv(saremote.sin_addr.s_addr, saremote.sin_port, recv_buffer, len);
	    if (rc == 0)
		return 1;
	    if (rc == 1)
	    	return 0;
	}
    }

    fprintf(stderr, "%s: No response from RADIUS server\n", progname);

    return 0;
}
コード例 #10
0
ファイル: gui.cpp プロジェクト: AscendNTNU/ai-sim
int main(int argc, char *argv[])
{
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        Printf("Failed to initialize SDL: %s\n", SDL_GetError());
        return -1;
    }

    VideoMode mode = {};
    mode.width = 800;
    mode.height = 600;
    mode.gl_major = 1;
    mode.gl_minor = 5;
    mode.double_buffer = 1;
    mode.depth_bits = 24;
    mode.stencil_bits = 8;
    mode.multisamples = 4;
    mode.swap_interval = 1;

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, mode.gl_major);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, mode.gl_minor);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,          mode.double_buffer);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,            mode.depth_bits);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,          mode.stencil_bits);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,    mode.multisamples>0?1:0);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,    mode.multisamples);

    mode.window = SDL_CreateWindow(
        "World Simulator",
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        mode.width, mode.height,
        SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

    if (!mode.window)
    {
        Printf("Failed to create a window: %s\n", SDL_GetError());
        return -1;
    }

    SDL_GLContext context = SDL_GL_CreateContext(mode.window);

    // Note: This must be set on a valid context
    SDL_GL_SetSwapInterval(mode.swap_interval);

    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &mode.gl_major);
    SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &mode.gl_minor);
    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER,          &mode.double_buffer);
    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE,            &mode.depth_bits);
    SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE,          &mode.stencil_bits);
    SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES,    &mode.multisamples);
    mode.swap_interval = SDL_GL_GetSwapInterval();

    sim_init_msgs(false);

    ImGui_ImplSdl_Init(mode.window);

    STATE = sim_init((u32)get_tick());
    HISTORY_LENGTH = 0;

    bool running = true;
    u64 initial_tick = get_tick();
    u64 last_frame_t = initial_tick;
    r32 elapsed_time = 0.0f;
    r32 delta_time = 1.0f / 60.0f;
    while (running)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            ImGui_ImplSdl_ProcessEvent(&event);
            switch (event.type)
            {
                case SDL_WINDOWEVENT:
                {
                    switch (event.window.event)
                    {
                        case SDL_WINDOWEVENT_SIZE_CHANGED:
                        {
                            Printf("Window %d size changed to %dx%d\n",
                                    event.window.windowID,
                                    event.window.data1,
                                    event.window.data2);
                            mode.width = event.window.data1;
                            mode.height = event.window.data2;
                        } break;
                    }
                } break;

                case SDL_QUIT:
                {
                    running = false;
                } break;
            }
        }
        gui_tick(mode, elapsed_time, delta_time);
        SDL_GL_SwapWindow(mode.window);

        delta_time = time_since(last_frame_t);
        if (mode.fps_lock > 0)
        {
            r32 target_time = 1.0f / (r32)mode.fps_lock;
            r32 sleep_time = target_time - delta_time;
            if (sleep_time >= 0.01f)
                SDL_Delay((u32)(sleep_time * 1000.0f));
            delta_time = time_since(last_frame_t);
        }
        last_frame_t = get_tick();
        elapsed_time = time_since(initial_tick);

        GLenum error = glGetError();
        if (error != GL_NO_ERROR)
        {
            Printf("An error occurred: %s\n", gl_error_message(error));
            running = false;
        }
    }

    ImGui_ImplSdl_Shutdown();
    SDL_GL_DeleteContext(context);
    SDL_DestroyWindow(mode.window);
    SDL_Quit();

    return 0;
}
コード例 #11
0
ファイル: nixie.c プロジェクト: MGraefe/nixie-clock
//The main program (this function is called in an endless loop)
void main_program(void)
{
	uint8_t output[2];
	
	update_buttons();
	dcf77_update(!read_pin(&pin_dcf77), g_ticks);
	
	//Menu button pressed? Switch menu mode
	if(g_buttons[0] && !g_last_buttons[0])
	{
		g_mode = (enum modes_e)((g_mode + 1) % MODE_COUNT);
		switch(g_mode)
		{
			case MODE_SET_HOURS:
			case MODE_SET_DAY:
				g_blink_numbers = 1;
				break;
			case MODE_SET_MINUTES:
			case MODE_SET_MONTH:
				g_blink_numbers = 2;
				break;
			default:
				g_blink_numbers = 0;
		};
		g_last_blink_action = g_ticks;
		g_last_blink_state = 1;
		g_last_inc_action = g_ticks;
		g_inc_pressed_time = g_ticks;
	}

	if(g_mode != MODE_NORMAL) //Inside Setup-mode?
	{
		//date/inc buttons pressed
		if(g_buttons[1])
		{
			if(!g_last_buttons[1])
			{
				on_increment_pressed();
				g_inc_pressed_time = g_ticks;
			}

			//Increment continously if pressed & hold
			if(time_since(g_inc_pressed_time) > 100 && time_since(g_last_inc_action) > 15)
			{
				g_last_inc_action = g_ticks;
				on_increment_pressed();
			}
		}
		
		//Are we currently setting time or date? display the appropriate output
		if(g_mode == MODE_SET_HOURS || g_mode == MODE_SET_MINUTES)
		{
			output[0] = g_time.hours;
			output[1] = g_time.minutes;
		}
		else
		{
			output[0] = g_time.day;
			output[1] = g_time.month;
		}
		
		// handle blinking of modifiable numbers
		if(g_blink_numbers != 0)
		{
			if(time_since(g_last_blink_action) > 50)
			{
				g_last_blink_action = g_ticks;
				g_last_blink_state = !g_last_blink_state;
			}
			// Going beyond single-digit range of the display
			// should turn the digit off
			if(g_last_blink_state == 0)
				output[g_blink_numbers-1] = 0xFF;
		}
	}
	else //normal operation (non-setup)
	{
		if(g_buttons[1])
		{
			output[0] = g_time.day;
			output[1] = g_time.month;
		}
		else
		{
			output[0] = g_time.hours;
			output[1] = g_time.minutes;
		}
	}
	
	write_output(output[0], output[1]);
}
コード例 #12
0
uint32_t health_get_ref_age() {
  return time_since(reftime_upper, reftime_lower);
}