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
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.