Misplaced Pages

Stackless Python

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

Stackless Python , or Stackless , is a Python programming language interpreter, so named because it avoids depending on the C call stack for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function calls. The most prominent feature of Stackless is microthreads , which avoid much of the overhead associated with usual operating system threads . In addition to Python features, Stackless also adds support for coroutines , communication channels , and task serialization .

#130869

63-466: With Stackless Python, a running program is split into microthreads that are managed by the language interpreter itself, not the operating system kernel — context switching and task scheduling is done purely in the interpreter (these are thus also regarded as a form of green thread ). Microthreads manage the execution of different subtasks in a program on the same CPU core. Thus, they are an alternative to event-based asynchronous programming and also avoid

126-561: A green threading solution for CPython. Python since has received a native solution for green threads: await /async. Stackless is used extensively in the implementation of the Eve Online massively multiplayer online game as well as in IronPort 's mail platform. Kernel (operating system) The kernel is a computer program at the core of a computer 's operating system and generally has complete control over everything in

189-491: A language-based protection system , the kernel will only allow code to execute that has been produced by a trusted language compiler . The language may then be designed such that it is impossible for the programmer to instruct it to do something that will violate a security requirement. Advantages of this approach include: Disadvantages include: Examples of systems with language-based protection include JX and Microsoft 's Singularity . Edsger Dijkstra proved that from

252-407: A bug in a device driver might crash the entire system – and the fact that large kernels can become very difficult to maintain; Thompson also stated that "It is also easier for [a monolithic kernel] to turn into a mess in a hurry as it is modified." Monolithic kernels, which have traditionally been used by Unix-like operating systems, contain all the operating system core functions and

315-425: A checked copy of the request is passed through the system call. Hence, not far to travel at all. The monolithic Linux kernel can be made extremely small not only because of its ability to dynamically load modules but also because of its ease of customization. In fact, there are some versions that are small enough to fit together with a large number of utilities and other programs on a single floppy disk and still provide

378-461: A device present on the system, or any form of communication with other processes requires the use of system calls. A system call is a mechanism that is used by the application program to request a service from the operating system. They use a machine-code instruction that causes the processor to change mode. An example would be from supervisor mode to protected mode. This is where the operating system performs actions like accessing hardware devices or

441-468: A driver is abstraction; the function of the driver is to translate the OS-mandated abstract function calls (programming calls) into device-specific calls. In theory, a device should work correctly with a suitable driver. Device drivers are used for e.g. video cards, sound cards, printers, scanners, modems, and Network cards. At the hardware level, common abstractions of device drivers include: And at

504-604: A fully functional operating system (one of the most popular of which is muLinux ). This ability to miniaturize its kernel has also led to a rapid growth in the use of Linux in embedded systems . Address space In computing , an address space defines a range of discrete addresses, each of which may correspond to a network host , peripheral device , disk sector , a memory cell or other logical or physical entity. For software programs to save and retrieve stored data, each datum must have an address where it can be located. The number of address spaces available depends on

567-515: A kernel where I/O devices are handled uniformly with other processes, as parallel co-operating processes, was first proposed and implemented by Brinch Hansen (although similar ideas were suggested in 1967 ). In Hansen's description of this, the "common" processes are called internal processes , while the I/O devices are called external processes . Similar to physical memory, allowing applications direct access to controller ports and registers can cause

630-528: A logical point of view, atomic lock and unlock operations operating on binary semaphores are sufficient primitives to express any functionality of process cooperation. However this approach is generally held to be lacking in terms of safety and efficiency, whereas a message passing approach is more flexible. A number of other approaches (either lower- or higher-level) are available as well, with many modern kernels providing support for systems such as shared memory and remote procedure calls . The idea of

693-423: A particular (virtual) address may be different memory from what another process accesses at the same address. This allows every program to behave as if it is the only one (apart from the kernel) running and thus prevents applications from crashing each other. On many systems, a program's virtual address may refer to data which is not currently in memory. The layer of indirection provided by virtual addressing allows

SECTION 10

#1732773315131

756-726: A partitioning to several regions according to the mathematical structure it has. In the case of total order , as for memory addresses , these are simply chunks . Like the hierarchical design of postal addresses , some nested domain hierarchies appear as a directed ordered tree , such as with the Domain Name System or a directory structure . In the Internet , the Internet Assigned Numbers Authority (IANA) allocates ranges of IP addresses to various registries so each can manage their parts of

819-684: A point where it is as fast as or faster than the one that was specifically designed for the hardware, although more relevant in a general sense. Modern monolithic kernels, such as the Linux kernel , the FreeBSD kernel, the AIX kernel, the HP-UX kernel, and the Solaris kernel, all of which fall into the category of Unix-like operating systems, support loadable kernel modules , allowing modules to be loaded into

882-592: A policy is a particular "mode of operation". Example: Because the mechanism and policy are separated, the policy can be easily changed to e.g. require the use of a security token . In minimal microkernel just some very basic policies are included, and its mechanisms allows what is running on top of the kernel (the remaining part of the operating system and the other applications) to decide which policies to adopt (as memory management, high level process scheduling, file system management, etc.). A monolithic kernel instead tends to include many policies, therefore restricting

945-407: A process must be able to access the services provided by the kernel. This is implemented differently by each kernel, but most provide a C library or an API , which in turn invokes the related kernel functions. The method of invoking the kernel function varies from kernel to kernel. If memory isolation is in use, it is impossible for a user process to call the kernel directly, because that would be

1008-446: A separate area of memory, user space . This separation prevents user data and kernel data from interfering with each other and causing instability and slowness, as well as preventing malfunctioning applications from affecting other applications or crashing the entire operating system. Even in systems where the kernel is included in application address spaces , memory protection is used to prevent unauthorized applications from modifying

1071-401: A shared CPU and not parallelism (preemption was originally not available but is now in some form). To use multiple CPU cores, one would still need to build an interprocess communication system on top of Stackless Python processes. Due to the considerable number of changes in the source, Stackless Python cannot be installed on a preexisting Python installation as an extension or library . It

1134-449: A user-level application may only be permitted to perform some of these operations (e.g., it may only be allowed to read the file). A common implementation of this is for the kernel to provide an object to the application (typically so called a "file handle") which the application may then invoke operations on, the validity of which the kernel checks at the time the operation is requested. Such a system may be extended to cover all objects that

1197-478: A violation of the processor's access control rules. A few possibilities are: An important consideration in the design of a kernel is the support it provides for protection from faults ( fault tolerance ) and from malicious behaviours ( security ). These two aspects are usually not clearly distinguished, and the adoption of this distinction in the kernel design leads to the rejection of a hierarchical structure for protection . The mechanisms or policies provided by

1260-447: Is a computer program encapsulating, monitoring and controlling a hardware device (via its Hardware/Software Interface (HSI) ) on behalf of the OS. It provides the operating system with an API, procedures and information about how to control and communicate with a certain piece of hardware. Device drivers are an important and vital dependency for all OS and their applications. The design goal of

1323-423: Is a notable example of microkernel design. The Linux kernel is both monolithic and modular, since it can insert and remove loadable kernel modules at runtime. This central component of a computer system is responsible for executing programs. The kernel takes responsibility for deciding at any time which of the many running programs should be allocated to the processor or processors. Random-access memory (RAM)

SECTION 20

#1732773315131

1386-423: Is an example of inter-process communication (IPC). The above listed tasks and features can be provided in many ways that differ from each other in design and implementation. The principle of separation of mechanism and policy is the substantial difference between the philosophy of micro and monolithic kernels. Here a mechanism is the support that allows the implementation of many different policies, while

1449-420: Is an exokernel. In a monolithic kernel, all OS services run along with the main kernel thread, thus also residing in the same memory area. This approach provides rich and powerful hardware access. UNIX developer Ken Thompson stated that "it is in [his] opinion easier to implement a monolithic kernel". The main disadvantages of monolithic kernels are the dependencies between system components –

1512-499: Is common in conventional commercial systems; in fact, every module needing protection is therefore preferably included into the kernel. This link between monolithic design and "privileged mode" can be reconducted to the key issue of mechanism-policy separation; in fact the "privileged mode" architectural approach melds together the protection mechanism with the security policies, while the major alternative architectural approach, capability-based addressing , clearly distinguishes between

1575-454: Is instead a complete Python distribution in itself. The majority of Stackless's features have also been implemented in PyPy , a self-hosting Python interpreter and JIT compiler . Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a CPython extension called greenlet. It is used by a number of libraries (e.g. gevent) to provide

1638-505: Is that any security policy can be implemented in an application regardless of kernel support. According to Mars Research Group developers, a lack of isolation is one of the main factors undermining kernel security. They propose their driver isolation framework for protection, primarily in the Linux kernel. Typical computer systems today use hardware-enforced rules about what programs are allowed to access what data. The processor monitors

1701-452: Is to simulate capabilities using commonly supported hierarchical domains. In this approach, each protected object must reside in an address space that the application does not have access to; the kernel also maintains a list of capabilities in such memory. When an application needs to access an object protected by a capability, it performs a system call and the kernel then checks whether the application's capability grants it permission to perform

1764-441: Is typically implemented using CPU modes . Many kernels provide implementation of "capabilities", i.e., objects that are provided to user code which allow limited access to an underlying object managed by the kernel. A common example is file handling: a file is a representation of information stored on a permanent storage device. The kernel may be able to perform many different operations, including read, write, delete or execute, but

1827-663: Is used to store both program instructions and data. Typically, both need to be present in memory in order for a program to execute. Often multiple programs will want access to memory, frequently demanding more memory than the computer has available. The kernel is responsible for deciding which memory each process can use, and determining what to do when not enough memory is available. I/O devices include, but are not limited to, peripherals such as keyboards, mice, disk drives, printers, USB devices, network adapters, and display devices . The kernel provides convenient methods for applications to use these devices which are typically abstracted by

1890-583: The address space would be a combination of locations, such as a neighborhood, town, city, or country. Some elements of a data address space may be the same, but if any element in the address is different, addresses in said space will reference different entities. For example, there could be multiple buildings at the same address of "32 Main Street" but in different towns, demonstrating that different towns have different, although similarly arranged, street address spaces. An address space usually provides (or allows)

1953-401: The compiler . Approaches that delegate enforcement of security policy to the compiler and/or the application level are often called language-based security . The lack of many critical security mechanisms in current mainstream operating systems impedes the implementation of adequate security policies at the application abstraction level . In fact, a common misconception in computer security

Stackless Python - Misplaced Pages Continue

2016-408: The memory management unit . Generally the operating system provides a library that sits between the operating system and normal user programs. Usually it is a C library such as Glibc or Windows API. The library handles the low-level details of passing information to the kernel and switching to supervisor mode. System calls include close, open, read, wait and write. To actually perform useful work,

2079-490: The appropriate drivers. As device management is a very OS -specific topic, these drivers are handled differently by each kind of kernel design, but in every case, the kernel has to provide the I/O to allow drivers to physically access their devices through some port or memory location. Important decisions have to be made when designing the device management system, as in some designs accesses may involve context switches , making

2142-457: The controller to malfunction, or system to crash. With this, depending on the complexity of the device, some devices can get surprisingly complex to program, and use several different controllers. Because of this, providing a more abstract interface to manage the device is important. This interface is normally done by a device driver or hardware abstraction layer. Frequently, applications will require access to these devices. The kernel must maintain

2205-478: The data requested by the program. The program can then be resumed from the point where it was stopped. This scheme is generally known as demand paging . Virtual addressing also allows creation of virtual partitions of memory in two disjointed areas, one being reserved for the kernel ( kernel space ) and the other for the applications ( user space ). The applications are not permitted by the processor to address kernel memory, thus preventing an application from damaging

2268-518: The device drivers. A monolithic kernel is one single program that contains all of the code necessary to perform every kernel-related task. Every part which is to be accessed by most programs which cannot be put in a library is in the kernel space: Device drivers, scheduler, memory handling, file systems, and network stacks. Many system calls are provided to applications, to allow them to access all those services. A monolithic kernel, while initially loaded with subsystems that may not be needed, can be tuned to

2331-459: The edge of different IP spaces, such as a local area network and the Internet. An iconic example of virtual-to-physical address translation is virtual memory , where different pages of virtual address space map either to page file or to main memory physical address space. It is possible that several numerically different virtual addresses all refer to one physical address and hence to

2394-432: The execution and stops a program that violates a rule, such as a user process that tries to write to kernel memory. In systems that lack support for capabilities, processes are isolated from each other by using separate address spaces. Calls from user processes into the kernel are regulated by requiring them to use one of the above-described system call methods. An alternative approach is to use language-based protection. In

2457-418: The firmware does not support protection mechanisms, it is possible to simulate protection at a higher level, for example by simulating capabilities by manipulating page tables , but there are performance implications. Lack of hardware support may not be an issue, however, for systems that choose to use language-based protection. An important kernel design decision is the choice of the abstraction levels where

2520-502: The global Internet address space. Uses of addresses include, but are not limited to the following: Another common feature of address spaces are mappings and translations , often forming numerous layers. This usually means that some higher-level address must be translated to lower-level ones in some way. For example, a file system on a logical disk operates using linear sector numbers, which have to be translated to absolute LBA sector addresses, in simple cases, via addition of

2583-399: The kernel at runtime, permitting easy extension of the kernel's capabilities as required, while helping to minimize the amount of code running in kernel space. Most work in the monolithic kernel is done via system calls. These are interfaces, usually kept in a tabular structure, that access some subsystem within the kernel such as disk operations. Essentially calls are made within programs and

Stackless Python - Misplaced Pages Continue

2646-425: The kernel can be classified according to several criteria, including: static (enforced at compile time ) or dynamic (enforced at run time ); pre-emptive or post-detection; according to the protection principles they satisfy (e.g., Denning ); whether they are hardware supported or language based; whether they are more an open mechanism or a binding policy; and many more. Support for hierarchical protection domains

2709-438: The kernel is usually loaded into a separate area of memory, which is protected from access by application software or other less critical parts of the operating system. The kernel performs its tasks, such as running processes, managing hardware devices such as the hard disk , and handling interrupts, in this protected kernel space . In contrast, application programs such as browsers, word processors, or audio or video players use

2772-402: The kernel itself or the kernel can also rely on other processes it is running. Although the kernel must provide IPC in order to provide access to the facilities provided by each other, kernels must also provide running programs with a method to make requests to access these facilities. The kernel is also responsible for context switching between processes or threads. The kernel has full access to

2835-431: The kernel manages, and indeed to objects provided by other user applications. An efficient and simple way to provide hardware support of capabilities is to delegate to the memory management unit (MMU) the responsibility of checking access-rights for every memory access, a mechanism called capability-based addressing . Most commercial computer architectures lack such MMU support for capabilities. An alternative approach

2898-405: The kernel so that applications do not need to know their implementation details. Key aspects necessary in resource management are defining the execution domain ( address space ) and the protection mechanism used to mediate access to the resources within a domain. Kernels also provide methods for synchronization and inter-process communication (IPC). These implementations may be located within

2961-475: The kernel will be rewritten if the available hardware changes), configured by the user (typical on older PCs and on systems that are not designed for personal use) or detected by the operating system at run time (normally called plug and play ). In plug-and-play systems, a device manager first performs a scan on different peripheral buses , such as Peripheral Component Interconnect (PCI) or Universal Serial Bus (USB), to detect installed devices, then searches for

3024-568: The kernel. The kernel's interface is a low-level abstraction layer . When a process requests a service from the kernel, it must invoke a system call , usually through a wrapper function . There are different kernel architecture designs. Monolithic kernels run entirely in a single address space with the CPU executing in supervisor mode , mainly for speed. Microkernels run most but not all of their services in user space, like user processes do, mainly for resilience and modularity . MINIX 3

3087-489: The list of these devices by querying the system for them in some way. This can be done through the BIOS, or through one of the various system buses (such as PCI/PCIE, or USB). Using an example of a video driver, when an application requests an operation on a device, such as displaying a character, the kernel needs to send this request to the current active video driver. The video driver, in turn, needs to carry out this request. This

3150-528: The operating system to use other data stores, like a hard drive , to store what would otherwise have to remain in main memory ( RAM ). As a result, operating systems can allow programs to use more memory than the system has physically available. When a program needs data which is not currently in RAM, the CPU signals to the kernel that this has happened, and the kernel responds by writing the contents of an inactive memory block to disk (if necessary) and replacing it with

3213-445: The operation very CPU-intensive and easily causing a significant performance overhead. In computing, a system call is how a process requests a service from an operating system's kernel that it does not normally have permission to run. System calls provide the interface between a process and the operating system. Most operations interacting with the system require permissions not available to a user-level process, e.g., I/O performed with

SECTION 50

#1732773315131

3276-434: The overhead of using separate threads for single-core programs (because no mode switching between user mode and kernel mode needs to be done, so CPU usage can be reduced). Although microthreads make it easier to deal with running subtasks on a single core, Stackless Python does not remove CPython's global interpreter lock (GIL), nor does it use multiple threads and/or processes. So it allows only cooperative multitasking on

3339-645: The partition's first sector address. Then, for a disk drive connected via Parallel ATA , each of them must be converted to logical cylinder-head-sector address due to the interface historical shortcomings. It is converted back to LBA by the disk controller , then, finally, to physical cylinder , head and sector numbers. The Domain Name System maps its names to and from network-specific addresses (usually IP addresses), which in turn may be mapped to link layer network addresses via Address Resolution Protocol . Network address translation may also occur on

3402-435: The requested action, and if it is permitted performs the access for it (either directly, or by delegating the request to another user-level process). The performance cost of address space switching limits the practicality of this approach in systems with complex interactions between objects, but it is used in current operating systems for objects that are not accessed frequently or which are not expected to perform quickly. If

3465-488: The rest of the system to rely on them. Per Brinch Hansen presented arguments in favour of separation of mechanism and policy. The failure to properly fulfill this separation is one of the major causes of the lack of substantial innovation in existing operating systems, a problem common in computer architecture. The monolithic design is induced by the "kernel mode"/"user mode" architectural approach to protection (technically called hierarchical protection domains ), which

3528-435: The running kernel. This fundamental partition of memory space has contributed much to the current designs of actual general-purpose kernels and is almost universal in such systems, although some research kernels (e.g., Singularity ) take other approaches. To perform useful functions, processes need access to the peripherals connected to the computer, which are controlled by the kernel through device drivers . A device driver

3591-410: The security mechanisms and policies should be implemented. Kernel security mechanisms play a critical role in supporting security at higher levels. One approach is to use firmware and kernel support for fault tolerance (see above), and build the security policy for malicious behavior on top of that (adding features such as cryptography mechanisms where necessary), delegating some responsibility to

3654-413: The software level, device driver abstractions include: For example, to show the user something on the screen, an application would make a request to the kernel, which would forward the request to its display driver, which is then responsible for actually plotting the character/pixel. A kernel must maintain a list of available devices. This list may be known in advance (e.g., on an embedded system where

3717-431: The system's memory and must allow processes to safely access this memory as they require it. Often the first step in doing this is virtual addressing , usually achieved by paging and/or segmentation . Virtual addressing allows the kernel to make a given physical address appear to be another address, the virtual address. Virtual address spaces may be different for different processes; the memory that one process accesses at

3780-448: The system. The kernel is also responsible for preventing and mitigating conflicts between different processes. It is the portion of the operating system code that is always resident in memory and facilitates interactions between hardware and software components. A full kernel controls all hardware resources (e.g. I/O, memory, cryptography) via device drivers , arbitrates conflicts between processes concerning such resources, and optimizes

3843-629: The two, leading naturally to a microkernel design (see Separation of protection and security ). While monolithic kernels execute all of their code in the same address space ( kernel space ), microkernels try to run most of their services in user space, aiming to improve maintainability and modularity of the codebase. Most kernels do not fit exactly into one of these categories, but are rather found in between these two designs. These are called hybrid kernels . More exotic designs such as nanokernels and exokernels are available, but are seldom used for production systems. The Xen hypervisor, for example,

SECTION 60

#1732773315131

3906-486: The underlying address structure, which is usually limited by the computer architecture being used. Often an address space in a system with virtual memory corresponds to a highest level translation table, e.g., a segment table in IBM System/370 . Address spaces are created by combining enough uniquely identified qualifiers to make an address unambiguous within the address space. For a person's physical address,

3969-432: The utilization of common resources e.g. CPU & cache usage, file systems, and network sockets. On most systems, the kernel is one of the first programs loaded on startup (after the bootloader ). It handles the rest of startup as well as memory, peripherals , and input/output (I/O) requests from software , translating them into data-processing instructions for the central processing unit . The critical code of

#130869