UserMode&Kernel ModeRemember this?userprocessusermode(modebit=1)callssystemcallreturnfromsystemcalluserprocessexecutingreturntrapkernelmode bit=0modebit=1kernelmode(mode bit = 0)executesystemcallAnother question: How much time was spent in each part?11
User Mode & Kernel Mode • Remember this? 11 Another question: How much time was spent in each part?
UsertimevsSystemtimeSo, not just the memory, but also the execution of aprocess is also divided into two parts.-Usertimeandsystemtime12
User time VS System time • So, not just the memory, but also the execution of a process is also divided into two parts. – User time and system time 12
UsertimevS SystemtimeSo, not just the memory, but also the execution of aprocess is also divided into two parts.-UsertimeandsystemtimeSomesystemcallsmaytakealongtimecallingsystemcall.E.g.,accessingafloppydrivee.g.,getpid()Usertime-Timespentoncodesinuser-spacememory.Systemtime-Timespentoncodesinkernel-spacememory.ReadinformationandTotal running time = user time + system timethesystemcall returns.13
User time VS System time • So, not just the memory, but also the execution of a process is also divided into two parts. – User time and system time 13 calling system call. e.g., getpid() Read information and the system call returns. Some system calls may take a long time. E.g., accessing a floppy drive. Total running time = user time + system time. User time – Time spent on codes in user-space memory. System time – Time spent on codes in kernel-space memory
Usertime vs Systemtime-example1Let's tell the difference...with the tool "time"Timeelapsed when"./time example"terminates$time./time_examplerealOm0.003sTheusertimeof"/timeexample"measurecuser0m0.003swhentheprocessisonCPU0m0.000ssys$Thesystemtimeof"./timeexample"measuredwhentheprocessisonCPUint main(void)(int x =0for(i=1;i<=100000;i++)x=x+i/printf("x=%d\n",x);Why comment7Commented on purpose.this line???return 0;714
• Let’s tell the difference.with the tool “time”. $ time ./time_example real 0m0.003s user 0m0.003s sys 0m0.000s $ _ User time VS System time – example 1 14 int main(void) { int x = 0; for(i = 1; i <= 100000; i++) { x = x + i; // printf(“x = %d\n”, x); } return 0; } Commented on purpose. Time elapsed when “./time_example” terminates. The user time of “./time_example” measured when the process is on CPU. The system time of “./time_example” measured when the process is on CPU. Why comment this line???
Usertimevs Systemtime-example1Let's tell the difference...with the tool "time"int main(void)$time./time_exampleint x=o;for(i=1;i<=100000;i++){realOm0.003sx=x+i;/printf("x=%d\n",x);user0m0.003s0m0.000ssys$Commentedonpurpose.return Q;int main(void)$time./timeexampleint x= o;for(i=1;i<=100000;i++){realOm0.677sx=x+i0mo.032suserprintf("x=%d\n",x);sysOmo.227s子6ACommentreleasedreturn ;See?Accessinghardwarecoststheprocessmoretime.15
• Let’s tell the difference.with the tool “time”. $ time ./time_example real 0m0.003s user 0m0.003s sys 0m0.000s $ _ User time VS System time – example 1 15 int main(void) { int x = 0; for(i = 1; i <= 100000; i++) { x = x + i; printf(“x = %d\n”, x); } return 0; } Comment released. $ time ./time_example real 0m0.677s user 0m0.032s sys 0m0.227s $ _ See? Accessing hardware costs the process more time. int main(void) { int x = 0; for(i = 1; i <= 100000; i++) { x = x + i; // printf(“x = %d\n”, x); } return 0; } Commented on purpose