OS Customization versus OS Code Modularity

Similar documents
CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Course 6 7 November Adrian Iftene

Separation of Concerns. AspectJ. What if the concerns are Cross-Cutting? SoC: Programming Paradigms. Key theme: Modularity and Encapsulation

Aspect Refactoring Verifier

Concurrency, Thread. Dongkun Shin, SKKU

Threads. studykorner.org

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

In Java we have the keyword null, which is the value of an uninitialized reference type

Presentation Overview

Chapter 32. Aspect-Oriented Software Development (AOSD) Ian Sommerville 2006 Software Engineering. Chapter 32 Slide 1

A short introduction to INF329. Spring AOP

Aspect-Oriented Programming

Memory and C/C++ modules

Aspect-Oriented Programming with C++ and AspectC++

SmartHeap for Multi-Core

System Programming And C Language

Multicore and Multiprocessor Systems: Part I

Aspect Oriented Programming with AspectJ. Ted Leung Sauria Associates, LLC

AJDT: Getting started with Aspect-Oriented Programming in Eclipse

PROGRAMOVÁNÍ V C++ CVIČENÍ. Michal Brabec

ANITA S SUPER AWESOME RECITATION SLIDES

Mobile and Context-aware Interactive Systems

Aspect-Oriented Programming

CSC 1600 Memory Layout for Unix Processes"

4.8 Summary. Practice Exercises

CPSC 427: Object-Oriented Programming

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Scalable Linux Scheduling (Paper # 9)

Chapitre 6 Programmation orientée aspect (AOP)

Aspect Oriented Programming

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

AOSA - Betriebssystemkomponenten und der Aspektmoderatoransatz

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

Kurt Schmidt. October 30, 2018

Chapter 21 Aspect-Oriented Software Engineering (AOSE)

CS240: Programming in C

EL2310 Scientific Programming

Aspect-oriented Software Development. Ian Sommerville 2006 Software Engineering, 8th edition. Chapter 32 Slide 1

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Heap Arrays. Steven R. Bagley

Reminder: compiling & linking

Language support for AOP

,879 B FAT #1 FAT #2 root directory data. Figure 1: Disk layout for a 1.44 Mb DOS diskette. B is the boot sector.

Compilation/linking revisited. Memory and C/C++ modules. Layout of C/C++ programs. A sample C program demo.c. A possible structure of demo.

EECS 482 Introduction to Operating Systems

Linux Kernel Development (LKD)

Using kgdb and the kgdb Internals

Information systems modeling. Tomasz Kubik

A First Book of ANSI C

Using Aspect-Oriented Programming to extend Protégé. Henrik Eriksson Linköping University

Project 1. Fast correction

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Shmuel Ur Shady Copty Software and Verification Technologies

ECE 598 Advanced Operating Systems Lecture 23

NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313.

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

CSE 333 Lecture 4 - malloc, free, struct, typedef

Advanced Pointer & Data Storage

CSCI 171 Chapter Outlines

"Secure" Coding Practices Nicholas Weaver

Lecture 8 Dynamic Memory Allocation

POINTER AND ARRAY SUNU WIBIRAMA

Memory and C/C++ modules

Implementing Producers/Consumers Problem Using Aspect-Oriented Framework

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Introduction to. Bruno Harbulot. ESNW, the University of Manchester.

Multithreaded Programming

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Embedded Linux. Session 4: Introduction to the GPIO Kernel API. Martin Aebersold BFH-TI Dipl. El.-Ing. FH.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Adventures in building open source software. Sevan Janiyan - BSDCan pkgsrc

Advanced use of the C language

o Code, executable, and process o Main memory vs. virtual memory

Aspects and Soar: A Behavior Development Model. Jacob Crossman

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

Computer Systems Laboratory Sungkyunkwan University

Comparative Analysis Of Strategies For Applying AOP On Legacy Code

A Quantitative Analysis of Aspects in the ecos Kernel

More on C programming

1. Overview This project will help you understand address spaces and virtual memory management.

Come and join us at WebLyceum

Refactoring Aspect Oriented Software

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

Processes. Johan Montelius KTH

1. We have a code sequence that is potentially executed twice.

CS61C : Machine Structures

pthreads CS449 Fall 2017

Shared Memory Programming. Parallel Programming Overview

Pointers. A pointer is simply a reference to a variable/object. Compilers automatically generate code to store/retrieve variables from memory

CSCE 455/855 Distributed Operating Systems

Applying Aspect Oriented Programming on Security

What are some common categories of system calls? What are common ways of structuring an OS? What are the principles behind OS design and

A process. the stack

Topic 6: A Quick Intro To C

A Brief Introduction to Aspect-Oriented Programming. Historical View Of Languages. Procedural language Functional language Object-Oriented language

CS420: Operating Systems

A Brief Introduction to Aspect-Oriented Programming" Historical View Of Languages"

Base Component. Chapter 1. *Memory Management. Memory management Errors Exception Handling Messages Debug code Options Basic data types Multithreading

AOP 101: Intro to Aspect Oriented Programming. Ernest Hill

Transcription:

OS Customization versus OS Code Modularity ECE 344 Fall 2006 Hans-Arno Jacobsen Thanks to Michael Gong, Vinod Muthusamy, and Charles Zhang for helping to find interesting examples et al.

Possibly a Debugging Concern #ifdef SLOWER #ifndef SLOW #define SLOW #endif #endif #ifdef SLOW static void checksubpage(struct pageref *pr){ // code removed (next column) OS/161 Kernel: kern/lib/kheap.c #else #define checksubpage(pr) ((void)(pr)) #endif #ifdef SLOWER static void checksubpages(void) { // code removed #else #define checksubpages() #endif

Possibly a Debugging Concern /* SLOWER implies SLOW */ #ifdef SLOWER #ifndef SLOW #define SLOW #endif #endif #ifdef SLOW static void checksubpage(struct pageref *pr){ // code removed (next column) OS/161 Kernel: kern/lib/kheap.c #else #define checksubpage(pr) ((void)(pr)) #endif // ifdef SLOW #ifdef SLOWER static void checksubpages(void) { // code removed #else #define checksubpages() #endif // ifdef SLOWER

Observations Most likely the OS designers way of debugging memory allocation (guess) Multiple highly concentrated concerns to customize a part of OS for debugging Hard to read, understand, modify, test FAST or NORMAL not even explicitly documented in code

Platform Support #ifdef MIPSEB /* For big-endian machines. */ #define va_arg( AP, type) \ (( AP = (char *) (( alignof ( type) > 4 \? ((int) AP + 8-1) & -8 \ : ((int) AP + 4-1) & -4) \ + va_rounded_size ( type))), \ *( type *) (void *) ( AP - va_rounded_size ( type))) #else /* For little-endian machines. */ #endif #endif #endif /*! defined ( mips_eabi) */ More of the above Hardware platform specific customizations OS/161 Kernel: kern/arch/mips/include/stdarg.h

Error Checking Concern static int init readonly(char *str) { if (*str) return 0; root_mountflags = MS_RDONLY; return 1; Error checking code scatters across code base It cuts across core logic static int init readwrite(char *str) { if (*str) return 0; root_mountflags &= ~MS_RDONLY; return 1; Linux Kernel 2.6: kernel initialization: do_mount.c

Lock & unlock I int is_orphaned_pgrp(int pgrp) { int retval; read_lock(&tasklist_lock); retval = will_become_orphaned_pgrp(pgrp, NULL); read_unlock(&tasklist_lock); return retval; The same scattering and crosscutting of synchronization concern (see error checking) Similar pieces of code all over the place Linux Kernel 2.6: kernel/exit.c

Lock & unlock II int session_of_pgrp(int pgrp) { struct task_struct *p; int sid = -1; read_lock(&tasklist_lock); do_each_task_pid(pgrp, PIDTYPE_PGID, p) { if (p->signal->session > 0) { sid = p->signal->session; goto out; while_each_task_pid(pgrp, PIDTYPE_PGID, p); p = find_task_by_pid(pgrp); if (p) sid = p->signal->session; out: read_unlock(&tasklist_lock); return sid;

Multiprocessor Support I static int try_to_wake_up(task_t *p, unsigned int state, int sync) { int cpu, this_cpu, success = 0; unsigned long flags; long old_state; runqueue_t *rq; #ifdef CONFIG_SMP unsigned long load, this_load; struct sched_domain *sd, *this_sd = NULL; int new_cpu; #endif (next slide) Linux Kernel 2.6: kernel/sched.c

Multiprocessor Support II rq = task_rq_lock(p, &flags); old_state = p->state; if (!(old_state & state)) goto out; if (p->array) goto out_running; cpu = task_cpu(p); this_cpu = smp_processor_id(); #ifdef CONFIG_SMP if (unlikely(task_running(rq, p))) goto out_activate; new_cpu = cpu; schedstat_inc(rq, ttwu_cnt); #endif pieces of multiprocessing concern tangled with core logic (1 CPU case) not the same piece of code as in previous cases

Summary Certain concerns crosscut the principal or core logic (a.k.a. crosscutting concerns) Similar concern code scatters across the code base Different pieces of concern code tangled with core logic Scattering, tangling, and crosscutting apparently leads to code that is hard to read and understand, let alone maintain where the design intent is not cleanly represented in the code where concerns are not well separated and modularized removing a concern is error-prone

Need for Customization Customization of OS code is unavoidable OS code is often tailored to different hardware platforms creating a whole family of OS versions Variety of hardware features (on different platforms) have far reaching implication for OS code Traditionally dealt with At configuration time (various tools) At compile time #ifdefs/#defines (driven through a make process or by a configuration tool) Dynamically loadable kernel modules

Customization in OS/161 "options" declarations in the config file options dumbvm defines OPT_DUMBVM in the code Definition of OPT_SYNCHPROBS leads to conditional code in kern/include/clock.h kern/include/test.h kern/main/menu.c kern/test/tt3.c kern/thread/thread.c This is an example for crosscutting conditional compilation in OS/161

Crosscutting Crosscutting phenomenon is often not due to bad design But tied to the characteristics of traditional development techniques the decomposition mechanism of traditional development paradigms Files, functions, structures Classes, objects, interfaces, methods

Conventional Programming Paradigms A file (a module) Red shows lines pertaining to a given concern Not in just one place (i.e., file, function) Not even in a small number of places (files or functions) Example is a bit out of context for operating systems OS code would show very similar footprints

Is there a Solution? For separating crosscutting concerns from core code Pick and choose the concerns required (based on hardware platform etc.)

Yes!

Aspect-oriented Programming (AOP) AOP is a programming paradigm that aims to support the modularization of crosscutting concerns in software AOP is complementary to existing paradigms Emerged about 10 years ago from different research efforts studying the Separation of Concerns in software Supported in industry today by IBM, BEA, AOP support is available for Java, C, C++ AspectJ, AspectC, AspectC++

Key Idea Crosscutting concerns are represented by aspects in the program sources Required aspects are woven into the program The program is fully unaware of the aspect (i.e., in the sources, there is no aspect code inside the program) Note, there are a few AOP approaches around today that do not fully follow this model (i.e., some code present in program) The program is often referred to as the base program or the core advised by the aspect code Aspects specify when and what code to execute This specification is declarative and outside the core For AspectC weaving happens at compile time (other models are load time or run-time weaving.)

Example: Key Idea OS/161 src/kern/aspect/trace.ac: Join point declaration Pointcut before(): call ( $ $bootstrap$(...) ) declaration { kprintf("> Entering %s \n", this->funcname); advice

Join Points Well-defined points in the execution of a program The point a function is called The point a function is executed Examples for C Function calls (before/after) (call site) Function execution (before/after) (called site) Examples for Java Method calls & execution Field reads & writes Exceptions

Pointcuts Declaratively define sets of join points Call pointcut (all join points associated with the call of a function) Execution pointcut (all join points associated with the execution of a function) Example call($ $bootstrap$(...)) All call join points involving functions that contain the word bootstrap in the function name With any list of input parameter types With any return value type

Advice The code executed when the associated pointcut matches a join point

Example: Memory Profiling I size_t totalmemoryallocated; int totalallocationfunccalled; int totalfreefunccalled; void initprofiler(){ totalmemoryallocated = 0; totalallocationfunccalled = 0; totalfreefunccalled = 0; void printprofiler(){ printf("total memory allocated = %d bytes\n", totalmemoryallocated); totalallocationfunccalled); totalfreefunccalled);

Example: Memory Profiling II before(): execution(int main()) { initprofiler(); after(): execution(int main()) { printprofiler(); before(size_t s): call($ malloc(...)) && args(s) { totalmemoryallocated += s; totalallocationfunccalled ++;

Example: Memory Profiling III before(size_t n, size_t s): call($ calloc(...)) && args(n, s) { totalmemoryallocated += n * s; totalallocationfunccalled ++; before(size_t s): call($ realloc(...)) && args(void *, s) { totalmemoryallocated += s; totalallocationfunccalled ++; before() : call(void free(void *)) { totalfreefunccalled++;

Example: Memory Profiling IV Is the code thread safe? Is thread-safety an aspect? Left as an exercise for the reader.

Use of AOP Build aspects into systems right from the start (i.e., design with aspects in mind) Use aspects to aid in debugging, analyzing, policy checking Use aspects to refactor existing systems Tailoring and customization Adaptation Extension

AspectC Developed by Michael Gong and myself Aspect-oriented extension to C ANSI-C compliant gcc source-compatibility Compiler and generated code is portable (mostly ) Seamless Linux, Solaris and Windows support (Mac OS X support in progress.) Integration in existing build processes possible Code transparency through source-to-source transformations Based on open source license and compiler

AspectC Resources http://www.aspectc.net Assignment 0 handout AspectC Tutorial AspectC Language Specification See the AspectC web site for submitting a bug report, if you think you found one

Resources Aspect-oriented Software Development Portal http://www.aosd.net AspectJ http://www.eclipse.org/aspectj/ AspectC++ http://www.aspectc.org AspectC http://www.aspectc.net