1
00:00:00,003 --> 00:00:05,005
(upbeat music)

2
00:00:05,005 --> 00:00:09,000
- [Instructor] Let's look at those pretty good challenges.

3
00:00:09,000 --> 00:00:10,001
So the first thing was

4
00:00:10,001 --> 00:00:13,009
to go get some Linux kernel source code.

5
00:00:13,009 --> 00:00:15,009
So I did a little grep from my history here.

6
00:00:15,009 --> 00:00:19,000
You can see I did a few things,

7
00:00:19,000 --> 00:00:22,006
but it's this one right here

8
00:00:22,006 --> 00:00:25,009
with noble in lowercase that was correct.

9
00:00:25,009 --> 00:00:28,003
So maybe you did something like that.

10
00:00:28,003 --> 00:00:33,009
Then after that we wanted you to do a make cscope.

11
00:00:33,009 --> 00:00:35,003
And we'll do that again.

12
00:00:35,003 --> 00:00:38,007
And then a make tags.

13
00:00:38,007 --> 00:00:40,008
All right, and if those worked,

14
00:00:40,008 --> 00:00:45,002
then you got some cscope.out files,

15
00:00:45,002 --> 00:00:48,001
and you got a tags file.

16
00:00:48,001 --> 00:00:49,003
Those are text files.

17
00:00:49,003 --> 00:00:50,001
You can look at those.

18
00:00:50,001 --> 00:00:52,007
They're essentially indexes of where stuff is.

19
00:00:52,007 --> 00:00:57,003
So now that you got those, you can use cscope and tags.

20
00:00:57,003 --> 00:01:00,002
So let's go cscope -d,

21
00:01:00,002 --> 00:01:03,003
and we want to look for the write zero function.

22
00:01:03,003 --> 00:01:05,008
We want the definition of that.

23
00:01:05,008 --> 00:01:11,002
Write_zero.

24
00:01:11,002 --> 00:01:13,003
And it's a macro.

25
00:01:13,003 --> 00:01:17,006
Write_Zero is actually the same as write_null.

26
00:01:17,006 --> 00:01:18,008
They didn't make a new function,

27
00:01:18,008 --> 00:01:22,000
so they're just reusing the write_null,

28
00:01:22,000 --> 00:01:24,001
and we looked at that earlier.

29
00:01:24,001 --> 00:01:27,006
And write_null just says,

30
00:01:27,006 --> 00:01:32,001
yeah, I wrote how many ever you wanted me to write.

31
00:01:32,001 --> 00:01:36,000
But we also want to look at read_zero.

32
00:01:36,000 --> 00:01:38,006
So we'll go back to Cscope.

33
00:01:38,006 --> 00:01:40,008
Back here where we started by getting out of VI,

34
00:01:40,008 --> 00:01:42,003
just a colon Q.

35
00:01:42,003 --> 00:01:45,007
Then I do a tab to get to the bottom,

36
00:01:45,007 --> 00:01:49,002
and then I'm going to do read_zero

37
00:01:49,002 --> 00:01:53,003
looking for the definition of that, and I hit enter,

38
00:01:53,003 --> 00:01:54,002
and there's only one.

39
00:01:54,002 --> 00:01:56,004
So it brings me right to it.

40
00:01:56,004 --> 00:01:59,003
So here's read_zero,

41
00:01:59,003 --> 00:02:03,008
and let me get the loop in the window here.

42
00:02:03,008 --> 00:02:07,001
So count is the number of bites we want to read.

43
00:02:07,001 --> 00:02:11,005
So we're going to loop while that's not zero,

44
00:02:11,005 --> 00:02:15,008
and we chunk it up a little bit, and we use some function.

45
00:02:15,008 --> 00:02:17,008
That's probably what zeroes it out.

46
00:02:17,008 --> 00:02:23,002
Clear user, and we check to make sure stuff worked.

47
00:02:23,002 --> 00:02:26,001
But down here we got a couple interesting things.

48
00:02:26,001 --> 00:02:29,008
Here we check to see if our current process,

49
00:02:29,008 --> 00:02:33,002
that's the process essentially that's called read,

50
00:02:33,002 --> 00:02:34,005
has a signal pending.

51
00:02:34,005 --> 00:02:36,002
So did a signal happen?

52
00:02:36,002 --> 00:02:40,008
So in the kernel, signals don't interrupt us

53
00:02:40,008 --> 00:02:41,008
at arbitrary points.

54
00:02:41,008 --> 00:02:46,005
The kernel has to check to see if a signal was sent,

55
00:02:46,005 --> 00:02:48,003
and if a signal was sent,

56
00:02:48,003 --> 00:02:51,007
then we break out of the while loop, right?

57
00:02:51,007 --> 00:02:56,007
Then the cond_resched checks

58
00:02:56,007 --> 00:02:59,004
to see essentially if some other process

59
00:02:59,004 --> 00:03:01,007
has its turn to run

60
00:03:01,007 --> 00:03:04,009
like it has a higher priority or we used up our time slice.

61
00:03:04,009 --> 00:03:07,004
So the cond_resched checks to see

62
00:03:07,004 --> 00:03:09,003
if the scheduler has set a flag

63
00:03:09,003 --> 00:03:12,005
saying I need to reschedule you.

64
00:03:12,005 --> 00:03:14,009
And if that flag's been set,

65
00:03:14,009 --> 00:03:19,002
then cond_resched will call the scheduler function

66
00:03:19,002 --> 00:03:21,003
which will then schedule another function.

67
00:03:21,003 --> 00:03:22,005
So we do that in the loop.

68
00:03:22,005 --> 00:03:27,005
Every time through, we do some chunk

69
00:03:27,005 --> 00:03:30,002
and then we check for signals,

70
00:03:30,002 --> 00:03:32,002
and we check to see if we lost our turn.

71
00:03:32,002 --> 00:03:33,009
Then we do another chunk.

72
00:03:33,009 --> 00:03:38,001
So if you're reading a large amount,

73
00:03:38,001 --> 00:03:40,008
you can't just keep the kernel busy

74
00:03:40,008 --> 00:03:42,009
for that whole time.

75
00:03:42,009 --> 00:03:46,000
All right, that should have been pretty interesting.

