Weekly Notes for Week 06
- In this week I will finish with the Chapter “System Structures (Chapter 2)”, I will give an introduction to the 1st mandatory assignment and if time allows, start with the Chapter 3: “Processes”.
- The 1st mandatory assignment will be made available on the course homepage at the end of week 6 latest.
-
The following voluntary reading material will augment my presentation of DTrace, bpftrace, and perf.
- Dynamic Instrumentation of Production Systems, Bryan M. Cantrill, Michael W. Shapiro and Adam H. Leventhal, Solaris Kernel Development Sun Microsystems link
- bpftrace and its bpftrace Tutorial
- DTrace (from Oracle, pdf) and Brandan Gregg’s page on dtrace
- The examples that will be shown in the lecture can already be downloaded here, and will very likely be updated in week 8.
- Voluntary reading for SystemTap
- Voluntary reading on Linux kernel profiling with perf
- Note: The slides used in the lecture for the second chapter differ significantly from the original slides provided by Wiley.
Tutorial Session Week 06
- Prepare for the Tutorial Session in Week 06 from Chapter 1 the following exercises
-
What are the three main purposes of an operating system?
-
What is the main difficulty that a programmer must overcome in writing an operating system for a real-time environment?
-
Keeping in mind the various definitions of operating system, consider whether the operating system should include applications such as web browsers and mail programs. Argue both that it should and that it should not, and support your answers.
-
How does the distinction between kernel mode and user mode function as a rudimentary form of protection (security)?
- Which of the following instructions should be privileged?
- Set value of timer.
- Read the clock.
- Clear memory.
- Issue a trap instruction.
- Turn off interrupts.
- Modify entries in device-status table.
- Switch from user to kernel mode.
- Access I/O device.
-
Some CPUs provide for more than two modes of operation. What are two possible uses of these multiple modes?
-
Give two reasons why caches are useful. What problems do they solve? What problems do they cause? If a cache can be made as large as the device for which it is caching (for instance, a cache as large as a disk), why not make it that large and eliminate the device?
-
How do clustered systems differ from multiprocessor systems? What is required for two machines belonging to a cluster to cooperate to provide a highly available service?
-
(important) What is the purpose of interrupts? How does an interrupt differ from a trap? Can traps be generated intentionally by a user program? If so, for what purpose?
- Direct memory access is used for high-speed I/O devices in order to avoid increasing the CPU’s execution load.
- How does the CPU interface with the device to coordinate the transfer?
- How does the CPU know when the memory operations are complete?
- The CPU is allowed to execute other programs while the DMA controller is transferring data. Does this process interfere with the execution of the user programs? If so, describe what forms of interference are caused.
- (important) Rank the following storage systems from slowest to fastest:
- Hard-disk drives
- Registers
- Optical disk
- Main memory
- Nonvolatile memory
- Magnetic tapes
- Cache
- Describe some of the challenges of designing operating systems for mobile devices compared with designing operating systems for traditional PCs.
C Programming (refresh)
- Which of the following is the proper declaration of a pointer?
- int x;
- int &x;
- ptr x;
- int *x;
- Which of the following gives the memory address of integer variable a?
- *a;
- a;
- &a;
- address(a);
- Which of the following gives the memory address of a variable pointed to by pointer a?
- a;
- *a;
- &a;
- address(a);
- Which of the following gives the value stored at the address pointed to by pointer a?
- a;
- val(a);
- *a;
- &a;
- Which of the following is the proper keyword or function to allocate memory in C?
- new
- malloc
- create
- value
- Which of the following is the proper keyword or function to deallocate memory?
- free
- delete
- clear
- remove
- Repeat the discussion of the four following examples to swap the content of two variables. Which of the examples are correct, which are wrong?
- Analyse the following C source code. Discuss what it does (this prepares you for the 1st mandatory assignment).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "dm510_msgbox.h"
#include <stdlib.h>
#include <string.h>
typedef struct _msg_t msg_t;
struct _msg_t{
msg_t* previous;
int length;
char* message;
};
static msg_t *bottom = NULL;
static msg_t *top = NULL;
int dm510_msgbox_put( char *buffer, int length ) {
msg_t* msg = malloc(sizeof(msg_t));
msg->previous = NULL;
msg->length = length;
msg->message = malloc(length);
memcpy(msg->message, buffer, length);
if (bottom == NULL) {
bottom = msg;
top = msg;
} else {
/* not empty stack */
msg->previous = top;
top = msg;
}
return 0;
}
int dm510_msgbox_get( char* buffer, int length ) {
if (top != NULL) {
msg_t* msg = top;
int mlength = msg->length;
top = msg->previous;
/* copy message */
memcpy(buffer, msg->message, mlength);
/* free memory */
free(msg->message);
free(msg);
return mlength;
}
return -1;
}
int main(int argc, char** argv) {
char *in = "This is a stupid message.";
char msg[50];
int msglen;
/* Send a message containing 'in' */
dm510_msgbox_put(in, strlen(in)+1);
/* Read a message */
msglen = dm510_msgbox_get(msg, 50);
return 0;
}