《125521_Solaris1-Overview-processmodel-mdb-dtrace》由会员分享,可在线阅读,更多相关《125521_Solaris1-Overview-processmodel-mdb-dtrace(45页珍藏版)》请在金锄头文库上搜索。
1、Agenda?Opensolaris Overview?Solaris Introduction?Solaris Introduction?Multithread process modelu t tead p ocessode?Dtrace and Mdb Intro and DemoOpensolaris OverviewOpensolaris Overviewp p开放源代码首创行动组织开放源代码首创行动组织?Open Source Initiative Association (OSIA)?Open Source Initiative Association (OSIA)?非盈利的组织
2、,是美国的非盈利的组织,是美国的Bruce Perens 和和Eric S. Raymond 等人于等人于1998年在美国加州发年在美国加州发起设立的起设立的起设立的起设立的?倡导“开放源代码首创行动” (倡导“开放源代码首创行动” (Open Source 简称简称)其目的就是要让开放源其目的就是要让开放源Initiative,简称简称OSI),其目的就是要让开放源其目的就是要让开放源代代码软件的发展有一个更好的土壤。码软件的发展有一个更好的土壤。代代经经OSIA认证的开放源代码软件的软件认证的开放源代码软件的软件许可证许可证?The GNU General Public License (
3、GPL)?The GNU Library or Lesser Public License (LGPL)?The GNU Library or Lesser Public License (LGPL)?The BSD license?The MIT license?The MIT license?The Mozilla Public License v. 1.0 (MPL)ThIBM P bliLi?The IBM Public License?The Apache Software License?The Sun Internet Standards Source License (SISS
4、L)?The Intel Open Source License?The Mozilla Public License 1.1 (MPL 1.1)?The Nokia Open Source License?等二十几种等二十几种GPL规定的权利规定的权利?为了任何目的的运行该程序为了任何目的的运行该程序?为了任何目的的运行该程序为了任何目的的运行该程序?有自由获得源代码的权利,并在此基础上研究有自由获得源代码的权利,并在此基础上研究程序是如何运行的,并可为了个人的目的改变程序是如何运行的,并可为了个人的目的改变该程序该程序该程序该程序?有自由散发该复制件的权利有自由散发该复制件的权利?有自由改
5、进程序,并要求将自己的改进向公众有自由改进程序,并要求将自己的改进向公众公布的权利公布的权利公布的权利公布的权利GPL规定的义务规定的义务?用户在发布源代码和用户在发布源代码和一一切派生工作时不收费切派生工作时不收费?用户在发布源代码和切派生工作时不收费用户在发布源代码和切派生工作时不收费(除必要的工本费),不附加其他条款,并必(除必要的工本费),不附加其他条款,并必须附带须附带GPL条款条款这样任何人无论是否作了修这样任何人无论是否作了修须附带须附带GPL条款条款。这样任何人无论是否作了修这样任何人无论是否作了修改,都必须连带传递复制和修改这个软件的自改,都必须连带传递复制和修改这个软件的自
6、由度,使得自由软件工作得到延续和认可由度,使得自由软件工作得到延续和认可OpenSolaris开源的模式开源的模式CDDL?基于基于MPL?基于基于MPL?公开源码公开源码?自有使用自有使用被被采纳采纳?CDDL已已被被OSI采纳采纳CDDL与与GPL的不同的不同?在开源代码的基础上加入了新的代码形成的软在开源代码的基础上加入了新的代码形成的软?在开源代码的基础上加入了新的代码形成的软在开源代码的基础上加入了新的代码形成的软件,并不一定需要将其变为开源的东西。件,并不一定需要将其变为开源的东西。?协议与法律权限范围分离协议与法律权限范围分离?Sun授权开发者可以使用与授权开发者可以使用与Sol
7、aris相关的专相关的专?Sun授权开发者可以使用与授权开发者可以使用与Solaris相关的专相关的专利(约利(约600项)项)开放的步骤开放的步骤?免费使用免费使用?免费使用免费使用?开放源代码开放源代码Solaris开放的内容开放的内容?一一千万行源代码千万行源代码?千万行源代码千万行源代码?Solaris 10耗资耗资5亿美元亿美元?内容包括:内容包括:作系核作系核- 操- 操作系作系统内统内核核- - 网络网络网络网络- 系统库- 系统库- 命令- 命令Solaris IntroductionSolaris IntroductionIntroduction?What is Solari
8、s?What is Solaris?Sun Microsystems, Inc.?A complete operating environment, built on a modular, dynamic kernel,y?SOE- Solaris Operating Environment?3 major components:?SunOS- the kernel?Windowing desktop environment, CDE default, OpenWindows still included. Gnome, KDE?Open Networking ComputingA brief
9、 history?BSD UNIX ?1982, Sun UNIX 0.7,?1983 SunOS 1.01992 SOS 4 1 3?1992 SunOS 4.1.3?1992 Solaris 2.0?1998 Solaris 72000 S li 8?2000 Solaris 8?2001 Solaris 9?2005 Solaris 10, OpenSolarisSolaris Kernel FeaturesM l i hd d P M d l?Multithreaded Process Model?Multithreaded kernel?Preemptive kernel?Multi
10、ple Scheduling Classespg?Including real-time support?Tightly Integrated File System & ?Tightly Integrated File System & Virtual Memory?64-bit kernel?32-bit and 64-bit application support?Resource Management?Resource Management?Service Management & Fault Handling?Integrated Networking?Integrated Netw
11、orkingSolaris kernel overview Solaris 10 Feature?Solaris Containers (Zones)?允许允许一一个个Solaris系统内划分多个分区系统内划分多个分区,分别独立运行分别独立运行Solaris实例实例?允许个允许个Solaris系统内划分多个分区系统内划分多个分区,分别独立运行分别独立运行Solaris实例实例?Predictive Self Healing?可预测性自我修复技术,使可预测性自我修复技术,使Sun系统和服务在出现软硬件故障时得到系统和服务在出现软硬件故障时得到最大可用性,此功能在最大可用性,此功能在Sun高端服务
12、器上得到了支持,以后会支持高端服务器上得到了支持,以后会支持x86平台平台?Zetabyte File system (ZFS)?Zetabyte File system (ZFS)?海量的日志文件系统,具有相当于现有文件系统海量的日志文件系统,具有相当于现有文件系统160亿倍的容量亿倍的容量?支持支持128位寻址空间,可以支持位寻址空间,可以支持Zbyte级(级(1G个个GB!)的文件系统)的文件系统轻松管理跨区卷轻松管理跨区卷自动在读写数据时校验错误自动在读写数据时校验错误?轻松管理跨区卷轻松管理跨区卷,自动在读写数据时校验错误自动在读写数据时校验错误?Sun Studio 10?Sola
13、ris和和Linux平台上的平台上的C+、Frotran开发环境开发环境?Sun Java Studio Creator可视化开发环境可视化开发环境?综合开发综合开发/调试调试/部署功能部署功能?包括包括 Sun Java System Application Server 8 平台版软件平台版软件?包括包括 Sun Java System Application Server 8 平台版软件平台版软件?Solaris Dynamic Tracing (dtrace)?Solaris Modular Debugger(mdb)gg)The Process ModelThe Process Mo
14、delThe Process Model?Solaris Kernel is Multi-threaded?Solaris Kernel is Multi threaded?Kernel level threads (kthreads) are the unit of concurrency within the kernelof concurrency within the kernel?Scheduling, synchronization are kernel-level (kthread) concepts(kthread) concepts?Processes are a combi
15、nation of state and one or more user threadsone or more user threads?Process threads are abstracted upon kernel thdthreads?Single threaded processes have just one thdthreadThe Process Model?Processesan abstraction that contains the execution ?an abstraction that contains the execution environment fo
16、r a user program ?consists of a virtual memory environment (an ?consists of a virtual memory environment (an address space), program resources, and at least one thread of executionHardware context?Hardware context?The processor state, which is CPU architecture dependent.dependent.?In general, the st
17、ate of the hardware registers (general registers, privileged registers)?Maintained in the LWP?Software context?Address space, credentials, open files, resource limits, etc stuff shared by all the threads in a processpMulti-threaded Solaris Kernel?kernel services and tasks ?are executed as kernel thr
18、eads ?Kernel threads ?Kernel threads ?have an execution state and context that includes a global priority and that includes a global priority and scheduling class?the unit of concurrency within the t e ut o co cue cytt ekernel?Scheduling, synchronization g,y?are kernel-level (kthread) concepts?user
19、process is a container?user process is a container?defines much of the execution context for its threads.for its threads.Nucleus of the Solaris kernel threads model?Kernel threads?The object that gets scheduled and executed on a processor?User threads?The user-level (non-kernel) thread ?The user lev
20、el (non kernel) thread state maintained within a user process.?Process ocess?The executable form of a program; the execution environment for a user program.?Lightweight process (LWP)ggp()?The kernel-visible execution context for a user thread.The Lightweight Process (LWP) ?the attribute of a LWP?the
21、 attribute of a LWP?Resource utilization counters and microstate accounting informationmicrostate accounting information?The sum total of all LWPs resource usage is stored in the process usage is stored in the process ?Most of the LWP structure members i t t t t ll d t exist to support system calls
22、and to maintain hardware context information?An LWP blocked on a system call does not cause the entire process to blockProcess, LWP, and Kthread Linkage?Kernel maintains system-wide linked lists of yprocesses, LWPs and kthreads?Relationship links maintained at every levelpyConceptual View of a Proce
23、ss?Proc structure?define the context and ti execution environment?uarea is ?uarea is embedded in the process structureit is not is not maintained as a t separate structure.process ?process kernel Stack in the Stack in the LWPProcess Execution EnvironmentProcess State Diagram?For the most part, for e
24、ach process state, ?For the most part, for each process state, there is a corresponding kthread state?Somewhat misleading - kthreads change ?Somewhat misleading kthreads change state, not processesThread StatesProcess and Kernel Thread States?Kthread creation is not flagged as a distinct state gg- t
25、hey go right to TS_RUN?Kthread structures are flagged as TS_FREE when the proc or kthread/LWP is terminated?This allows the kernel to maintain a cache of free kthread/LWP structureskthread/LWP structuresThe Multithreading Model RevolutionTwo level Thread Model (M:N thread model)?Pros:?Fast user thre
26、ad create and destroy?No system call required for synchronization?Fast context-switching?Cons:Co s?Complex, and tricky programming modelprogramming model?Signal deliveryTwo-level model challenges?Asynchronous signal handling?Asynchronous signal handling?user thread that is not masking a posted signa
27、l may not be on an LWP when the system may not be on an LWP when the system attempts to deliver the signal?Scheduling latency ?Scheduling latency ?waiting for the threads library scheduler to link a user thread to an available LWPa user thread to an available LWP?Concurrency issue?Maintain a suffici
28、ent number of LWPs such that ?Maintain a sufficient number of LWPs such that the process does not have runnable user threads waiting for an execution resource (an g(LWP). Single-level Thread Model(1:1 Thread Model)?Every user level hd hlthread has an lwp, and a kthread ?Kernel level ?Kernel level sc
29、heduling?More expensive ?More expensive thread create/destroy, hiisynchronization?More responsive scheduling scheduling, synchronizationMdb and DtraceMdb and DtraceMDB 简介简介?Modular Debugger?Modular DebuggerSolaris中一个通用调试器中一个通用调试器?可以用来查看动态运行的系统可以用来查看动态运行的系统,也可以基于系统崩溃以后的也可以基于系统崩溃以后的?可以用来查看动态运行的系统可以用来查
30、看动态运行的系统,也可以基于系统崩溃以后的也可以基于系统崩溃以后的Dump文件进行静态的分析Dump文件进行静态的分析?支持对进程的调试支持对进程的调试?支持对进程的调试支持对进程的调试?提供丰富的API接口集合,以定制自己的命令提供丰富的API接口集合,以定制自己的命令?MDB的特性的特性?MDB的特性的特性?能对内核或进程的核心转储(能对内核或进程的核心转储(dump)文件进行分析)文件进行分析可扩展可扩展用户可以编写自己的调试命令用户可以编写自己的调试命令?可扩展可扩展,用户可以编写自己的调试命令用户可以编写自己的调试命令?与与adb兼容,包含了兼容,包含了adb的所有命令和宏的所有命令
31、和宏使用使用选项以察内核中的数据选项以察内核中的数据?使用使用-k选项选项可可以以观观察内核中的数据察内核中的数据?通过修改启动选项,可以使用通过修改启动选项,可以使用kmdb调试内核调试内核DTrace介绍介绍?DTraceDTrace是一个动态跟踪工具是一个动态跟踪工具?DTraceDTrace是一个动态跟踪工具是一个动态跟踪工具?基本原理基本原理?在系统中插入大量probe(大约3万个)在系统中插入大量probe(大约3万个)?通过通过DtraceDtrace脚本激活脚本激活probeprobe,并规定在该并规定在该probeprobe处执处执?通过通过DtraceDtrace脚本激活脚
32、本激活probeprobe,并规定在该并规定在该probeprobe处执处执行什么操作,例如读取变量值、统计、打印消息等行什么操作,例如读取变量值、统计、打印消息等程序运行到程序运行到probeprobe处会自动执行规定的操作处会自动执行规定的操作,执行执行?程序运行到程序运行到probeprobe处会自动执行规定的操作处会自动执行规定的操作,执行执行完后再继续执行原来的程序完后再继续执行原来的程序?特点特点?动态跟踪动态跟踪,非交互式非交互式,对原程序运行影响很小对原程序运行影响很小?动态跟踪动态跟踪,非交互式非交互式,对原程序运行影响很小对原程序运行影响很小DTrace工作原理工作原理pl
33、ockstat(1M)intrstat(1M)a.db.dlockstat(1M)dtrace(1M)D program source filesDtrace consumerslibdtrace(3LIB)dt(7D)userlandDtracekerneldtrace(7D)fasttrapvminfosysinfoDtrace providerssyscallpsdtyfbtprofileDTrace脚本脚本内容内容脚本脚本示例示例1:tfork.d/ bi /d#!/usr/sbin/dtrace -s#pragma D option flowindentsyscall:fork1:e
34、ntry./tfork.d -c “sh -c ls”CPU FUNCTION 0 - fork1 0- cforkprobeyy/ pid = $target /self-trace = 1;0 - cfork 0 - secpolicy_basic_fork 0 - priv_policy 0 trace /0 holdlwps 0 - schedctl_finish_sigblock 0- schedctl finish sigblocksyscall:fork1:return0 pokelwps 0 - pokelwps 0 trace /self-trace = 0;0- cfork
35、exit(0);0 cfork 0 - fork1 0 :ps!grep more :ps!grep moreR 2473 2465 2473 2455 0 0x42004000 d3e6e1c8 more d3e6e1c8 $ More , , q, n, c, a ? More space , cr , q, n, c, a ?Dtrace and Mdb Experience Demo 1 0xd37a0768 $ d3e6e1c8 $ More , , q, n, c, a ? 9a9 =D2473 :ps !grep 2473R 2473 2465 2473 2455 0 0x420
36、04000 d3e6e1c8 more Dtrace and Mdb Experience Demo 1 9a9 $ d3e6e1c8:print proc_tp_lockp = 0xd2997400。p_wcode = 0p_exec = 0xd7c2e9c0p_as = 0xd570ba28。 d3e6e1c8:print struct proc。p_pidflag = 0p_wdata = 0p_exec = 0xd7c2e9c0。p tlist = 0xd4808000p_tlist = 0xd4808000。 d4808000:print kthread_t t_link = 0t_
37、stk = 0xd6109fact_startpc = 0t_bound_cpu = 0t_affinitycnt = 0_yt_bind_cpu = 0xfffft_flag = 0x1002。Dtrace and Mdb Experience Demo d4808000:print kthread t d4808000:print kthread_t 。t lwp = 0xd4414120t_lwp = 0xd4414120t_procp = 0xd3e6e1c8。t sysnum = 0x3t_sysnum = 0x3。 d4414120:print klwp t d4414120:pr
38、int klwp_tlwp_pcb = pcb fpu = pcb_fpu = fpu_regs = kfpu_u = 。Dtrace and Mdb Experience Demo d4414120:print klwp_tlwp_ru = d4414120:print klwp_tlwp_ru = minflt = 0minflt = 0majflt = 0nswap = 0minflt 0majflt = 0nswap = 0inblock = 0inblock = 0oublock = 0msgsnd = 0inblock = 0oublock = 0msgsnd = 0msgrcv = 0msgrcv = 0nsignals = 0 nvcsw = 0x2msgrcv = 0nsignals = 0 nvcsw = 0x1nivcsw0x1nivcsw = 0x1sysc = 0x9bioch = 0x2c90nivcsw = 0x1sysc = 0x79ioch = 0x2a0c。Dtrace and Mdb Experience Demo