Can I designate a core to excute code?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can I designate a core to excute code?

Jump to solution
1,318 Views
JHY
Contributor IV

I use i.MX6 dual in Linux and want to seperate tasks each cores.

Then is it possible to designate a core to excute codes?

For example, UART0 is running in core 0 and UART1 is running in core 1.

Labels (1)
Tags (3)
1 Solution
972 Views
igorpadykov
NXP Employee
NXP Employee

Hi Jaehee

in Linux kernel takes all task for multiprocessing,

not leaving chance to change smth, you can not change its behaviour.

So trying to implement this seemingly simple task will bring you

to jungles of kernel programming

Linux Knowledge Base and Tutorial

However in SDK you will find such example, described in

Chapter 3 "Multicore Startup" document iMX6_Firmware_Guide.pdf

i.MX 6Series Platform SDK

Best regards

chip

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
971 Views
LuisCasado
NXP Employee
NXP Employee

Hello,

You could try "isolcpus” kernel parameter.

http://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/re46.html

You could isolate a CPU. Then a threat can be assigned to that core using cpu affinity to run the process on this core and IRQ affinity to freeze the isolated core of managing irq's.

Best Regards,

Luis

971 Views
EdSutter
Senior Contributor II

Luis,

Have you tried this?

I need to do this exact thing, but it doesn't quite work as I think it should...

I'm running with an iMX6Dual.

I want to put *everything* on core 0.

Then bring up one thread and set its affinity to core1.

So, in my kernel command line I add:  ... isolcpus=1... to isolate core 1

And in the thread I run:

    cpu_set_t mask;

    CPU_ZERO(&mask);

    CPU_SET(1,&mask);

    sched_setaffinity(0,sizeof(mask),&mask);

to push it onto core 1; however, later I run:

printf("taskCore1 started (cpu=%d)\n",sched_getcpu());

and it tells me I'm on core 0.

Note if I don't include "isolcpus=1" on the command line, then this does

put that thread on core 1.

Any idea what's wrong here?

Ed

0 Kudos
972 Views
LuisCasado
NXP Employee
NXP Employee

Hi Ed,

Try building this code: http://people.seas.harvard.edu/~apw/stress/

With standard parameters you should get:

./stress -c 4 &

top

CPU0: 99.2% usr 0.7% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU1: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU2: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU3: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

With isolcpus=1

Mem: 57632K used, 708340K free, 0K shrd, 3512K buff, 15920K cached

CPU0: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU1: 0.0% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU2: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU3: 99.6% usr 0.3% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

And with :

taskset 2 ./stress -c 4 &

top

Mem: 58320K used, 707652K free, 0K shrd, 3784K buff, 15920K cached

CPU0: 0.0% usr 1.0% sys 0.0% nic 98.9% idle 0.0% io 0.0% irq 0.0% sirq

CPU1: 100% usr 0.0% sys 0.0% nic 0.0% idle 0.0% io 0.0% irq 0.0% sirq

CPU2: 0.0% usr 0.0% sys 0.0% nic 100% idle 0.0% io 0.0% irq 0.0% sirq

CPU3: 0.0% usr 0.0% sys 0.0% nic 100% idle 0.0% io 0.0% irq 0.0% sirq

In your case with 2 cores.

Best Regards,

Luis

This email and any associated attachments have been classified as

Freescale General Business

Freescale Internal Use Only

Freescale Confidential Proprietary

"All types of technical support (Schematic review, layout review, software review, hardware board and software) provided by Freescale Field application team are subject to Freescale's general Terms and Conditions unless superseded by a direct contract".

972 Views
EdSutter
Senior Contributor II

Thanks Luis,

once I realized the mistake I made (and fixed it), everything worked as expected.

Ed

0 Kudos
972 Views
EdSutter
Senior Contributor II

Ok, nevermind, I'm a moron...

I had misplaced one line in the code.

If I actually had used the code that I show above it would have worked.

I add this comment instead of deleting the previous reply I made because it may be useful to someone else.

:-(

0 Kudos
973 Views
igorpadykov
NXP Employee
NXP Employee

Hi Jaehee

in Linux kernel takes all task for multiprocessing,

not leaving chance to change smth, you can not change its behaviour.

So trying to implement this seemingly simple task will bring you

to jungles of kernel programming

Linux Knowledge Base and Tutorial

However in SDK you will find such example, described in

Chapter 3 "Multicore Startup" document iMX6_Firmware_Guide.pdf

i.MX 6Series Platform SDK

Best regards

chip

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------