Test for kernel state and user-state switching overhead

Source: Internet
Author: User

Recently developed with the fuse file system, the file system is implemented in the user-state, but its filesystem operation interface must be registered in the kernel state, so it is necessary to study the kernel state to the user state overhead.
The following example is seen on StackOverflow, which basically reflects the difference in overhead:
In Linux testing this test program, GETUID is a system call that returns the ID of the current user

1 #include <unistd.h>23#define MAX 1000000004int  Main () {5   int  II; 6    for (ii=0; ii<max; ii++) getuid (); 7   return 0 ; 8 }

The result shows that the loop is 100 million times more than 8 seconds.
Real 0m8.438s
User 0m3.952s
SYS 0m4.485s

When testing with the following program,

1#include <unistd.h>2 #defineMAX 1000000003 4 int_getid ()5 {6         return 1;7 }8 9 intMain () {Ten   intII; One    for(ii=0; ii<max; ii++) _getid (); A   return 0; -}

The results of the operation are as follows:

Real 0m0.305s
User 0m0.304s
SYS 0m0.000s

The time consumption is significantly reduced.

The two program time consumption mainly lies in the kernel state and the user state switch, each cycle involves the user state and so on the user state and so on the switch, therefore consumes the time to be many.

It also means that I have to modify the functionality of the various file interfaces of fuse to make it no longer repeatedly switch the user's kernel state.

Test for kernel state and user-state switching overhead

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.