示例#1
0
文件: timer.c 项目: CSU-GH/okl4_3.0
void *ChildTimer(void *vtest)
#endif
{
#ifndef WINDOWS
    test_ll_t *test = (test_ll_t *)vtest;
#endif
    extern time_t global_end_time;		/* overall end time of test */
    time_t local_end_time = 0;
    int i;

    child_args_t *args = test->args;
    test_env_t *env = test->env;

    if((args->flags & CLD_FLG_TMD)) {
        local_end_time = global_end_time;
    } else { /* force the longest time */
        for(i=0; i<(sizeof(time_t)*8)-1; i++) {
            local_end_time |= 0x1ULL<<i;
        }
    }

    PDBG4(DEBUG, test->args, "In timer %lu < %lu, %d\n", time(NULL), local_end_time, env->bContinue);
    do {
        Sleep(1000);
        PDBG4(DEBUG, test->args, "Continue timing %lu < %lu, %d\n", time(NULL), local_end_time, env->bContinue);
        if(args->flags & CLD_FLG_W) {
            if((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
                if(TST_OPER(args->test_state) == WRITER) {
                    env->cycle_stats.wtime++;
                }
            } else {
                env->cycle_stats.wtime++;
            }
        }
        if(args->flags & CLD_FLG_R) {
            if((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
                if(TST_OPER(args->test_state) == READER) {
                    env->cycle_stats.rtime++;
                }
            } else {
                env->cycle_stats.rtime++;
            }
        }
        if((args->hbeat > 0) && ((env->cycle_stats.wtime % args->hbeat) || (env->cycle_stats.rtime % args->hbeat)) == 0) {
            print_stats(args, env, CYCLE);
        }
        /* If test failed don't continue to report stats */
        if(!(TST_STS(args->test_state))) {
            break;
        }
    } while((time(NULL) < local_end_time) && (env->bContinue));
    PDBG4(DEBUG, test->args, "Out of timer %lu < %lu, %d\n", time(NULL), local_end_time, env->bContinue);
    env->bContinue = FALSE;
    TEXIT(GETLASTERROR());
}
示例#2
0
文件: timer.c 项目: 1587/ltp
void *ChildTimer(void *vtest)
#endif
{
#ifndef WINDOWS
	test_ll_t *test = (test_ll_t *) vtest;
#endif
	time_t ioTimeoutCount = 0;
	time_t total_time = 0;
	OFF_T cur_total_io_count = 0;
	OFF_T last_total_io_count = 0;

	OFF_T tmp_io_count = 0;
	time_t run_time = 0;

	lvl_t msg_level = WARN;

	child_args_t *args = test->args;
	test_env_t *env = test->env;

	extern int signal_action;
	extern unsigned short glb_run;

#ifdef _DEBUG
	PDBG3(DBUG, args, "In timer %lu, %d\n", time(NULL), env->bContinue);
#endif
	do {
		Sleep(1000);
		run_time++;
#ifdef _DEBUG
		PDBG3(DBUG, args, "Continue timing %lu, %lu, %d\n", time(NULL),
		      run_time, env->bContinue);
#endif
		if (args->flags & CLD_FLG_W) {
			if ((args->flags & CLD_FLG_LINEAR)
			    && !(args->flags & CLD_FLG_NTRLVD)) {
				if (TST_OPER(args->test_state) == WRITER) {
					env->hbeat_stats.wtime++;
				}
			} else {
				env->hbeat_stats.wtime++;
			}
		}
		if (args->flags & CLD_FLG_R) {
			if ((args->flags & CLD_FLG_LINEAR)
			    && !(args->flags & CLD_FLG_NTRLVD)) {
				if (TST_OPER(args->test_state) == READER) {
					env->hbeat_stats.rtime++;
				}
			} else {
				env->hbeat_stats.rtime++;
			}
		}

		/*
		 * Check to see if we have made any IO progress in the last interval,
		 * if not incremment the ioTimeout timer, otherwise, clear it
		 */
		cur_total_io_count = env->global_stats.wcount
		    + env->cycle_stats.wcount
		    + env->hbeat_stats.wcount
		    + env->global_stats.rcount
		    + env->cycle_stats.rcount + env->hbeat_stats.rcount;

		if (cur_total_io_count == 0) {
			tmp_io_count = 1;
		} else {
			tmp_io_count = cur_total_io_count;
		}

		total_time = env->global_stats.rtime
		    + env->cycle_stats.rtime
		    + env->hbeat_stats.rtime
		    + env->global_stats.wtime
		    + env->cycle_stats.wtime + env->hbeat_stats.wtime;

#ifdef _DEBUG
		PDBG3(DBUG, args, "average number of seconds per IO: %0.8lf\n",
		      ((double)(total_time) / (double)(tmp_io_count)));
#endif

		if (cur_total_io_count == last_total_io_count) {	/* no IOs completed in interval */
			if (0 == (++ioTimeoutCount % args->ioTimeout)) {	/* no progress after modulo ioTimeout interval */
				if (args->flags & CLD_FLG_TMO_ERROR) {
					args->test_state =
					    SET_STS_FAIL(args->test_state);
					env->bContinue = FALSE;
					msg_level = ERR;
				}
				pMsg(msg_level, args,
				     "Possible IO hang condition, IO timeout reached, %lu seconds\n",
				     args->ioTimeout);
			}
#ifdef _DEBUG
			PDBG3(DBUG, args, "io timeout count: %lu\n",
			      ioTimeoutCount);
#endif
		} else {
			ioTimeoutCount = 0;
			last_total_io_count = cur_total_io_count;
#ifdef _DEBUG
			PDBG3(DBUG, args, "io timeout reset\n");
#endif
		}

		if (((args->hbeat > 0) && ((run_time % args->hbeat) == 0))
		    || (signal_action & SIGNAL_STAT)) {
			print_stats(args, env, HBEAT);
			update_cyc_stats(env);
			clear_stat_signal();
		}

		if (glb_run == 0) {
			break;
		}		/* global run flag cleared */
		if (signal_action & SIGNAL_STOP) {
			break;
		}
		/* user request to stop */
		if (args->flags & CLD_FLG_TMD) {	/* if timing */
			if (run_time >= args->run_time) {	/* and run time exceeded */
				break;
			}
		} else {	/* if not timing */
			if (env->kids <= 1) {	/* and the timer is the only child */
				break;
			}
		}
	} while (TRUE);
#ifdef _DEBUG
	PDBG3(DBUG, args, "Out of timer %lu, %lu, %d, %d\n", time(NULL),
	      run_time, env->bContinue, env->kids);
#endif

	if (args->flags & CLD_FLG_TMD) {	/* timed test, timer exit needs to stop io threads */
#ifdef _DEBUG
		PDBG3(DBUG, args,
		      "Setting bContinue to FALSE, timed test & timer exit\n");
#endif
		env->bContinue = FALSE;
	}

	TEXIT((uintptr_t) GETLASTERROR());
}
示例#3
0
文件: main.c 项目: 1587/ltp
void *threadedMain(void *vtest)
#endif
{
#ifndef WINDOWS
	test_ll_t *test = (test_ll_t *) vtest;
#endif

	OFF_T *pVal1;
	unsigned char *data_buffer_unaligned = NULL;
	unsigned long ulRV;
	int i;
	unsigned char *sharedMem;

	extern unsigned short glb_run;
	extern int signal_action;

	test->args->pid = GETPID();

	init_gbl_data(test->env);

	if (make_assumptions(test->args) < 0) {
		TEXIT((uintptr_t) GETLASTERROR());
	}
	if (check_conclusions(test->args) < 0) {
		TEXIT((uintptr_t) GETLASTERROR());
	}
	if (test->args->flags & CLD_FLG_DUMP) {
		/*
		 * All we are doing is dumping filespec data to STDOUT, so
		 * we will do this here and be done.
		 */
		do_dump(test->args);
		TEXIT((uintptr_t) GETLASTERROR());
	} else {
		ulRV = init_data(test, &data_buffer_unaligned);
		if (ulRV != 0) {
			TEXIT(ulRV);
		}
		pVal1 = (OFF_T *) test->env->shared_mem;
	}

	pMsg(START, test->args, "Start args: %s\n", test->args->argstr);

	/*
	 * This loop takes care of passes
	 */
	do {
		test->env->pass_count++;
		test->env->start_time = time(NULL);
		if (test->args->flags & CLD_FLG_RPTYPE) {	/* force random data to be different each cycle */
			fill_buffer(test->env->data_buffer,
				    ((test->args->htrsiz * BLK_SIZE) * 2), NULL,
				    0, CLD_FLG_RPTYPE);
		}
		sharedMem = test->env->shared_mem;
		memset(sharedMem + BMP_OFFSET, 0, test->env->bmp_siz);
		if ((test->args->flags & CLD_FLG_LINEAR)
		    && !(test->args->flags & CLD_FLG_NTRLVD)) {
			linear_read_write_test(test);
		} else {
			/* we only reset the end time if not running a linear read / write test */
			test->env->end_time =
			    test->env->start_time + test->args->run_time;
			test->env->bContinue = TRUE;
			*(pVal1 + OFF_WLBA) = test->args->start_lba;
			test->args->test_state =
			    DIRCT_INC(test->args->test_state);
			test->args->test_state =
			    SET_wFST_TIME(test->args->test_state);
			test->args->test_state =
			    SET_rFST_TIME(test->args->test_state);
			if (test->args->flags & CLD_FLG_W) {
				test->env->lastAction.oper = WRITER;
				test->args->test_state =
				    SET_OPER_W(test->args->test_state);
			} else {
				test->env->lastAction.oper = READER;
				test->args->test_state =
				    SET_OPER_R(test->args->test_state);
			}
			memset(test->env->action_list, 0,
			       sizeof(action_t) * test->args->t_kids);
			test->env->action_list_entry = 0;
			test->env->wcount = 0;
			test->env->rcount = 0;

			if (test->args->flags & CLD_FLG_CYC)
				if (test->args->cycles == 0) {
					pMsg(INFO, test->args,
					     "Starting pass %lu\n",
					     (unsigned long)test->env->
					     pass_count);
				} else {
					pMsg(INFO, test->args,
					     "Starting pass %lu of %lu\n",
					     (unsigned long)test->env->
					     pass_count, test->args->cycles);
			} else {
				pMsg(INFO, test->args, "Starting pass\n");
			}

			CreateTestChild(ChildTimer, test);
			for (i = 0; i < test->args->t_kids; i++) {
				CreateTestChild(ChildMain, test);
			}
			/* Wait for the children to finish */
			cleanUpTestChildren(test);
		}

		update_cyc_stats(test->env);
		if ((test->args->flags & CLD_FLG_CYC)
		    && (test->args->flags & CLD_FLG_PCYC)) {
			print_stats(test->args, test->env, CYCLE);
		}
		update_gbl_stats(test->env);

		if (signal_action & SIGNAL_STOP) {
			break;
		}		/* user request to stop */
		if ((glb_run == 0)) {
			break;
		}
		/* global request to stop */
		if (!(test->args->flags & CLD_FLG_CYC)) {
			break;	/* leave, unless cycle testing */
		} else {
			if ((test->args->cycles > 0)
			    && (test->env->pass_count >= test->args->cycles)) {
				break;	/* leave, cycle testing complete */
			}
		}
	} while (TST_STS(test->args->test_state));
	print_stats(test->args, test->env, TOTAL);

	FREE(data_buffer_unaligned);
	FREE(test->env->shared_mem);
#ifdef WINDOWS
	CloseHandle(OpenMutex(SYNCHRONIZE, TRUE, "gbl"));
	CloseHandle(OpenMutex(SYNCHRONIZE, TRUE, "data"));
#endif

	if (TST_STS(test->args->test_state)) {
		if (signal_action & SIGNAL_STOP) {
			pMsg(END, test->args,
			     "User Interrupt: Test Done (Passed)\n");
		} else {
			pMsg(END, test->args, "Test Done (Passed)\n");
		}
	} else {
		if (signal_action & SIGNAL_STOP) {
			pMsg(END, test->args,
			     "User Interrupt: Test Done (Failed)\n");
		} else {
			pMsg(END, test->args, "Test Done (Failed)\n");
		}
	}
	TEXIT((uintptr_t) GETLASTERROR());
}