All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu
@ 2014-01-16  9:40 嵌入式工程师
  0 siblings, 0 replies; 4+ messages in thread
From: 嵌入式工程师 @ 2014-01-16  9:40 UTC (permalink / raw
  To: xenomai@xenomai.org, Gilles Chanteperdrix

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(0)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!




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu
@ 2014-01-16  9:45 嵌入式工程师
  2014-01-16 22:33 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 4+ messages in thread
From: 嵌入式工程师 @ 2014-01-16  9:45 UTC (permalink / raw
  To: Gilles Chanteperdrix, xenomai@xenomai.org



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!







^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu
  2014-01-16  9:45 [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu 嵌入式工程师
@ 2014-01-16 22:33 ` Gilles Chanteperdrix
  2014-01-16 22:58   ` Gilles Chanteperdrix
  0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2014-01-16 22:33 UTC (permalink / raw
  To: 嵌入式工程师; +Cc: xenomai@xenomai.org

On 01/16/2014 10:45 AM, 嵌入式工程师 wrote:
> 
> 
> 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;
		}
	}
}

-- 
                                                                Gilles.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu
  2014-01-16 22:33 ` Gilles Chanteperdrix
@ 2014-01-16 22:58   ` Gilles Chanteperdrix
  0 siblings, 0 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2014-01-16 22:58 UTC (permalink / raw
  To: 嵌入式工程师; +Cc: xenomai@xenomai.org

On 01/16/2014 11:33 PM, Gilles Chanteperdrix wrote:
> On 01/16/2014 10:45 AM, 嵌入式工程师 wrote:
>>
>>
>> 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,

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;
		}
	}
}



-- 
                                                                Gilles.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-16 22:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-16  9:45 [Xenomai] xenomai-2.6.3 with freescale imx6 kernel threads binding cpu 嵌入式工程师
2014-01-16 22:33 ` Gilles Chanteperdrix
2014-01-16 22:58   ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2014-01-16  9:40 嵌入式工程师

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.