int read_file(char *filepath, int action, unsigned int *value)
{
    int num_line = 0;
    FILE *fp;
    switch (action)
    {
    case GET_SHARES:
        *value = read_shares_file(filepath);
        if (*value == -1)
            return -1;
        break;

    case GET_TASKS:
        fp = fopen (filepath, "r");
        if (fp == NULL)
            error_function("Could not open file", filepath);
        while (fgets(target, LINE_MAX, fp) != NULL)
            num_line++;
        *value = (unsigned int)num_line;
        if (fclose (fp))
            error_function ("Could not close file", filepath);
        break;

    default:
        error_function("Wrong action type passed to fun read_file for ", filepath);
        break;
    }
    return 0;
}
示例#2
0
int main(int argc, char* argv[])
{

	int test_num;
	int task_num;
	int len;
	int num_cpus;	/* Total time = TIME_INTERVAL *num_cpus in the machine */
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char mysharesfile[FILENAME_MAX], ch;
	/* Following variables are to capture parameters from script*/
	char *group_num_p, *mygroup_p, *script_pid_p, *num_cpus_p, *test_num_p, *task_num_p;
	gid_t mygroup_num;	        /* A number attached with a group*/
	int fd;          	        /* A descriptor to open a fifo for synchronized start*/
	int counter =0; 	 	/* To take n number of readings*/
	double total_cpu_time,  	/* Accumulated cpu time*/
		delta_cpu_time,  	/* Time the task could run on cpu(s) (in an interval)*/
		prev_cpu_time=0;
	double exp_cpu_time;            /* Expected time in % as obtained by shares calculation */
	struct rusage cpu_usage;
	unsigned long int mygroup_shares;
	time_t current_time, prev_time, delta_time;
	unsigned int fmyshares, num_tasks;/* f-> from file. num_tasks is tasks in this group*/
	struct sigaction newaction, oldaction;

	mygroup_num = -1;
	num_cpus = 0;
	task_num = 0;
	test_num = 0;

	/* Signal handling for alarm*/
	sigemptyset (&newaction.sa_mask);
	newaction.sa_handler = signal_handler_alarm;
	newaction.sa_flags=0;
	sigaction (SIGALRM, &newaction, &oldaction);

	/* Collect the parameters passed by the script */
	group_num_p	= getenv("GROUP_NUM");
	mygroup_p	= getenv("MYGROUP");
	script_pid_p 	= getenv("SCRIPT_PID");
	num_cpus_p 	= getenv("NUM_CPUS");
	test_num_p 	= getenv("TEST_NUM");
	task_num_p 	= getenv("TASK_NUM");
	/* Check if all of them are valid */
	if ((test_num_p != NULL) && (((test_num =atoi(test_num_p)) <= 10) && ((test_num =atoi(test_num_p)) >= 9)))
	{
		if ((group_num_p != NULL) && (mygroup_p != NULL) && \
			(script_pid_p != NULL) && (num_cpus_p != NULL) && (task_num_p != NULL))
		{
			mygroup_num	 = atoi(group_num_p);
			scriptpid	 = atoi(script_pid_p);
			num_cpus	 = atoi (num_cpus_p);
			task_num	 = atoi (task_num_p);
			sprintf(mygroup,"%s", mygroup_p);
		}
		else
		{
			tst_brkm (TBROK, cleanup, "Invalid other input parameters\n");
		}
	}
	else
	{
		tst_brkm (TBROK, cleanup, "Invalid test number passed\n");
	}

	/*
	 * Let us give the default group 100 shares, as other groups will have
	 * a multiple of 100 shares.
	 * WARN: For large num of groups this may hit MAX_SHARES
	 */
	mygroup_shares = mygroup_num * 100;

	sprintf(mytaskfile, "%s", mygroup);
	strcat (mytaskfile,"/tasks");
	sprintf(mysharesfile, "%s", mygroup);
	strcat (mysharesfile,"/cpu.shares");
	/* Need some technique so as only 1 task per grp writes to shares file */
	if (test_num == 9)
		write_to_file (mysharesfile, "w", mygroup_shares);    /* Write the shares of the group*/

	write_to_file (mytaskfile, "a", getpid());    /* Assign the task to it's group*/

	fd = open ("./myfifo", 0);
	if (fd == -1)
	{
		tst_brkm (TBROK, cleanup, "Could not open fifo for synchronization");
	}

	read (fd, &ch, 1);	         /* To block all tasks here and fire them up at the same time*/

	/*
	 * We now calculate the expected % cpu time of this task by getting
	 * it's group's shares, the total shares of all the groups and the
	 * number of tasks in this group.
	 */
	FLAG = 0;
	total_shares = 0;
	shares_pointer = &total_shares;
	len = strlen (path);
	if (!strncpy (fullpath, path, len))
		tst_brkm (TBROK, cleanup, "Could not copy directory path %s ", path);

	if (scan_shares_files(shares_pointer) != 0)
		tst_brkm (TBROK, cleanup, "From function scan_shares_files in %s ", fullpath);

	/* return val: -1 in case of function error, else 2 is min share value */
	if ((fmyshares = read_shares_file(mysharesfile)) < 2)
		tst_brkm (TBROK, cleanup, "in reading shares files  %s ", mysharesfile);

	if ((read_file (mytaskfile, GET_TASKS, &num_tasks)) < 0)
		tst_brkm (TBROK, cleanup, "in reading tasks files  %s ", mytaskfile);

	exp_cpu_time = (double)(fmyshares * 100) /(total_shares * num_tasks);

	prev_time = time (NULL);	 /* Note down the time*/

	while (1)
	{
		/* Need to run some cpu intensive task, which also frequently checks the timer value*/
		double f = 274.345, mytime;	/*just a float number to take sqrt*/
		alarm (TIME_INTERVAL);
		timer_expired = 0;
		while (!timer_expired)	/* Let the task run on cpu for TIME_INTERVAL*/
			f = sqrt (f*f); /* Time of this operation should not be high otherwise we can
					 * exceed the TIME_INTERVAL to measure cpu usage
					 */
		current_time = time (NULL);
		delta_time = current_time - prev_time;	/* Duration in case its not exact TIME_INTERVAL*/

		getrusage (0, &cpu_usage);
		total_cpu_time = (cpu_usage.ru_utime.tv_sec + cpu_usage.ru_utime.tv_usec * 1e-6 + /* user time*/
				cpu_usage.ru_stime.tv_sec + cpu_usage.ru_stime.tv_usec * 1e-6) ;  /* system time*/
		delta_cpu_time = total_cpu_time - prev_cpu_time;

		prev_cpu_time = total_cpu_time;
		prev_time = current_time;

		/* calculate % cpu time each task gets */
		if (delta_time > TIME_INTERVAL)
			mytime =  (delta_cpu_time * 100) / (delta_time * num_cpus);
		else
			mytime =  (delta_cpu_time * 100) / (TIME_INTERVAL * num_cpus);

                fprintf (stdout,"Grp:-%3d task-%3d:CPU TIME{calc:-%6.2f(s)i.e. %6.2f(%%) exp:-%6.2f(%%)}\
with %3u shares in %lu (s) INTERVAL\n",mygroup_num, task_num, delta_cpu_time, mytime,\
exp_cpu_time, fmyshares, delta_time);

		counter++;

		if (counter >= NUM_INTERVALS)	 /* Take n sets of readings for each shares value*/
		{
		switch (test_num)
			{
			case 9:			/* Test 09 */
				exit (0);	/* This task is done with its job*/
				break;
			case 10:			/* Test 10 */
				exit (0);		/* This task is done with its job*/
				break;
			default:
				tst_brkm (TBROK, cleanup, "Invalid test number passed\n");
				break;

			}	/* end switch*/
		}	/* end if*/
        }	/* end while*/
}	/* end main*/
示例#3
0
int main(int argc, char *argv[])
{

	int test_num, task_num, len, num_cpus;
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char mysharesfile[FILENAME_MAX], ch;
	/* Following variables are to capture parameters from script */
	char *group_num_p, *mygroup_p, *script_pid_p, *num_cpus_p;
	char *test_num_p, *task_num_p;
	pid_t pid;
	gid_t mygroup_num;	/* A number attached with a group */
	int fd;			/* to open a fifo to synchronize */
	int counter = 0;	/* To take n number of readings */
	double total_cpu_time,	/* Accumulated cpu time */
	 delta_cpu_time,	/* Time the task could run on cpu(s) */
	 prev_cpu_time = 0;
	double exp_cpu_time;	/* Exp time in % by shares calculation */

	struct rusage cpu_usage;
	time_t current_time, prev_time, delta_time;
	unsigned int fmyshares, num_tasks;
	struct sigaction newaction, oldaction;

	mygroup_num = -1;
	num_cpus = 0;
	task_num = 0;
	test_num = 0;

	/* Signal handling for alarm */
	sigemptyset(&newaction.sa_mask);
	newaction.sa_handler = signal_handler_alarm;
	newaction.sa_flags = 0;
	sigaction(SIGALRM, &newaction, &oldaction);

	/* Collect the parameters passed by the script */
	group_num_p = getenv("GROUP_NUM");
	mygroup_p = getenv("MYGROUP");
	script_pid_p = getenv("SCRIPT_PID");
	num_cpus_p = getenv("NUM_CPUS");
	test_num_p = getenv("TEST_NUM");
	task_num_p = getenv("TASK_NUM");
	/* Check if all of them are valid */
	if ((test_num_p != NULL) && (((test_num = atoi(test_num_p)) <= 8) &&
				     ((test_num = atoi(test_num_p)) >= 6))) {
		if ((group_num_p != NULL) && (mygroup_p != NULL) &&
		    (script_pid_p != NULL) && (num_cpus_p != NULL) &&
		    (task_num_p != NULL)) {
			mygroup_num = atoi(group_num_p);
			scriptpid = atoi(script_pid_p);
			num_cpus = atoi(num_cpus_p);
			task_num = atoi(task_num_p);
			sprintf(mygroup, "%s", mygroup_p);
		} else {
			tst_brkm(TBROK, cleanup,
				 "Invalid other input parameters\n");
		}
	} else {
		tst_brkm(TBROK, cleanup, "Invalid test number passed\n");
	}

	sprintf(mytaskfile, "%s", mygroup);
	sprintf(mysharesfile, "%s", mygroup);
	strcat(mytaskfile, "/tasks");
	strcat(mysharesfile, "/cpu.shares");
	pid = getpid();
	write_to_file(mytaskfile, "a", pid);	/* Assign task to it's group */

	fd = open("./myfifo", 0);
	if (fd == -1)
		tst_brkm(TBROK, cleanup, "Could not open fifo synchronize");

	read(fd, &ch, 1);	/* Block task here to synchronize */

	/*
	 * We need not calculate the expected % cpu time of this task, as
	 * neither it is required nor it can be predicted as there are idle
	 * system tasks (and others too) in this group.
	 */
	FLAG = 0;
	total_shares = 0;
	shares_pointer = &total_shares;
	len = strlen(path);
	if (!strncpy(fullpath, path, len))
		tst_brkm(TBROK, cleanup,
			 "Could not copy directory path %s ", path);

	if (scan_shares_files(shares_pointer) != 0)
		tst_brkm(TBROK, cleanup,
			 "From function scan_shares_files in %s ", fullpath);

	/* return val -1 in case of function error, else 2 is min share value */
	if ((fmyshares = read_shares_file(mysharesfile)) < 2)
		tst_brkm(TBROK, cleanup,
			 "in reading shares files  %s ", mysharesfile);

	if ((read_file(mytaskfile, GET_TASKS, &num_tasks)) < 0)
		tst_brkm(TBROK, cleanup,
			 "in reading tasks files  %s ", mytaskfile);

	exp_cpu_time = (double)(fmyshares * 100) / (total_shares * num_tasks);

	prev_time = time(NULL);	/* Note down the time */

	while (1) {
		/*
		 * Need to run some cpu intensive task, which also
		 * frequently checks the timer value
		 */
		double f = 274.345, mytime;	/*just a float number for sqrt */
		alarm(TIME_INTERVAL);
		timer_expired = 0;
		/*
		 * Let the task run on cpu for TIME_INTERVAL. Time of this
		 * operation should not be high otherwise we can exceed the
		 * TIME_INTERVAL to measure cpu usage
		 */
		while (!timer_expired)
			f = sqrt(f * f);

		current_time = time(NULL);
		/* Duration in case its not exact TIME_INTERVAL */
		delta_time = current_time - prev_time;

		getrusage(0, &cpu_usage);
		/* total_cpu_time = total user time + total sys time */
		total_cpu_time = (cpu_usage.ru_utime.tv_sec +
				  cpu_usage.ru_utime.tv_usec * 1e-6 +
				  cpu_usage.ru_stime.tv_sec +
				  cpu_usage.ru_stime.tv_usec * 1e-6);
		delta_cpu_time = total_cpu_time - prev_cpu_time;

		prev_cpu_time = total_cpu_time;
		prev_time = current_time;

		/* calculate % cpu time each task gets */
		if (delta_time > TIME_INTERVAL)
			mytime = (delta_cpu_time * 100) /
			    (delta_time * num_cpus);
		else
			mytime = (delta_cpu_time * 100) /
			    (TIME_INTERVAL * num_cpus);

		/* No neeed to print the results */
		fprintf(stdout, "Grp:-%3d task-%3d:CPU TIME{calc:-%6.2f(s)"
			" i.e. %6.2f(%%) exp:-%6.2f(%%)} in %lu (s)\n",
			mygroup_num, task_num, delta_cpu_time, mytime,
			exp_cpu_time, delta_time);

		counter++;

		if (counter >= NUM_INTERVALS) {
			switch (test_num) {
			case 6:	/* Test 06 */
			case 7:	/* Test 07 */
			case 8:	/* Test 08 */
				exit(0);	/* This task is done */
				break;
			default:
				tst_brkm(TBROK, cleanup,
					 "Invalid test num passed\n");
				break;

			}	/* end switch */
		}		/* end if */
	}			/* end while */
}				/* end main */
int main(int argc, char *argv[])
{

	int num_cpus, test_num, len;	/* Total time = TIME_INTERVAL*num_cpus*/
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char mysharesfile[FILENAME_MAX], ch;
	pid_t pid;
	int my_group_num;	        /* A number attached with a group*/
	int fd;          	        /* To open a fifo for synchronization*/
	int first_counter = 0;  	/* To take n number of readings*/
	int second_counter = 0;    	/* no of times shares have changed*/
	double total_cpu_time;  	/* Accumulated cpu time*/
	double delta_cpu_time;  	/* Time the task could run on cpu(s)*/
	double prev_cpu_time = 0;
	double exp_cpu_time;		/* Exp time in % by shares calculation*/
	struct rusage cpu_usage;
	time_t current_time, prev_time, delta_time;
	unsigned long int myshares = 2, baseshares = 1000;
	unsigned int fmyshares, num_tasks;
	struct sigaction newaction, oldaction;

	num_cpus = 0;
	test_num = 0;
	my_group_num = -1;

	/* Signal handling for alarm*/
	sigemptyset(&newaction.sa_mask);
	newaction.sa_handler = signal_handler_alarm;
	newaction.sa_flags = 0;
	sigaction(SIGALRM, &newaction, &oldaction);

	/* Check if all parameters passed are correct*/
	if ((argc < 5) || ((my_group_num = atoi(argv[1])) <= 0) || \
				((scriptpid = atoi(argv[3])) <= 0) || \
					((num_cpus = atoi(argv[4])) <= 0) || \
						(test_num = atoi(argv[5])) <= 0)
		tst_brkm(TBROK, cleanup, "Invalid input parameters\n");

	if (test_num == 1)
		myshares *= my_group_num;
	else if (test_num == 3)
		myshares = baseshares;
	else
		tst_brkm(TBROK, cleanup, "Wrong Test num passed. Exiting.\n");

	sprintf(mygroup, "%s", argv[2]);
	sprintf(mytaskfile, "%s", mygroup);
	sprintf(mysharesfile, "%s", mygroup);
	strcat(mytaskfile, "/tasks");
	strcat(mysharesfile, "/cpu.shares");
	pid = getpid();
	write_to_file(mytaskfile, "a", pid);    /* Assign task to it's group*/
	write_to_file(mysharesfile, "w", myshares);
	dbg("Default task's initial shares = %u", myshares);

	fd = open("./myfifo", 0);
	if (fd == -1)
		tst_brkm(TBROK, cleanup, "Could not open fifo to synchronizae");

	read(fd, &ch, 1);	/* To fire all the tasks up at the same time*/

	/*
	 * We need not calculate the expected % cpu time of this task, as
	 * neither it is required nor it can be predicted as there are idle
	 * system tasks (and others too) in this group.
	 */
	FLAG = 0;
	total_shares = 0;
	shares_pointer = &total_shares;
	len = strlen(path);
	if (!strncpy(fullpath, path, len))
		tst_brkm(TBROK, cleanup,
			 "Could not copy directory path %s ", path);

	if (scan_shares_files(shares_pointer) != 0)
		tst_brkm(TBROK, cleanup,
		 "From function scan_shares_files in %s ", fullpath);

	/* return val -1 in case of function error, else 2 is min share value */
	if ((fmyshares = read_shares_file(mysharesfile)) < 2)
		tst_brkm(TBROK, cleanup,
			 "in reading shares files  %s ", mysharesfile);

	if ((read_file(mytaskfile, GET_TASKS, &num_tasks)) < 0)
		tst_brkm(TBROK, cleanup,
			 "in reading tasks files  %s ", mytaskfile);

	exp_cpu_time = (double)(fmyshares * 100) / (total_shares * num_tasks);

	prev_time = time(NULL);	 /* Note down the time*/

	while (1) {
		/*
		 * Need to run some cpu intensive task, which also
		 * frequently checks the timer value
		 */
		double f = 274.345, mytime;	/*just a float number for sqrt*/
		alarm(TIME_INTERVAL);
		timer_expired = 0;
		/*
		 * Let the task run on cpu for TIME_INTERVAL. Time of this
		 * operation should not be high otherwise we can exceed the
		 * TIME_INTERVAL to measure cpu usage
		 */
		while (!timer_expired)
			f = sqrt(f * f);

		current_time = time(NULL);
		/* Duration in case its not exact TIME_INTERVAL*/
		delta_time = current_time - prev_time;

		getrusage(0, &cpu_usage);
		/* total_cpu_time = total user time + total sys time */
		total_cpu_time = (cpu_usage.ru_utime.tv_sec +
				cpu_usage.ru_utime.tv_usec * 1e-6 +
				cpu_usage.ru_stime.tv_sec +
				cpu_usage.ru_stime.tv_usec * 1e-6) ;
		delta_cpu_time = total_cpu_time - prev_cpu_time;

		prev_cpu_time = total_cpu_time;
		prev_time = current_time;

		/* calculate % cpu time each task gets */
		if (delta_time > TIME_INTERVAL)
			mytime = (delta_cpu_time * 100) /
					 (delta_time * num_cpus);
		else
			mytime = (delta_cpu_time * 100) /
					 (TIME_INTERVAL * num_cpus);

		/*
		 * Lets print the results. The exp cpu time calculated may not
		 * be correct due to running system tasks at the moment
		 */
		fprintf(stdout, "DEF TASK:CPU TIME{calc:-%6.2f(s)"
			" i.e. %6.2f(%%) exp:-%6.2f(%%)} with %lu(shares)"
			" in %lu (s) INTERVAL\n", delta_cpu_time,  mytime,
					 exp_cpu_time, myshares, delta_time);
		first_counter++;

		/* Take n sets of readings for each shares value*/
		if (first_counter >= NUM_INTERVALS) {
			first_counter = 0;
			second_counter++;
			if (second_counter >= NUM_SETS)
				exit(0);	/* This task is done */

			/* Keep same ratio but change values*/
			if (test_num == 1) {
				myshares = MULTIPLIER * myshares;
				write_to_file(mysharesfile, "w", myshares);
			}
			/* No need to change shares for def task for test 3 */

		}/* end if*/
	}/* end while*/
}/* end main*/
示例#5
0
int main(int argc, char *argv[])
{

	int num_cpus;
	int test_num;
	int len;		/* Total time = TIME_INTERVAL *num_cpus in the machine */
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char mysharesfile[FILENAME_MAX], ch;
	pid_t pid;
	gid_t my_group_num;	/* A number attached with a group */
	int fd;			/* A descriptor to open a fifo for synchronized start */
	int first_counter = 0;	/* To take n number of readings */
	int second_counter = 0;	/* To track number of times the base value of shares has been changed */
	double total_cpu_time,	/* Accumulated cpu time */
	 delta_cpu_time,	/* Time the task could run on cpu(s) (in an interval) */
	 prev_cpu_time = 0;
	double exp_cpu_time;	/* Expected time in % as obtained by shares calculation */
	struct rusage cpu_usage;
	time_t current_time, prev_time, delta_time;
	unsigned long int myshares = 2, baseshares = 1000;	/* Simply the base value to start with */
	unsigned int fmyshares, num_tasks;	/* f-> from file. num_tasks is tasks in this group */
	struct sigaction newaction, oldaction;

	my_group_num = -1;
	num_cpus = 0;
	test_num = 0;

	/* Signal handling for alarm */
	sigemptyset(&newaction.sa_mask);
	newaction.sa_handler = signal_handler_alarm;
	newaction.sa_flags = 0;
	sigaction(SIGALRM, &newaction, &oldaction);

	/* Check if all parameters passed are correct */
	if ((argc < 5) || ((my_group_num = atoi(argv[1])) <= 0)
	    || ((scriptpid = atoi(argv[3])) <= 0)
	    || ((num_cpus = atoi(argv[4])) <= 0)
	    || (test_num = atoi(argv[5])) <= 0) {
		tst_brkm(TBROK, cleanup, "Invalid input parameters\n");
	}

	if (test_num == 1)	/* Test 01 & Test 02 */
		myshares *= my_group_num;
	else if (test_num == 3)	/* Test 03 */
		myshares = baseshares;
	else {
		tst_brkm(TBROK, cleanup,
			 "Wrong Test number passed. Exiting Test...\n");
	}

	sprintf(mygroup, "%s", argv[2]);
	sprintf(mytaskfile, "%s", mygroup);
	sprintf(mysharesfile, "%s", mygroup);
	strcat(mytaskfile, "/tasks");
	strcat(mysharesfile, "/cpu.shares");
	pid = getpid();
	write_to_file(mytaskfile, "a", pid);	/* Assign the task to it's group */
	write_to_file(mysharesfile, "w", myshares);

	fd = open("./myfifo", 0);
	if (fd == -1) {
		tst_brkm(TBROK, cleanup,
			 "Could not open fifo for synchronization");
	}

	fprintf(stdout, "\ntask-%d SHARES=%lu\n", my_group_num, myshares);
	read(fd, &ch, 1);	/* To block all tasks here and fire them up at the same time */

	/*
	 * We now calculate the expected % cpu time of this task by getting
	 * it's group's shares, the total shares of all the groups and the
	 * number of tasks in this group.
	 */
	FLAG = 0;
	total_shares = 0;
	shares_pointer = &total_shares;
	len = strlen(path);
	if (!strncpy(fullpath, path, len))
		tst_brkm(TBROK, cleanup, "Could not copy directory path %s ",
			 path);

	if (scan_shares_files(shares_pointer) != 0)
		tst_brkm(TBROK, cleanup,
			 "From function scan_shares_files in %s ", fullpath);

	/* return val: -1 in case of function error, else 2 is min share value */
	if ((fmyshares = read_shares_file(mysharesfile)) < 2)
		tst_brkm(TBROK, cleanup, "in reading shares files  %s ",
			 mysharesfile);

	if ((read_file(mytaskfile, GET_TASKS, &num_tasks)) < 0)
		tst_brkm(TBROK, cleanup, "in reading tasks files  %s ",
			 mytaskfile);

	exp_cpu_time = (double)(fmyshares * 100) / (total_shares * num_tasks);

	prev_time = time(NULL);	/* Note down the time */

	while (1) {
		/* Need to run some cpu intensive task, which also frequently checks the timer value */
		double f = 274.345, mytime;	/*just a float number to take sqrt */
		alarm(TIME_INTERVAL);
		timer_expired = 0;
		while (!timer_expired)	/* Let the task run on cpu for TIME_INTERVAL */
			f = sqrt(f * f);	/* Time of this operation should not be high otherwise we can
						 * exceed the TIME_INTERVAL to measure cpu usage
						 */
		current_time = time(NULL);
		delta_time = current_time - prev_time;	/* Duration in case its not exact TIME_INTERVAL */

		getrusage(0, &cpu_usage);
		total_cpu_time = (cpu_usage.ru_utime.tv_sec + cpu_usage.ru_utime.tv_usec * 1e-6 +	/*user */
				  cpu_usage.ru_stime.tv_sec + cpu_usage.ru_stime.tv_usec * 1e-6);	/*sys */
		delta_cpu_time = total_cpu_time - prev_cpu_time;

		prev_cpu_time = total_cpu_time;
		prev_time = current_time;

		/* calculate % cpu time each task gets */
		if (delta_time > TIME_INTERVAL)
			mytime =
			    (delta_cpu_time * 100) / (delta_time * num_cpus);
		else
			mytime =
			    (delta_cpu_time * 100) / (TIME_INTERVAL * num_cpus);

		fprintf(stdout, "task-%d:CPU TIME{calc:-%6.2f(s)i.e. %6.2f(%%) exp:-%6.2f(%%)}\
with %lu(shares) in %lu (s) INTERVAL\n", my_group_num, delta_cpu_time, mytime,
			exp_cpu_time, myshares, delta_time);
		first_counter++;

		if (first_counter >= NUM_INTERVALS) {	/* Take n sets of readings for each shares value */
			first_counter = 0;
			second_counter++;
			if (second_counter >= NUM_SETS)
				exit(0);	/* This task is done with its job */

			/* Change share values depending on the test_num */
			if (test_num == 1) {
				/* Keep same ratio but change values */
				myshares = MULTIPLIER * myshares;
			} else {
				/* Increase for odd task and decrease for even task */
				if (my_group_num % 2)
					myshares +=
					    baseshares * GRANULARITY / 100;
				else
					myshares -=
					    baseshares * GRANULARITY / 100;
			}
			write_to_file(mysharesfile, "w", myshares);
			if (test_num == 3) {
				/*
				 * Read the shares file and again calculate the cpu fraction
				 * No need to read tasks file as we do not migrate tasks
				 * No need to scan all shares file as total shares are const
				 */
				if ((fmyshares =
				     read_shares_file(mysharesfile)) < 2)
					tst_brkm(TBROK, cleanup,
						 "in reading shares files  %s ",
						 mysharesfile);
				exp_cpu_time =
				    (double)(fmyshares * 100) / (total_shares *
								 num_tasks);
			}

			fprintf(stdout, "\ntask-%d SHARES=%lu\n", my_group_num,
				myshares);
		}		/* end if */
	}			/* end while */
}				/* end main */
/*
 * Function: scan_shares_file()
 * This function scans all the shares files under the mountpoint
 * of the controller and returns the total added shares of all
 * the groups (currently excludes default group) ??
 */
int scan_shares_files(unsigned int *shares_pointer)
{
    struct stat 	statbuffer;
    DIR		*dp;
    char		*path_pointer;

    /*
     * Check if we can get stat of the file
     */
    if (lstat (fullpath, &statbuffer) < 0)
        error_function("Can not read stat for file ", fullpath);

    if (S_ISDIR (statbuffer.st_mode) == 0) /* not a directory */
    {
        /*
         * We run all user tasks in the created groups and not default groups. So
         * exclude the shares of default group. FLAG to ensure dir_pointer is non NULL
         */
        if ((FLAG == 1) && (strcmp(fullpath, "/dev/cpuctl/cpu.shares") != 0) &&\
                (strcmp (dir_pointer->d_name, "cpu.shares") == 0))
        {
            *shares_pointer += read_shares_file (fullpath);
        }
        return 0;
    }

    /*
     * Now it's a directory. let the path_pointer point to the end
     * of fullpath to append new files names
     */

    path_pointer = fullpath + strlen(fullpath);
    *path_pointer++ = '/';
    *path_pointer	= 0;

    if ((dp = opendir(fullpath)) == NULL) /* Error in opening directory */
        error_function("Can't open ", fullpath);
    /*
     * search all groups recursively and get total shares
     */

    while ((dir_pointer = readdir(dp)) != NULL) /* Error in reading directory */
    {
        if ((strcmp(dir_pointer->d_name, ".") == 0) || (strcmp(dir_pointer->d_name, "..") == 0))
            continue;	/* ignore current and parent directory */

        FLAG = 1;
        strcpy (path_pointer, dir_pointer->d_name ); /* append name to fullpath */

        if ((retval = scan_shares_files(shares_pointer)) != 0)
            break;
    }

    /*
     * This directory is searched fully. let us go back to parent directory again
     */

    path_pointer[-1] = 0;

    if (closedir (dp) < 0)
        error_function("Could not close dir ", fullpath);
    return 0;
}