CSCI2467: Systems Programming Concepts

Similar documents
CSCI2467: Systems Programming Concepts

Chris Riesbeck, Fall Introduction to Computer Systems

Introduction to Computer Systems

Introduction to Computer Systems

Introduction to Computer Systems

Bilgisayar Sistemlerine Genel Bakış

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

CSCI 2467, Fall 2017 Lab 0: Introductions to C and Unix Due: Thursday August. 24, 11:59PM

Computer Systems Organization

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

Lab 1 Introduction to UNIX and C

Introduction Presentation A

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Linux and Git Boot Camp

CSCI2467: Systems Programming Concepts

Intermediate Programming, Spring Misha Kazhdan

Perl and R Scripting for Biologists

Read-only memory (ROM): programmed during production Programmable ROM (PROM): can be programmed once SRAM (Static RAM)

Introduction to Linux. Fundamentals of Computer Science

Introduction to Linux

CS CS Tutorial 2 2 Winter 2018

Session 1: Accessing MUGrid and Command Line Basics

Lec 1 add-on: Linux Intro

A Tour of Computer Systems

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

CSE 351. Introduction & Course Tools

Lab 1 Introduction to UNIX and C

CSC111 Computer Science II

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

1 Installation (briefly)

Recitation #1 Boot Camp. August 30th, 2016

Introduction to Linux

INF322 Operating Systems

EE516: Embedded Software Project 1. Setting Up Environment for Projects

Introduction to Supercomputing

CS197U: A Hands on Introduction to Unix

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

EL2310 Scientific Programming

Chapter 1 A Tour of Computer Systems

Introduction to Linux

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Recitation #1 Unix Boot Camp. August 29th, 2017

Linux at the Command Line Don Johnson of BU IS&T

CISC 220 fall 2011, set 1: Linux basics

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

CS Fundamentals of Programming II Fall Very Basic UNIX

Version Control with Git

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

EL2310 Scientific Programming

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

CSC209. Software Tools and Systems Programming.

Linux Systems Administration Getting Started with Linux

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

LAB #5 Intro to Linux and Python on ENGR

Introduction to Linux for BlueBEAR. January

CSCI 2132 Software Development. Lecture 4: Files and Directories

Programming 1 - Honors

CSC209. Software Tools and Systems Programming.

Introduction to Cygwin Operating Environment

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Filesystem Hierarchy and Permissions

Getting started with Hugs on Linux

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Welcome To The New Foundations of Computer Systems (Fall 2017)

C++ Programming on Linux

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Introduction to Linux

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Compilation, Disassembly, and Profiling (in Linux)

Review of Fundamentals

F28HS Hardware-Software Interface: Systems Programming

CSCI2467: Systems Programming Concepts

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Unix and C Program Development SEEM

Intro to HPC Exercise

Getting Started with UNIX

Laboratory 1 Semester 1 11/12

Filesystem Hierarchy and Permissions

Introduction of Linux

Introduction to Linux Basics

Short Read Sequencing Analysis Workshop

CSC116: Introduction to Computing - Java

The Memory Hierarchy 10/25/16

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

9 and 11-Jan CSCI 4152/6509 Natural Language Processing Lab 1: FCS Computing Environment, SVN Tutorial. FCS Computing Environment, SVN Tutorial

What s next. Computer Systems A Programmer s Perspective

CS 246 Winter Tutorial 1

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Linux for Beginners. Windows users should download putty or bitvise:

Transcription:

CSCI2467: Systems Programming Concepts Slide set 1: A Tour of Computer Systems (CS:APP Chapter 1) Instructor: M. Toups Spring 2018

Overview 1 A Tour of Computer Systems Systems Information is bits plus context Programs Are Translated by Other Programs into Different Forms Processors Read and Interpret Instructions Stored in Memory Caches & Memory Hierarchy The Operating System manages processes, memory, and more Wrapping up the intro 2 Lab 0 Prerequisites review Remote access with ssh The terminal Text editors Part 1 Part 2 Part 3 Handin notes 3 Preview of next week Reading Data surprises!

Systems vs. Applications Applications software provides services to a user Systems software provides a platform for applications and services to build upon Application programs Operating system Processor Main memory I/O devices Software Hardware Figure 1.10 from CS:APP by: Uwe Kils CC BY-SA 3.0 Not pictured: numerous examples of libraries, firmware (for each hardware device, network switches), remote services

Systems code is everywhere Running networks 24/7 Cisco Catalyst network switch A Tour of Computer Systems Lab 0 Preview of next week

Systems code is everywhere Running networks 24/7 Linksys WRT54G switch/router A Tour of Computer Systems Lab 0 Preview of next week

Systems code is everywhere Feeding us!

Systems code is everywhere Feeding us!

Creating a programming language for systems Originally all systems level code written as assembly

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) 1 See Aside on p.4 of CS:APP

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) C89/C90 most common. Some updates since then: C99, C11 2 1 See Aside on p.4 of CS:APP 2 See Aside on p.35 of CS:APP

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) C89/C90 most common. Some updates since then: C99, C11 2 C was created for a specific purpose: to implement the UNIX OS (kernel, libraries, tools) 1 See Aside on p.4 of CS:APP 2 See Aside on p.35 of CS:APP

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) C89/C90 most common. Some updates since then: C99, C11 2 C was created for a specific purpose: to implement the UNIX OS (kernel, libraries, tools) Small, simple language. Easily ported to different hardware. 1 See Aside on p.4 of CS:APP 2 See Aside on p.35 of CS:APP

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) C89/C90 most common. Some updates since then: C99, C11 2 C was created for a specific purpose: to implement the UNIX OS (kernel, libraries, tools) Small, simple language. Easily ported to different hardware. C becomes de facto choice for systems (OS, drivers, tools) 1 See Aside on p.4 of CS:APP 2 See Aside on p.35 of CS:APP

Creating a programming language for systems Originally all systems level code written as assembly C developed 1969-1973 by Dennis Ritchie 1 1978: K&R book published 1988: 2nd edition (ANSI/ISO standard) C89/C90 most common. Some updates since then: C99, C11 2 C was created for a specific purpose: to implement the UNIX OS (kernel, libraries, tools) Small, simple language. Easily ported to different hardware. C becomes de facto choice for systems (OS, drivers, tools) C also becomes used in applications, but with some difficulty (pointers, fewer abstractions) 1 See Aside on p.4 of CS:APP 2 See Aside on p.35 of CS:APP

C: the Systems programming language

C: the Systems programming language No classes or objects

C: the Systems programming language No classes or objects (therefore no constructors or destructors)

C: the Systems programming language No classes or objects (therefore no constructors or destructors) No exceptions (no throw or catch)

C: the Systems programming language No classes or objects (therefore no constructors or destructors) No exceptions (no throw or catch) No templates/generics

C: the Systems programming language No classes or objects (therefore no constructors or destructors) No exceptions (no throw or catch) No templates/generics... C++ adds these things

C: the Systems programming language No classes or objects (therefore no constructors or destructors) No exceptions (no throw or catch) No templates/generics... C++ adds these things... making it very different! Don t confuse C and C++

hello.c (bits) 00100011 01101001 01101110 01100011 01101100 01110101 #inclu 01100100 01100101 00100000 00111100 01110011 01110100 de <st 01100100 01101001 01101111 00101110 01101000 00111110 dio.h> 00001010 00001010 01101001 01101110 01110100 00100000..int 01101101 01100001 01101001 01101110 00101000 00101001 main() 00001010 01111011 00001010 00100000 00100000 00100000.{. 00100000 01110000 01110010 01101001 01101110 01110100 print 01100110 00101000 00100010 01101000 01100101 01101100 f("hel 01101100 01101111 00101100 00100000 01110111 01101111 lo, wo 01110010 01101100 01100100 01011100 01101110 00100010 rld\n" 00101001 00111011 00001010 00100000 00100000 00100000 );. 00100000 01110010 01100101 01110100 01110101 01110010 retur 01101110 00100000 00110000 00111011 00001010 01111101 n 0;.} 00001010.

hello.c (hexadecimal) 2369 6e63 6c75 6465 203c 7374 6469 6f2e #include <stdio. 683e 0a0a 696e 7420 6d61 696e 2829 0a7b h>..int main().{ 0a20 2020 2070 7269 6e74 6628 2268 656c. printf("hel 6c6f 2c20 776f 726c 645c 6e22 293b 0a20 lo, world\n");. 2020 2072 6574 7572 6e20 303b 0a7d 0a return 0;.}.

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello.c (hexadecimal)

hello compiled (hexadecimal)

hello compiled (hexadecimal)

Overview 1 A Tour of Computer Systems Systems Information is bits plus context Programs Are Translated by Other Programs into Different Forms Processors Read and Interpret Instructions Stored in Memory Caches & Memory Hierarchy The Operating System manages processes, memory, and more Wrapping up the intro 2 Lab 0 Prerequisites review Remote access with ssh The terminal Text editors Part 1 Part 2 Part 3 Handin notes 3 Preview of next week Reading Data surprises!

Steps in which hello.c gets converted to an executable printf.o hello.c Source program (text) Pre- processor (cpp) hello.i source program (text) Compiler (cc1) hello.s Assembly program (text) Assembler (as) hello.o Relocatable object programs (binary) Linker (ld) hello Executable object program (binary) Source: CS:APP, Bryant & O Hallaron

Layered view of systems Application programs Operating system Processor Main memory I/O devices Software Hardware Source: CS:APP, Bryant & O Hallaron

A diagram of the computer s hardware CPU PC ALU System bus Memory bus Bus interface I/O bridge Main memory USB Graphics adapter I/O bus Disk other devices such as network adapters Mouse Keyboard Disk hello executable stored on disk Source: CS:APP, Bryant & O Hallaron

Someone types in the hello command... CPU PC ALU System bus Memory bus Bus interface I/O bridge Main "hello" memory USB Graphics adapter I/O bus Disk controller Expansion slots for other devices such as network adapters Mouse Keyboard User types "hello" Display Disk Source: CS:APP, Bryant & O Hallaron

OS loads hello from the disk into memory CPU PC ALU System bus Memory bus Bus interface I/O bridge Main memory "hello,world\n" hello code USB Graphics adapter I/O bus Disk controller other devices such as network adapters Mouse Keyboard Disk hello executable stored on disk Source: CS:APP, Bryant & O Hallaron

How hello output reaches the display CPU PC ALU System bus Memory bus Bus interface I/O bridge Main "hello,world\n" memory hello code USB Graphics adapter I/O bus Disk other devices such as network adapters Mouse Keyboard "hello,world\n" Disk hello executable stored on disk Source: CS:APP, Bryant & O Hallaron

Caches on the Intel Core i7 CPU Processor package Core 0 Core 3 Regs Regs L1 d-cache L1 i-cache L1 d-cache L1 i-cache (shared by all cores) Main memory

Memory Hierarchy: many layers, from fast down to slow Smaller, faster, and costlier (per byte) storage devices Larger, slower, and cheaper (per byte) storage devices L5: L6: L4: L3: L2: L1: L0: Regs L1 cache (SRAM) L2 cache (SRAM) L3 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Remote secondary storage CPU registers hold words retrieved from cache memory. L1 cache holds cache lines retrieved from the L2 cache. L2 cache holds cache lines retrieved from L3 cache L3 cache holds cache lines retrieved from memory. Main memory holds disk blocks retrieved from local disks. retrieved from disks on remote network servers.

OS Kernel handles switching between two processes Process A Process B Time read Disk interrupt Return from read CS:APP, Bryant & O Hallaron User code Kernel code User code Kernel code User code Context switch Context switch Source:

OS Kernel also manages Virtual Memory addressing Kernel virtual memory User stack (created at runtime) Memory invisible to user code Memory mapped region for shared libraries printf function Run-time heap (created by malloc) Program start 0 Read/write data Read-only code and data Loaded from the hello Source: CS:APP, Bryant & O Hallaron

Chapter 1: to sum up Systems skills give you a broad and deep insight into what happens when you write and/or run programs

Chapter 1: to sum up Systems skills give you a broad and deep insight into what happens when you write and/or run programs Potentially big impacts on speed, reliability, security

Chapter 1: to sum up Systems skills give you a broad and deep insight into what happens when you write and/or run programs Potentially big impacts on speed, reliability, security This is a brief preview of what is to come! You aren t expected to know all of this... yet

Chapter 1: to sum up Systems skills give you a broad and deep insight into what happens when you write and/or run programs Potentially big impacts on speed, reliability, security This is a brief preview of what is to come! You aren t expected to know all of this... yet Chapter 1 should be a quick read.

Chapter 1: to sum up Systems skills give you a broad and deep insight into what happens when you write and/or run programs Potentially big impacts on speed, reliability, security This is a brief preview of what is to come! You aren t expected to know all of this... yet Chapter 1 should be a quick read. Don t worry about memorizing Amdahl s law, it is a useful principle to keep in mind but I will not ask you to solve those math problems

2 Lab 0 Prerequisites review Remote access with ssh The terminal Text editors Part 1 Part 2 Part 3 Handin notes

Your first lab assignment

Prerequisites A few notes on this process: bash shell, text editors, permissions Also: remote access via ssh Be careful about usernames, and be aware there is a temporary block after a certain number of failed login attempts.

Using Sun Ray terminals Log in using UNO username, password.

Using Sun Ray terminals All labs are done using math209 (linux)... BUT you can access math209 on the Sun Ray in class OR remotely (on or off-campus) using ssh

Using git-bash

Using git-bash

Using PuTTY

Using PuTTY Pay attention to which prompt is which

Directories and permissions changed directory with cd command

Directories and permissions changed directory with cd command created a directory with mkdir command

Directories and permissions changed directory with cd command created a directory with mkdir command changed permissions with chmod command

Directories and permissions changed directory with cd command created a directory with mkdir command changed permissions with chmod command

Directories and permissions Source: Open Source GIS: A GRASS GIS Approach, First Edition, 2002

Directory hierarchy Starting at the root / (root of file system) bin etc home lib opt sbin tmp usr var

Directory hierarchy System files/programs / (root of file system) bin bash home usr bin... firefox vim lib share...

Directory hierarchy Our work happens in /home / (root of file system)... home... hmahdi matoups2... usr...

Directory hierarchy We each created a 2467 working directory in our own home directory / (root of file system)... home... hmahdi matoups2 2467 Downloads...... usr

Directory hierarchy... and worked on files within that directory / (root of file system) home matoups2 2467 introlab-handout.tar part1 part1.c student.c student.h part2 part3

Directory hierarchy There is also a separate class directory /home/csci2467 / (root of file system) home CSCI2467 handin labs lab0 introlab-handout.tar matoups2 2467 part1 part1.c part1

Directory hierarchy / (root of file system) home CSCI2467 handin matoups2 labs lab0 introlab-handout.tar matoups2 2467

Directory hierarchy / (root of file system) home CSCI2467 handin... matoups2 labs matoups2 2467 part1 part1.c part1

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt.

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt... is an alias to the parent directory: cp ~/foo.txt..

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt... is an alias to the parent directory: cp ~/foo.txt.. * will match as many characters as it can. cp ~/*.txt.

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt... is an alias to the parent directory: cp ~/foo.txt.. * will match as many characters as it can. cp ~/*.txt. Example: objdump -d *

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt... is an alias to the parent directory: cp ~/foo.txt.. * will match as many characters as it can. cp ~/*.txt. Example: objdump -d * Example: rm *.c (be very very very careful!!)

Terminal Shortcuts (bash shell) is an alias to your home directory: cp foo.txt ~. is an alias to your present directory: cp ~/foo.txt... is an alias to the parent directory: cp ~/foo.txt.. * will match as many characters as it can. cp ~/*.txt. Example: objdump -d * Example: rm *.c (be very very very careful!!) There is no trash with rm. It is gone.

More bash tricks Pressing tab will autocomplete filenames.

More bash tricks Pressing tab will autocomplete filenames. Use the up & down arrow keys to scroll through your previous commands.

More bash tricks Pressing tab will autocomplete filenames. Use the up & down arrow keys to scroll through your previous commands. Control+R lets you search your command history.

More bash tricks Pressing tab will autocomplete filenames. Use the up & down arrow keys to scroll through your previous commands. Control+R lets you search your command history. Control+C terminates your current program.

More bash tricks Pressing tab will autocomplete filenames. Use the up & down arrow keys to scroll through your previous commands. Control+R lets you search your command history. Control+C terminates your current program. Control+D (on a blank line) exits the terminal.

Text editors Source: xkcd.com

nano Note command-key functions described at bottom

vi / vim see vimtutor command stateful or modal editor: can be in command, insert or visual mode.

emacs Described in Section 4 of Unix programming tools (optional reading)

gedit Nice GUI you can use in the lab Disadvantage: doesn t work (easily) via ssh Previous examples were all text-mode (terminal-based, work the same over ssh)

Sublime Text

How to use Sublime Text for these labs Haydar can show you how to set up SFTP for sublime to keep files in sync with our server. (See resources section of class website)

Notepad++ Haydar can show you the steps to get notepad++ to sync with our server.

Notepad++ Haydar can show you the steps to get notepad++ to sync with our server.

Notepad++ Haydar can show you the steps to get notepad++ to sync with our server.

Part 1: Who are you?

Part 1: Who are you?

Part 1: Who are you?

Part 1: Compiling and running Save (in text editor)

Part 1: Compiling and running Save (in text editor) Compile with gcc as given in lab manual

Part 1: Compiling and running Save (in text editor) Compile with gcc as given in lab manual Did compilation succeed? (No errors means yes)

Part 1: Compiling and running Save (in text editor) Compile with gcc as given in lab manual Did compilation succeed? (No errors means yes) Run with./part1

Part 1: Compiling and running Save (in text editor) Compile with gcc as given in lab manual Did compilation succeed? (No errors means yes) Run with./part1 Turn in by copying into /home/csci2467/handin/<userid>

Part 2: lifecycle of a C program A slightly modified hello.c

Part 2: lifecycle of a C program printf.o hello.c Source program (text) Pre- hello.i processor (cpp) source program (text) Compiler (cc1) hello.s Assembly program (text) Assembler (as) hello.o Relocatable object programs (binary) Linker (ld) hello Executable object program (binary) Source: Bryant & O Hallaron (2003)

Part 3: How long does it take to copy an array? Source: Bryant & O Hallaron (2003)

Part 3: How long does it take to copy an array? Source: Bryant & O Hallaron (2003)

Part 3: Memory mountain Source: Bryant & O Hallaron (2003)

Part 3: Memory hierarchy from Chapter 1 Smaller, faster, and costlier (per byte) storage devices Larger, slower, and cheaper (per byte) storage devices L5: L6: O Hallaron (2003) L4: L3: L2: L1: L0: Regs L1 cache (SRAM) L2 cache (SRAM) L3 cache (SRAM) Main memory (DRAM) Local secondary storage (local disks) Remote secondary storage CPU registers hold words retrieved from cache memory. L1 cache holds cache lines retrieved from the L2 cache. L2 cache holds cache lines retrieved from L3 cache L3 cache holds cache lines retrieved from memory. Main memory holds disk blocks retrieved from local disks. retrieved from disks on remote network servers. Source: Bryant &

Wrapping up: Handing in your work To hand in your work (when finished), you will put the files into /home/csci2467/handin/<username> on math209 (not your own system) Programs must work when compiled with gcc on math209 You can work in the lab or remotely via ssh. Either way your program must compile and run on math209. (Compile and run before you hand in)

3 Preview of next week Reading Data surprises!

Chapter 2 is long, start today! Read 2.1 before Monday January 29 Section 2.2 for Wednesday January 31 Section 2.3 for Monday February 5

Source: xkcd.com

ints are not Integers Source: xkcd.com Z is infinitely large, computer memory is not. This is the fundamental challenge!