Skip to contentSkip to conversation

xenomai-2.6.3 with freescale imx6 kernel threads binding cpu

Xenomai 嵌入式工程师 2 participants 3 messages Jan 16, 2014

lore
Share & tools
lore
#0 lore raw

Just the wrong message,below is my question。

I use xenomai-2.6.3 with freescale imx6 kernel-3.0.35 threads binding cpu。 rt_task_create(&t1, "task1", 4096, 88, T_FPU|T_CPU(1));
But will randomly select binding cpu, not what I want cpu1,what is wrong? thanks!

#1 lore raw
Quoted 9 lines · 嵌入式工程师

Just the wrong message,below is my question。

I use xenomai-2.6.3 with freescale imx6 kernel-3.0.35 threads binding cpu。 rt_task_create(&t1, "task1", 4096, 88, T_FPU|T_CPU(1));
But will randomly select binding cpu, not what I want cpu1,what is wrong? thanks!

Hi,

I have been trying to reproduce this issue with the program which follows, and was unable to do it. Could you try to run this program on your system? Or post a program, reduced to its simplest possible form, demonstrating the issue you observe?

Regards.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <sched.h>
#include <unistd.h>

#include <native/task.h>

void body(void *cookie)

{
	long target_cpu = (long)cookie;
	long real_cpu = sched_getcpu();
	
	if (real_cpu < 0) {
		perror("sched_getcpu");
		exit(EXIT_FAILURE);
	}
	
	if (real_cpu != target_cpu) {
		fprintf(stderr, "Real cpu is %ld instead of %ld\n", 
			real_cpu, target_cpu);
		exit(EXIT_FAILURE);
	}
}

int main(void)

{
	int nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
	double divider = 1 / sqrt(RAND_MAX);
	unsigned i = 0;

	if (nrcpus < 0) {
		perror("sysconf(_SC_NPROCESSORS_ONLN)");
		return EXIT_FAILURE;
	}

	srandom(time(NULL));

	for(;;) {
		char name[80];
		long target_cpu;
		cpu_set_t cpu_set;
		RT_TASK task;
		long mycpu;
		int err;
		++i;

		target_cpu = (int)(random() * divider) % nrcpus;
		mycpu = (int)(random() * divider) % nrcpus;

		CPU_ZERO(&cpu_set);
		CPU_SET(mycpu, &cpu_set);
		
		err = sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
		if (err < 0) {
			perror("sched_setaffinity");
			return EXIT_FAILURE;
		}
		
		fprintf(stderr, "%09d: mine: %ld, target: %ld\n", 
			i, mycpu, target_cpu);

		snprintf(name, sizeof(name), "task%d", i);
		err = rt_task_create(&task, name, 65536, 88, 
				T_FPU | T_CPU(target_cpu) | T_JOINABLE);
		if (err < 0) {
			fprintf(stderr, "rt_task_create: %d, %d\n", err, i);
			return EXIT_FAILURE;
		}

		err = rt_task_start(&task, body, (void *)target_cpu);
		if (err < 0) {
			fprintf(stderr, "rt_task_start: %d\n", err);
			return EXIT_FAILURE;
		}
		
		err = rt_task_join(&task);
		if (err < 0) {
			fprintf(stderr, "rt_task_join: %d\n", err);
			return EXIT_FAILURE;
		}
	}
}
Signature · 1 line
                                                                Gilles.
#2 lore raw
Quoted 11 lines · Gilles Chanteperdrix
Quoted 9 lines · 嵌入式工程师

Just the wrong message,below is my question。

I use xenomai-2.6.3 with freescale imx6 kernel-3.0.35 threads binding cpu。 rt_task_create(&t1, "task1", 4096, 88, T_FPU|T_CPU(1));
But will randomly select binding cpu, not what I want cpu1,what is wrong? thanks!

Quoted 4 lines

Hi,

I have been trying to reproduce this issue with the program which follows,

Or better:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <sched.h>
#include <unistd.h>

#include <native/task.h>

void body(void *cookie)

{
	long target_cpu = (long)cookie;
	long real_cpu = sched_getcpu();
	
	if (real_cpu < 0) {
		perror("sched_getcpu");
		exit(EXIT_FAILURE);
	}
	
	if (real_cpu != target_cpu) {
		fprintf(stderr, "Real cpu is %ld instead of %ld\n", 
			real_cpu, target_cpu);
		exit(EXIT_FAILURE);
	}
}

int main(void)

{
	int nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
	double divider = 1 / sqrt(RAND_MAX);
	unsigned i = 0;

	if (nrcpus < 0) {
		perror("sysconf(_SC_NPROCESSORS_ONLN)");
		return EXIT_FAILURE;
	}

	srandom(time(NULL));

	for(;;) {
		char name[80];
		long target_cpu;
		cpu_set_t cpu_set;
		RT_TASK task;
		long aff;
		int err;
		++i;

		target_cpu = (int)(random() * divider) % nrcpus;
		aff = 1 + (int)(random() * divider) % ((1 << nrcpus) - 1);

		CPU_ZERO(&cpu_set);
		for (err = 0; err < nrcpus; err++)
			if (aff & (1 << err))
				CPU_SET(err, &cpu_set);
		
		err = sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
		if (err < 0) {
			perror("sched_setaffinity");
			return EXIT_FAILURE;
		}
		
		fprintf(stderr, "%09d: affinity: %ld, target: %ld\n", 
			i, aff, target_cpu);

		snprintf(name, sizeof(name), "task%d", i);
		err = rt_task_create(&task, name, 65536, 88, 
				T_FPU | T_CPU(target_cpu) | T_JOINABLE);
		if (err < 0) {
			fprintf(stderr, "rt_task_create: %d, %d\n", err, i);
			return EXIT_FAILURE;
		}

		err = rt_task_start(&task, body, (void *)target_cpu);
		if (err < 0) {
			fprintf(stderr, "rt_task_start: %d\n", err);
			return EXIT_FAILURE;
		}
		
		err = rt_task_join(&task);
		if (err < 0) {
			fprintf(stderr, "rt_task_join: %d\n", err);
			return EXIT_FAILURE;
		}
	}
}
Signature · 1 line
                                                                Gilles.