1 / 107

Linux

Linux. Code.  Initialization Cheng Qian , Jingchen Xu Scheduler (CFS) Songcheng Li, Enkelai. Linux and freebsd initialization. CIS 657 Cheng Qian & Jingchen Xu. Linux boot and initialization. function begin with #ifdef __SMP__ static int boot_cpu = 1;

lane
Download Presentation

Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Code Initialization Cheng Qian, JingchenXu Scheduler (CFS) Songcheng Li, Enkelai

  2. Linux and freebsd initialization CIS 657 Cheng Qian & Jingchen Xu

  3. Linux boot and initialization function begin with #ifdef __SMP__ static int boot_cpu = 1; /* "current" has been set up, we need to load it now, find current system is signal CPU or not*/ if (!boot_cpu)  initialize_secondary(); boot_cpu = 0;#endif /* strategy for not a signal cpu*/ then system calling printk(linux_banner); function to print linux banner information

  4. Kernel phase initialization device for operating system (including memory,hardware ,scheduler): Here is an example for memory and paging initialization setup_arch(&command_line, &memory_start, &memory_end);/*memory initialization*/ memory_start =paging_init(memory_start,memory_end);

  5. Kernel phase trap_init();   /*trap initializaion*/ sched_init()  /*process management and scheduler initializaion*/ parse_options(command_line) /*analyse all the optional choice which passed to kernel*/ memory_start =console_init(memory_start,memory_end) /*console initialization*/ memory_start = kmem_cache_init(memory_start, memory_end) /*kernel mem cache initialization

  6. Kernel Phase 420 /* 421 * Activate the first processor. 422 */ 423 424 static void __init boot_cpu_init(void) 425 { 426 int cpu = smp_processor_id(); 427 /* Mark the boot cpu "present", "online" etc for SMP and UP case */ 428 set_cpu_online(cpu, true); 429 set_cpu_active(cpu, true); 430 set_cpu_present(cpu, true); 431 set_cpu_possible(cpu, true); 432 }

  7. Kernel Phase 442 /* 443 * Set up kernel memory allocators 444 */ 445 static void __init mm_init(void) 446 { 447 /* 448 * page_cgroup requires countinous pages as memmap 449 * and it's bigger than MAX_ORDER unless SPARSEMEM. 450 */ 451 page_cgroup_init_flatmem(); 452 mem_init(); 453 kmem_cache_init(); 454 percpu_init_late(); 455 pgtable_cache_init(); 456 vmalloc_init(); 457

  8. Kernel Phase 459 asmlinkage void __initstart_kernel(void){ .... 487 tick_init(); 488 boot_cpu_init(); 489 page_address_init(); 490 printk(KERN_NOTICE "%s", linux_banner); .... 508 * These use large bootmem allocations and must precede 509 * kmem_cache_init() 511 setup_log_buf(0); 512 pidhash_init(); 513 vfs_caches_init_early(); 514 sort_main_extable(); 515 trap_init(); 516 mm_init(); }

  9. Kernel Phase 518 /* 519 * Set up the scheduler prior starting any interrupts (such as the 520 * timer interrupt). Full topology setup happens at smp_init() 521 * time - but meanwhile we still have a functioning scheduler. 522 */ 523 sched_init();

  10. Init Process • In a standard Linux system, Init is executed with a parameter, known as a runlevel, that takes a value from 1 to 6, and that determines which subsystems are to be made to load. • 0: halt • 1: single user mode • 2: multi-user mode • 3: multi-user mode with networking • 4: undefined/user-defined • 5: Normal system start (with GUI desktop, in multi-user mode) • 6: reboot

  11. Linux:/etc/inittab • Sample inittab lines: # default runlevel id:5:initdefault # runlevel 1 is Single user mode # runlevel 5 is Full multiuser with network and xdm l1:1:wait:/etc/init.d/rc 1 l5:5:wait:/etc/init.d/rc 5 # Single user mode ls:S:wait:/etc/init.d/rc S ~~:S:respawn:/sbin/sulogin # CTRL-ALT-DEL ca::ctrlaltdel:/sbin/shutdown –r –t 4 now • Runlevel 5 runs /etc/init.d/rc 5, which runs scripts under /etc/init.d/rc.5/

  12. Linux Code Initialization Cheng Qian, JingchenXu  Scheduler (CFS) Songcheng Li, Enkelai

  13. Completely Fair Scheduler Team 8: Enkelai Songcheng Li

  14. Task Structure <sched.h> struct task_struct { ... int prio, static_prio, normal_prio; const struct sched_class *sched_class; struct sched_entity se; ... }

  15. Scheduler Classes <sched.h> struct sched_class { const struct sched_class *next; void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup); void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep); void (*check_preempt_curr) (struct rq *rq, struct task_struct *p); struct task_struct * (*pick_next_task) (struct rq *rq); void (*put_prev_task) (struct rq *rq, struct task_struct *p); void (*set_curr_task) (struct rq *rq); void (*task_new) (struct rq *rq, struct task_struct *p); };

  16. Scheduling Entities <sched.h> struct sched_entity { struct load_weight load; struct rb_node run_node; unsigned int on_rq; u64 exec_start; u64 sum_exec_runtime; u64 vruntime; ... }

  17. Run Queues kernel/sched.c struct rq { unsigned long nr_running; ... struct load_weight load; struct cfs_rq cfs; struct task_struct *curr; ... };

  18. CFS run queue kernel/sched.c struct cfs_rq { struct load_weight load; unsigned long nr_running; u64 min_vruntime; struct rb_root tasks_timeline; struct rb_node *rb_leftmost; struct sched_entity *curr; }

  19. Vruntime kernel/sched_fair.c static void update_curr(struct cfs_rq *cfs_rq) { struct sched_entity *curr = cfs_rq->curr; u64 now = rq_of(cfs_rq)->clock; unsigned long delta_exec; if (unlikely(!curr)) return; … delta_exec = (unsigned long)(now - curr->exec_start); __update_curr(cfs_rq, curr, delta_exec); curr->exec_start = now; }

  20. Vruntime kernel/sched_fair.c static inline void __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr, unsigned long delta_exec) { unsigned long delta_exec_weighted; u64 vruntime; curr->sum_exec_runtime += delta_exec; ... delta_exec_weighted = delta_exec; if (unlikely(curr->load.weight != NICE_0_LOAD)) { delta_exec_weighted = calc_delta_fair(delta_exec_weighted, &curr->load); } curr->vruntime += delta_exec_weighted; ...

  21. min_vruntime static void update_min_vruntime(struct cfs_rq *cfs_rq) { u64 vruntime = cfs_rq->min_vruntime; if (cfs_rq->curr) vruntime = cfs_rq->curr->vruntime; if (cfs_rq->rb_leftmost) { struct sched_entity *se = rb_entry(cfs_rq->rb_leftmost, struct sched_entity, run_node); if (!cfs_rq->curr) vruntime = se->vruntime; else vruntime = min_vruntime(vruntime, se->vruntime); } cfs_rq->min_vruntime = max_vruntime(cfs_rq->min_vruntime, vruntime); }

  22. Enqueue

  23. Pick next task

  24. Code Android Binder DrumilBhattad, ParminderBhela Paranoid Network Dipen Shah, Rohan Shah Early Suspend Chen Chen, Botong Tao Logger, apanicAdityaPatil, SanketGhia Bluetooth Shaojie Liu adb(debug bridge) Lusha Wang, Mu Zhang Scheduler Ravi Kumar, AshishAgarwal App Security AgneloDcosta, Nijeel Parekh Alarm Timers Xiao Zhang, Christopher Wang

  25. ANDROID Binder CIS 657 Drumil Bhattad Parminder Bhela

  26. Binder Sample Example • Remote Service • IMathService.aidl

  27. Stub Proxy

  28. Return Proxy to client • Generated Method signature

  29. Client Activity

  30. Service implementation

  31. Output Addition Subtraction

  32. References • https://www.nds.rub.de/media/attachments/files/2011/10/main.pdf • http://developer.android.com/reference/android/os/IBinder.html

  33. Code Android Binder DrumilBhattad, ParminderBhela  Paranoid Network Dipen Shah, Rohan Shah Early Suspend Chen Chen, Botong Tao Logger, apanicAdityaPatil, SanketGhia Bluetooth Shaojie Liu adb(debug bridge) Lusha Wang, Mu Zhang Scheduler Ravi Kumar, AshishAgarwal App Security AgneloDcosta, Nijeel Parekh Alarm Timers Xiao Zhang, Christopher Wang

  34. PARANOID NETWORK& ANDROID SECURITY By Dipen Shah Rohan Shah

  35. MANIFEST.XML

  36. Example: Friend Tracker Application • FriendTracker Service to poll for friend locations •  Broadcasts an Intent when near a friend • FriendProvider Content Provider to store location of friends • Cross references friends with system Contacts Provider • FriendTrackerControl Activity to start and stop the Service • BootReceiver Broadcast Receiver to start the service on boot

  37. Intent Broadcast Permission

  38. Pending Intents

  39. Content Provider Permissions

  40. REFERENCES • http://developer.android.com/guide/topics/security/security.html • http://siis.cse.psu.edu/slides/android-sec-tutorial.pdf

  41. Code Android Binder DrumilBhattad, ParminderBhela Paranoid Network Dipen Shah, Rohan Shah  Early Suspend Chen Chen, Botong Tao Logger, apanicAdityaPatil, SanketGhia Bluetooth Shaojie Liu adb(debug bridge) Lusha Wang, Mu Zhang Scheduler Ravi Kumar, AshishAgarwal App Security AgneloDcosta, Nijeel Parekh Alarm Timers Xiao Zhang, Christopher Wang

  42. Android System Early Suspend CHEN CHEN BOTONG TAO

  43. Kernel Code Slide Android SYstemearly suspend

  44. The entrance function of the kernel/power/main.c early suspend procedure (1)

  45. In the HAL of Android, we check hardware/libhardware_legacy/power/power.c early suspend procedure (2)

  46. We start from the initialization function in kernel/power/wakelock.c early suspend procedure (3)

  47. In the kernel/power/main.c early suspend procedure (4)

  48. In the kernel/power/earlysuspend.c early suspend procedure (5)

  49. In the kernel/power /earlysuspend.c early suspend procedure (6)

  50. In the kernel/power /earlysuspend.c early suspend procedure (7)

More Related