1
00:00:00,005 --> 00:00:03,003
- [Instructor] Let's look at kernel's source code.

2
00:00:03,003 --> 00:00:09,008
So I cloned the Ubuntu Noble repository like this,

3
00:00:09,008 --> 00:00:12,007
like we showed earlier.

4
00:00:12,007 --> 00:00:15,003
That took a little while.

5
00:00:15,003 --> 00:00:19,001
And then I got something like this

6
00:00:19,001 --> 00:00:22,003
and I've done a make cscope and a make tags in here

7
00:00:22,003 --> 00:00:25,003
and that's why I've got those cscope.files

8
00:00:25,003 --> 00:00:28,005
and I've got the file called tags.

9
00:00:28,005 --> 00:00:32,003
You can see kernel Makefile is in here.

10
00:00:32,003 --> 00:00:37,000
Let's see how much space this takes up.

11
00:00:37,000 --> 00:00:41,004
Hoo, seven gig, pretty big.

12
00:00:41,004 --> 00:00:46,007
And get an idea of how many tags

13
00:00:46,007 --> 00:00:50,001
they have in the repo here we cloned.

14
00:00:50,001 --> 00:01:00,008
That start with the string ubuntu dash.

15
00:01:00,008 --> 00:01:03,003
What did I do different?

16
00:01:03,003 --> 00:01:06,004
You got to capitalize the U in Ubuntu.

17
00:01:06,004 --> 00:01:07,006
All right.

18
00:01:07,006 --> 00:01:12,004
And if we look at the Makefile,

19
00:01:12,004 --> 00:01:15,008
we can see the version there, so forth.

20
00:01:15,008 --> 00:01:19,008
How long is the Makefile?

21
00:01:19,008 --> 00:01:23,008
Over 2000 lines long. All right.

22
00:01:23,008 --> 00:01:29,009
And with that kind of length, having a help in there is nice.

23
00:01:29,009 --> 00:01:32,004
Get an idea.

24
00:01:32,004 --> 00:01:33,009
Starts with cleaning targets

25
00:01:33,009 --> 00:01:38,003
and there's lots of stuff you can make, right?

26
00:01:38,003 --> 00:01:41,007
And these days you can write kernel code in Rust.

27
00:01:41,007 --> 00:01:44,009
So there's a bunch of Rust stuff there.

28
00:01:44,009 --> 00:01:48,008
Let's make a PDF doc.

29
00:01:48,008 --> 00:01:53,003
So here's making the scheduler PDF.

30
00:01:53,003 --> 00:01:54,008
I already did that.

31
00:01:54,008 --> 00:01:57,003
That's part of the disk space taken up is

32
00:01:57,003 --> 00:01:59,003
I was doing stuff like this.

33
00:01:59,003 --> 00:02:04,003
The fresh clone was a little over four gig, not seven gig.

34
00:02:04,003 --> 00:02:10,004
And if we look in the Documentation/output/scheduler/pdf

35
00:02:10,004 --> 00:02:14,004
directory, there's the PDF.

36
00:02:14,004 --> 00:02:18,002
So I already did a make cscope

37
00:02:18,002 --> 00:02:19,004
so I'm not going to do that again.

38
00:02:19,004 --> 00:02:23,003
And I did a make tags so I'm not going to do that again.

39
00:02:23,003 --> 00:02:25,000
Those are ready to go like I showed you.

40
00:02:25,000 --> 00:02:26,008
So let's go cscope -d.

41
00:02:26,008 --> 00:02:30,008
The -d says don't make a new index, I already got one.

42
00:02:30,008 --> 00:02:33,006
And we get this simple little interface

43
00:02:33,006 --> 00:02:35,002
but we've indexed the kernel source code

44
00:02:35,002 --> 00:02:36,008
so we can look in the kernel source.

45
00:02:36,008 --> 00:02:38,002
So let's look.

46
00:02:38,002 --> 00:02:41,001
There's a cool function called copy_to_user

47
00:02:41,001 --> 00:02:46,000
that's used throughout the kernel by device drivers

48
00:02:46,000 --> 00:02:49,001
and other things, to copy stuff back to user space,

49
00:02:49,001 --> 00:02:53,003
like when a process calls read, goes in the kernel,

50
00:02:53,003 --> 00:02:56,003
the kernel's got to fill stuff into that user space buffer

51
00:02:56,003 --> 00:02:59,001
to return that can use copy_to_user.

52
00:02:59,001 --> 00:03:03,000
So we're going to look for the definition of that function.

53
00:03:03,000 --> 00:03:05,001
It's got two hits, let's go in the first one,

54
00:03:05,001 --> 00:03:06,002
I just hit enter,

55
00:03:06,002 --> 00:03:08,009
but I could do down arrow to go to the next one.

56
00:03:08,009 --> 00:03:10,001
Up arrow to get back.

57
00:03:10,001 --> 00:03:16,000
So I hit enter, brings me into VI on the definition.

58
00:03:16,000 --> 00:03:18,007
Alright, and then I can move around in VI

59
00:03:18,007 --> 00:03:20,007
like I'm using my arrow key.

60
00:03:20,007 --> 00:03:23,006
Let's see, I put my cursor somewhere on this function

61
00:03:23,006 --> 00:03:26,005
that's getting called and I do control

62
00:03:26,005 --> 00:03:29,006
close square bracket.

63
00:03:29,006 --> 00:03:31,005
Control, close square bracket

64
00:03:31,005 --> 00:03:34,001
when I'm on a symbol like that.

65
00:03:34,001 --> 00:03:36,009
And it just jumped me up there.

66
00:03:36,009 --> 00:03:40,005
And I'm going to look for the next one.

67
00:03:40,005 --> 00:03:43,002
Next tag with that name. So I do :tn.

68
00:03:43,002 --> 00:03:47,000
You can see that at the bottom there, :tn.

69
00:03:47,000 --> 00:03:48,004
And there's the next one.

70
00:03:48,004 --> 00:03:50,003
And on the bottom it says tag 2 of 3.

71
00:03:50,003 --> 00:03:52,002
So there's actually three of 'em.

72
00:03:52,002 --> 00:03:55,004
And if you look up a couple lines here it says,

73
00:03:55,004 --> 00:03:57,003
ifdef INLINE_COPY_TO_USER,

74
00:03:57,003 --> 00:04:00,008
this is the inline definition of it.

75
00:04:00,008 --> 00:04:05,003
And if we do :tn, we can get to the third tag.

76
00:04:05,003 --> 00:04:08,000
And here it's if not defined.

77
00:04:08,000 --> 00:04:09,006
Right, so we're looking at the code,

78
00:04:09,006 --> 00:04:11,002
we can keep going.

79
00:04:11,002 --> 00:04:16,002
To go back, we do control T.

80
00:04:16,002 --> 00:04:21,000
I keep doing control T until I'm back

81
00:04:21,000 --> 00:04:23,000
for where the stack was.

82
00:04:23,000 --> 00:04:28,001
And then I can just get out of VI with usual :q.

83
00:04:28,001 --> 00:04:30,005
If I want to get back to the menu of choice down there,

84
00:04:30,005 --> 00:04:32,001
I hit the tab key.

85
00:04:32,001 --> 00:04:34,002
So I'm hitting tab, I'm down here.

86
00:04:34,002 --> 00:04:37,004
I can move between these with the arrow key.

87
00:04:37,004 --> 00:04:41,002
To get out of cscope, it's control D.

88
00:04:41,002 --> 00:04:44,005
Control D is also known as end of file for a lot of things.

89
00:04:44,005 --> 00:04:47,005
Control D as in dog.

90
00:04:47,005 --> 00:04:51,001
So we saw tags, we saw cscope, we saw kernel

91
00:04:51,001 --> 00:04:54,000
(indistinct) Makefile, good stuff.

