Homework 1: Getting Started, and Analyzing Dynamic Memory Usage
This homework has two main parts. Part one is making sure you are able to log into your Amazon EC2 virtual machine, as well as checking out the homework template from svn, and committing files to your turn-in repository.
In step 2, we do a little bit of analysis of dynamic memory usage by malloc and the stack.
Getting Started with Amazon EC2
You should have received two emails by now, one with your Amazon AWS credentials, and one with your turn-in subversion repository credentials. If you did not receive these, check your spam folder. If it's not there either, contact Jakob immediately.
While you are free to use any linux machine for your homework projects, you have been provided with a free Amazon EC2 virtual machine, which provides a consistent and reliable environment to work with. All grading will be done using this platform, so to be safe, you'll probably want to use it to test your programs as well.
Follow
this link and instructions provided in the Amazon credentials email to start your virtual machine. If you can't find your VM in the list, try switching the "zone" in the top right corner to "N.Virginia".
Then log into it using ssh from your computer. Attached to the email was a file named id_rsa, use that as the private key or identity file when logging into your VM. Your username for the ssh login is "ubuntu". There is no password (the id_rsa file is used instead of a password).
You'll want to install some programs on your VM. To get the essentials, run these commands:
sudo apt-get install build-essential
sudo apt-get install subversion
Getting Started with Subversion
For this class, we use the subversion revision control system to handle homework templates and turn-ins. Every student has their own individual turn-in repository, where you are expected to commit your homework solutions. There is also a shared repository, at svn://bits.cs.uic.edu/cs361/pub, which contains class materials such as homework templates, previous homework solutions, drawings from lecture, etc.
To check out your personal turn-in repository, which will be empty at this point, go to the directory where you would like the new repository folder to appear. Then type
svn checkout svn://bits.cs.uic.edu/cs361/f13/USERNAME --username USERNAME
where
USERNAME
obviously is your svn username. This creates a folder called
USERNAME
, with a hidden
.svn
folder inside it.
To check out the first homework template, cd to this folder, and type (pay attention!)
svn export svn://bits.cs.uic.edu/cs361/pub/homeworks/hw1
note that it says
export
, not
checkout
. This is a very important detail:
never use checkout to get your homework template. It'll cause you (and us) all manner of headaches.
This creates a new folder called hw1. To commit the template as your homework solution (you actually get points for this, this time only!), type
svn add hw1
to tell subversion that hw1 is a folder (including its current contents) that svn should keep track of for you. Then, type
svn commit -m "my very first commit"
to tell svn that this version of the folder is something svn should remember. Note that every new file or folder that you want to have in your repository needs to be "added" once, and every version you want to store needs to be "committed". svn does not add files or commit versions for you automatically.
Dynamic Memory Usage Diagnostics
The template provides a couple of small programs that allocate memory according to different patterns. These programs periodically call the function
check_memory()
which, at the moment, does nothing useful at all. Your job is to change
check_memory()
and
init_hw1()
in hw1.c so that both
iterative
and
recursive
produce the following output on
stderr
.
- heap segment size: total size of the current heap segment in bytes
- number of allocated
malloc()
chunks on the heap.
- number of free
malloc()
chunks on the heap.
- total bytes in allocated chunks.
- total bytes in free chunks.
- current stack size: total number of bytes used by the stack at present. Note: this is not the segment size, just the current stack size.
To test your program, type
make
and then run either
./iterative
or
./recursive
.
The output format should be space-separated decimal numbers on a single line per call to
check_memory()
. You may estimate the location of the top of the stack, and the bottom of the heap, by recording the current bottom of the stack and top of the heap in
init_hw1()
.
hint: sbrk(0) tells you the current top of the heap.
hint2: for compatibility across platforms, use the type size_t to represent the boundary tags, rather than manually choosing a 32-bit or 64-bit type. This is what malloc does anyway.
Turn-in instructions
To prove that you got subversion working, you just have to commit the hw1 template to your personal turn-in repository following the instructions above.
To prove that you got your EC2 instance up and running, and that you logged in successfully, copy-paste the output of the following two commands to a new file called "EC2.txt" in your hw1 directory.
uname -a
who
Don't forget to
svn add EC2.txt
and
svn commit
with a message, to complete the turn-in.
Finally, commit your updated homework template, producing the correct output, to receive the full score on this homework.
Output example
This is an example of the exact format of output that should appear on stderr:
135160 1 0 144 0 108
135160 2 0 432 0 108
135160 3 0 848 0 108
135160 4 0 1408 0 108
135160 5 0 2096 0 108
135160 6 0 2928 0 108
135160 7 0 3888 0 108
135160 8 0 4992 0 108
135160 9 0 6224 0 108
135160 10 0 7600 0 108
these are the first few lines from my solution running with the 'iterative' program.