Weekly Notes for Week 06

Tutorial Session Week 06

  1. What are the three main purposes of an operating system?

  2. What is the main difficulty that a programmer must overcome in writing an operating system for a real-time environment?

  3. 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.

  4. How does the distinction between kernel mode and user mode function as a rudimentary form of protection (security)?

  5. 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.
  6. Some CPUs provide for more than two modes of operation. What are two possible uses of these multiple modes?

  7. 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?

  8. 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?

  9. (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?

  10. 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.
  11. (important) Rank the following storage systems from slowest to fastest:
    • Hard-disk drives
    • Registers
    • Optical disk
    • Main memory
    • Nonvolatile memory
    • Magnetic tapes
    • Cache
  12. Describe some of the challenges of designing operating systems for mobile devices compared with designing operating systems for traditional PCs.

C Programming (refresh)

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;
}