Fusion-Introduction to Linux-reprint and Translation

Source: Internet
Author: User
I'm so happy today. I have to post more messages to celebrate. Haha 1. Fusion Overview

Fusion is an IPC-(Inter Process Communication) kernel module. The philosophy of fusion is that processes can use only the primivites provided by fusion to "speak" each other ". Any process can apply to create a primitive instance. All fusion processes associated with an ID can access and use this instance. Fusion supports the following primivites:

Ø call: calls other processes asynchronously (synchronously;

Ø Ref: Reference Value

Ø reactor: asynchronous event Distribution

Ø skirmish: Counting lock

Ø property: Multi-Level locking

Ø shmpool: shared memory usage management

The/proc file system is provided to view the status of each primivites.

Several Basic concepts:

World: A fusion user's operation and communication environment for clients to discover each other. For example, fusion primitives relies on worldwide IDs for identification and use. Each world has its own device node. Fusion allows multiple worlds to exist at the same time.

Fusionee: Participants of world. Each application in the user space enters the world and obtains a fusion ID. It is possible but uncommon for an application to obtain multiple fusion IDs. This fusion ID is used to "target" Other fusionee handles. Each world has at most one fusionee as the master, and other fusionee as the slave.

Fusion registers a 250 character device as the master device, with eight device nodes in/dev/fusion0-7. Each device node represents an independent fusion world.

Note that the directfb project encapsulates fusion's ioctl api.

2. Fusion api2.1 enable the device Node

Int FD;

FD = open ("/dev/fusion/0", flags );

 

Flags = o_rdwr; defaultvalue.

Flags | = o_nonblock; addthisforanon-blockingreadcall.

Flags | = o_excl; addthistobethe fusion masterofthisworld.

Flags | = o_append; addthistobea fusion slaveinthisworld.

 

Ebusy requesttobe master, butthis worldalready hasafusion master.

Eintr aninterruptoccurred. nochanges were made.

Enomem insuf extends cientkernel memory.

2.2 Common calls-note that there is no write call

Int close (int fd );

Ssize_t read (int fd, void * Buf, size_t count );

Int IOCTL (int fd, int request ,...);

Void * MMAP (void * Start, size_t length, int Prot, int flags, int FD, off_t offset );

2.2.1 read operation example

Char Buf [buf_size]

Char * buf_p = Buf;

Int FD = open ("/dev/fusion/0", o_rdwr | o_nonblock );

Int Len = read (FD, Buf, buf_size );

While (buf_p <BUF + Len)

{

Fusionreadmessage * Header = (fusionreadmessage *) buf_p;

Void * Data = buf_p + sizeof (fusionreadmessage );

... Handle message...

Buf_p = Data + (header-> msg_size + 3 )&~ 3 );

}

2.2.2 IOCTL example

Int FD = open ("/dev/fusion/0", o_rdwr | o_nonblock );

Fusionenter;

... Init enter. API...

Ret = IOCTL (FD, fusion_enter, & enter );

... Store fusion_id...

2.2.3 MMAP call

Used to create a shared area. Generally, the size of a kernel page cannot exceed 4 kb. The same memory area is mapped to all fusionees in the same world. The first MMAP call must be initiated by the fusion master.

2.2.3 Return Value

Einvalinputparameterout-of-range.

Efaultkernelmemoryfault.

Eintraninterruptoccurred. nochangeswere made.

Additional return values of read calls:

Emsgsizeifthe specified rstmessagedoesnot specified tinthebuffer.

Eagainforanon-blockingread: nomessagesavailable.

Additional returned values of MMAP calls:

Epermfirsponmap notfound medby fusion master.

Enomemnokernel memoryleft.

2.3 call IOCTL 2.3.1 fusion_enter

IOCTL (FD, fusion_enter, fusionenter)

 

Typedef struct {

Struct {

Int Major;/* [in] */

Int minor;/* [in] */

} API;

Fusionid fusion_id;/* [out] */

} Fusionenter;

After the device node is opened, use this call to enter fusion world. Then, the assigned unique handle: Fusion ID is obtained. For all slaves, this call will be blocked until the master calls fusion_unblock 'unblock' world.

The relationship between major and minor is as follows: 3.x, 4.X, and 8. X correspond to directfb 1.0, 1.2, and Versions later than 1.2, respectively. For example, my current DirectFB-1.4.10-IR-GFX, the corresponding settings are as follows:

# Define fusion_api_major_required 8

# Define fusion_api_minor_required 0

After a correct call, fusion_id is returned. This fusion_id isfusion_id_master for the master.

Return Value:

(Except 0, efault and eintr)

Enoprotoopt: Unsupported apiversion or the master uses an incompatible API version.

2.3.2 fusion_unlock

It is called by the fusion master and used to unblock fusion world, so that slaves enters the world.

Return Value:

(Except 0, efault and eintr)

Perm: not called by fusion master.

2.3.2 fusion_kill

Typedef struct {

Fusionid fusion_id;

Int signal;

Int timeout_ms;

} Fusionkill;

Used to send signal to other fusionees.

The fusion_id corresponds to the target fusionee. 0 means all but ourself. If there is no relative fusionee, success is returned for this call.

Signal is a signal used for transmission, such as sigterm and sigkill.

Timeout_ms is set to the supermarket millisecond count. -1 indicates no waiting, and 0 indicates no restriction. In other words, wait until at least one fusionee is terminated.

Return Value:

(Except 0, efault and eintr)

Etimedout: timeout.

2.3.3 fusion_entry_set_info and fusion_entry_get_info

Typedefstruct {

Fusiontype type;

Int ID;

Char name [fusion_entry_info_name_length];/* [in] or [out] */

} Fusionentryinfo;

Store or read humanreadable names for skirmish, property, reactor, ref, and shmpool. This name is only used in The IOCTL call and/proc file system.

2.3.4 fusion_fork

Typedef struct {

Fusionid fusion_id;

} Fusionfork;

To be determined.

Perform a 'fork' of shared memory pools, reactorsand local references. This will copy these entities from fusionee fusion_id to thecalling fusionee. Upon return, fusion_id holds the calling fusionee ID.

Return values are efault or eintrforfailure, 0forsuccess.

2.3.5 fusion_send_message

Typedef struct {

Fusionid fusion_id;

Int msg_id;

Int msg_channel;

Int msg_size;

Const void * msg_data;

} Fusionsendmessage;

Send a fusion message to the fusionee corresponding to fusion_id. The other party uses the read call to receive the message. The receiver can use this message to parse the sender's ID.

Msg_id is a custom msg id. Msg_channel is an optional channel number. Msg_size is the MSG load size [0, 65536]. Msg_data points to the load data, which must not be blank.

Return Value:

(Except 0, efaultand eintr)

Einval: msg_sizet is too small (less than 0 );

Emsgsize: msg_sizet is too large (greater than 65536 );

Enomemkernel: memory is insufficient. Try to make msg_size smaller;

2.4 IOCTL: Call primitive

IOCTL (FD, fusion_call_new, fusioncallnew)

IOCTL (FD, fusion_call_execute, fusioncallexecute)

IOCTL (FD, fusion_call_return, fusioncallreturn)

IOCTL (FD, fusion_call_destroy, INT)

2.5 IOCTL: refprimitive

2.6 IOCTL: skirmishprimitive

2.7 IOCTL: propertyprimitive

2.8 IOCTL: reactorprimitive

Reactor Mode

2.9 IOCTL: shmpoolprimitive

Extracted from Dr. Li's note:

In traditional directfb applications, all applications are in one process and have some advantages in performance. However, the instability of an application may result in instability of the entire system. If the C/S model is used, it will undoubtedly be the same as xwidnow and will lose its performance advantage.

Therefore, directfb adopts another method, which is different from C/S and called the Master/Slave model (Master/Slave ). It adds a kernel module called fusion. Fusion means melting. Multiple applications communicate through this kernel module in a non-process space. Here, everything is integrated. The master application is responsible for initializing a thing called an actual technical field. Other slave applications can join or exit the actual technical field. When the master node exits, all other slave instances must exit.

Fusion uses the reactor mode. Each application can register an event processor with the reactor through IOCTL. when an event occurs, when the reactor writes the event to the fusion file descriptor of the registered application, the application can then read the event data from the fusion file descriptor.

Of course, applications can also send events to other applications through ioctl, and events will be distributed to other applications during reactor.

The following uses a touch screen as an example to describe the process of a point event:

1. during initialization, driver_open_device creates a process, hangs on/dev/input/event0, and waits for the pen event.

2. During initialization, the application creates another thread and hangs on/dev/fusionn (different application N values.

3. When a vertex event exists, call the function dfb_input_dispatch --> fusion_reactor_dispatch-> IOCTL (fusion_reactor_dispatch) to throw the message to the kernel module.

4. The reactor in the kernel module writes event data to the/dev/fusionn of each registered event processor.

5. The application retrieves event data from the/dev/fusionn file and calls the reactor processing function in the application. Generally, the two functions are idirectfbeventbuffer_inputreact/idirectfbeventbuffer_windowreact.

6. Then, in the idirectfbeventbuffer_inputreact/idirectfbeventbuffer_windowreact functions, call idirectfbeventbuffer_additem to add the event to the event queue in the window.

7. In the main thread of the application, you can call the getevent function of the window to obtain the event from the event queue. Finally, the obtained events are distributed to the event handlers of each window.

Reference

1. http://www.directfb.com.cn/viewthread.php? Tid = 6

Directfb message stream based on fusion

Indicate the source and author's contact information during reprinting.

Contact information of the author: Li xianjing <xianjimli at Hotmail dot com>

2. linux-fusion-8.2.0 documentation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.