@@ -137,11 +137,10 @@ static int shutdown;
137
137
static pthread_barrier_t barrier ;
138
138
139
139
static int cpu_count ;
140
- static cpu_set_t * cpusetp ;
141
- static int cpuset_size ;
140
+ static int all_cpus ;
142
141
143
- static int nr_threads = 2 ;
144
- static int use_nsecs = 0 ;
142
+ static int nr_threads ;
143
+ static int use_nsecs ;
145
144
146
145
static int mark_fd ;
147
146
@@ -650,6 +649,9 @@ static void teardown(void)
650
649
{
651
650
int fd ;
652
651
652
+ if (all_cpus )
653
+ return ;
654
+
653
655
fd = open_cpuset (CPUSET_PATH , "cpuset.cpu_exclusive" );
654
656
if (fd >= 0 ) {
655
657
write (fd , "0" , 2 );
@@ -1030,6 +1032,10 @@ static void loop(struct sched_data *sched_data, int nr_threads)
1030
1032
usleep (10000 );
1031
1033
printf ("\033[%dA" , nr_threads );
1032
1034
}
1035
+ usleep (10000 );
1036
+ for (i = 0 ; i < nr_threads ; i ++ ) {
1037
+ printf ("\n" );
1038
+ }
1033
1039
}
1034
1040
1035
1041
int main (int argc , char * * argv )
@@ -1043,11 +1049,11 @@ int main (int argc, char **argv)
1043
1049
pthread_t * thread ;
1044
1050
unsigned int interval = 1000 ;
1045
1051
unsigned int step = 500 ;
1052
+ int percent = 60 ;
1046
1053
u64 runtime ;
1047
1054
u64 start_period ;
1048
1055
u64 end_period ;
1049
1056
int nr_cpus ;
1050
- int all_cpus = 0 ;
1051
1057
int i ;
1052
1058
int c ;
1053
1059
@@ -1061,6 +1067,8 @@ int main (int argc, char **argv)
1061
1067
switch (c ) {
1062
1068
case 'a' :
1063
1069
all_cpus = 1 ;
1070
+ if (!nr_threads )
1071
+ nr_threads = cpu_count ;
1064
1072
break ;
1065
1073
case 'c' :
1066
1074
setcpu = optarg ;
@@ -1080,16 +1088,19 @@ int main (int argc, char **argv)
1080
1088
}
1081
1089
}
1082
1090
1091
+ if (!nr_threads )
1092
+ nr_threads = 1 ;
1093
+
1083
1094
if (setcpu ) {
1084
1095
nr_cpus = calc_nr_cpus (setcpu , & setcpu_buf );
1085
- if (nr_cpus < 0 ) {
1096
+ if (nr_cpus < 0 || nr_cpus > cpu_count ) {
1086
1097
fprintf (stderr , "Invalid cpu input '%s'\n" , setcpu );
1087
1098
exit (-1 );
1088
1099
}
1089
1100
} else
1090
- nr_cpus = 1 ;
1101
+ nr_cpus = cpu_count ;
1091
1102
1092
- if (!all_cpus && setcpu && cpu_count == nr_cpus ) {
1103
+ if (!all_cpus && cpu_count == nr_cpus ) {
1093
1104
printf ("Using all CPUS\n" );
1094
1105
all_cpus = 1 ;
1095
1106
}
@@ -1113,13 +1124,6 @@ int main (int argc, char **argv)
1113
1124
perror ("mlockall" );
1114
1125
}
1115
1126
1116
- cpusetp = CPU_ALLOC (cpu_count );
1117
- cpuset_size = CPU_ALLOC_SIZE (cpu_count );
1118
- if (!cpusetp ) {
1119
- perror ("allocating cpuset" );
1120
- exit (-1 );
1121
- }
1122
-
1123
1127
setup_ftrace_marker ();
1124
1128
1125
1129
thread = calloc (nr_threads , sizeof (* thread ));
@@ -1129,14 +1133,22 @@ int main (int argc, char **argv)
1129
1133
exit (-1 );
1130
1134
}
1131
1135
1136
+ if (nr_threads > nr_cpus ) {
1137
+ /*
1138
+ * More threads than CPUs, then have the total be
1139
+ * no more than 80 percent.
1140
+ */
1141
+ percent = nr_cpus * 80 / nr_threads ;
1142
+ }
1143
+
1132
1144
/* Set up the data while sill in SCHED_FIFO */
1133
1145
for (i = 0 ; i < nr_threads ; i ++ ) {
1134
1146
sd = & sched_data [i ];
1135
1147
/*
1136
1148
* Interval is the deadline/period
1137
1149
* The runtime is the percentage of that period.
1138
1150
*/
1139
- runtime = interval * 50 / 100 ;
1151
+ runtime = interval * percent / 100 ;
1140
1152
1141
1153
if (runtime < 2000 ) {
1142
1154
/*
@@ -1192,7 +1204,6 @@ int main (int argc, char **argv)
1192
1204
int * pids ;
1193
1205
1194
1206
res = make_cpuset (CPUSET_ALL , allcpu_buf , "0" ,
1195
- // CPUSET_FL_CPU_EXCLUSIVE |
1196
1207
CPUSET_FL_SET_LOADBALANCE |
1197
1208
CPUSET_FL_CLONE_CHILDREN |
1198
1209
CPUSET_FL_ALL_TASKS );
0 commit comments