Commit 4cf44657 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'sched_ext-for-7.0-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext

Pull sched_ext fixes from Tejun Heo:

 - Various bug fixes for the example schedulers and selftests

* tag 'sched_ext-for-7.0-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext:
  tools/sched_ext: fix getopt not re-parsed on restart
  tools/sched_ext: scx_userland: fix data races on shared counters
  tools/sched_ext: scx_pair: fix stride == 0 crash on single-CPU systems
  tools/sched_ext: scx_central: fix CPU_SET and skeleton leak on early exit
  tools/sched_ext: scx_userland: fix stale data on restart
  tools/sched_ext: scx_flatcg: fix potential stack overflow from VLA in fcg_read_stats
  selftests/sched_ext: Fix rt_stall flaky failure
  tools/sched_ext: scx_userland: fix restart and stats thread lifecycle bugs
  tools/sched_ext: scx_central: fix sched_setaffinity() call with the set size
  tools/sched_ext: scx_flatcg: zero-initialize stats counter array
parents 8eb604d4 640c9dc7
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -50,11 +50,13 @@ int main(int argc, char **argv)
	__u64 seq = 0, ecode;
	__s32 opt;
	cpu_set_t *cpuset;
	size_t cpuset_size;

	libbpf_set_print(libbpf_print_fn);
	signal(SIGINT, sigint_handler);
	signal(SIGTERM, sigint_handler);
restart:
	optind = 1;
	skel = SCX_OPS_OPEN(central_ops, scx_central);

	skel->rodata->central_cpu = 0;
@@ -73,6 +75,7 @@ int main(int argc, char **argv)
			u32 central_cpu = strtoul(optarg, NULL, 0);
			if (central_cpu >= skel->rodata->nr_cpu_ids) {
				fprintf(stderr, "invalid central CPU id value, %u given (%u max)\n", central_cpu, skel->rodata->nr_cpu_ids);
				scx_central__destroy(skel);
				return -1;
			}
			skel->rodata->central_cpu = (s32)central_cpu;
@@ -106,9 +109,10 @@ int main(int argc, char **argv)
	 */
	cpuset = CPU_ALLOC(skel->rodata->nr_cpu_ids);
	SCX_BUG_ON(!cpuset, "Failed to allocate cpuset");
	CPU_ZERO_S(CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids), cpuset);
	CPU_SET(skel->rodata->central_cpu, cpuset);
	SCX_BUG_ON(sched_setaffinity(0, sizeof(*cpuset), cpuset),
	cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids);
	CPU_ZERO_S(cpuset_size, cpuset);
	CPU_SET_S(skel->rodata->central_cpu, cpuset_size, cpuset);
	SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset),
		   "Failed to affinitize to central CPU %d (max %d)",
		   skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);
	CPU_FREE(cpuset);
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
	signal(SIGINT, sigint_handler);
	signal(SIGTERM, sigint_handler);
restart:
	optind = 1;
	skel = SCX_OPS_OPEN(cpu0_ops, scx_cpu0);

	skel->rodata->nr_cpus = libbpf_num_possible_cpus();
+10 −3
Original line number Diff line number Diff line
@@ -102,21 +102,27 @@ static float read_cpu_util(__u64 *last_sum, __u64 *last_idle)

static void fcg_read_stats(struct scx_flatcg *skel, __u64 *stats)
{
	__u64 cnts[FCG_NR_STATS][skel->rodata->nr_cpus];
	__u64 *cnts;
	__u32 idx;

	cnts = calloc(skel->rodata->nr_cpus, sizeof(__u64));
	if (!cnts)
		return;

	memset(stats, 0, sizeof(stats[0]) * FCG_NR_STATS);

	for (idx = 0; idx < FCG_NR_STATS; idx++) {
		int ret, cpu;

		ret = bpf_map_lookup_elem(bpf_map__fd(skel->maps.stats),
					  &idx, cnts[idx]);
					  &idx, cnts);
		if (ret < 0)
			continue;
		for (cpu = 0; cpu < skel->rodata->nr_cpus; cpu++)
			stats[idx] += cnts[idx][cpu];
			stats[idx] += cnts[cpu];
	}

	free(cnts);
}

int main(int argc, char **argv)
@@ -135,6 +141,7 @@ int main(int argc, char **argv)
	signal(SIGINT, sigint_handler);
	signal(SIGTERM, sigint_handler);
restart:
	optind = 1;
	skel = SCX_OPS_OPEN(flatcg_ops, scx_flatcg);

	skel->rodata->nr_cpus = libbpf_num_possible_cpus();
+7 −1
Original line number Diff line number Diff line
@@ -53,10 +53,10 @@ int main(int argc, char **argv)
	signal(SIGINT, sigint_handler);
	signal(SIGTERM, sigint_handler);
restart:
	optind = 1;
	skel = SCX_OPS_OPEN(pair_ops, scx_pair);

	skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus();
	assert(skel->rodata->nr_cpu_ids > 0);
	skel->rodata->pair_batch_dur_ns = __COMPAT_ENUM_OR_ZERO("scx_public_consts", "SCX_SLICE_DFL");

	/* pair up the earlier half to the latter by default, override with -s */
@@ -76,6 +76,12 @@ int main(int argc, char **argv)
		}
	}

	/* Stride must be positive to pair distinct CPUs. */
	if (stride <= 0) {
		fprintf(stderr, "Invalid stride %d, must be positive\n", stride);
		scx_pair__destroy(skel);
		return -1;
	}
	bpf_map__set_max_entries(skel->maps.pair_ctx, skel->rodata->nr_cpu_ids / 2);

	/* Resize arrays so their element count is equal to cpu count. */
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ int main(int argc, char **argv)
	signal(SIGINT, sigint_handler);
	signal(SIGTERM, sigint_handler);
restart:
	optind = 1;
	skel = SCX_OPS_OPEN(sdt_ops, scx_sdt);

	while ((opt = getopt(argc, argv, "fvh")) != -1) {
Loading