gsoh83
gsoh83

Reputation: 177

Why is there code running speed difference between linux user space and kernel space?

When I run some simple while loop code in linux user space and kernel space and measure elapsed time, I can get difference.

test code is that access some hardware registers in Arm Cortex SoC chip.

for(k = 0; k < 100000; k++)
{   //I tested this code in user space and kernel space with IOCTL.
    for(i = 0; i < 1000; i++)  
    {  
        tv2 = *(volatile UInt32 *)(0xfe110080);  
        *(volatile UInt32 *)(0xfe628024) = i + tv2 ;  
    }
}

The result is
User Layer : 52002.16 ms
Kernel Layer : 32650.53 ms

Kernel layer was 1.6x faster than User layer.

Upvotes: 1

Views: 748

Answers (1)

Balu
Balu

Reputation: 128

In general, User layer takes more time because it makes few extra calls to complete task.

For example, take an example of reading a file. to read a file from user layer, we call read(file_name). This read call internally calls kernel read call, which talks with device driver of disk and gets data.

Therefore, kernel layer is performing better because of reduction in number of calls.

Upvotes: 4

Related Questions