Use the clock_getres system call to extract the clock resolution.
See posix_getres.c code example.
Comment on result, i.e. the importance of resolution in determining overall system
performance and responsiveness.
The resolution value is returned in the clock_getres() system call to give application programmers an idea of the (in)accuracy of timers. Timer values are rounded up to this resolution values.
Figure 1: Clock Resolution : posix_getres.c
Without time synchronization, accurately correlating information among devices becomes very difficult, and almost impossible. When it comes to security, if you cannot successfully compare logs between each of your devices such as routers and all your network servers, you will find it very hard to develop a reliable picture of an incident. Again, even if you are able to put the pieces together, unsynchronized times, especially between log files, may give an attacker with a good attorney enough wiggle room to escape prosecution.
Part A: nice
Implement a simple piece of code where the process runtime is measured e.g.
similar to timer_usleep.c code provided in the attachment. Ensure
sleeptime argument is greater than resolution. Summarise the results, i.e.
distribution of sleep times and the total process run time.
usleep – suspends execution for microsecond intervals. The usleep() function suspends execution of the calling thread for (at least) usec microseconds. The sleep may be lengthened slightly by any system activity or by the time spent processing the call or by the granularity of system timers.
The source code for this is as below:
#include<stdio.h>
#include<time.h>
#include <sys/time.h>
#include <sys/resource.h>
int main(int argc, char** argv)
{
struct timeval tv;
int i,delay,num_iter;
double init,start,stop;
if (argc!=3)
{
fprintf(stderr, “Usage: %s <sleep time..msec><num_iteration>n”, argv[0]);
exit(1);
}
// progname=argv[0];
delay=atoi(argv[1]);
num_iter=atoi(argv[2]);
printf(“Delay is %d..num_iter is %dn”,delay,num_iter);
gettimeofday( &tv,&tz);
init=tv.tv_sec + tv.tv_usec*0.000001;
for(i=0;i<num_iter;++i)
{
gettimeofday( &tv,&tz);
start=tv.tv_sec + tv.tv_usec*0.000001;
// Now sleep
usleep(delay*1000);
gettimeofday( &tv,&tz);
stop=tv.tv_sec + tv.tv_usec*0.000001;
printf(“Time is %ld : %ld..slept for %lf msn”,tv.tv_sec,tv.tv_usec,(stop-start)*1000);
}
printf(“Total time taken : actual %lf theory(excl. runtime): %d, ms n”,(stop-
init)*1000,num_iter*delay);
return 0;
}
Upon execution of the above code, the below screenshot is the running program.
Figure 2.1: Usleep – time_usleep.c
In Figure 2.1, demonstrates how usleep allocates execution time to processes by suspending execution of other processes by microseconds. In my case, running usleep with sleep time set to 100 resulted to “Total time taken : actual 18.857956 theory(excl. runtime): 0, ms”
Implement the very same code but use the FIFO scheduling policy for one
version. (Need to run as root). See timer_mod_FIFO.c as an example.
This code implements the process at the highest FIFO priority. Run this
concurrently with other versions running under default timesharing policy
i.e. timer_usleep.c. Summarise and analyse performance.
The below is the souce code for the same:
#include<stdio.h>
#include<time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sched.h>
int main(int argc, char** argv){
struct timeval tv;
struct timezone tz;
int i,delay,num_iter;
double init,start,stop;
// FIFO stuff
int j;
struct sched_param my_sched_params;
int scheduler,prio;
// Start
// Set this process to highest priority FIFO
my_sched_params.sched_priority=sched_get_priority_max(SCHED_FIFO);
printf(“Max FIFO priority is %d n”,my_sched_params.sched_priority);
j=sched_setscheduler(getpid(),SCHED_FIFO,&my_sched_params);
// Now check actual parameters
scheduler=sched_getscheduler(0); // 0 is shorthand for calling process ID
prio=sched_getparam(getpid(),&my_sched_params);
printf(“Scheduler is %d (0=TS, 1=FIFO, 2=RR)and priority is %dn”,scheduler,my_sched_params.sched_priority);
if (argc!=3) {
fprintf(stderr, “Usage: %s <sleep time..msec><num_iter>n”, argv[0]);
exit(1);
}
// progname=argv[0];
delay=atoi(argv[1]);
num_iter=atoi(argv[2]);printf(“Delay is %d..num_iter is %dn”,delay,num_iter);
gettimeofday( &tv,&tz);
init=tv.tv_sec + tv.tv_usec*0.000001;
for(i=0;i<num_iter;++i)
{
gettimeofday( &tv,&tz);
start=tv.tv_sec + tv.tv_usec*0.000001;
// now sleep
usleep(delay*1000);
gettimeofday( &tv,&tz);
stop=tv.tv_sec + tv.tv_usec*0.000001;
printf(“Time is %ld : %ld..slept for %lf msn”,tv.tv_sec,tv.tv_usec,(stop-
start)*1000);
}
printf(“Total time taken : actual %lf theory(excl. runtime): %d, ms n”,(stop-
init)*1000,num_iter*delay);
return 0;
}
The screen shots below shows execution of the FIFO vs Time sharing
Figure 2b: 1-FIFO vs TimeSharing-FIFO.png
Figure 2b: 2-Fifo vs TimeSharing-Usleep
From the two figures above (figure 2b 1-2). it is clearly evident that FIFO performs better than Usleep. Looking closely at the ranges, FIFO takes approximately 0.0128 ms while Usleep takes around 0.060 ms. This makes a huge difference as show by the total time. For Instance, with sleep time set to 200 for both the Fifo and Usleep, Fifo total execution time was 2428 ms while usleep had an execution time of 5893.69.
Part C: FIFO vs timesharing part 2
Repeat part B above, but use code timer_FIFO_loop.c. Compare with
part B; the results should show benefits of FIFO much more clearly. If so, why?
Figure 2c : timer_FIFO_loop
Figure 2c : timer_usleep.c.
In Part B, we already compared Fifo performance against Usleep’s. Here in part C we carry out almost a similar comparison, but with Fifo_loop. The Out come is so impressive. Fifo execution time is less than half that of usleep. In both cases, sleep time was set to 50000.
Part A:
Implement a memory intensive piece of code where process runtime is measured (similar to timer_mem_use.c provided). Run and analyse performance (an array of 10000000 floats take up approximately 40MB). As above, use a system monitor tool to get a feel for what’s happening with memory. Run a number of processes concurrently thus increasing the memory requirement until memory is being fully utilised and paging is a necessity. The command line vmstat utility allows you to look at the degree of paging going on. Increase number of concurrent processes until paging is occurring frequently and you can see significant changes in runtime. Summarise and analyse results.
Running timer_mem_use.c really used up more resource therefore the use of this was intensive in terms of resources to an extent of making the operating system hanging and also I had to halt it. In my opinion the memory used went beyond the 40MB. 100% of the ram was used up, this is because the timer_mem_use used up alot of resources that resulted to the same effect.
Part B:
Implement POSIX.4 memory locking (root access required) for one instance of code. See timer_memlock.c provided. Run this with other concurrent versions without memory locking (timer_mem_use.c) and increase number of these until paging is required. Be careful to start timer_memlock.c version first. Watch what is happening with memory. Summarise/ analyse performance.
Upon running the timer_mem_use with timer_memlock running, the memory usage seems to be controlled as compared to when test_mem_use running on its own. Running the timer_mem_use alone really used alot of reasources than wen i runned both the timer_memlock.c alongside with the timer_mem_use.c. The memory used therefore was less than 40MB , and also less ram was used up.
Problem 4: Nanosleep
Compile and run the code posix_nanosleep.c. Compare the code and the
results with those from timer_usleep.c
posix_nanosleep.c output
Time is 1521450831 : 518881185..slept for 60081.481934 nsec
Time is 1521450831 : 519056840..slept for 146389.007568 nsec
Time is 1521450831 : 519250185..slept for 63419.342041 nsec
Time is 1521450831 : 519343611..slept for 61035.156250 nsec
Time is 1521450831 : 519434236..slept for 60319.900513 nsec
Time is 1521450831 : 519524797..slept for 60319.900513 nsec
Time is 1521450831 : 519614164..slept for 60081.481934 nsec
Time is 1521450831 : 519703684..slept for 60319.900513 nsec
Time is 1521450831 : 519793408..slept for 60796.737671 nsec
Time is 1521450831 : 519883478..slept for 59843.063354 nsec
Time is 1521450831 : 519972603..slept for 60081.481934 nsec
Time is 1521450831 : 520062079..slept for 60081.481934 nsec
Total time taken : actual 7409.404278 msec theory(excl. runtime): 0 msec
timer_usleep.c
Time is 1521451058 : 14321..slept for 0.059128 ms
Time is 1521451058 : 14458..slept for 0.109911 ms
Time is 1521451058 : 14625..slept for 0.063181 ms
Time is 1521451058 : 14740..slept for 0.060081 ms
Time is 1521451058 : 14830..slept for 0.060081 ms
Time is 1521451058 : 14919..slept for 0.059128 ms
Time is 1521451058 : 15007..slept for 0.059128 ms
Time is 1521451058 : 15095..slept for 0.058889 ms
Time is 1521451058 : 15182..slept for 0.059128 ms
Time is 1521451058 : 15270..slept for 0.060081 ms
Time is 1521451058 : 15357..slept for 0.059128 ms
Time is 1521451058 : 15445..slept for 0.060081 ms
Time is 1521451058 : 15532..slept for 0.059128 ms
Time is 1521451058 : 15702..slept for 0.142097 ms
Total time taken : actual 6857.501030 theory(excl. runtime): 0, ms
Usleep performs better than
References
Essay Writing Service Features
Our Experience
No matter how complex your assignment is, we can find the right professional for your specific task. Contact Essay is an essay writing company that hires only the smartest minds to help you with your projects. Our expertise allows us to provide students with high-quality academic writing, editing & proofreading services.Free Features
Free revision policy
$10Free bibliography & reference
$8Free title page
$8Free formatting
$8How Our Essay Writing Service Works
First, you will need to complete an order form. It's not difficult but, in case there is anything you find not to be clear, you may always call us so that we can guide you through it. On the order form, you will need to include some basic information concerning your order: subject, topic, number of pages, etc. We also encourage our clients to upload any relevant information or sources that will help.
Complete the order formOnce we have all the information and instructions that we need, we select the most suitable writer for your assignment. While everything seems to be clear, the writer, who has complete knowledge of the subject, may need clarification from you. It is at that point that you would receive a call or email from us.
Writer’s assignmentAs soon as the writer has finished, it will be delivered both to the website and to your email address so that you will not miss it. If your deadline is close at hand, we will place a call to you to make sure that you receive the paper on time.
Completing the order and download