Skip to content

Commit 9d89850

Browse files
committed
cyclicdeadline: More progress
Still in the development phase. Cleaned up some code and also made it default to use all CPUs (no cgroups created), and a single task. Currently, the -a is used to make a thread per CPU. Signed-off-by: Steven Rostedt <[email protected]>
1 parent e5bdbb3 commit 9d89850

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

cyclicdeadline.c

+28-17
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,10 @@ static int shutdown;
137137
static pthread_barrier_t barrier;
138138

139139
static int cpu_count;
140-
static cpu_set_t *cpusetp;
141-
static int cpuset_size;
140+
static int all_cpus;
142141

143-
static int nr_threads = 2;
144-
static int use_nsecs = 0;
142+
static int nr_threads;
143+
static int use_nsecs;
145144

146145
static int mark_fd;
147146

@@ -650,6 +649,9 @@ static void teardown(void)
650649
{
651650
int fd;
652651

652+
if (all_cpus)
653+
return;
654+
653655
fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
654656
if (fd >= 0) {
655657
write(fd, "0", 2);
@@ -1030,6 +1032,10 @@ static void loop(struct sched_data *sched_data, int nr_threads)
10301032
usleep(10000);
10311033
printf("\033[%dA", nr_threads);
10321034
}
1035+
usleep(10000);
1036+
for (i = 0; i < nr_threads; i++) {
1037+
printf("\n");
1038+
}
10331039
}
10341040

10351041
int main (int argc, char **argv)
@@ -1043,11 +1049,11 @@ int main (int argc, char **argv)
10431049
pthread_t *thread;
10441050
unsigned int interval = 1000;
10451051
unsigned int step = 500;
1052+
int percent = 60;
10461053
u64 runtime;
10471054
u64 start_period;
10481055
u64 end_period;
10491056
int nr_cpus;
1050-
int all_cpus = 0;
10511057
int i;
10521058
int c;
10531059

@@ -1061,6 +1067,8 @@ int main (int argc, char **argv)
10611067
switch (c) {
10621068
case 'a':
10631069
all_cpus = 1;
1070+
if (!nr_threads)
1071+
nr_threads = cpu_count;
10641072
break;
10651073
case 'c':
10661074
setcpu = optarg;
@@ -1080,16 +1088,19 @@ int main (int argc, char **argv)
10801088
}
10811089
}
10821090

1091+
if (!nr_threads)
1092+
nr_threads = 1;
1093+
10831094
if (setcpu) {
10841095
nr_cpus = calc_nr_cpus(setcpu, &setcpu_buf);
1085-
if (nr_cpus < 0) {
1096+
if (nr_cpus < 0 || nr_cpus > cpu_count) {
10861097
fprintf(stderr, "Invalid cpu input '%s'\n", setcpu);
10871098
exit(-1);
10881099
}
10891100
} else
1090-
nr_cpus = 1;
1101+
nr_cpus = cpu_count;
10911102

1092-
if (!all_cpus && setcpu && cpu_count == nr_cpus) {
1103+
if (!all_cpus && cpu_count == nr_cpus) {
10931104
printf("Using all CPUS\n");
10941105
all_cpus = 1;
10951106
}
@@ -1113,13 +1124,6 @@ int main (int argc, char **argv)
11131124
perror("mlockall");
11141125
}
11151126

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-
11231127
setup_ftrace_marker();
11241128

11251129
thread = calloc(nr_threads, sizeof(*thread));
@@ -1129,14 +1133,22 @@ int main (int argc, char **argv)
11291133
exit(-1);
11301134
}
11311135

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+
11321144
/* Set up the data while sill in SCHED_FIFO */
11331145
for (i = 0; i < nr_threads; i++) {
11341146
sd = &sched_data[i];
11351147
/*
11361148
* Interval is the deadline/period
11371149
* The runtime is the percentage of that period.
11381150
*/
1139-
runtime = interval * 50 / 100;
1151+
runtime = interval * percent / 100;
11401152

11411153
if (runtime < 2000) {
11421154
/*
@@ -1192,7 +1204,6 @@ int main (int argc, char **argv)
11921204
int *pids;
11931205

11941206
res = make_cpuset(CPUSET_ALL, allcpu_buf, "0",
1195-
// CPUSET_FL_CPU_EXCLUSIVE |
11961207
CPUSET_FL_SET_LOADBALANCE |
11971208
CPUSET_FL_CLONE_CHILDREN |
11981209
CPUSET_FL_ALL_TASKS);

0 commit comments

Comments
 (0)