Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Systems programming is for everyone

Systems programming is for everyone

Julia Evans

July 02, 2016
Tweet

More Decks by Julia Evans

Other Decks in Technology

Transcript

  1. SYSTEMS PROGRAMMING IS FOR EVERYONE by Julia Evans Stripe twitter:

    @b0rk blog: jvns.ca Tweet questions to @b0rk
  2. perl | go | c++ | fortran php | python

    | java | smalltalk INTERCAL | BASIC | erlang
  3. DEBUGGING: look at the source code add print statements know

    the programming language ★★★ be a wizard★★★
  4. THIS TALK Wizard school (or, an operating systems primer) Chapter

    1: The Case of the Mystery Config File Chapter 2: The Case of the French Website Chapter 3: The Case of the Slow Program
  5. When I go to http://google.com, kernel code runs for: Typing

    in the address Handling every network packet Writing history files to disk Allocating memory Communicating with the graphics card
  6. SYSTEM CALLS: AN OS'S INTERFACE open a file! (o p

    e n ) start a program! (e x e c v e ) change a file's permissions! (c h m o d )
  7. WHAT WE'VE LEARNED Your OS does tons of stuff Programs

    tell it what to do using system calls
  8. Does bash use . b a s h _ p

    r o f i l e or . b a s h r c ??!??
  9. HOW TO STRACE $ s t r a c e

    g o o g l e - c h r o m e e x e c v e ( " / u s r / b i n / g o o g l e - c h r o m e " , [ " g o o g l e - c h r o m e " ] , [ / * 5 1 v a r s * / ] b r k ( 0 ) = 0 x 1 2 4 f 0 0 0 a c c e s s ( " / e t c / l d . s o . n o h w c a p " , F _ O K ) = - 1 E N O E N T ( N o s u c h f i l e o
  10. OTHER AWESOME SYSTEM CALLS w r i t e for

    log files e x e c v e for starting programs r e c v f r o m for receiving data
  11. ???

  12. 3 SLOW PROGRAMS 1. CPU time 2. too many writes

    3. waiting for a slow server
  13. /PROC/P I D /STACK $ p g r e p

    - f m y s t e r y _ 1 3 1 7 2 8 $ s u d o c a t / p r o c / 3 1 7 2 8 / s t a c k [ < f f f f f f f f 8 1 7 0 2 4 6 7 > ] s k _ w a i t _ d a t a + 0 x 1 0 7 / 0 x 1 2 0 [ < f f f f f f f f 8 1 7 6 7 1 1 2 > ] t c p _ r e c v m s g + 0 x 2 e 2 / 0 x b 8 0 [ < f f f f f f f f 8 1 7 9 4 d 6 e > ] i n e t _ r e c v m s g + 0 x 7 e / 0 x b 0 [ < f f f f f f f f 8 1 6 f d b 6 b > ] s o c k _ r e c v m s g + 0 x 3 b / 0 x 5 0 [ < f f f f f f f f 8 1 6 f d d c 1 > ] S Y S C _ r e c v f r o m + 0 x e 1 / 0 x 1 6 0 [ < f f f f f f f f 8 1 6 f f 1 c e > ] S y S _ r e c v f r o m + 0 x e / 0 x 1 0 [ < f f f f f f f f 8 1 8 2 4 4 f 2 > ] e n t r y _ S Y S C A L L _ 6 4 _ f a s t p a t h + 0 x 1 6 / 0 x 7 1 [ < f f f f f f f f f f f f f f f f > ] 0 x f f f f f f f f f f f f f f f
  14. rust_mutex system_call_fastpath ttwu_.. en.. enq.. enqu.. futex_wait main::.. [unknown] _raw_..

    [unknown] futex_wake do_futex __ticket_spin_lock __schedule __lll_lock_wait wake_futex acti.. schedule sys_futex futex_wait_que.. dea.. __lll_unlock_wake wake_up_state _raw_spin_lock __tic.. __ticket_spin_lock de.. try_to_wake_up se.. _raw_spin_lock ttwu_.. system_call_fastpath deq.. d.. sys_futex futex_wait_setup do_futex
  15. RULES OF RULES OF PROGRAMMING PROGRAMMING EXPERIMENTS EXPERIMENTS it doesn't

    have to work 1. you don't have to finish it 2. you have to learn something 3.
  16. EXPERIMENT 1: WRITE AN EXPERIMENT 1: WRITE AN OPERATING SYSTEM

    OPERATING SYSTEM remember it doesn't have to work
  17. WHAT I LEARNED WHAT I LEARNED having more than once

    process is hard filesystems are hard operating systems are SO COMPLICATED
  18. static MemPage *btreePageFromDbPage(DbPage *pDbPage, Pgno pgno, BtSha // actual code

    printf("Read a btree page, page number %d\n", pgno); // added by me // actual code }
  19. sqlite> select * from fun where id = 1; Read

    a btree page, page number 1 Read a btree page, page number 5 Read a btree page, page number 828 Read a btree page, page number 10 Read a btree page, page number 2 Read a btree page, page number 76 Read a btree page, page number 6 1|A's
  20. sqlite> select * from fun where id = 20; Read

    a btree page, page number 1 Read a btree page, page number 5 Read a btree page, page number 828 Read a btree page, page number 10 Read a btree page, page number 2 Read a btree page, page number 76 Read a btree page, page number 6 20|Aaliyah
  21. sqlite> select * from fun where id = 80000; Read

    a btree page, page number 1 Read a btree page, page number 5 Read a btree page, page number 1198 Read a btree page, page number 992 Read a btree page, page number 2 Read a btree page, page number 1813 Read a btree page, page number 449 80000|scarfs
  22. WHAT I LEARNED WHAT I LEARNED databases tables are trees

    databases are made of pages i can read some of the SQLite source code!
  23. ip_header = IP(dst=dest_ip, src=src_ip) syn = TCP(dport=80, sport=59333, ack=0, flags="S")

    # Send the SYN packet to Google response = srp(ip_header + syn)
  24. WHAT I LEARNED WHAT I LEARNED how TCP packets are

    put together! you can write a 10% working TCP from scratch in 2 weeks python can't keep up
  25. int counter; void *AddThings(void *threadid) { for (int i =

    0; i < 10000; i++) counter += 1; pthread_exit(NULL); }
  26. "can you discuss the pros and cons of using a

    lock-free approach for implementing a thread-safe hashmap?"
  27. THANKS! Julia Evans twitter: @b0rk learn more by reading my

    blog: http://jvns.ca Come ask me questions & get a zine!