1.1k likes | 1.39k Views
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;
E N D
Linux Code Initialization Cheng Qian, JingchenXu 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; /* "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
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);
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
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 }
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
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(); }
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();
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
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/
Linux Code Initialization Cheng Qian, JingchenXu Scheduler (CFS) Songcheng Li, Enkelai
Completely Fair Scheduler Team 8: Enkelai Songcheng Li
Task Structure <sched.h> struct task_struct { ... int prio, static_prio, normal_prio; const struct sched_class *sched_class; struct sched_entity se; ... }
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); };
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; ... }
Run Queues kernel/sched.c struct rq { unsigned long nr_running; ... struct load_weight load; struct cfs_rq cfs; struct task_struct *curr; ... };
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; }
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; }
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; ...
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); }
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
ANDROID Binder CIS 657 Drumil Bhattad Parminder Bhela
Binder Sample Example • Remote Service • IMathService.aidl
Stub Proxy
Return Proxy to client • Generated Method signature
Output Addition Subtraction
References • https://www.nds.rub.de/media/attachments/files/2011/10/main.pdf • http://developer.android.com/reference/android/os/IBinder.html
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
PARANOID NETWORK& ANDROID SECURITY By Dipen Shah Rohan Shah
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
REFERENCES • http://developer.android.com/guide/topics/security/security.html • http://siis.cse.psu.edu/slides/android-sec-tutorial.pdf
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
Android System Early Suspend CHEN CHEN BOTONG TAO
Kernel Code Slide Android SYstemearly suspend
The entrance function of the kernel/power/main.c early suspend procedure (1)
In the HAL of Android, we check hardware/libhardware_legacy/power/power.c early suspend procedure (2)
We start from the initialization function in kernel/power/wakelock.c early suspend procedure (3)
In the kernel/power/main.c early suspend procedure (4)
In the kernel/power/earlysuspend.c early suspend procedure (5)
In the kernel/power /earlysuspend.c early suspend procedure (6)
In the kernel/power /earlysuspend.c early suspend procedure (7)