Hi,
This patch adds the ninth testcase (stress) for cpu controller.
<cpuctl-stress2.patch>
Signed-off-by: Sudhir Kumar <[EMAIL PROTECTED]>
Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
===================================================================
--- /dev/null
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/cpuctl_test04.c
@@ -0,0 +1,209 @@
+/******************************************************************************/
+/*
*/
+/* Copyright (c) International Business Machines Corp., 2007
*/
+/*
*/
+/* This program is free software; you can redistribute it and/or modify
*/
+/* it under the terms of the GNU General Public License as published by
*/
+/* the Free Software Foundation; either version 2 of the License, or
*/
+/* (at your option) any later version.
*/
+/*
*/
+/* This program is distributed in the hope that it will be useful,
*/
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of
*/
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
*/
+/* the GNU General Public License for more details.
*/
+/*
*/
+/* You should have received a copy of the GNU General Public License
*/
+/* along with this program; if not, write to the Free Software
*/
+/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+/*
*/
+/******************************************************************************/
+
+/******************************************************************************/
+/*
*/
+/* File: cpuctl_test04.c
*/
+/*
*/
+/* Description: This is a c program that tests the cpucontroller fairness of
*/
+/* scheduling the tasks according to their group shares. This
*/
+/* testcase tests the ability of the cpu controller to provide
*/
+/* fairness for share values (absolute).
*/
+/*
*/
+/* Total Tests: 1
*/
+/*
*/
+/* Test Name: cpu_controller_test04
*/
+/*
*/
+/* Test Assertion
*/
+/* Please refer to the file cpuctl_testplan.txt
*/
+/*
*/
+/* Author: Sudhir Kumar [EMAIL PROTECTED] */
+/*
*/
+/* History:
*/
+/* Created- 20/12/2007 -Sudhir Kumar [EMAIL PROTECTED] */
+/*
*/
+/******************************************************************************/
+
+/* Standard Include Files */
+#include <unistd.h>
+#include <math.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/resource.h>
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "test.h" /* LTP harness APIs*/
+
+#define TIME_INTERVAL 200 /* Time interval in seconds*/
+#define NUM_INTERVALS 2 /* How many iterations of TIME_INTERVAL */
+
+extern int Tst_count;
+char *TCID = "cpu_controller_test06";
+int TST_TOTAL = 1;
+pid_t scriptpid;
+extern void
+cleanup()
+{
+ kill (scriptpid, SIGUSR1);/* Inform the shell to do cleanup*/
+ tst_exit (); /* Report exit status*/
+}
+
+int write_to_file (char * file, const char* mode, unsigned int value);
+void signal_handler_alarm (int signal );
+int timer_expired = 0;
+
+int main(int argc, char* argv[])
+{
+
+ int test_num, task_num, num_cpus; /* To calculate cpu time in %*/
+ char mygroup[64], mytaskfile[64], mysharesfile[64], 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;
+ int mygroup_num, /* A number attached with a group*/
+ fd, /* A descriptor to open a fifo for
synchronized start*/
+ 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;
+ struct rusage cpu_usage;
+ unsigned long int mygroup_shares;
+ time_t current_time, prev_time, delta_time;
+ struct sigaction newaction, oldaction;
+ /* 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)) <= 4) &&
((test_num =atoi(test_num_p)) >= 1)))
+ {
+ 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");
+ }
+
+ mygroup_shares = mygroup_num + 1; /* Min shares value currently
is 2 */
+ 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
*/
+ 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*/
+ 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;
+ 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,"Group-%3d(Shares-%4u) task_num:%3d cpu time-->
%6.3f\%(%6.3fs)\tinterval:%lu\n",
+ mygroup_num, mygroup_shares, task_num, mytime, delta_cpu_time,
delta_time);
+ counter++;
+
+ if (counter >= NUM_INTERVALS) /* Take n sets of readings for
each shares value*/
+ {
+ switch (test_num)
+ {
+ case 4:
+ 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*/
+
+
+int write_to_file (char *file, const char *mode, unsigned int value)
+{
+ FILE *fp;
+ fp = fopen (file, mode);
+ if (fp == NULL)
+ {
+ tst_brkm (TBROK, cleanup, "Could not open file %s for writing",
file);
+ }
+ fprintf (fp, "%u\n", value);
+ fclose (fp);
+ return 0;
+}
+void signal_handler_alarm (int signal)
+{
+ timer_expired = 1;
+}
Index:
ltp-full-20080131/testcases/kernel/controllers/cpuctl/run_cpuctl_stress_test.sh
===================================================================
---
ltp-full-20080131.orig/testcases/kernel/controllers/cpuctl/run_cpuctl_stress_test.sh
+++
ltp-full-20080131/testcases/kernel/controllers/cpuctl/run_cpuctl_stress_test.sh
@@ -25,10 +25,15 @@
# After setup it runs some of the tasks in different groups.
#
# setup includes creating controller device, mounting it with
#
# cgroup filesystem with option cpu and creating groups in it.
#
+# This same script can run 4 testcases depending on test number
#
+# depending on the test number passed by the calling script.
#
#
#
# Functions: get_num_groups(): decides num of groups based on num of cpus
#
# setup(): creaes /dev/cpuctl, mounts cgroup fs on it, creates
#
# groups in that, creates fifo to fire tasks at one time.
#
+# cleanup(): Does the required cleanup after running test.
#
+# usage(): Displays the usage of the script.
#
+# Common functions are kept in a file parameters.sh
#
#
#
# Precaution: Avoid system use by other applications/users to get fair and
#
# appropriate results
#
@@ -45,7 +50,7 @@
export TCID="cpuctl_test06";
-export TST_TOTAL=3;
+export TST_TOTAL=4;
export TST_COUNT=1; # how to tell here ??
RC=0; # return code from functions
@@ -55,6 +60,7 @@ TEST_NUM=$1; # To run the des
TASK_NUM=0; # The serial number of a task
TOTAL_TASKS=0; # Total num of tasks in any test
TASKS_IN_GROUP=0; # Total num of tasks in a group
+NICEVALUE=0;
SCRIPT_PID=$$;
FILE="stress-123"; # suffix for results file
@@ -77,23 +83,41 @@ usage ()
}
########################## main #######################
# For testcase 1, 2 & 3 N--> $NUM_CPUS
- # i,2 & 3 are not heavy stress test
+ # 1,2 & 3 are not heavy stress test
case ${TEST_NUM} in
"1" ) # N X M (N groups with M tasks each)
+ if [ $N -eq 1 ]
+ then
+ N=2; # Min 2 groups for group scheduling
+ fi;
NUM_GROUPS=$N;
TASKS_IN_GROUP=$M;
echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
;;
"2" ) # N*M X 1 (N*M groups with 1 task each)
+ if [ $N -eq 1 ]
+ then
+ N=2; # To keep total tasks same as in case 1
+ fi;
NUM_GROUPS=`expr $N \* $M`;
TASKS_IN_GROUP=1;
;;
"3" ) # 1 X N*M (1 group with N*M tasks)
+ if [ $N -eq 1 ]
+ then
+ N=2; # To keep total tasks same as in case 1
+ fi;
NUM_GROUPS=1;
TASKS_IN_GROUP=`expr $N \* $M`;
;;
+ "4" ) # Heavy stress test
+ NUM_GROUPS=`expr $N \* $M`;
+ TASKS_IN_GROUP=`expr 1 \* $M`;
+ FILE="stress-4";
+ echo `date` >> $LTPROOT/output/cpuctl_results_$FILE.txt;
+ ;;
* )
usage;
;;
@@ -116,9 +140,10 @@ usage ()
if [ -f cpuctl_test03 ]
then
+ echo CPUCTL NUM_GROUPS vs NUM_TASKS TEST $TEST_NUM >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
echo Test $TEST_NUM: NUM_GROUPS=$NUM_GROUPS >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
echo Test $TEST_NUM: TASKS PER GROUP=$TASKS_IN_GROUP >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
- echo "==========================" >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
+ echo "==========================================" >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
for i in $(seq 1 $NUM_GROUPS)
do
MYGROUP=/dev/cpuctl/group_$i
@@ -150,12 +175,70 @@ usage ()
fi;
TOTAL_TASKS=$TASK_NUM;
;;
+ "4" )
+
+ if [ -f cpuctl_test04 ]
+ then
+ echo CPU CONTROLLER HEAVY STRESS TEST 4: >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
+ echo Test $TEST_NUM: NUM_GROUPS=$NUM_GROUPS >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
+ echo Test $TEST_NUM: TASKS PER GROUP=$TASKS_IN_GROUP >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
+ echo "===============================" >>
$LTPROOT/output/cpuctl_results_$FILE.txt;
+
+ # Create 4 priority windows
+ RANGE1=`expr $NUM_GROUPS / 4`;
+ RANGE2=`expr $RANGE1 + $RANGE1`;
+ RANGE3=`expr $RANGE2 + $RANGE1`;
+ for i in $(seq 1 $NUM_GROUPS)
+ do
+ MYGROUP=/dev/cpuctl/group_$i
+ for j in $(seq 1 $TASKS_IN_GROUP)
+ do
+ TASK_NUM=`expr $TASK_NUM + 1`;
+ cp cpuctl_test04 cpuctl_task_$TASK_NUM 2>/dev/null;
+ chmod +x cpuctl_task_$TASK_NUM;
+
+ # Per group nice value change must not affect
group/task fairness
+ if [ $i -le $RANGE1 ]
+ then
+ NICEVALUE=-16;
+ elif [ $i -gt $RANGE1 ] && [ $i -le $RANGE2 ]
+ then
+ NICEVALUE=-17;
+ elif [ $i -gt $RANGE2 ] && [ $i -le $RANGE3 ]
+ then
+ NICEVALUE=-18;
+ else
+ NICEVALUE=-19;
+ fi
+
+ GROUP_NUM=$i MYGROUP=$MYGROUP SCRIPT_PID=$SCRIPT_PID
NUM_CPUS=$NUM_CPUS \
+ TEST_NUM=$TEST_NUM TASK_NUM=$TASK_NUM nice -n
$NICEVALUE ./cpuctl_task_$TASK_NUM \
+ >>$LTPROOT/output/cpuctl_results_$FILE.txt 2>/dev/null &
+ if [ $? -ne 0 ]
+ then
+ echo "Error: Could not run
./cpuctl_task_$TASK_NUM"
+ cleanup;
+ exit -1;
+ else
+ PID[$TASK_NUM]=$!;
+ fi;
+ j=`expr $j + 1`
+ done; # end j loop
+ i=`expr $i + 1`
+ done; # end i loop
+ else
+ echo "Source file not compiled..Plz check
Makefile...Exiting test"
+ cleanup;
+ exit -1;
+ fi;
+ TOTAL_TASKS=$TASK_NUM;
+ ;;
* )
usage;
;;
esac
- sleep 3
+ sleep 8
echo TASKS FIRED
echo helloworld > myfifo;
Index: ltp-full-20080131/testcases/kernel/controllers/test_controllers.sh
===================================================================
--- ltp-full-20080131.orig/testcases/kernel/controllers/test_controllers.sh
+++ ltp-full-20080131/testcases/kernel/controllers/test_controllers.sh
@@ -46,6 +46,7 @@ then
$LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 1;
$LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 2;
$LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 3;
+ $LTPROOT/testcases/bin/run_cpuctl_stress_test.sh 4;
else
echo "CONTROLLERS TESTCASES: WARNING";
echo "Kernel does not support for cpu controller";
Index: ltp-full-20080131/testcases/kernel/controllers/cpuctl/parameters.sh
===================================================================
--- ltp-full-20080131.orig/testcases/kernel/controllers/cpuctl/parameters.sh
+++ ltp-full-20080131/testcases/kernel/controllers/cpuctl/parameters.sh
@@ -63,8 +63,7 @@ setup ()
fi
# Create different groups
- i=1;
- while [ "$i" -le "$NUM_GROUPS" ]
+ for i in $(seq 1 $NUM_GROUPS)
do
group=group_$i;
mkdir /dev/cpuctl/$group;# 2>/dev/null
@@ -74,7 +73,6 @@ setup ()
cleanup;
exit -1;
fi
- i=`expr $i + 1`
done
}
Thanks,
Sudhir Kumar
LTC, ISTL
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list