aboutsummaryrefslogtreecommitdiffstats
path: root/tasks/18/readme
blob: 082bc8fa9fa17dd0c470a40f75454fde2a22c5d8 (plain) (blame)
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
65
66
67
68
Task 18
=======

Nice job with the kernel thread.  It really doesn't take much code at
all to create a new thread.  So now let us get some data into the module
to give the thread something to do.

Base all of this work on your task 17 codebase.

Go back and dig up task 12's source code, the one with the list
handling.  Copy the structure into this module, and the
identity_create(), identity_find(), and identity_destroy() functions
into this module as well.

Write a new function, identity_get(), that looks like:

  struct identity identity_get(void);

and returns the next "identity" structure that is on the list, and
removes it from the list.  If nothing is on the list, return NULL.

Then, hook up the misc char device "write" function to do the following:

  - If a write is larger than 19 characters, truncate it at 19.

  - Take the write data and pass it to identity_create() as the string,
    and use an incrementing counter as the "id" value.

  - Wake up the "wee_wait" queue.

In the kernel thread function:

  - If the "wee_wait" queue wakes us up, get the next identity in the
    system with a call to identity_get().

  - Sleep (in an interruptable state, don't go increasing the system
    load in a bad way) for 5 seconds.

  - Write out the identity name, and id to the debug kernel log and then
    free the memory.

When the module exits, clean up the whole list by using the functions
given, no fair mucking around with the list variables directly.

Yes, it's a bit clunky, but it shows the basics of taking work from
userspace, and then quickly returning to the user, and then going off
and doing something else with the data and cleaning everything up.  It's
a common pattern for a kernel, as it's really all that a kernel ends up
doing most of the time (get a disk block, write a disk block, handle a
mouse event, etc.)

Load and unload the module and "prove" that it works properly by writing
and looking at the debug log, and that everything cleans up properly
when the module is unloaded.

Send in the proof and the .c file for the module.

A good test script would be the following:

  echo "Alice" > /dev/eudyptula
  echo "Bob" > /dev/eudyptula
  sleep 15
  echo "Dave" > /dev/eudyptula
  echo "Gena" > /dev/eudyptula
  rmmod task18

Removing the module while there is pending work is always a good stress
test.